mozapi 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/mozapi.rb +44 -5
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 77250e2514066976dcaeb9c307281db32d1a433e
4
- data.tar.gz: f107cc53711a4f14f0373759753c0a1179e3239d
3
+ metadata.gz: 46fb14903a567cbc5bcaab61d7aa6605f968fdd0
4
+ data.tar.gz: 684d328470ab4df0b6c3344a589ec306ae811415
5
5
  SHA512:
6
- metadata.gz: f581807f7b8232cd9555be201ecef4ecde70b48a199bd04f859efa613349206cfae0b4b7ce6bb1887f2df9225d87edd373977bf18477cb0a6f70a91b140ae0b2
7
- data.tar.gz: 34da714cec0a2df47a39ea2fcd2f93c6d8216a2272a734346f5615c69155befdbc79b699db10ece23e70bb9a9dc0cee669586c2219880253b97959d3379223bb
6
+ metadata.gz: ed299a6e7d6aeed995dc4272dd44337da7c2ff7aa77ccccb7719cc6a3a774cf2a3e5fff92fa3e45e949cac73ff3297cb2dae3ec67177f25e30046182fcc95028
7
+ data.tar.gz: f7811c1eb2c80c459796bdc2ca0465e4abed31a3f888ff9021c1720214bb1d13c74324315f38fe583d789ef4c4ba08d42ad62bd4d92811c84f6201739970c544
data/lib/mozapi.rb CHANGED
@@ -20,12 +20,19 @@ class MozAPI
20
20
  GLOBAL_LIMIT = 100000
21
21
 
22
22
  LIMIT = 100
23
+
24
+ URL = 4
25
+ ROOT_DOMAIN = 16
26
+ DOMAIN_AUTHORITY = 68719476736
27
+
23
28
  # URL + root_domain + page_authority + domain_authority
24
- DEFAULT_SOURCE_COLS = 4 + 16 + 34359738368 + 68719476736
29
+ DEFAULT_SOURCE_COLS = URL + ROOT_DOMAIN + 34359738368 + DOMAIN_AUTHORITY
25
30
  # URL + root_domain
26
- DEFAULT_TARGET_COLS = 4 + 16
31
+ DEFAULT_TARGET_COLS = URL + ROOT_DOMAIN
27
32
  # anchor_text
28
- DEFAULT_LINK_COLS = 4
33
+ DEFAULT_LINK_COLS = URL
34
+ # linking root domains + links
35
+ DEFAULT_URL_METRICS_COLS = 1024 + 2048 + DOMAIN_AUTHORITY
29
36
 
30
37
 
31
38
  def initialize
@@ -35,8 +42,8 @@ class MozAPI
35
42
 
36
43
  def links(target_url, options)
37
44
  sleep(10) # do this to honor the API rate limit
38
- # add 5 minutes
39
- expires = (Time.now + 5 * 60).utc.to_i
45
+
46
+ expires = expiration_time
40
47
 
41
48
  options = {
42
49
  Sort: 'page_authority',
@@ -55,12 +62,40 @@ class MozAPI
55
62
  req_url = "http://lsapi.seomoz.com/linkscape/links/#{URI::encode(target_url)}?#{options.to_query}"
56
63
 
57
64
  response = HTTParty.get(req_url, :headers => {"User-Agent" => 'node-linkscape (https://github.com/mjp/node-linkscape)'})
65
+
66
+ raise "unknown endpoint for URL: #{req_url}" if 404 == response.code
58
67
  json = JSON.parse response.body
59
68
  puts "[MozAPI#links] links returned: #{json.size}"
60
69
 
61
70
  json
62
71
  end
63
72
 
73
+ #
74
+ def url_metrics(url)
75
+ sleep 10
76
+
77
+ expires = expiration_time
78
+
79
+ options = {
80
+ AccessID: @api_id,
81
+ Expires: expires,
82
+ Signature: calculate_signature(expires),
83
+ Cols: DEFAULT_URL_METRICS_COLS
84
+ }.merge(options)
85
+
86
+ #puts "[MozAPI#links] options: #{options[:Offset]}"
87
+ req_url = "http://lsapi.seomoz.com/linkscape/url_metrics/#{URI::encode(target_url)}?#{options.to_query}"
88
+
89
+ response = HTTParty.get(req_url, :headers => {"User-Agent" => 'node-linkscape (https://github.com/mjp/node-linkscape)'})
90
+
91
+ raise "unknown endpoint for URL: #{req_url}" if 404 == response.code
92
+ json = JSON.parse response.body
93
+ puts "[MozAPI#links] links returned: #{json.size}"
94
+
95
+ json
96
+ end
97
+
98
+
64
99
  # private
65
100
  def calculate_signature(expires)
66
101
  signature = "#{@api_id}\n#{expires}"
@@ -69,4 +104,8 @@ class MozAPI
69
104
  b64 = Digest::HMAC.base64digest(signature, @api_key, Digest::SHA1)
70
105
  CGI::escape(Base64.encode64(digest).chomp)
71
106
  end
107
+
108
+ def expiration_time
109
+ (Time.now + 5 * 60).utc.to_i
110
+ end
72
111
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mozapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christoph Engelhardt