moz-url-metrics 0.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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/moz.rb +51 -0
  3. metadata +43 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 209044905dbb247d72ea9ba7b8c2b6cf17d32c15
4
+ data.tar.gz: 426117c143e35ce743ef108cf0a0c856f17bc113
5
+ SHA512:
6
+ metadata.gz: a065286bc0d732def6a0d5c6427b60336221b74cd01dc75d3abef0ca51e8633d28e4ef57c218b29099d9eae36c3b0676eb82174c847a0372f161c002b39e4348
7
+ data.tar.gz: 1687e3738b7df63a6df935562c35c2514ad16ebd722a87dddcfaa70938f0a12b4d9e2af464aafcfc958f111ad1b7a73ecad52f24b5ef821e584cbbdfaaccc92a
data/lib/moz.rb ADDED
@@ -0,0 +1,51 @@
1
+ require 'base64'
2
+ require 'cgi'
3
+ require 'json'
4
+ require 'openssl'
5
+ require 'open-uri'
6
+
7
+ class Moz
8
+ TITLE = 1 # ut
9
+ CANONICAL_URL = 4 # uu
10
+ SUBDOMAIN = 8 # ufq
11
+ ROOT_DOMAIN = 16 # upl
12
+ EXTERNAL_LINKS = 32 # ueid
13
+ SUBDOMAIN_EXTERNAL_LINKS = 64 # feid
14
+ ROOT_DOMAIN_EXTERNAL_LINKS = 128 # peid
15
+ EQUITY_LINKS = 256 #ujid
16
+ SUBDOMAINS_LINKING = 512 # uifq
17
+ ROOT_DOMAINS_LINKING = 1024 # uipl
18
+ LINKS = 2048 # uid
19
+ SUBDOMAIN_SUBDOMAINS_LINKING = 4096 # fid
20
+ ROOT_DOMAIN_ROOT_DOMAINS_LINKING = 8192 # pid
21
+ # TODO: The rest...
22
+
23
+ ALL_COLUMNS = 103079215104
24
+
25
+ def mozRequestBatch(urls, access_id, secret_key, cols)
26
+ expires = Time.now.to_i + 30
27
+
28
+ # A new linefeed is necessary between your AccessID and Expires.
29
+ string_to_sign = "#{access_id}\n#{expires}"
30
+
31
+ # Get the "raw" or binary output of the hmac hash.
32
+ binary_signature = OpenSSL::HMAC.digest('sha1', secret_key, string_to_sign)
33
+
34
+ # We need to base64-encode it and then url-encode that.
35
+ url_safe_signature = CGI::escape(Base64.encode64(binary_signature).chomp)
36
+
37
+ # Now put your entire request together.
38
+ # This example uses the Mozscape URL Metrics API.
39
+ request_url = "http://lsapi.seomoz.com/linkscape/url-metrics/?Cols=#{cols}&AccessID=#{access_id}&Expires=#{expires}&Signature=#{url_safe_signature}"
40
+
41
+ # Go and fetch the URL
42
+ uri = URI.parse("#{request_url}")
43
+ http = Net::HTTP.new(uri.host, uri.port)
44
+ request = Net::HTTP::Post.new(uri.request_uri)
45
+ # Put your URLS into an array and json_encode them.
46
+ request.body = urls.to_json
47
+ response = http.request(request)
48
+
49
+ response.body
50
+ end
51
+ end
metadata ADDED
@@ -0,0 +1,43 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: moz-url-metrics
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Han Chang
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-14 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: ''
14
+ email: hello@szuhanchang.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/moz.rb
20
+ homepage: http://rubygems.org/gems/moz-url-metrics
21
+ licenses: []
22
+ metadata: {}
23
+ post_install_message:
24
+ rdoc_options: []
25
+ require_paths:
26
+ - lib
27
+ required_ruby_version: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - '>='
30
+ - !ruby/object:Gem::Version
31
+ version: '0'
32
+ required_rubygems_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - '>='
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ requirements: []
38
+ rubyforge_project:
39
+ rubygems_version: 2.0.3
40
+ signing_key:
41
+ specification_version: 4
42
+ summary: ''
43
+ test_files: []