awis-sdk-ruby 1.1.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
- SHA1:
3
- metadata.gz: 3f60e08f71c0092e6c7ff4185e1e64a6af7776d9
4
- data.tar.gz: cb3a28d169416fb66d36ff7d662295b777709de7
2
+ SHA256:
3
+ metadata.gz: c1b8b0369cacf309ffff5b752c458d3465ef51b7b085fd9c55fce22f8651807d
4
+ data.tar.gz: a78a3affebba1ae56d03b0db2173044e29ae5139d02a8ea3051ba5a0b0708c13
5
5
  SHA512:
6
- metadata.gz: b27b1755fc104f0fc196f1ed91c5e0d93408f3fbd62ccb39b3f7d02c135e2a34eca4db3d4a8a60ee819e0b9bf84aa48c8a392da7e5ed1c4d139e2f4474c0d553
7
- data.tar.gz: 9d9e2c0011a964374a10a9d89680b57aeebbe44bc5333980f4e40fe163af26c699caecdfbf493f1222aa7f136c59ae084407409ea6223752ed78862f0bfff388
6
+ metadata.gz: 7229cf7a29ab8992f30e9aef6e51471250de75a7830a1021b4df1fb6d00ce5009fbf2b2410f9cb7903dfb580cda97b73b3f0080f49023d9bfac09a252eaa7c11
7
+ data.tar.gz: 503f910fbb860e7aab95022c0559a5c36418ddbd602e06cd6009dc07c305364075ef7b6e97987be08627773387add3f2be9710ed0bd48cb4921b7ee5754da4cd
data/.rubocop.yml CHANGED
@@ -84,4 +84,4 @@ Style/NumericLiterals:
84
84
  Enabled: false
85
85
 
86
86
  Rails:
87
- Enabled: true
87
+ Enabled: false
data/.travis.yml CHANGED
@@ -2,7 +2,6 @@ notifications:
2
2
  disabled: true
3
3
  bundler_args: --without extra
4
4
  rvm:
5
- - 1.9.3
6
5
  - 2.0.0
7
6
  - 2.1.1
8
7
  - 2.2.3
data/README.md CHANGED
@@ -1,63 +1,116 @@
1
1
  ## Amazon - Alexa Web Information Service (AWIS)
2
- Ruby Library for AWIS REST API - See: [Alexa Docs](http://docs.amazonwebservices.com/AlexaWebInfoService/latest/)
2
+ Ruby Library for AWIS REST API - see: [Alexa Docs](http://docs.amazonwebservices.com/AlexaWebInfoService/latest/)
3
3
 
4
4
  ### How to installation
5
5
 
6
- ```
6
+ ```ruby
7
7
  gem install awis-sdk-ruby
8
8
  ```
9
9
 
10
+ ### Support Ruby 2.x
11
+
12
+ - The latest update requires Ruby 2.0 or higher
13
+
10
14
  ### How to usage
11
15
 
12
16
  ##### Configure your amazon certificate
13
17
 
14
- ```
18
+ ```ruby
15
19
  require 'awis'
16
20
 
17
21
  AWIS_CONFIG = YAML.load(File.read('awis.yml'))
18
22
  Awis.config do |c|
19
- c.access_key_id = AWIS_CONFIG['access_key_id']
20
- c.secret_access_key = AWIS_CONFIG['secret_access_key']
21
- c.debug = AWIS_CONFIG['debug']
22
- c.protocol = 'https' # Default 'https'
23
- c.timeout = 10 # Default 10
24
- c.open_timeout = 10 # Default 10
25
- c.logger = false # Default nil
23
+ c.access_key_id = AWIS_CONFIG['access_key_id']
24
+ c.secret_access_key = AWIS_CONFIG['secret_access_key']
25
+ c.debug = AWIS_CONFIG['debug']
26
+ c.protocol = 'https' # Default 'https'
27
+ c.timeout = 10 # Default 10
28
+ c.open_timeout = 10 # Default 10
29
+ c.logger = false # Default nil
26
30
  end
27
31
  ```
28
32
 
29
- ##### Get UrlInfo Information
33
+ ##### Get Url Info
30
34
 
31
- ``` ruby
35
+ ```ruby
32
36
  client = Awis::Client.new
33
37
  url_info = client.url_info(url: "site.com")
34
38
  ```
35
39
 
36
40
  If you looking for the API request URI:
37
41
 
38
- * Awis::API::UrlInfo.new.load_request_uri(url: 'site.com')
39
-
42
+ ```ruby
43
+ Awis::API::UrlInfo.new.load_request_uri(url: 'site.com')
44
+ ```
40
45
 
41
- Returns object that contains attributes:
46
+ returns object that contains attributes:
42
47
 
43
48
  * data_url
44
49
  * rank
45
50
  * asin
46
-
47
- Returns object that contains relationships:
48
-
49
- * contact_info [:data_url, :owner_name, :email, :physical_address, :company_stock_ticker, :phone_numbers]
50
- * content_data [:data_url, :site_title, :site_description, :speed_median_load_time, :speed_percentile, :adult_content, :language_locale, :links_in_count, :owned_domains]
51
- * usage_statistics [:time_range_months, :time_range_days, :rank_value, :rank_delta, :reach_rank_value, :reach_rank_delta,
52
- :reach_per_million_value, :reach_per_million_delta, :reach_page_views_per_million_value, :reach_page_views_per_million_delta,
53
- :reach_page_views_rank_value, :reach_page_views_rank_delta, :reach_page_views_per_user_value, :reach_page_views_per_user_delta]
54
- - add two methods: [range_type, range_count]
55
- * related_links [:data_url, :navigable_url, :title]
56
- * categories [:title, :absolute_path]
51
+ * xml
57
52
 
58
53
  New methods:
59
54
 
60
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
+
61
+ returns object that contains relationships:
62
+
63
+ **contact_info**
64
+ - attrubutes
65
+ - data_url
66
+ - owner_name
67
+ - email
68
+ - physical_address
69
+ - company_stock_ticker
70
+ - phone_numbers
71
+
72
+ **content_data**
73
+ - attrubutes
74
+ - data_url
75
+ - site_title
76
+ - site_description
77
+ - speed_median_load_time
78
+ - speed_percentile
79
+ - adult_content
80
+ - language_locale
81
+ - links_in_count
82
+ - owned_domains
83
+
84
+ **usage_statistics**
85
+ - attrubutes
86
+ - time_range_months
87
+ - time_range_days
88
+ - rank_value
89
+ - rank_delta
90
+ - reach_rank_value
91
+ - reach_rank_delta,
92
+ - reach_per_million_value
93
+ - reach_per_million_delta
94
+ - page_views_per_million_value
95
+ - page_views_per_million_delta,
96
+ - page_views_rank_value
97
+ - page_views_rank_delta
98
+ - page_views_per_user_value
99
+ - page_views_per_user_delta
100
+ - Methods:
101
+ - range_type
102
+ - range_count
103
+
104
+ **related_links**
105
+ - attrubutes
106
+ - data_url
107
+ - navigable_url
108
+ - title
109
+
110
+ **categories**
111
+ - attrubutes
112
+ - title
113
+ - absolute_path
61
114
 
62
115
  You can specify options:
63
116
 
@@ -66,14 +119,16 @@ You can specify options:
66
119
 
67
120
  ##### Get Sites Linking In
68
121
 
69
- ``` ruby
122
+ ```ruby
70
123
  client = Awis::Client.new
71
124
  sites_linking_in = client.sites_linking_in(url: "site.com")
72
125
  ```
73
126
 
74
127
  If you looking for the API request URI:
75
128
 
76
- * Awis::API::SitesLinkingIn.new.load_request_uri(url: 'site.com')
129
+ ```ruby
130
+ Awis::API::SitesLinkingIn.new.load_request_uri(url: 'site.com')
131
+ ```
77
132
 
78
133
  Returns object that contains relationships:
79
134
 
@@ -87,14 +142,16 @@ You can specify options:
87
142
 
88
143
  ##### Get Traffic History
89
144
 
90
- ``` ruby
145
+ ```ruby
91
146
  client = Awis::Client.new
92
147
  traffic_history = client.traffic_history(url: "site.com")
93
148
  ```
94
149
 
95
150
  If you looking for the API request URI:
96
151
 
97
- * Awis::API::TrafficHistory.new.load_request_uri(url: 'site.com')
152
+ ```ruby
153
+ Awis::API::TrafficHistory.new.load_request_uri(url: 'site.com')
154
+ ```
98
155
 
99
156
  Returns object that contains methods:
100
157
 
@@ -114,14 +171,16 @@ You can specify options:
114
171
 
115
172
  ##### Get Category Listings
116
173
 
117
- ``` ruby
174
+ ```ruby
118
175
  client = Awis::Client.new
119
176
  category_listings = client.category_listings(path: "Top/Arts")
120
177
  ```
121
178
 
122
179
  If you looking for the API request URI:
123
180
 
124
- * Awis::API::CategoryListings.new.load_request_uri(path: "Top/Games/Card_Games")
181
+ ```ruby
182
+ Awis::API::CategoryListings.new.load_request_uri(path: "Top/Games/Card_Games")
183
+ ```
125
184
 
126
185
  Returns object that contains methods:
127
186
 
@@ -134,14 +193,16 @@ Returns object that contains relationships:
134
193
 
135
194
  ##### Get Category Browse
136
195
 
137
- ``` ruby
196
+ ```ruby
138
197
  client = Awis::Client.new
139
198
  category_browses = client.category_browse(path: "Top/Arts")
140
199
  ```
141
200
 
142
201
  If you looking for the API request URI:
143
202
 
144
- * Awis::API::CategoryBrowse.new.load_request_uri(path: "Top/Games/Card_Games")
203
+ ```ruby
204
+ Awis::API::CategoryBrowse.new.load_request_uri(path: "Top/Games/Card_Games")
205
+ ```
145
206
 
146
207
  Returns object that contains methods:
147
208
 
@@ -156,7 +217,7 @@ Returns object that contains relationships:
156
217
 
157
218
  ##### How to run test
158
219
 
159
- * rake test
220
+ * bundle exec rake test
160
221
 
161
222
  ##### Request ID and Status Code
162
223
 
data/awis.gemspec CHANGED
@@ -1,8 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- lib = File.expand_path('lib', __dir__)
4
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require 'awis/version'
3
+ require_relative "./lib/awis/version"
6
4
 
7
5
  Gem::Specification.new do |spec|
8
6
  spec.name = 'awis-sdk-ruby'
data/lib/awis.rb CHANGED
@@ -4,19 +4,19 @@ require 'multi_xml'
4
4
  require 'nokogiri'
5
5
  require 'aws-sigv4'
6
6
 
7
- require 'awis/version'
8
- require 'awis/hash'
9
- require 'awis/utils'
10
- require 'awis/exceptions'
11
- require 'awis/connection'
12
- require 'awis/config'
13
- require 'awis/client'
14
- require 'awis/api'
15
- require 'awis/models'
7
+ require_relative './awis/version'
8
+ require_relative './awis/hash'
9
+ require_relative './awis/utils'
10
+ require_relative './awis/exceptions'
11
+ require_relative './awis/connection'
12
+ require_relative './awis/config'
13
+ require_relative './awis/client'
14
+ require_relative './awis/api'
15
+ require_relative './awis/models'
16
16
 
17
17
  module Awis
18
18
  SERVICE_PATH = 'api'
19
19
  SERVICE_NAME = 'awis'
20
20
  SERVICE_REGION = 'us-west-1'
21
- SERVICE_HOST = "#{SERVICE_NAME}.amazonaws.com"
21
+ SERVICE_HOST = "#{SERVICE_NAME}.#{SERVICE_REGION}.amazonaws.com"
22
22
  end
data/lib/awis/api.rb CHANGED
@@ -1,5 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative './api/base'
4
+ require_relative './api/url_info'
5
+ require_relative './api/traffic_history'
6
+ require_relative './api/sites_linking_in'
7
+ require_relative './api/category_listings'
8
+ require_relative './api/category_browse'
9
+
3
10
  module Awis
4
11
  module API
5
12
  autoload :Base, 'awis/api/base'
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)
@@ -28,7 +28,7 @@ module Awis
28
28
 
29
29
  @arguments = arguments
30
30
  @arguments[:range] = arguments.fetch(:range, 31)
31
- @arguments[:start] = arguments.fetch(:start) { Time.zone.now - (3600 * 24 * @arguments[:range].to_i) }
31
+ @arguments[:start] = arguments.fetch(:start) { Time.now - (3600 * 24 * @arguments[:range].to_i) }
32
32
  end
33
33
 
34
34
  def start_date
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
@@ -10,14 +10,14 @@ module Awis
10
10
  attr_reader :params, :secret_access_key, :access_key_id
11
11
 
12
12
  HEADERS = {
13
- 'Content-Type' => 'application/xml',
14
- 'Accept' => 'application/xml',
15
- 'User-Agent' => "awis-sdk-ruby v#{Awis::VERSION}"
13
+ 'accept' => 'application/xml',
14
+ 'content-type' => 'application/xml',
15
+ 'user-agent' => "awis-sdk-ruby v#{Awis::VERSION}"
16
16
  }.freeze
17
17
 
18
18
  def initialize(options = {})
19
- @secret_access_key = options.fetch(:secret_access_key, Awis.config.access_key_id)
20
- @access_key_id = options.fetch(:access_key_id, Awis.config.secret_access_key)
19
+ @secret_access_key = options.fetch(:secret_access_key, Awis.config.secret_access_key)
20
+ @access_key_id = options.fetch(:access_key_id, Awis.config.access_key_id)
21
21
  raise CertificateError, 'Amazon access certificate is missing!' if @secret_access_key.nil? || @access_key_id.nil?
22
22
 
23
23
  setup_options!
@@ -31,13 +31,20 @@ module Awis
31
31
  end
32
32
 
33
33
  def get(params = {})
34
+ set_params(params)
35
+
36
+ handle_response(request).body
37
+ end
38
+
39
+ def set_params(params)
34
40
  @params = params
35
- handle_response(request).body.force_encoding(Encoding::UTF_8)
36
41
  end
37
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
@@ -77,7 +84,7 @@ module Awis
77
84
  end
78
85
 
79
86
  def uri
80
- @uri ||= URI.parse("#{protocol}://#{Awis::SERVICE_HOST}/#{Awis::SERVICE_PATH}?" << query)
87
+ @uri ||= URI.parse("#{protocol}://#{Awis::SERVICE_HOST}/#{Awis::SERVICE_PATH}?#{query}")
81
88
  end
82
89
 
83
90
  def headers
data/lib/awis/models.rb CHANGED
@@ -1,5 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative './models/base'
4
+ require_relative './models/base_entity'
5
+ require_relative './models/url_info'
6
+ require_relative './models/traffic_history'
7
+ require_relative './models/sites_linking_in'
8
+ require_relative './models/category_listings'
9
+ require_relative './models/category_browse'
10
+
3
11
  module Awis
4
12
  module Models
5
13
  autoload :Base, 'awis/models/base'
@@ -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
@@ -3,14 +3,17 @@
3
3
  module Awis
4
4
  module Models
5
5
  class UrlInfo < Base
6
- attr_accessor :data_url, :rank, :asin, :contact_info, :content_data, :usage_statistics, :related_links, :categories
6
+ attr_accessor :data_url, :rank, :asin, :contact_info, :content_data, :usage_statistics, :related_links,
7
+ :categories, :contributing_subdomains, :rank_by_country
7
8
 
8
9
  def initialize(response)
9
10
  @usage_statistics = []
10
11
  @related_links = []
11
12
  @categories = []
13
+ @contributing_subdomains = []
14
+ @rank_by_country = []
12
15
 
13
- setup_data! loading_response(response)
16
+ super(response)
14
17
  end
15
18
 
16
19
  def setup_data!(response)
@@ -23,94 +26,122 @@ module Awis
23
26
  statistics = []
24
27
  related_related_links = []
25
28
  category_data = []
29
+ rank_by_country = []
30
+ contributing_subdomains = []
26
31
 
27
32
  response.each_node do |node, path|
28
33
  text = node.inner_xml
29
- text = text.to_i if text.to_i.to_s == text && node.name != 'aws:Delta'
30
- text = nil if text.class == String && text.empty?
34
+ candidate_text = text.delete(',')
35
+ value = if integer_value?(candidate_text) && node.name != 'aws:Delta'
36
+ candidate_text.to_i
37
+ elsif float_value?(candidate_text)
38
+ candidate_text.to_f
39
+ elsif text.is_a?(String) && text.empty?
40
+ nil
41
+ else
42
+ text
43
+ end
31
44
 
32
45
  if node.name == 'aws:RequestId'
33
- @request_id ||= text
46
+ @request_id ||= value
34
47
  elsif node.name == 'aws:StatusCode'
35
- @status_code ||= text
48
+ @status_code ||= value
36
49
  elsif node.name == 'aws:DataUrl' && path == "#{traffic_node_name}/aws:DataUrl"
37
- @data_url = text
50
+ @data_url = value
38
51
  elsif node.name == 'aws:Asin' && path == "#{traffic_node_name}/aws:Asin"
39
- @asin = text
52
+ @asin = value
40
53
  elsif node.name == 'aws:Rank' && path == "#{traffic_node_name}/aws:Rank"
41
- @rank = text
54
+ @rank = value
42
55
  elsif node.name == 'aws:DataUrl' && path == "#{content_node_name}/aws:DataUrl"
43
- content_data[:data_url] = text
56
+ content_data[:data_url] = value
44
57
  elsif node.name == 'aws:Title' && path == "#{content_node_name}/aws:SiteData/aws:Title"
45
- content_data[:site_title] = text
58
+ content_data[:site_title] = value
46
59
  elsif node.name == 'aws:Description'
47
- content_data[:site_description] = text
60
+ content_data[:site_description] = value
48
61
  elsif node.name == 'aws:MedianLoadTime'
49
- content_data[:speed_median_load_time] = text
62
+ content_data[:speed_median_load_time] = value
50
63
  elsif node.name == 'aws:Percentile'
51
- content_data[:speed_percentile] = text
64
+ content_data[:speed_percentile] = value
52
65
  elsif node.name == 'aws:AdultContent'
53
- content_data[:adult_content] = text
66
+ content_data[:adult_content] = value
54
67
  elsif node.name == 'aws:Locale'
55
- content_data[:language_locale] = text
68
+ content_data[:language_locale] = value
56
69
  elsif node.name == 'aws:LinksInCount'
57
- content_data[:links_in_count] = text
70
+ content_data[:links_in_count] = value
58
71
  elsif node.name == 'aws:Domain' && path == "#{content_node_name}/aws:OwnedDomains/aws:OwnedDomain/aws:Domain"
59
- content_data[:owned_domains] << { domain: text }
72
+ content_data[:owned_domains] << { domain: value }
60
73
  elsif node.name == 'aws:Title' && path == "#{content_node_name}/aws:OwnedDomains/aws:OwnedDomain/aws:Title"
61
- content_data[:owned_domains] << { title: text }
74
+ content_data[:owned_domains] << { title: value }
62
75
  elsif node.name == 'aws:OnlineSince'
63
- content_data[:online_since] = text
76
+ content_data[:online_since] = value
64
77
  elsif node.name == 'aws:DataUrl' && path == "#{root_node_name}/aws:ContactInfo/aws:DataUrl"
65
- contact_info[:data_url] = text
78
+ contact_info[:data_url] = value
66
79
  elsif node.name == 'aws:OwnerName'
67
- contact_info[:owner_name] = text
80
+ contact_info[:owner_name] = value
68
81
  elsif node.name == 'aws:Email'
69
- contact_info[:email] = text
82
+ contact_info[:email] = value
70
83
  elsif node.name == 'aws:PhysicalAddress'
71
- contact_info[:physical_address] = text
84
+ contact_info[:physical_address] = value
72
85
  elsif node.name == 'aws:CompanyStockTicker'
73
- contact_info[:company_stock_ticker] = text
86
+ contact_info[:company_stock_ticker] = value
74
87
  elsif node.name == 'aws:PhoneNumber'
75
- contact_info[:phone_numbers] << text
88
+ contact_info[:phone_numbers] << value
76
89
  elsif node.name == 'aws:DataUrl' && path == "#{related_links_node_name}/aws:DataUrl"
77
- related_related_links << { data_url: text }
90
+ related_related_links << { data_url: value }
78
91
  elsif node.name == 'aws:NavigableUrl' && path == "#{related_links_node_name}/aws:NavigableUrl"
79
- related_related_links << { navigable_url: text }
92
+ related_related_links << { navigable_url: value }
80
93
  elsif node.name == 'aws:Title' && path == "#{related_links_node_name}/aws:Title"
81
- related_related_links << { title: text }
94
+ related_related_links << { title: value }
82
95
  elsif node.name == 'aws:Title' && path == "#{categories_node_name}/aws:Title"
83
- category_data << { title: text }
96
+ category_data << { title: value }
84
97
  elsif node.name == 'aws:AbsolutePath' && path == "#{categories_node_name}/aws:AbsolutePath"
85
- category_data << { absolute_path: text }
98
+ category_data << { absolute_path: value }
86
99
  elsif node.name == 'aws:Months' && path == "#{statistic_node_name}/aws:TimeRange/aws:Months"
87
- statistics << { time_range_months: text }
100
+ statistics << { time_range_months: value }
88
101
  elsif node.name == 'aws:Days' && path == "#{statistic_node_name}/aws:TimeRange/aws:Days"
89
- statistics << { time_range_days: text }
102
+ statistics << { time_range_days: value }
90
103
  elsif node.name == 'aws:Value' && path == "#{statistic_node_name}/aws:Rank/aws:Value"
91
- statistics << { rank_value: text }
104
+ statistics << { rank_value: value }
92
105
  elsif node.name == 'aws:Delta' && path == "#{statistic_node_name}/aws:Rank/aws:Delta"
93
- statistics << { rank_delta: text }
106
+ statistics << { rank_delta: value }
94
107
  elsif node.name == 'aws:Value' && path == "#{statistic_node_name}/aws:Reach/aws:Rank/aws:Value"
95
- statistics << { reach_rank_value: text }
108
+ statistics << { reach_rank_value: value }
96
109
  elsif node.name == 'aws:Delta' && path == "#{statistic_node_name}/aws:Reach/aws:Rank/aws:Delta"
97
- statistics << { reach_rank_delta: text }
110
+ statistics << { reach_rank_delta: value }
98
111
  elsif node.name == 'aws:Value' && path == "#{statistic_node_name}/aws:Reach/aws:PerMillion/aws:Value"
99
- statistics << { reach_per_million_value: text }
112
+ statistics << { reach_per_million_value: value }
100
113
  elsif node.name == 'aws:Delta' && path == "#{statistic_node_name}/aws:Reach/aws:PerMillion/aws:Delta"
101
- statistics << { reach_per_million_delta: text }
114
+ statistics << { reach_per_million_delta: value }
102
115
  elsif node.name == 'aws:Value' && path == "#{statistic_node_name}/aws:PageViews/aws:PerMillion/aws:Value"
103
- statistics << { reach_page_views_per_million_value: text }
116
+ statistics << { page_views_per_million_value: value }
104
117
  elsif node.name == 'aws:Delta' && path == "#{statistic_node_name}/aws:PageViews/aws:PerMillion/aws:Delta"
105
- statistics << { reach_page_views_per_million_delta: text }
118
+ statistics << { page_views_per_million_delta: value }
106
119
  elsif node.name == 'aws:Value' && path == "#{statistic_node_name}/aws:PageViews/aws:Rank/aws:Value"
107
- statistics << { reach_page_views_rank_value: text }
120
+ statistics << { page_views_rank_value: value }
108
121
  elsif node.name == 'aws:Delta' && path == "#{statistic_node_name}/aws:PageViews/aws:Rank/aws:Delta"
109
- statistics << { reach_page_views_rank_delta: text }
122
+ statistics << { page_views_rank_delta: value }
110
123
  elsif node.name == 'aws:Value' && path == "#{statistic_node_name}/aws:PageViews/aws:PerUser/aws:Value"
111
- statistics << { reach_page_views_per_user_value: text }
124
+ statistics << { page_views_per_user_value: value }
112
125
  elsif node.name == 'aws:Delta' && path == "#{statistic_node_name}/aws:PageViews/aws:PerUser/aws:Delta"
113
- statistics << { reach_page_views_per_user_delta: text }
126
+ statistics << { page_views_per_user_delta: value }
127
+ elsif node.name == 'aws:Country' && path == rank_by_country_node_name
128
+ rank_by_country << { country_code: node.attributes['Code'] }
129
+ elsif node.name == 'aws:Rank' && path == "#{rank_by_country_node_name}/aws:Rank"
130
+ rank_by_country << { rank: value }
131
+ elsif node.name == 'aws:PageViews' && path == "#{rank_by_country_node_name}/aws:Contribution/aws:PageViews"
132
+ rank_by_country << { contribution_page_views: value }
133
+ elsif node.name == 'aws:Users' && path == "#{rank_by_country_node_name}/aws:Contribution/aws:Users"
134
+ rank_by_country << { contribution_users: value }
135
+ elsif node.name == 'aws:DataUrl' && path == "#{contributing_subdomains_node_name}/aws:DataUrl"
136
+ contributing_subdomains << { data_url: value }
137
+ elsif node.name == 'aws:Months' && path == "#{contributing_subdomains_node_name}/aws:TimeRange/aws:Months"
138
+ contributing_subdomains << { time_range_months: value }
139
+ elsif node.name == 'aws:Percentage' && path == "#{contributing_subdomains_node_name}/aws:Reach/aws:Percentage"
140
+ contributing_subdomains << { reach_percentage: value }
141
+ elsif node.name == 'aws:Percentage' && path == "#{contributing_subdomains_node_name}/aws:PageViews/aws:Percentage"
142
+ contributing_subdomains << { page_views_percentage: value }
143
+ elsif node.name == 'aws:PerUser' && path == "#{contributing_subdomains_node_name}/aws:PageViews/aws:PerUser"
144
+ contributing_subdomains << { page_views_per_user: value }
114
145
  end
115
146
  end
116
147
 
@@ -120,10 +151,8 @@ module Awis
120
151
  relationship_collections(@usage_statistics, statistics, 13, UsageStatistic)
121
152
  relationship_collections(@related_links, related_related_links, 3, RelatedLink)
122
153
  relationship_collections(@categories, category_data, 3, CategoryData)
123
- end
124
-
125
- def is_404?
126
- success? && rank == 404
154
+ relationship_collections(@rank_by_country, rank_by_country, 4, RankByCountry)
155
+ relationship_collections(@contributing_subdomains, contributing_subdomains, 5, ContributingSubdomain)
127
156
  end
128
157
 
129
158
  def init_entity_data(attr_name, data, kclass)
@@ -155,10 +184,137 @@ module Awis
155
184
  def statistic_node_name
156
185
  "#{traffic_node_name}/aws:UsageStatistics/aws:UsageStatistic"
157
186
  end
187
+
188
+ def contributing_subdomains_node_name
189
+ "#{traffic_node_name}/aws:ContributingSubdomains/aws:ContributingSubdomain"
190
+ end
191
+
192
+ def rank_by_country_node_name
193
+ "#{traffic_node_name}/aws:RankByCountry/aws:Country"
194
+ end
195
+
196
+ def has_data?
197
+ !@rank.nil?
198
+ end
199
+
200
+ def geos_sorted
201
+ rank_by_country.select { |rbc| !rbc.rank.nil? && !rbc.contribution_page_views.nil? }.
202
+ sort_by { |rbc| - rbc.contribution_page_views.round }.
203
+ map { |rbc| { rbc.country_code => rbc.contribution_page_views.round } }
204
+ end
205
+
206
+ def geos_hash
207
+ @geos_hash ||= geos_sorted.reduce({}, :merge)
208
+ end
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
+ def domains
216
+ content_data.owned_domains.map(&:domain)
217
+ end
218
+
219
+ def contributing_hostnames
220
+ contributing_subdomains.map(&:data_url).reject { |hostname| hostname == 'OTHER' }
221
+ end
222
+
223
+ def pvs_per_user
224
+ usage_statistics.first.page_views_per_user_value
225
+ end
226
+
227
+ def pvs_rank
228
+ usage_statistics.first.page_views_rank_value
229
+ end
230
+
231
+ def get_pvs_per_mil
232
+ usage_statistics.first.page_views_per_million_value
233
+ end
234
+
235
+ def speed_percentile
236
+ content_data.speed_percentile
237
+ end
238
+
239
+ def get_median_load_time
240
+ content_data.speed_median_load_time
241
+ end
242
+
243
+ def daily_GDN_page_views
244
+ return unless rank
245
+
246
+ alexa_gdn.each do |max_pvs, gdn_range|
247
+ return gdn_range if rank > max_pvs
248
+ end
249
+ end
250
+
251
+ def speed_rating
252
+ if get_median_load_time
253
+ alexa_speed_rating.each do |max_load_time, rating|
254
+ return rating if get_median_load_time > max_load_time
255
+ end
256
+ end
257
+
258
+ 'AVERAGE ( < 5s)'
259
+ end
260
+
261
+ def alexa_speed_rating
262
+ {
263
+ 2200 => 'POOR ( > 5s)',
264
+ 1200 => 'AVERAGE ( < 5s)',
265
+ 0 => 'GOOD ( < 3s)'
266
+ }
267
+ end
268
+
269
+ def rank_page_view
270
+ {
271
+ 20000 => '< 1K',
272
+ 5000 => '1K - 10K',
273
+ 3000 => '10K - 100K',
274
+ 1900 => '100K - 500K',
275
+ 1300 => '500K - 1M',
276
+ 850 => '2M - 5M',
277
+ 550 => '5M - 10M',
278
+ 350 => '10M - 20M',
279
+ 200 => '20M - 50M',
280
+ 100 => '50M - 100M',
281
+ 28 => '100M+'
282
+ }
283
+ end
284
+
285
+ def alexa_gdn
286
+ {
287
+ 250000 => '< 1K',
288
+ 100000 => '1K - 10K',
289
+ 50000 => '10K - 100K',
290
+ 20000 => '100K - 500K',
291
+ 10000 => '500K - 1M',
292
+ 5000 => '1M - 2M',
293
+ 2000 => '2M - 5M',
294
+ 1000 => '5M - 10M',
295
+ 500 => '10M - 20M',
296
+ 150 => '20M - 50M',
297
+ 30 => '50M - 100M',
298
+ 0 => '100M+'
299
+ }
300
+ end
301
+
302
+ private
303
+
304
+ def integer_value?(text)
305
+ text.to_i.to_s == text
306
+ end
307
+
308
+ def float_value?(text)
309
+ !!Float(text.delete('%'))
310
+ rescue ::StandardError
311
+ false
312
+ end
158
313
  end
159
314
 
160
315
  class ContentData < BaseEntity
161
- 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,
162
318
  :language_locale, :links_in_count, :owned_domains
163
319
 
164
320
  def initialize(options)
@@ -190,7 +346,7 @@ module Awis
190
346
  end
191
347
 
192
348
  def phone_number_collections(phone_numbers)
193
- return @phone_numbers = [] if phone_numbers.blank?
349
+ return @phone_numbers = [] if phone_numbers.nil? || phone_numbers.empty?
194
350
 
195
351
  phone_numbers.map { |item| @phone_numbers << PhoneNumber.new(item) }
196
352
  end
@@ -212,12 +368,12 @@ module Awis
212
368
  attr_accessor :time_range_months, :time_range_days, :rank_value, :rank_delta,
213
369
  :reach_rank_value, :reach_rank_delta,
214
370
  :reach_per_million_value, :reach_per_million_delta,
215
- :reach_page_views_per_million_value, :reach_page_views_per_million_delta,
216
- :reach_page_views_rank_value, :reach_page_views_rank_delta,
217
- :reach_page_views_per_user_value, :reach_page_views_per_user_delta
371
+ :page_views_per_million_value, :page_views_per_million_delta,
372
+ :page_views_rank_value, :page_views_rank_delta,
373
+ :page_views_per_user_value, :page_views_per_user_delta
218
374
 
219
375
  def range_type
220
- return 'month' if time_range_months.present?
376
+ return 'month' unless time_range_months.nil?
221
377
 
222
378
  'day'
223
379
  end
@@ -226,5 +382,13 @@ module Awis
226
382
  (time_range_months || time_range_days)
227
383
  end
228
384
  end
385
+
386
+ class ContributingSubdomain < BaseEntity
387
+ attr_accessor :data_url, :time_range_months, :reach_percentage, :page_views_percentage, :page_views_per_user
388
+ end
389
+
390
+ class RankByCountry < BaseEntity
391
+ attr_accessor :country_code, :rank, :contribution_page_views, :contribution_users
392
+ end
229
393
  end
230
394
  end
data/lib/awis/utils.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'awis/utils/extra'
4
- require 'awis/utils/variable'
3
+ require_relative './utils/extra'
4
+ require_relative './utils/variable'
5
+ require_relative './utils/xml'
5
6
 
6
7
  module Awis
7
8
  module Utils
@@ -3,6 +3,8 @@
3
3
  module Awis
4
4
  module Utils
5
5
  class XML
6
+ attr_reader :data
7
+
6
8
  def initialize(data)
7
9
  @data = data
8
10
  end
data/lib/awis/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Awis
4
- VERSION = '1.1.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: 1.1.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Encore Shao
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-10-02 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
@@ -168,7 +168,7 @@ files:
168
168
  homepage: https://github.com/encoreshao/amazon-awis
169
169
  licenses: []
170
170
  metadata: {}
171
- post_install_message:
171
+ post_install_message:
172
172
  rdoc_options: []
173
173
  require_paths:
174
174
  - lib
@@ -183,9 +183,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
183
183
  - !ruby/object:Gem::Version
184
184
  version: '0'
185
185
  requirements: []
186
- rubyforge_project:
187
- rubygems_version: 2.6.11
188
- signing_key:
186
+ rubygems_version: 3.0.3
187
+ signing_key:
189
188
  specification_version: 4
190
189
  summary: Ruby - Amazon Alexa Web Information Service Library (AWIS)
191
190
  test_files: []