awis-sdk-ruby 0.0.3 → 0.0.4
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.
- data/.travis.yml +3 -0
- data/Gemfile +0 -4
- data/README.md +2 -2
- data/lib/awis.rb +5 -3
- data/lib/awis/connection.rb +14 -18
- data/lib/awis/models/category_browse.rb +16 -8
- data/lib/awis/models/category_listings.rb +4 -2
- data/lib/awis/models/sites_linking_in.rb +4 -2
- data/lib/awis/models/traffic_history.rb +4 -2
- data/lib/awis/models/url_info.rb +58 -18
- data/lib/awis/version.rb +1 -1
- metadata +3 -3
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -12,9 +12,9 @@ gem install awis-sdk-ruby
|
|
12
12
|
##### Configure your amazon certificate
|
13
13
|
|
14
14
|
```
|
15
|
-
AWIS_CONFIG = YAML.load(File.read('awis.yml'))
|
16
|
-
|
17
15
|
require 'awis'
|
16
|
+
|
17
|
+
AWIS_CONFIG = YAML.load(File.read('awis.yml'))
|
18
18
|
Awis.config do |c|
|
19
19
|
c.access_key_id = AWIS_CONFIG['access_key_id']
|
20
20
|
c.secret_access_key = AWIS_CONFIG['secret_access_key']
|
data/lib/awis.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require "multi_xml"
|
2
|
-
require
|
2
|
+
require "nokogiri"
|
3
3
|
|
4
4
|
require "awis/version"
|
5
5
|
require "awis/hash"
|
@@ -13,8 +13,10 @@ require "awis/api"
|
|
13
13
|
require "awis/models"
|
14
14
|
|
15
15
|
module Awis
|
16
|
-
API_VERSION
|
17
|
-
API_HOST
|
16
|
+
API_VERSION = "2005-07-11".freeze
|
17
|
+
API_HOST = "awis.amazonaws.com".freeze
|
18
|
+
API_SIGNATURE_VERSION = "2".freeze
|
19
|
+
|
18
20
|
class << self
|
19
21
|
end
|
20
22
|
end
|
data/lib/awis/connection.rb
CHANGED
@@ -7,17 +7,13 @@ require "time"
|
|
7
7
|
|
8
8
|
module Awis
|
9
9
|
class Connection
|
10
|
-
attr_accessor :
|
10
|
+
attr_accessor :debug
|
11
11
|
attr_writer :params
|
12
12
|
|
13
|
-
RFC_3986_UNRESERVED_CHARS = "-_.~a-zA-Z\\d".freeze
|
14
|
-
|
15
13
|
def initialize
|
16
14
|
raise CertificateError.new("Amazon access certificate is missing!") if Awis.config.access_key_id.nil? || Awis.config.secret_access_key.nil?
|
17
15
|
|
18
|
-
@
|
19
|
-
@secret_access_key = Awis.config.secret_access_key
|
20
|
-
@debug = Awis.config.debug || nil
|
16
|
+
@debug = Awis.config.debug || false
|
21
17
|
end
|
22
18
|
|
23
19
|
def params
|
@@ -48,43 +44,43 @@ module Awis
|
|
48
44
|
end
|
49
45
|
|
50
46
|
def request
|
51
|
-
|
47
|
+
showing_request_uri
|
52
48
|
|
53
49
|
Faraday.get(uri)
|
54
50
|
end
|
55
51
|
|
52
|
+
def showing_request_uri
|
53
|
+
puts "[DEBUG] -> #{uri}" if debug
|
54
|
+
end
|
55
|
+
|
56
56
|
def timestamp
|
57
57
|
@timestamp ||= Time::now.utc.strftime("%Y-%m-%dT%H:%M:%S.000Z")
|
58
58
|
end
|
59
59
|
|
60
60
|
def signature
|
61
|
-
Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest.new("sha256"), secret_access_key, sign)).strip
|
61
|
+
Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest.new("sha256"), Awis.config.secret_access_key, sign)).strip
|
62
62
|
end
|
63
63
|
|
64
64
|
def uri
|
65
|
-
URI.parse("http://#{Awis::API_HOST}/?" +
|
65
|
+
URI.parse("http://#{Awis::API_HOST}/?" + query_params + "&Signature=" + CGI::escape(signature))
|
66
66
|
end
|
67
67
|
|
68
68
|
def default_params
|
69
69
|
{
|
70
|
-
"AWSAccessKeyId" => access_key_id,
|
70
|
+
"AWSAccessKeyId" => Awis.config.access_key_id,
|
71
71
|
"SignatureMethod" => "HmacSHA256",
|
72
|
-
"SignatureVersion" =>
|
72
|
+
"SignatureVersion" => Awis::API_SIGNATURE_VERSION,
|
73
73
|
"Timestamp" => timestamp,
|
74
74
|
"Version" => Awis::API_VERSION
|
75
75
|
}
|
76
76
|
end
|
77
77
|
|
78
78
|
def sign
|
79
|
-
"GET\n" + Awis::API_HOST + "\n/\n" +
|
80
|
-
end
|
81
|
-
|
82
|
-
def query
|
83
|
-
default_params.merge(params).map { |key, value| "#{key}=#{regexp_params(value)}" }.sort.join("&")
|
79
|
+
"GET\n" + Awis::API_HOST + "\n/\n" + query_params
|
84
80
|
end
|
85
81
|
|
86
|
-
def
|
87
|
-
|
82
|
+
def query_params
|
83
|
+
default_params.merge(params).map { |key, value| "#{key}=#{CGI::escape(value.to_s)}" }.sort.join("&")
|
88
84
|
end
|
89
85
|
end
|
90
86
|
end
|
@@ -91,32 +91,40 @@ module Awis
|
|
91
91
|
class Category
|
92
92
|
attr_accessor :path, :title, :sub_category_count, :total_listing_count
|
93
93
|
|
94
|
-
def initialize(
|
95
|
-
|
94
|
+
def initialize(options)
|
95
|
+
options.each do |key, value|
|
96
|
+
instance_variable_set("@#{key}", value)
|
97
|
+
end
|
96
98
|
end
|
97
99
|
end
|
98
100
|
|
99
101
|
class LanguageCategory
|
100
102
|
attr_accessor :path, :title, :sub_category_count, :total_listing_count
|
101
103
|
|
102
|
-
def initialize(
|
103
|
-
|
104
|
+
def initialize(options)
|
105
|
+
options.each do |key, value|
|
106
|
+
instance_variable_set("@#{key}", value)
|
107
|
+
end
|
104
108
|
end
|
105
109
|
end
|
106
110
|
|
107
111
|
class RelatedCategory
|
108
112
|
attr_accessor :path, :title, :sub_category_count, :total_listing_count
|
109
113
|
|
110
|
-
def initialize(
|
111
|
-
|
114
|
+
def initialize(options)
|
115
|
+
options.each do |key, value|
|
116
|
+
instance_variable_set("@#{key}", value)
|
117
|
+
end
|
112
118
|
end
|
113
119
|
end
|
114
120
|
|
115
121
|
class LetterBar
|
116
122
|
attr_accessor :path, :title, :sub_category_count, :total_listing_count
|
117
123
|
|
118
|
-
def initialize(
|
119
|
-
|
124
|
+
def initialize(options)
|
125
|
+
options.each do |key, value|
|
126
|
+
instance_variable_set("@#{key}", value)
|
127
|
+
end
|
120
128
|
end
|
121
129
|
end
|
122
130
|
end
|
@@ -45,8 +45,10 @@ module Awis
|
|
45
45
|
class Listing
|
46
46
|
attr_accessor :data_url, :title, :popularity_rank, :description
|
47
47
|
|
48
|
-
def initialize(
|
49
|
-
|
48
|
+
def initialize(options)
|
49
|
+
options.each do |key, value|
|
50
|
+
instance_variable_set("@#{key}", value)
|
51
|
+
end
|
50
52
|
end
|
51
53
|
end
|
52
54
|
end
|
@@ -32,8 +32,10 @@ module Awis
|
|
32
32
|
class Site
|
33
33
|
attr_accessor :title, :url
|
34
34
|
|
35
|
-
def initialize(
|
36
|
-
|
35
|
+
def initialize(options)
|
36
|
+
options.each do |key, value|
|
37
|
+
instance_variable_set("@#{key}", value)
|
38
|
+
end
|
37
39
|
end
|
38
40
|
end
|
39
41
|
end
|
@@ -51,8 +51,10 @@ module Awis
|
|
51
51
|
class HistoricalData
|
52
52
|
attr_accessor :date, :page_views_per_million, :page_views_per_user, :rank, :reach_per_million
|
53
53
|
|
54
|
-
def initialize(
|
55
|
-
|
54
|
+
def initialize(options)
|
55
|
+
options.each do |key, value|
|
56
|
+
instance_variable_set("@#{key}", value)
|
57
|
+
end
|
56
58
|
end
|
57
59
|
end
|
58
60
|
end
|
data/lib/awis/models/url_info.rb
CHANGED
@@ -11,9 +11,11 @@ module Awis
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def setup_data!(response)
|
14
|
-
content_data = {
|
14
|
+
content_data = {
|
15
|
+
owned_domains: []
|
16
|
+
}
|
15
17
|
contact_info = {
|
16
|
-
|
18
|
+
phone_numbers: []
|
17
19
|
}
|
18
20
|
statistics = []
|
19
21
|
related_related_links = []
|
@@ -49,8 +51,12 @@ module Awis
|
|
49
51
|
content_data[:language_locale] = text
|
50
52
|
elsif node.name == 'aws:LinksInCount'
|
51
53
|
content_data[:links_in_count] = text
|
52
|
-
elsif node.name == 'aws:OwnedDomains
|
53
|
-
content_data[:owned_domains]
|
54
|
+
elsif node.name == 'aws:Domain' && path == "#{content_node_name}/aws:OwnedDomains/aws:OwnedDomain/aws:Domain"
|
55
|
+
content_data[:owned_domains] << { domain: text }
|
56
|
+
elsif node.name == 'aws:Title' && path == "#{content_node_name}/aws:OwnedDomains/aws:OwnedDomain/aws:Title"
|
57
|
+
content_data[:owned_domains] << { title: text }
|
58
|
+
elsif node.name == 'aws:OnlineSince'
|
59
|
+
content_data[:online_since] = text
|
54
60
|
elsif node.name == 'aws:DataUrl' && path == "#{root_node_name}/aws:ContactInfo/aws:DataUrl"
|
55
61
|
contact_info[:data_url] = text
|
56
62
|
elsif node.name == 'aws:OwnerName'
|
@@ -144,21 +150,47 @@ module Awis
|
|
144
150
|
end
|
145
151
|
|
146
152
|
class ContentData
|
147
|
-
attr_accessor :data_url, :site_title, :site_description, :speed_median_load_time, :speed_percentile, :adult_content,
|
153
|
+
attr_accessor :data_url, :site_title, :site_description, :online_since, :speed_median_load_time, :speed_percentile, :adult_content,
|
148
154
|
:language_locale, :links_in_count, :owned_domains
|
149
155
|
|
150
|
-
def initialize(
|
151
|
-
|
156
|
+
def initialize(options)
|
157
|
+
@owned_domains = []
|
158
|
+
owned_domain_objects = options.delete(:owned_domains)
|
159
|
+
|
160
|
+
options.each do |key, value|
|
161
|
+
instance_variable_set("@#{key}", value)
|
162
|
+
end
|
163
|
+
|
164
|
+
owned_domains_relationship_collections(@owned_domains, owned_domain_objects, 2, OwnedDomain)
|
165
|
+
end
|
166
|
+
|
167
|
+
def owned_domains_relationship_collections(_object, items, items_count, kclass)
|
168
|
+
return if items.empty?
|
169
|
+
|
170
|
+
all_items = {}.array_slice_merge!(:item, items, items_count)
|
171
|
+
all_items.map { |item| _object << kclass.new(item) }
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
class OwnedDomain
|
176
|
+
attr_accessor :domain, :title
|
177
|
+
|
178
|
+
def initialize(options)
|
179
|
+
options.each do |key, value|
|
180
|
+
instance_variable_set("@#{key}", value)
|
181
|
+
end
|
152
182
|
end
|
153
183
|
end
|
154
184
|
|
155
185
|
class ContactInfo
|
156
186
|
attr_accessor :data_url, :owner_name, :email, :physical_address, :company_stock_ticker, :phone_numbers
|
157
187
|
|
158
|
-
def initialize(
|
159
|
-
phone_numbers =
|
188
|
+
def initialize(options)
|
189
|
+
phone_numbers = options.delete(:phone_numbers)
|
160
190
|
|
161
|
-
|
191
|
+
options.each do |key, value|
|
192
|
+
instance_variable_set("@#{key}", value)
|
193
|
+
end
|
162
194
|
phone_number_collections(phone_numbers)
|
163
195
|
end
|
164
196
|
|
@@ -172,24 +204,30 @@ module Awis
|
|
172
204
|
class PhoneNumber
|
173
205
|
attr_accessor :number
|
174
206
|
|
175
|
-
def initialize(
|
176
|
-
|
207
|
+
def initialize(options)
|
208
|
+
options.each do |key, value|
|
209
|
+
instance_variable_set("@#{key}", value)
|
210
|
+
end
|
177
211
|
end
|
178
212
|
end
|
179
213
|
|
180
214
|
class RelatedLink
|
181
215
|
attr_accessor :data_url, :navigable_url, :title
|
182
216
|
|
183
|
-
def initialize(
|
184
|
-
|
217
|
+
def initialize(options)
|
218
|
+
options.each do |key, value|
|
219
|
+
instance_variable_set("@#{key}", value)
|
220
|
+
end
|
185
221
|
end
|
186
222
|
end
|
187
223
|
|
188
224
|
class CategoryData
|
189
225
|
attr_accessor :title, :absolute_path
|
190
226
|
|
191
|
-
def initialize(
|
192
|
-
|
227
|
+
def initialize(options)
|
228
|
+
options.each do |key, value|
|
229
|
+
instance_variable_set("@#{key}", value)
|
230
|
+
end
|
193
231
|
end
|
194
232
|
end
|
195
233
|
|
@@ -198,8 +236,10 @@ module Awis
|
|
198
236
|
:reach_per_million_value, :reach_per_million_delta, :reach_page_views_per_million_value, :reach_page_views_per_million_delta,
|
199
237
|
:reach_page_views_rank_value, :reach_page_views_rank_delta, :reach_page_views_per_user_value, :reach_page_views_per_user_delta
|
200
238
|
|
201
|
-
def initialize(
|
202
|
-
|
239
|
+
def initialize(options)
|
240
|
+
options.each do |key, value|
|
241
|
+
instance_variable_set("@#{key}", value)
|
242
|
+
end
|
203
243
|
end
|
204
244
|
end
|
205
245
|
end
|
data/lib/awis/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: awis-sdk-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-03-
|
12
|
+
date: 2017-03-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: multi_xml
|
@@ -165,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
165
165
|
version: '0'
|
166
166
|
segments:
|
167
167
|
- 0
|
168
|
-
hash: -
|
168
|
+
hash: -2197500946134306758
|
169
169
|
requirements: []
|
170
170
|
rubyforge_project:
|
171
171
|
rubygems_version: 1.8.23
|