mozapi 0.1.9 → 1.0.0
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.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/.project +12 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +20 -0
- data/README.md +4 -0
- data/lib/hash.rb +6 -0
- data/lib/mozapi.rb +6 -124
- data/lib/mozapi/base.rb +32 -0
- data/lib/mozapi/cols.rb +40 -0
- data/lib/mozapi/link_metrics.rb +38 -0
- data/lib/mozapi/url_metrics.rb +34 -0
- data/lib/mozapi/version.rb +3 -0
- data/mozapi.gemspec +23 -0
- metadata +14 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d76456421992f2c7fdb75f654d51129f23152d80
|
4
|
+
data.tar.gz: b6c0e6cb84f7189c14debd66789f6d1fbef82862
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2efc73b8089d5e37c5b678d89a7a8ba951e4ae507a83f635bf484956c641681a4bed4bb74c6b7e830e04a4562961869dfe3fb586ad76145cc5477fa1fd58f293
|
7
|
+
data.tar.gz: 2aa4844c8334b5ff8ee131079f88d7d355374e9228690e9dd467d4ae1d1e86e7c5f3276ae94053064109dad0c471cd304f5c57cda6be717fcdb15e93c05bb8ed
|
data/.gitignore
ADDED
data/.project
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<projectDescription>
|
3
|
+
<name>mozapi</name>
|
4
|
+
<comment></comment>
|
5
|
+
<projects>
|
6
|
+
</projects>
|
7
|
+
<buildSpec>
|
8
|
+
</buildSpec>
|
9
|
+
<natures>
|
10
|
+
<nature>com.aptana.projects.webnature</nature>
|
11
|
+
</natures>
|
12
|
+
</projectDescription>
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
mozapi (1.0.0)
|
5
|
+
httparty (~> 0.13.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
httparty (0.13.3)
|
11
|
+
json (~> 1.8)
|
12
|
+
multi_xml (>= 0.5.2)
|
13
|
+
json (1.8.2)
|
14
|
+
multi_xml (0.5.5)
|
15
|
+
|
16
|
+
PLATFORMS
|
17
|
+
ruby
|
18
|
+
|
19
|
+
DEPENDENCIES
|
20
|
+
mozapi!
|
data/README.md
ADDED
data/lib/hash.rb
ADDED
data/lib/mozapi.rb
CHANGED
@@ -1,124 +1,6 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
3
|
-
require '
|
4
|
-
require '
|
5
|
-
|
6
|
-
|
7
|
-
# very naive implementation of to_query
|
8
|
-
def to_query
|
9
|
-
map { |key, value| "#{key}=#{value}" }.join('&')
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
|
14
|
-
class MozAPI
|
15
|
-
include HTTParty
|
16
|
-
base_uri 'http://lsapi.seomoz.com/linkscape'
|
17
|
-
|
18
|
-
# there is a global limit on the Mozscape API that only lets you
|
19
|
-
# retrieve 100,000 links for any URL
|
20
|
-
GLOBAL_LIMIT = 100000
|
21
|
-
|
22
|
-
LIMIT = 100
|
23
|
-
|
24
|
-
# defined
|
25
|
-
|
26
|
-
|
27
|
-
URL = 4
|
28
|
-
# lt
|
29
|
-
ANCHOR_TEXT = 4
|
30
|
-
# lnt
|
31
|
-
ANCHOR_TEXT_NORMALIZED = 8
|
32
|
-
ROOT_DOMAIN = 16
|
33
|
-
# uipl - not in the free version
|
34
|
-
LINKING_ROOT_DOMAINS = 1024
|
35
|
-
# uid
|
36
|
-
LINKS = 2048
|
37
|
-
# upa
|
38
|
-
PAGE_AUTHORITY = 34359738368
|
39
|
-
# pda
|
40
|
-
DOMAIN_AUTHORITY = 68719476736
|
41
|
-
# pib
|
42
|
-
LINKING_C_BLOCKS = 36028797018963968
|
43
|
-
|
44
|
-
# URL + root_domain + page_authority + domain_authority
|
45
|
-
DEFAULT_SOURCE_COLS = URL + ROOT_DOMAIN + PAGE_AUTHORITY + DOMAIN_AUTHORITY
|
46
|
-
# URL + root_domain
|
47
|
-
DEFAULT_TARGET_COLS = URL + ROOT_DOMAIN
|
48
|
-
# anchor_text
|
49
|
-
DEFAULT_LINK_COLS = ANCHOR_TEXT_NORMALIZED
|
50
|
-
# linking root domains + links + DA
|
51
|
-
DEFAULT_URL_METRICS_COLS = LINKING_ROOT_DOMAINS + 2048 + DOMAIN_AUTHORITY + LINKING_C_BLOCKS
|
52
|
-
|
53
|
-
|
54
|
-
def initialize(id, key)
|
55
|
-
@api_id = id
|
56
|
-
@api_key = key
|
57
|
-
end
|
58
|
-
|
59
|
-
def links(target_url, options)
|
60
|
-
expires = expiration_time
|
61
|
-
|
62
|
-
options = {
|
63
|
-
Sort: 'page_authority',
|
64
|
-
Filter: 'follow+external',
|
65
|
-
SourceCols: DEFAULT_SOURCE_COLS,
|
66
|
-
TargetCols: DEFAULT_TARGET_COLS,
|
67
|
-
LinkCols: DEFAULT_LINK_COLS,
|
68
|
-
AccessID: @api_id,
|
69
|
-
Expires: expires,
|
70
|
-
Signature: calculate_signature(expires),
|
71
|
-
Limit: LIMIT,
|
72
|
-
Offset: 0
|
73
|
-
}.merge(options)
|
74
|
-
|
75
|
-
#puts "[MozAPI#links] options: #{options[:Offset]}"
|
76
|
-
req_url = "http://lsapi.seomoz.com/linkscape/links/#{URI::encode(target_url)}?#{options.to_query}"
|
77
|
-
|
78
|
-
response = HTTParty.get(req_url, :headers => {"User-Agent" => 'node-linkscape (https://github.com/mjp/node-linkscape)'})
|
79
|
-
|
80
|
-
raise "unknown endpoint for URL: #{req_url}" if 404 == response.code
|
81
|
-
json = JSON.parse response.body
|
82
|
-
puts "[MozAPI#links] links returned: #{json.size}"
|
83
|
-
|
84
|
-
json
|
85
|
-
end
|
86
|
-
|
87
|
-
#
|
88
|
-
def url_metrics(target_url, options = {})
|
89
|
-
|
90
|
-
expires = expiration_time
|
91
|
-
|
92
|
-
options = {
|
93
|
-
AccessID: @api_id,
|
94
|
-
Expires: expires,
|
95
|
-
Signature: calculate_signature(expires),
|
96
|
-
Cols: DEFAULT_URL_METRICS_COLS
|
97
|
-
}.merge(options)
|
98
|
-
|
99
|
-
#puts "[MozAPI#links] options: #{options[:Offset]}"
|
100
|
-
req_url = "http://lsapi.seomoz.com/linkscape/url-metrics/#{URI::encode(target_url)}?#{options.to_query}"
|
101
|
-
|
102
|
-
response = HTTParty.get(req_url, :headers => {"User-Agent" => 'node-linkscape (https://github.com/mjp/node-linkscape)'})
|
103
|
-
|
104
|
-
raise "unknown endpoint for URL: #{req_url}" if 404 == response.code
|
105
|
-
json = JSON.parse response.body
|
106
|
-
puts "[MozAPI#links] links returned: #{json.size}"
|
107
|
-
|
108
|
-
json
|
109
|
-
end
|
110
|
-
|
111
|
-
|
112
|
-
# private
|
113
|
-
def calculate_signature(expires)
|
114
|
-
signature = "#{@api_id}\n#{expires}"
|
115
|
-
digest = OpenSSL::HMAC.digest('sha1', @api_key, signature)
|
116
|
-
|
117
|
-
b64 = Digest::HMAC.base64digest(signature, @api_key, Digest::SHA1)
|
118
|
-
CGI::escape(Base64.encode64(digest).chomp)
|
119
|
-
end
|
120
|
-
|
121
|
-
def expiration_time
|
122
|
-
(Time.now + 5 * 60).utc.to_i
|
123
|
-
end
|
124
|
-
end
|
1
|
+
require 'hash'
|
2
|
+
require 'mozapi/version'
|
3
|
+
require 'mozapi/cols'
|
4
|
+
require 'mozapi/base'
|
5
|
+
require 'mozapi/url_metrics'
|
6
|
+
require 'mozapi/link_metrics'
|
data/lib/mozapi/base.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'open-uri'
|
3
|
+
require 'openssl'
|
4
|
+
require 'cgi'
|
5
|
+
|
6
|
+
module MozAPI
|
7
|
+
class Base
|
8
|
+
include HTTParty
|
9
|
+
include MozAPI::Cols
|
10
|
+
base_uri 'http://lsapi.seomoz.com/linkscape/'
|
11
|
+
|
12
|
+
attr_accessor :api_id, :api_key
|
13
|
+
|
14
|
+
def initialize(id, key)
|
15
|
+
@api_id = id
|
16
|
+
@api_key = key
|
17
|
+
end
|
18
|
+
|
19
|
+
protected
|
20
|
+
def calculate_signature(expires)
|
21
|
+
signature = "#{@api_id}\n#{expires}"
|
22
|
+
digest = OpenSSL::HMAC.digest('sha1', @api_key, signature)
|
23
|
+
|
24
|
+
b64 = Digest::HMAC.base64digest(signature, @api_key, Digest::SHA1)
|
25
|
+
CGI::escape(Base64.encode64(digest).chomp)
|
26
|
+
end
|
27
|
+
|
28
|
+
def expiration_time
|
29
|
+
(Time.now + 5 * 60).utc.to_i
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/mozapi/cols.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
|
2
|
+
module MozAPI
|
3
|
+
module Cols
|
4
|
+
# there is a global limit on the Mozscape API that only lets you
|
5
|
+
# retrieve 100,000 links for any URL
|
6
|
+
GLOBAL_LIMIT = 100000
|
7
|
+
|
8
|
+
LIMIT = 100
|
9
|
+
|
10
|
+
# defined
|
11
|
+
|
12
|
+
|
13
|
+
URL = 4
|
14
|
+
# lt
|
15
|
+
ANCHOR_TEXT = 4
|
16
|
+
# lnt
|
17
|
+
ANCHOR_TEXT_NORMALIZED = 8
|
18
|
+
ROOT_DOMAIN = 16
|
19
|
+
# uipl - not in the free version
|
20
|
+
LINKING_ROOT_DOMAINS = 1024
|
21
|
+
# uid
|
22
|
+
LINKS = 2048
|
23
|
+
# upa
|
24
|
+
PAGE_AUTHORITY = 34359738368
|
25
|
+
# pda
|
26
|
+
DOMAIN_AUTHORITY = 68719476736
|
27
|
+
# pib
|
28
|
+
LINKING_C_BLOCKS = 36028797018963968
|
29
|
+
|
30
|
+
# URL + root_domain + page_authority + domain_authority
|
31
|
+
DEFAULT_SOURCE_COLS = URL + ROOT_DOMAIN + PAGE_AUTHORITY + DOMAIN_AUTHORITY
|
32
|
+
# URL + root_domain
|
33
|
+
DEFAULT_TARGET_COLS = URL + ROOT_DOMAIN
|
34
|
+
# anchor_text
|
35
|
+
DEFAULT_LINK_COLS = ANCHOR_TEXT_NORMALIZED
|
36
|
+
# linking root domains + links + DA
|
37
|
+
DEFAULT_URL_METRICS_COLS = LINKING_ROOT_DOMAINS + LINKS + DOMAIN_AUTHORITY + LINKING_C_BLOCKS
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'open-uri'
|
3
|
+
require 'openssl'
|
4
|
+
require 'cgi'
|
5
|
+
|
6
|
+
module MozAPI
|
7
|
+
class LinkMetrics < MozAPI::Base
|
8
|
+
|
9
|
+
def get(target_url, options = {})
|
10
|
+
expires = expiration_time
|
11
|
+
|
12
|
+
options = {
|
13
|
+
Sort: 'page_authority',
|
14
|
+
Filter: 'follow+external',
|
15
|
+
Scope: 'page_to_page',
|
16
|
+
SourceCols: DEFAULT_SOURCE_COLS,
|
17
|
+
TargetCols: DEFAULT_TARGET_COLS,
|
18
|
+
LinkCols: DEFAULT_LINK_COLS,
|
19
|
+
AccessID: api_id,
|
20
|
+
Expires: expires,
|
21
|
+
Signature: calculate_signature(expires),
|
22
|
+
Limit: LIMIT,
|
23
|
+
Offset: 0
|
24
|
+
}.merge(options)
|
25
|
+
|
26
|
+
#puts "[MozAPI#links] options: #{options[:Offset]}"
|
27
|
+
req_url = "/links/#{URI::encode(target_url)}?#{options.to_query}"
|
28
|
+
|
29
|
+
response = self.class.get(req_url, :headers => {"User-Agent" => 'node-linkscape (https://github.com/mjp/node-linkscape)'})
|
30
|
+
|
31
|
+
raise "unknown endpoint for URL: #{req_url}" if 404 == response.code
|
32
|
+
json = JSON.parse response.body
|
33
|
+
puts "[MozAPI#links] links returned: #{json.size}"
|
34
|
+
|
35
|
+
json
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'open-uri'
|
3
|
+
require 'openssl'
|
4
|
+
require 'cgi'
|
5
|
+
|
6
|
+
module MozAPI
|
7
|
+
class URLMetrics < MozAPI::Base
|
8
|
+
|
9
|
+
debug_output $stdout
|
10
|
+
def get(target_url, options = {})
|
11
|
+
expires = expiration_time
|
12
|
+
|
13
|
+
options = {
|
14
|
+
AccessID: api_id,
|
15
|
+
Expires: expires,
|
16
|
+
Signature: calculate_signature(expires),
|
17
|
+
Cols: DEFAULT_URL_METRICS_COLS
|
18
|
+
}.merge(options)
|
19
|
+
|
20
|
+
|
21
|
+
unless target_url.is_a? Array
|
22
|
+
req_url = "/url-metrics/#{URI::encode(target_url)}?#{options.to_query}"
|
23
|
+
|
24
|
+
puts req_url
|
25
|
+
response = self.class.get(req_url, :headers => {"User-Agent" => 'node-linkscape (https://github.com/mjp/node-linkscape)'})
|
26
|
+
|
27
|
+
raise "unknown endpoint for URL: #{req_url}" if 404 == response.code
|
28
|
+
json = JSON.parse response.body
|
29
|
+
puts "[MozAPI#links] links returned: #{json.size}"
|
30
|
+
json
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/mozapi.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'mozapi/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
spec = s
|
7
|
+
s.name = 'mozapi'
|
8
|
+
s.version = MozAPI::VERSION
|
9
|
+
s.summary = "A light-weight wrapper around the Mozscape API"
|
10
|
+
s.description = "MozAPI is a light-weight wrapper for the MozscapeAPI (http://moz.com/products/api). It currently supports parts of the 'links' endpoint"
|
11
|
+
s.authors = ["Christoph Engelhardt"]
|
12
|
+
s.email = 'christoph@it-engelhardt.de'
|
13
|
+
s.homepage =
|
14
|
+
'https://github.com/yas4891/mozapi'
|
15
|
+
s.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0")
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_dependency('httparty', '~> 0.13.1')
|
23
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mozapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christoph Engelhardt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-03-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -31,7 +31,19 @@ executables: []
|
|
31
31
|
extensions: []
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- ".project"
|
36
|
+
- Gemfile
|
37
|
+
- Gemfile.lock
|
38
|
+
- README.md
|
39
|
+
- lib/hash.rb
|
34
40
|
- lib/mozapi.rb
|
41
|
+
- lib/mozapi/base.rb
|
42
|
+
- lib/mozapi/cols.rb
|
43
|
+
- lib/mozapi/link_metrics.rb
|
44
|
+
- lib/mozapi/url_metrics.rb
|
45
|
+
- lib/mozapi/version.rb
|
46
|
+
- mozapi.gemspec
|
35
47
|
homepage: https://github.com/yas4891/mozapi
|
36
48
|
licenses:
|
37
49
|
- MIT
|