Class: Moz

Inherits:
Object
  • Object
show all
Defined in:
lib/moz.rb

Constant Summary collapse

TITLE =

ut

1
CANONICAL_URL =

uu

4
32
2048
MOZ_RANK =

SUBDOMAIN_SUBDOMAINS_LINKING = 4096 # fid ROOT_DOMAIN_ROOT_DOMAINS_LINKING = 8192 # pid TODO: The rest…

16384
PAGE_AUTHORITY =

umrp / umrr

34359738368
DOMAIN_AUTHORITY =

upa

68719476736
INTERESTED_COLUMNS =

pda

EXTERNAL_LINKS + MOZ_RANK + PAGE_AUTHORITY + DOMAIN_AUTHORITY

Instance Method Summary collapse

Instance Method Details

#mozRequestBatch(urls, access_id, secret_key, cols) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/moz.rb', line 29

def mozRequestBatch(urls, access_id, secret_key, cols)
  expires = Time.now.to_i + 30

  # A new linefeed is necessary between your AccessID and Expires.
  string_to_sign = "#{access_id}\n#{expires}"

  # Get the "raw" or binary output of the hmac hash.
  binary_signature = OpenSSL::HMAC.digest('sha1', secret_key, string_to_sign)

  # We need to base64-encode it and then url-encode that.
  url_safe_signature = CGI::escape(Base64.encode64(binary_signature).chomp)

  # Now put your entire request together.
  # This example uses the Mozscape URL Metrics API.
  request_url = "http://lsapi.seomoz.com/linkscape/url-metrics/?Cols=#{cols}&AccessID=#{access_id}&Expires=#{expires}&Signature=#{url_safe_signature}"

  # Go and fetch the URL
  uri = URI.parse("#{request_url}")
  http = Net::HTTP.new(uri.host, uri.port)
  request = Net::HTTP::Post.new(uri.request_uri)
  # Put your URLS into an array and json_encode them.
  request.body = urls.to_json
  response = http.request(request)

  response.body
end