awis-sdk-ruby 2.0.0 → 2.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5c55c0fb766550990c1a7f6f07a64e68a61dbece692b9b6fa540986c247ee91a
4
- data.tar.gz: a6bde3ae5ae8493d6777a32614b004efc7991115e980aa274ddcaf7fd705dd4a
3
+ metadata.gz: c1b8b0369cacf309ffff5b752c458d3465ef51b7b085fd9c55fce22f8651807d
4
+ data.tar.gz: a78a3affebba1ae56d03b0db2173044e29ae5139d02a8ea3051ba5a0b0708c13
5
5
  SHA512:
6
- metadata.gz: 567fbf489d1ff95d74d4f6802c4c35738513aaa63942076f7c420653292445ae2178d331dcef206b5caf9bb960080e91a0701bb9d02d771f2a640d47063f8ff1
7
- data.tar.gz: 161b0a7db4c82ee52954319c12693b2e92472ad932e85545c917092e8e29fa75abe32cc9ad9a6f240778d42a8a1b77a42c70cb522b94fd2e2308d91f70799300
6
+ metadata.gz: 7229cf7a29ab8992f30e9aef6e51471250de75a7830a1021b4df1fb6d00ce5009fbf2b2410f9cb7903dfb580cda97b73b3f0080f49023d9bfac09a252eaa7c11
7
+ data.tar.gz: 503f910fbb860e7aab95022c0559a5c36418ddbd602e06cd6009dc07c305364075ef7b6e97987be08627773387add3f2be9710ed0bd48cb4921b7ee5754da4cd
data/README.md CHANGED
@@ -50,6 +50,14 @@ returns object that contains attributes:
50
50
  * asin
51
51
  * xml
52
52
 
53
+ New methods:
54
+
55
+ * is_404?
56
+ * not_found?
57
+ * pretty_xml
58
+
59
+ `pretty_xml` method will easily to review the XML response from the terminal
60
+
53
61
  returns object that contains relationships:
54
62
 
55
63
  **contact_info**
@@ -104,10 +112,6 @@ returns object that contains relationships:
104
112
  - title
105
113
  - absolute_path
106
114
 
107
- New methods:
108
-
109
- * is_404?
110
-
111
115
  You can specify options:
112
116
 
113
117
  * url
data/lib/awis/api/base.rb CHANGED
@@ -35,8 +35,8 @@ module Awis
35
35
 
36
36
  def load_request_uri(params)
37
37
  collection = Awis::Connection.new
38
- collection.setup_params(params)
39
- collection.uri
38
+ collection.set_params(params)
39
+ collection.send(:uri)
40
40
  end
41
41
 
42
42
  def before_validation_arguments(arguments)
data/lib/awis/client.rb CHANGED
@@ -29,18 +29,13 @@ module Awis
29
29
  private
30
30
 
31
31
  def parse_response_with_request(kclass, args)
32
- case kclass
33
- when 'UrlInfo'
34
- Models::UrlInfo.new API::UrlInfo.new.fetch(args)
35
- when 'SitesLinkingIn'
36
- Models::SitesLinkingIn.new API::SitesLinkingIn.new.fetch(args)
37
- when 'TrafficHistory'
38
- Models::TrafficHistory.new API::TrafficHistory.new.fetch(args)
39
- when 'CategoryBrowse'
40
- Models::CategoryBrowse.new API::CategoryBrowse.new.fetch(args)
41
- when 'CategoryListings'
42
- Models::CategoryListings.new API::CategoryListings.new.fetch(args)
43
- end
32
+ raise ArgumentError, 'Amazon class was missing!' unless [
33
+ 'UrlInfo', 'SitesLinkingIn', 'TrafficHistory',
34
+ 'CategoryBrowse', 'CategoryListings'
35
+ ].include?(kclass)
36
+
37
+ response = Kernel.const_get("Awis::API::#{kclass}").new.fetch(args)
38
+ Kernel.const_get("Awis::Models::#{kclass}").new(response)
44
39
  end
45
40
  end
46
41
  end
@@ -31,13 +31,20 @@ module Awis
31
31
  end
32
32
 
33
33
  def get(params = {})
34
- @params = params
34
+ set_params(params)
35
+
35
36
  handle_response(request).body
36
37
  end
37
38
 
39
+ def set_params(params)
40
+ @params = params
41
+ end
42
+
38
43
  private
39
44
 
40
45
  def handle_response(response)
46
+ puts ['URI ', response.uri].join if debug
47
+
41
48
  case response
42
49
  when Net::HTTPSuccess
43
50
  response
@@ -5,6 +5,14 @@ module Awis
5
5
  class Base
6
6
  attr_accessor :response, :status_code, :request_id
7
7
 
8
+ def initialize(response)
9
+ response_data = loading_response(response)
10
+
11
+ set_xml(response_data)
12
+ # Need to implement on sub-class
13
+ setup_data!(response_data)
14
+ end
15
+
8
16
  def loading_response(response)
9
17
  Awis::Utils::XML.new(response.response_body)
10
18
  end
@@ -27,6 +35,21 @@ module Awis
27
35
  def success?
28
36
  status_code == 'Success'
29
37
  end
38
+
39
+ def pretty_xml
40
+ doc = Nokogiri.XML(@xml.data) do |config|
41
+ config.default_xml.noblanks
42
+ end
43
+ puts doc.to_xml(:indent => 2)
44
+
45
+ nil
46
+ end
47
+
48
+ private
49
+
50
+ def set_xml(response)
51
+ @xml = response
52
+ end
30
53
  end
31
54
  end
32
55
  end
@@ -11,7 +11,7 @@ module Awis
11
11
  @related_categories = []
12
12
  @letter_bars = []
13
13
 
14
- setup_data! loading_response(response)
14
+ super(response)
15
15
  end
16
16
 
17
17
  # rubocop:disable Metrics/AbcSize
@@ -7,7 +7,8 @@ module Awis
7
7
 
8
8
  def initialize(response)
9
9
  @listings = []
10
- setup_data! loading_response(response)
10
+
11
+ super(response)
11
12
  end
12
13
 
13
14
  def setup_data!(response)
@@ -7,7 +7,8 @@ module Awis
7
7
 
8
8
  def initialize(response)
9
9
  @sites = []
10
- setup_data! loading_response(response)
10
+
11
+ super(response)
11
12
  end
12
13
 
13
14
  def setup_data!(response)
@@ -7,7 +7,8 @@ module Awis
7
7
 
8
8
  def initialize(response)
9
9
  @historical_data = []
10
- setup_data! loading_response(response)
10
+
11
+ super(response)
11
12
  end
12
13
 
13
14
  # rubocop:disable Metrics/AbcSize
@@ -4,7 +4,7 @@ module Awis
4
4
  module Models
5
5
  class UrlInfo < Base
6
6
  attr_accessor :data_url, :rank, :asin, :contact_info, :content_data, :usage_statistics, :related_links,
7
- :categories, :xml, :contributing_subdomains, :rank_by_country
7
+ :categories, :contributing_subdomains, :rank_by_country
8
8
 
9
9
  def initialize(response)
10
10
  @usage_statistics = []
@@ -13,11 +13,10 @@ module Awis
13
13
  @contributing_subdomains = []
14
14
  @rank_by_country = []
15
15
 
16
- setup_data! loading_response(response)
16
+ super(response)
17
17
  end
18
18
 
19
19
  def setup_data!(response)
20
- @xml = response
21
20
  content_data = {
22
21
  owned_domains: []
23
22
  }
@@ -156,10 +155,6 @@ module Awis
156
155
  relationship_collections(@contributing_subdomains, contributing_subdomains, 5, ContributingSubdomain)
157
156
  end
158
157
 
159
- def is_404?
160
- success? && rank == 404
161
- end
162
-
163
158
  def init_entity_data(attr_name, data, kclass)
164
159
  return if data.empty?
165
160
 
@@ -212,6 +207,11 @@ module Awis
212
207
  @geos_hash ||= geos_sorted.reduce({}, :merge)
213
208
  end
214
209
 
210
+ def not_found?
211
+ ([content_data.data_url, content_data.site_title] & [404, '404']).size > 0
212
+ end
213
+ alias :is_404? :not_found?
214
+
215
215
  def domains
216
216
  content_data.owned_domains.map(&:domain)
217
217
  end
@@ -241,10 +241,10 @@ module Awis
241
241
  end
242
242
 
243
243
  def daily_GDN_page_views
244
- if rank
245
- alexa_gdn.each do |max_pvs, gdn_range|
246
- return gdn_range if rank > max_pvs
247
- end
244
+ return unless rank
245
+
246
+ alexa_gdn.each do |max_pvs, gdn_range|
247
+ return gdn_range if rank > max_pvs
248
248
  end
249
249
  end
250
250
 
@@ -254,6 +254,7 @@ module Awis
254
254
  return rating if get_median_load_time > max_load_time
255
255
  end
256
256
  end
257
+
257
258
  'AVERAGE ( < 5s)'
258
259
  end
259
260
 
@@ -312,7 +313,8 @@ module Awis
312
313
  end
313
314
 
314
315
  class ContentData < BaseEntity
315
- attr_accessor :data_url, :site_title, :site_description, :online_since, :speed_median_load_time, :speed_percentile, :adult_content,
316
+ attr_accessor :data_url, :site_title, :site_description, :online_since,
317
+ :speed_median_load_time, :speed_percentile, :adult_content,
316
318
  :language_locale, :links_in_count, :owned_domains
317
319
 
318
320
  def initialize(options)
data/lib/awis/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Awis
4
- VERSION = '2.0.0'
4
+ VERSION = '2.1.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awis-sdk-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Encore Shao
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-12-04 00:00:00.000000000 Z
11
+ date: 2021-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sigv4