MozApi

package module
v0.0.0-...-d7c8e6d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 10, 2015 License: MIT Imports: 12 Imported by: 0

README

SEOMozAPIGolang

Golang for Moz API - currently very limited, only for the url-metrics

Install:

go get github.com/dentot/SEOMozAPIGolang

Usage:

urls := []string{"http://google.com", "http://yahoo.com"}

var cols uint64 = MozApi.URL_METRICS_PAGE_AUTHORITY | MozApi.URL_METRICS_DOMAIN_AUTHORITY

//supply your accessid and key
b, err := MozApi.GetURLMetrics("mozscape-accessid", "secretkey", cols, 300, urls)
if err != nil {
	panic(err)
}

// check if no error from moz api server
isError, data, err := MozApi.CheckResultError(b)
if isError {
	panic(data["error_message"])
}

// if no error, then extract the moz data
res, err := MozApi.ExtractMozData(b)
fmt.Println("The first item, upa of google.com", res[0]["upa"])
fmt.Println("The 2nd item, upa of yahoo.com", res[1]["upa"])

Documentation

Overview

MozApi project MozApi.go

Index

Constants

View Source
const (
	URL_METRICS_PAGE_AUTHORITY    = 34359738368
	URL_METRICS_DOMAIN_AUTHORITY  = 68719476736
	URL_METRICS_TIME_LAST_CRAWLED = 144115188075855872
)

Variables

This section is empty.

Functions

func CheckResultError

func CheckResultError(b []byte) (bool, map[string]interface{}, error)

Since return type of moz api can be: {status:401, error_message:"the error"} or [{pda:82}, {pda:71}] so we need a handler to check if return has error, or has the needed moz data values if no 'error_message', then proceed to extract the moz return data using the ExtractMozData

func ExtractMozData

func ExtractMozData(b []byte) ([](map[string]interface{}), error)

just convert the json string from moz api call to array of map

func GetURLMetrics

func GetURLMetrics(accessid string, key string, cols uint64, secondsExpire time.Duration, urls []string) ([]byte, error)

Does a http post to the moz api url, with your accessid, secret key, url metrics option, and the urls you want to get url metrics sample call: GetURLMetrics(xxxx, keyxxxx, URL_METRICS_PAGE_AUTHORITY | URL_METRICS_DOMAIN_AUTHORITY, 300, []string{"google.com", "yahoo.com"})

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL