awis-sdk-ruby 0.0.4 → 0.0.5

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.
@@ -5,6 +5,7 @@ require "awis/version"
5
5
  require "awis/hash"
6
6
  require "awis/utils/xml"
7
7
  require "awis/utils/extra"
8
+ require "awis/utils/variable"
8
9
  require "awis/exceptions"
9
10
  require "awis/connection"
10
11
  require "awis/config"
@@ -16,6 +16,12 @@ module Awis
16
16
  self.class.name.split(/\:\:/)[-1]
17
17
  end
18
18
 
19
+ def load_request_uri(params)
20
+ collection = Awis::Connection.new
21
+ collection.setup_params(params)
22
+ collection.uri
23
+ end
24
+
19
25
  class << self
20
26
  def loading_data_from_xml(xml_file_path)
21
27
  MultiXml.parse(File.new(xml_file_path))
@@ -5,16 +5,26 @@ module Awis
5
5
 
6
6
  def fetch(arguments = {})
7
7
  raise ArgumentError.new("Valid category path (Top/Arts, Top/Business/Automotive)") unless arguments.has_key?(:path)
8
+ validation_arguments!(arguments)
9
+
10
+ @response_body = Awis::Connection.new.get(params)
11
+ self
12
+ end
13
+
14
+ def load_request_uri(arguments = {})
15
+ validation_arguments!(arguments)
16
+
17
+ super(params)
18
+ end
19
+
20
+ private
21
+ def validation_arguments!(arguments)
8
22
  @arguments = arguments
9
23
 
10
24
  @arguments[:response_group] = Array(arguments.fetch(:response_group, DEFAULT_RESPONSE_GROUP))
11
25
  @arguments[:descriptions] = arguments.fetch(:descriptions, true)
12
-
13
- @response_body = Awis::Connection.new.get(params)
14
- self
15
26
  end
16
27
 
17
- private
18
28
  def params
19
29
  {
20
30
  "Action" => action_name,
@@ -3,6 +3,20 @@ module Awis
3
3
  class CategoryListings < Base
4
4
  def fetch(arguments = {})
5
5
  raise ArgumentError, "You must provide a URL" unless arguments.has_key?(:path)
6
+ validation_arguments!(arguments)
7
+
8
+ @response_body = Awis::Connection.new.get(params)
9
+ self
10
+ end
11
+
12
+ def load_request_uri(arguments = {})
13
+ validation_arguments!(arguments)
14
+
15
+ super(params)
16
+ end
17
+
18
+ private
19
+ def validation_arguments!(arguments)
6
20
  @arguments = arguments
7
21
 
8
22
  @arguments[:sort_by] = arguments.fetch(:sort_by, "popularity")
@@ -10,12 +24,8 @@ module Awis
10
24
  @arguments[:descriptions] = arguments.fetch(:descriptions, true)
11
25
  @arguments[:start] = arguments.fetch(:start, 0)
12
26
  @arguments[:count] = arguments.fetch(:count, 20)
13
-
14
- @response_body = Awis::Connection.new.get(params)
15
- self
16
27
  end
17
28
 
18
- private
19
29
  def params
20
30
  {
21
31
  "Action" => "CategoryListings",
@@ -5,16 +5,25 @@ module Awis
5
5
 
6
6
  def fetch(arguments = {})
7
7
  raise ArgumentError, "You must provide a URL" unless arguments.has_key?(:url)
8
-
9
- @arguments = arguments
10
- @arguments[:count] = arguments.fetch(:count, 20)
11
- @arguments[:start] = arguments.fetch(:start, 0)
8
+ validation_arguments!(arguments)
12
9
 
13
10
  @response_body = Awis::Connection.new.get(params)
14
11
  self
15
12
  end
16
13
 
14
+ def load_request_uri(arguments = {})
15
+ validation_arguments!(arguments)
16
+
17
+ super(params)
18
+ end
19
+
17
20
  private
21
+ def validation_arguments!(arguments)
22
+ @arguments = arguments
23
+ @arguments[:count] = arguments.fetch(:count, 20)
24
+ @arguments[:start] = arguments.fetch(:start, 0)
25
+ end
26
+
18
27
  def params
19
28
  {
20
29
  "Action" => "SitesLinkingIn",
@@ -3,15 +3,19 @@ module Awis
3
3
  class TrafficHistory < Base
4
4
  def fetch(arguments = {})
5
5
  raise ArgumentError, "Any valid URL." unless arguments.has_key?(:url)
6
- @arguments = arguments
7
-
8
- @arguments[:range] = arguments.fetch(:range, 31)
9
- @arguments[:start] = arguments.fetch(:start) { Time.now - (3600 * 24 * @arguments[:range].to_i) }
10
6
 
7
+ validation_arguments!(arguments)
11
8
  @response_body = Awis::Connection.new.get(params)
12
9
  self
13
10
  end
14
11
 
12
+ def load_request_uri(arguments = {})
13
+ validation_arguments!(arguments)
14
+
15
+ super(params)
16
+ end
17
+
18
+ private
15
19
  def params
16
20
  {
17
21
  "Action" => "TrafficHistory",
@@ -22,6 +26,13 @@ module Awis
22
26
  }
23
27
  end
24
28
 
29
+ def validation_arguments!(arguments)
30
+ @arguments = arguments
31
+
32
+ @arguments[:range] = arguments.fetch(:range, 31)
33
+ @arguments[:start] = arguments.fetch(:start) { Time.now - (3600 * 24 * @arguments[:range].to_i) }
34
+ end
35
+
25
36
  def start_param
26
37
  arguments[:start].respond_to?(:strftime) ? arguments[:start].strftime("%Y%m%d") : arguments[:start]
27
38
  end
@@ -5,18 +5,24 @@ module Awis
5
5
 
6
6
  def fetch(arguments = {})
7
7
  raise ArgumentError, "Any valid URL." unless arguments.has_key?(:url)
8
- @arguments = arguments
9
- @arguments[:response_group] = Array(arguments.fetch(:response_group, DEFAULT_RESPONSE_GROUP))
8
+ validation_arguments!(arguments)
10
9
 
11
- loading_response_data
10
+ @response_body = Awis::Connection.new.get(params)
12
11
  self
13
12
  end
14
13
 
15
- def loading_response_data
16
- @response_body = Awis::Connection.new.get(params)
14
+ def load_request_uri(arguments = {})
15
+ validation_arguments!(arguments)
16
+
17
+ super(params)
17
18
  end
18
19
 
19
20
  private
21
+ def validation_arguments!(arguments)
22
+ @arguments = arguments
23
+ @arguments[:response_group] = Array(arguments.fetch(:response_group, DEFAULT_RESPONSE_GROUP))
24
+ end
25
+
20
26
  def params
21
27
  {
22
28
  "Action" => action_name,
@@ -20,9 +20,13 @@ module Awis
20
20
  @params ||= {}
21
21
  end
22
22
 
23
- def get(params = {})
23
+ def setup_params(params)
24
24
  self.params = params
25
+ end
25
26
 
27
+ def get(params = {})
28
+ setup_params(params)
29
+
26
30
  handle_response(request).body.force_encoding(Encoding::UTF_8)
27
31
  end
28
32
 
@@ -1,6 +1,7 @@
1
1
  module Awis
2
2
  module Models
3
3
  autoload :Base, "awis/models/base"
4
+ autoload :BaseEntity, "awis/models/base_entity"
4
5
  autoload :UrlInfo, "awis/models/url_info"
5
6
  autoload :TrafficHistory, "awis/models/traffic_history"
6
7
  autoload :SitesLinkingIn, "awis/models/sites_linking_in"
@@ -0,0 +1,11 @@
1
+ module Awis
2
+ module Models
3
+ class BaseEntity
4
+ include Utils::Variable
5
+
6
+ def initialize(options)
7
+ custom_instance_variables(options)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -9,7 +9,7 @@ module Awis
9
9
  @related_categories = []
10
10
  @letter_bars = []
11
11
 
12
- setup_data!( loading_response(response) )
12
+ setup_data! loading_response(response)
13
13
  end
14
14
 
15
15
  def setup_data!(response)
@@ -21,6 +21,7 @@ module Awis
21
21
  response.each_node do |node, path|
22
22
  text = node.inner_xml
23
23
  text = text.to_i if text.to_i.to_s === text
24
+ text = nil if (text.class == String && text.empty?)
24
25
 
25
26
  if node.name == 'aws:RequestId'
26
27
  @request_id ||= text
@@ -88,44 +89,20 @@ module Awis
88
89
  end
89
90
  end
90
91
 
91
- class Category
92
+ class Category < BaseEntity
92
93
  attr_accessor :path, :title, :sub_category_count, :total_listing_count
93
-
94
- def initialize(options)
95
- options.each do |key, value|
96
- instance_variable_set("@#{key}", value)
97
- end
98
- end
99
94
  end
100
95
 
101
- class LanguageCategory
96
+ class LanguageCategory < BaseEntity
102
97
  attr_accessor :path, :title, :sub_category_count, :total_listing_count
103
-
104
- def initialize(options)
105
- options.each do |key, value|
106
- instance_variable_set("@#{key}", value)
107
- end
108
- end
109
98
  end
110
99
 
111
- class RelatedCategory
100
+ class RelatedCategory < BaseEntity
112
101
  attr_accessor :path, :title, :sub_category_count, :total_listing_count
113
-
114
- def initialize(options)
115
- options.each do |key, value|
116
- instance_variable_set("@#{key}", value)
117
- end
118
- end
119
102
  end
120
103
 
121
- class LetterBar
104
+ class LetterBar < BaseEntity
122
105
  attr_accessor :path, :title, :sub_category_count, :total_listing_count
123
-
124
- def initialize(options)
125
- options.each do |key, value|
126
- instance_variable_set("@#{key}", value)
127
- end
128
- end
129
106
  end
130
107
  end
131
108
  end
@@ -5,7 +5,7 @@ module Awis
5
5
 
6
6
  def initialize(response)
7
7
  @listings = []
8
- setup_data!( loading_response(response) )
8
+ setup_data! loading_response(response)
9
9
  end
10
10
 
11
11
  def setup_data!(response)
@@ -14,6 +14,7 @@ module Awis
14
14
  response.each_node do |node, path|
15
15
  text = node.inner_xml
16
16
  text = text.to_i if text.to_i.to_s === text
17
+ text = nil if (text.class == String && text.empty?)
17
18
 
18
19
  if node.name == 'aws:RequestId'
19
20
  @request_id ||= text
@@ -42,14 +43,8 @@ module Awis
42
43
  end
43
44
  end
44
45
 
45
- class Listing
46
+ class Listing < BaseEntity
46
47
  attr_accessor :data_url, :title, :popularity_rank, :description
47
-
48
- def initialize(options)
49
- options.each do |key, value|
50
- instance_variable_set("@#{key}", value)
51
- end
52
- end
53
48
  end
54
49
  end
55
50
  end
@@ -5,7 +5,7 @@ module Awis
5
5
 
6
6
  def initialize(response)
7
7
  @sites = []
8
- setup_data!( loading_response(response) )
8
+ setup_data! loading_response(response)
9
9
  end
10
10
 
11
11
  def setup_data!(response)
@@ -13,6 +13,7 @@ module Awis
13
13
 
14
14
  response.each_node do |node, path|
15
15
  text = node.inner_xml
16
+ text = nil if (text.class == String && text.empty?)
16
17
 
17
18
  if node.name == 'aws:RequestId'
18
19
  @request_id ||= text
@@ -29,14 +30,8 @@ module Awis
29
30
  end
30
31
  end
31
32
 
32
- class Site
33
+ class Site < BaseEntity
33
34
  attr_accessor :title, :url
34
-
35
- def initialize(options)
36
- options.each do |key, value|
37
- instance_variable_set("@#{key}", value)
38
- end
39
- end
40
35
  end
41
36
  end
42
37
  end
@@ -5,7 +5,7 @@ module Awis
5
5
 
6
6
  def initialize(response)
7
7
  @historical_data = []
8
- setup_data!( loading_response(response) )
8
+ setup_data! loading_response(response)
9
9
  end
10
10
 
11
11
  def setup_data!(response)
@@ -14,6 +14,7 @@ module Awis
14
14
  response.each_node do |node, path|
15
15
  text = node.inner_xml
16
16
  text = text.to_i if text.to_i.to_s === text
17
+ text = nil if (text.class == String && text.empty?)
17
18
 
18
19
  if node.name == 'aws:RequestId'
19
20
  @request_id ||= text
@@ -48,14 +49,8 @@ module Awis
48
49
  end
49
50
  end
50
51
 
51
- class HistoricalData
52
+ class HistoricalData < BaseEntity
52
53
  attr_accessor :date, :page_views_per_million, :page_views_per_user, :rank, :reach_per_million
53
-
54
- def initialize(options)
55
- options.each do |key, value|
56
- instance_variable_set("@#{key}", value)
57
- end
58
- end
59
54
  end
60
55
  end
61
56
  end
@@ -7,7 +7,8 @@ module Awis
7
7
  @usage_statistics = []
8
8
  @related_links = []
9
9
  @categories = []
10
- setup_data!( loading_response(response) )
10
+
11
+ setup_data! loading_response(response)
11
12
  end
12
13
 
13
14
  def setup_data!(response)
@@ -24,6 +25,7 @@ module Awis
24
25
  response.each_node do |node, path|
25
26
  text = node.inner_xml
26
27
  text = text.to_i if text.to_i.to_s === text && node.name != 'aws:Delta'
28
+ text = nil if (text.class == String && text.empty?)
27
29
 
28
30
  if node.name == 'aws:RequestId'
29
31
  @request_id ||= text
@@ -118,6 +120,10 @@ module Awis
118
120
  relationship_collections(@categories, category_data, 3, CategoryData)
119
121
  end
120
122
 
123
+ def is_404?
124
+ success? && rank == 404
125
+ end
126
+
121
127
  def init_entity_data(attr_name, data, kclass)
122
128
  return if data.empty?
123
129
 
@@ -149,18 +155,14 @@ module Awis
149
155
  end
150
156
  end
151
157
 
152
- class ContentData
158
+ class ContentData < BaseEntity
153
159
  attr_accessor :data_url, :site_title, :site_description, :online_since, :speed_median_load_time, :speed_percentile, :adult_content,
154
160
  :language_locale, :links_in_count, :owned_domains
155
161
 
156
162
  def initialize(options)
157
163
  @owned_domains = []
158
164
  owned_domain_objects = options.delete(:owned_domains)
159
-
160
- options.each do |key, value|
161
- instance_variable_set("@#{key}", value)
162
- end
163
-
165
+ super(options)
164
166
  owned_domains_relationship_collections(@owned_domains, owned_domain_objects, 2, OwnedDomain)
165
167
  end
166
168
 
@@ -172,25 +174,16 @@ module Awis
172
174
  end
173
175
  end
174
176
 
175
- class OwnedDomain
177
+ class OwnedDomain < BaseEntity
176
178
  attr_accessor :domain, :title
177
-
178
- def initialize(options)
179
- options.each do |key, value|
180
- instance_variable_set("@#{key}", value)
181
- end
182
- end
183
179
  end
184
180
 
185
- class ContactInfo
181
+ class ContactInfo < BaseEntity
186
182
  attr_accessor :data_url, :owner_name, :email, :physical_address, :company_stock_ticker, :phone_numbers
187
183
 
188
184
  def initialize(options)
189
185
  phone_numbers = options.delete(:phone_numbers)
190
-
191
- options.each do |key, value|
192
- instance_variable_set("@#{key}", value)
193
- end
186
+ super(options)
194
187
  phone_number_collections(phone_numbers)
195
188
  end
196
189
 
@@ -201,45 +194,31 @@ module Awis
201
194
  end
202
195
  end
203
196
 
204
- class PhoneNumber
197
+ class PhoneNumber < BaseEntity
205
198
  attr_accessor :number
206
-
207
- def initialize(options)
208
- options.each do |key, value|
209
- instance_variable_set("@#{key}", value)
210
- end
211
- end
212
199
  end
213
200
 
214
- class RelatedLink
201
+ class RelatedLink < BaseEntity
215
202
  attr_accessor :data_url, :navigable_url, :title
216
-
217
- def initialize(options)
218
- options.each do |key, value|
219
- instance_variable_set("@#{key}", value)
220
- end
221
- end
222
203
  end
223
204
 
224
- class CategoryData
205
+ class CategoryData < BaseEntity
225
206
  attr_accessor :title, :absolute_path
226
-
227
- def initialize(options)
228
- options.each do |key, value|
229
- instance_variable_set("@#{key}", value)
230
- end
231
- end
232
207
  end
233
208
 
234
- class UsageStatistic
209
+ class UsageStatistic < BaseEntity
235
210
  attr_accessor :time_range_months, :time_range_days, :rank_value, :rank_delta, :reach_rank_value, :reach_rank_delta,
236
211
  :reach_per_million_value, :reach_per_million_delta, :reach_page_views_per_million_value, :reach_page_views_per_million_delta,
237
212
  :reach_page_views_rank_value, :reach_page_views_rank_delta, :reach_page_views_per_user_value, :reach_page_views_per_user_delta
238
213
 
239
- def initialize(options)
240
- options.each do |key, value|
241
- instance_variable_set("@#{key}", value)
242
- end
214
+ def range_type
215
+ return 'month' unless time_range_months.blank?
216
+
217
+ 'day'
218
+ end
219
+
220
+ def range_count
221
+ (time_range_months || time_range_days)
243
222
  end
244
223
  end
245
224
  end
@@ -0,0 +1,13 @@
1
+ module Awis
2
+ module Utils
3
+ module Variable
4
+ def custom_instance_variables(options)
5
+ options.each do |key, value|
6
+ value = (value.class == String && value.empty?) ? nil : value
7
+
8
+ instance_variable_set("@#{key}", value)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module Awis
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
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.4
4
+ version: 0.0.5
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-11 00:00:00.000000000 Z
12
+ date: 2017-03-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multi_xml
@@ -137,12 +137,14 @@ files:
137
137
  - lib/awis/hash.rb
138
138
  - lib/awis/models.rb
139
139
  - lib/awis/models/base.rb
140
+ - lib/awis/models/base_entity.rb
140
141
  - lib/awis/models/category_browse.rb
141
142
  - lib/awis/models/category_listings.rb
142
143
  - lib/awis/models/sites_linking_in.rb
143
144
  - lib/awis/models/traffic_history.rb
144
145
  - lib/awis/models/url_info.rb
145
146
  - lib/awis/utils/extra.rb
147
+ - lib/awis/utils/variable.rb
146
148
  - lib/awis/utils/xml.rb
147
149
  - lib/awis/version.rb
148
150
  homepage: https://github.com/encoreshao/amazon-awis
@@ -165,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
167
  version: '0'
166
168
  segments:
167
169
  - 0
168
- hash: -2197500946134306758
170
+ hash: 3645655576391450679
169
171
  requirements: []
170
172
  rubyforge_project:
171
173
  rubygems_version: 1.8.23