awis-sdk-ruby 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,5 +5,8 @@ rvm:
5
5
  - 1.9.3
6
6
  - 2.0.0
7
7
  - 2.1.1
8
+ - 2.2.3
9
+ - 2.3.0
10
+ - 2.4.0
8
11
  env:
9
12
  - XML_PARSER=nokogiri
data/Gemfile CHANGED
@@ -1,9 +1,5 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- group :extra do
4
- gem "debugger"
5
- end
6
-
7
3
  gem "bundler"
8
4
  gem "rake"
9
5
 
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']
@@ -1,5 +1,5 @@
1
1
  require "multi_xml"
2
- require 'nokogiri'
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 = "2005-07-11".freeze
17
- API_HOST = "awis.amazonaws.com".freeze
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
@@ -7,17 +7,13 @@ require "time"
7
7
 
8
8
  module Awis
9
9
  class Connection
10
- attr_accessor :access_key_id, :secret_access_key, :proxy, :debug
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
- @access_key_id = Awis.config.access_key_id
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
- puts "[DEBUG] -> #{uri}" if debug
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}/?" + query + "&Signature=" + CGI::escape(signature))
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" => "2",
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" + query
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 regexp_params(value)
87
- URI.escape(value.to_s, Regexp.new("[^#{RFC_3986_UNRESERVED_CHARS}]"))
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(hash)
95
- hash.map { |k, v| instance_variable_set("@#{k}", v) }
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(hash)
103
- hash.map { |k, v| instance_variable_set("@#{k}", v) }
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(hash)
111
- hash.map { |k, v| instance_variable_set("@#{k}", v) }
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(hash)
119
- hash.map { |k, v| instance_variable_set("@#{k}", v) }
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(hash)
49
- hash.map { |k, v| instance_variable_set("@#{k}", v) }
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(hash)
36
- hash.map { |k, v| instance_variable_set("@#{k}", v) }
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(hash)
55
- hash.map { |k, v| instance_variable_set("@#{k}", v) }
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
@@ -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
- phone_number: []
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] = text
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(hash)
151
- hash.map { |k, v| instance_variable_set("@#{k}", v) }
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(hash)
159
- phone_numbers = hash.delete(:phone_numbers)
188
+ def initialize(options)
189
+ phone_numbers = options.delete(:phone_numbers)
160
190
 
161
- hash.map { |k, v| instance_variable_set("@#{k}", v) }
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(hash)
176
- hash.map { |k, v| instance_variable_set("@#{k}", v) }
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(hash)
184
- hash.map { |k, v| instance_variable_set("@#{k}", v) }
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(hash)
192
- hash.map { |k, v| instance_variable_set("@#{k}", v) }
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(hash)
202
- hash.map { |k, v| instance_variable_set("@#{k}", v) }
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
@@ -1,3 +1,3 @@
1
1
  module Awis
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
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.3
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-09 00:00:00.000000000 Z
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: -2746170648665062270
168
+ hash: -2197500946134306758
169
169
  requirements: []
170
170
  rubyforge_project:
171
171
  rubygems_version: 1.8.23