Class: MozAPI::URLMetrics

Inherits:
Base
  • Object
show all
Defined in:
lib/mozapi/url_metrics.rb

Constant Summary

Constants included from Cols

Cols::ANCHOR_TEXT, Cols::ANCHOR_TEXT_NORMALIZED, Cols::DEFAULT_LINK_COLS, Cols::DEFAULT_SOURCE_COLS, Cols::DEFAULT_TARGET_COLS, Cols::DEFAULT_URL_METRICS_COLS, Cols::DOMAIN_AUTHORITY, Cols::GLOBAL_LIMIT, Cols::LIMIT, Cols::LINKING_C_BLOCKS, Cols::LINKING_ROOT_DOMAINS, Cols::LINKS, Cols::PAGE_AUTHORITY, Cols::ROOT_DOMAIN, Cols::URL

Instance Attribute Summary

Attributes inherited from Base

#api_id, #api_key

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from MozAPI::Base

Instance Method Details

#get(target_url, options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/mozapi/url_metrics.rb', line 9

def get(target_url, options = {})
  expires = expiration_time
  
  options = {
    AccessID: api_id,
    Expires: expires,
    Signature: calculate_signature(expires),
    Cols: DEFAULT_URL_METRICS_COLS
  }.merge(options)
  
  
  unless target_url.is_a? Array
    req_url = "/url-metrics/#{URI::encode(target_url)}?#{options.to_query}"
    
    puts req_url
    response = self.class.get(req_url, :headers => {"User-Agent" => 'node-linkscape (https://github.com/mjp/node-linkscape)'})
    
    raise "unknown endpoint for URL: #{req_url}" if 404 == response.code
    json = JSON.parse response.body
    puts "[MozAPI#links] links returned: #{json.size}"
    json
  end
end