awis-sdk-ruby 0.0.1

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.
@@ -0,0 +1,59 @@
1
+ module Awis
2
+ module Models
3
+ class TrafficHistory < Base
4
+ attr_accessor :range, :site, :start, :historical_data
5
+
6
+ def initialize(response)
7
+ @historical_data = []
8
+ setup_data!( loading_response(response) )
9
+ end
10
+
11
+ def setup_data!(response)
12
+ datas = []
13
+
14
+ response.each_node do |node, path|
15
+ text = node.inner_xml
16
+ text = text.to_i if text.to_i.to_s === text
17
+
18
+ if node.name == 'aws:RequestId'
19
+ @request_id ||= text
20
+ elsif node.name == 'aws:StatusCode'
21
+ @status_code ||= text
22
+ elsif node.name == 'aws:Range'
23
+ @range ||= text
24
+ elsif node.name == 'aws:Site'
25
+ @site ||= text
26
+ elsif node.name == 'aws:Start'
27
+ @start ||= text
28
+ elsif node.name == 'aws:Rank'
29
+ @rank ||= text
30
+ elsif node.name == 'aws:Date' && path == "#{base_node_name}/aws:Date"
31
+ datas << { date: text }
32
+ elsif node.name == 'aws:PerMillion' && path == "#{base_node_name}/aws:PageViews/aws:PerMillion"
33
+ datas << { page_views_per_million: text }
34
+ elsif node.name == 'aws:PerUser' && path == "#{base_node_name}/aws:PageViews/aws:PerUser"
35
+ datas << { page_views_per_user: text }
36
+ elsif node.name == 'aws:PerMillion' && path == "#{base_node_name}/aws:Rank"
37
+ datas << { rank: text }
38
+ elsif node.name == 'aws:PerMillion' && path == "#{base_node_name}/aws:Reach/aws:PerMillion"
39
+ datas << { reach_per_million: text }
40
+ end
41
+ end
42
+
43
+ relationship_collections(@historical_data, datas, 5, HistoricalData)
44
+ end
45
+
46
+ def base_node_name
47
+ "#{root_node_name}/aws:TrafficHistory/aws:HistoricalData/aws:Data"
48
+ end
49
+ end
50
+
51
+ class HistoricalData
52
+ attr_accessor :date, :page_views_per_million, :page_views_per_user, :rank, :reach_per_million
53
+
54
+ def initialize(hash)
55
+ hash.map { |k, v| instance_variable_set("@#{k}", v) }
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,206 @@
1
+ module Awis
2
+ module Models
3
+ class UrlInfo < Base
4
+ attr_accessor :data_url, :rank, :asin, :contact_info, :content_data, :usage_statistics, :related_links, :categories
5
+
6
+ def initialize(response)
7
+ @usage_statistics = []
8
+ @related_links = []
9
+ @categories = []
10
+ setup_data!( loading_response(response) )
11
+ end
12
+
13
+ def setup_data!(response)
14
+ content_data = { }
15
+ contact_info = {
16
+ phone_number: []
17
+ }
18
+ statistics = []
19
+ related_related_links = []
20
+ category_data = []
21
+
22
+ response.each_node do |node, path|
23
+ text = node.inner_xml
24
+ text = text.to_i if text.to_i.to_s === text && node.name != 'aws:Delta'
25
+
26
+ if node.name == 'aws:RequestId'
27
+ @request_id ||= text
28
+ elsif node.name == 'aws:StatusCode'
29
+ @status_code ||= text
30
+ elsif node.name == 'aws:DataUrl' && path == "#{traffic_node_name}/aws:DataUrl"
31
+ @data_url = text
32
+ elsif node.name == 'aws:Asin' && path == "#{traffic_node_name}/aws:Asin"
33
+ @asin = text
34
+ elsif node.name == 'aws:Rank' && path == "#{traffic_node_name}/aws:Rank"
35
+ @rank = text
36
+ elsif node.name == 'aws:DataUrl' && path == "#{content_node_name}/aws:DataUrl"
37
+ content_data[:data_url] = text
38
+ elsif node.name == 'aws:Title' && path == "#{content_node_name}/aws:SiteData/aws:Title"
39
+ content_data[:site_title] = text
40
+ elsif node.name == 'aws:Description'
41
+ content_data[:site_description] = text
42
+ elsif node.name == 'aws:MedianLoadTime'
43
+ content_data[:speed_median_load_time] = text
44
+ elsif node.name == 'aws:Percentile'
45
+ content_data[:speed_percentile] = text
46
+ elsif node.name == 'aws:AdultContent'
47
+ content_data[:adult_content] = text
48
+ elsif node.name == 'aws:Locale'
49
+ content_data[:language_locale] = text
50
+ elsif node.name == 'aws:LinksInCount'
51
+ content_data[:links_in_count] = text
52
+ elsif node.name == 'aws:OwnedDomains'
53
+ content_data[:owned_domains] = text
54
+ elsif node.name == 'aws:DataUrl' && path == "#{root_node_name}/aws:ContactInfo/aws:DataUrl"
55
+ contact_info[:data_url] = text
56
+ elsif node.name == 'aws:OwnerName'
57
+ contact_info[:owner_name] = text
58
+ elsif node.name == 'aws:Email'
59
+ contact_info[:email] = text
60
+ elsif node.name == 'aws:PhysicalAddress'
61
+ contact_info[:physical_address] = text
62
+ elsif node.name == 'aws:CompanyStockTicker'
63
+ contact_info[:company_stock_ticker] = text
64
+ elsif node.name == 'aws:PhoneNumber'
65
+ contact_info[:phone_numbers] << text
66
+ elsif node.name == 'aws:DataUrl' && path == "#{related_links_node_name}/aws:DataUrl"
67
+ related_related_links << { data_url: text }
68
+ elsif node.name == 'aws:NavigableUrl' && path == "#{related_links_node_name}/aws:NavigableUrl"
69
+ related_related_links << { navigable_url: text }
70
+ elsif node.name == 'aws:Title' && path == "#{related_links_node_name}/aws:Title"
71
+ related_related_links << { title: text }
72
+ elsif node.name == 'aws:Title' && path == "#{categories_node_name}/aws:Title"
73
+ category_data << { title: text }
74
+ elsif node.name == 'aws:AbsolutePath' && path == "#{categories_node_name}/aws:AbsolutePath"
75
+ category_data << { absolute_path: text }
76
+ elsif node.name == 'aws:Months' && path == "#{statistic_node_name}/aws:TimeRange/aws:Months"
77
+ statistics << { time_range_months: text }
78
+ elsif node.name == 'aws:Days' && path == "#{statistic_node_name}/aws:TimeRange/aws:Days"
79
+ statistics << { time_range_days: text }
80
+ elsif node.name == 'aws:Value' && path == "#{statistic_node_name}/aws:Rank/aws:Value"
81
+ statistics << { rank_value: text }
82
+ elsif node.name == 'aws:Delta' && path == "#{statistic_node_name}/aws:Rank/aws:Delta"
83
+ statistics << { rank_delta: text }
84
+ elsif node.name == 'aws:Value' && path == "#{statistic_node_name}/aws:Reach/aws:Rank/aws:Value"
85
+ statistics << { reach_rank_value: text }
86
+ elsif node.name == 'aws:Delta' && path == "#{statistic_node_name}/aws:Reach/aws:Rank/aws:Delta"
87
+ statistics << { reach_rank_delta: text }
88
+ elsif node.name == 'aws:Value' && path == "#{statistic_node_name}/aws:Reach/aws:PerMillion/aws:Value"
89
+ statistics << { reach_per_million_value: text }
90
+ elsif node.name == 'aws:Delta' && path == "#{statistic_node_name}/aws:Reach/aws:PerMillion/aws:Delta"
91
+ statistics << { reach_per_million_delta: text }
92
+ elsif node.name == 'aws:Value' && path == "#{statistic_node_name}/aws:PageViews/aws:PerMillion/aws:Value"
93
+ statistics << { reach_page_views_per_million_value: text }
94
+ elsif node.name == 'aws:Delta' && path == "#{statistic_node_name}/aws:PageViews/aws:PerMillion/aws:Delta"
95
+ statistics << { reach_page_views_per_million_delta: text }
96
+ elsif node.name == 'aws:Value' && path == "#{statistic_node_name}/aws:PageViews/aws:Rank/aws:Value"
97
+ statistics << { reach_page_views_rank_value: text }
98
+ elsif node.name == 'aws:Delta' && path == "#{statistic_node_name}/aws:PageViews/aws:Rank/aws:Delta"
99
+ statistics << { reach_page_views_rank_delta: text }
100
+ elsif node.name == 'aws:Value' && path == "#{statistic_node_name}/aws:PageViews/aws:PerUser/aws:Value"
101
+ statistics << { reach_page_views_per_user_value: text }
102
+ elsif node.name == 'aws:Delta' && path == "#{statistic_node_name}/aws:PageViews/aws:PerUser/aws:Delta"
103
+ statistics << { reach_page_views_per_user_delta: text }
104
+ end
105
+ end
106
+
107
+ init_entity_data('content_data', content_data, ContentData)
108
+ init_entity_data('contact_info', contact_info, ContactInfo)
109
+
110
+ relationship_collections(@usage_statistics, statistics, 13, UsageStatistic)
111
+ relationship_collections(@related_links, related_related_links, 3, RelatedLink)
112
+ relationship_collections(@categories, category_data, 3, CategoryData)
113
+ end
114
+
115
+ def init_entity_data(attr_name, data, kclass)
116
+ return if data.empty?
117
+
118
+ instance_variable_set("@#{attr_name}", kclass.new(data))
119
+ end
120
+
121
+ def content_node_name
122
+ "#{root_node_name}/aws:ContentData"
123
+ end
124
+
125
+ def related_node_name
126
+ "#{root_node_name}/aws:Related"
127
+ end
128
+
129
+ def related_links_node_name
130
+ "#{related_node_name}/aws:RelatedLinks/aws:RelatedLink"
131
+ end
132
+
133
+ def categories_node_name
134
+ "#{related_node_name}/aws:Categories/aws:CategoryData"
135
+ end
136
+
137
+ def traffic_node_name
138
+ "#{root_node_name}/aws:TrafficData"
139
+ end
140
+
141
+ def statistic_node_name
142
+ "#{traffic_node_name}/aws:UsageStatistics/aws:UsageStatistic"
143
+ end
144
+ end
145
+
146
+ class ContentData
147
+ attr_accessor :data_url, :site_title, :site_description, :speed_median_load_time, :speed_percentile, :adult_content,
148
+ :language_locale, :links_in_count, :owned_domains
149
+
150
+ def initialize(hash)
151
+ hash.map { |k, v| instance_variable_set("@#{k}", v) }
152
+ end
153
+ end
154
+
155
+ class ContactInfo
156
+ attr_accessor :data_url, :owner_name, :email, :physical_address, :company_stock_ticker, :phone_numbers
157
+
158
+ def initialize(hash)
159
+ phone_numbers = hash.delete(:phone_numbers)
160
+
161
+ hash.map { |k, v| instance_variable_set("@#{k}", v) }
162
+ phone_number_collections(phone_numbers)
163
+ end
164
+
165
+ def phone_number_collections(phone_numbers)
166
+ return @phone_numbers = [] if phone_numbers.nil? || phone_numbers.empty?
167
+
168
+ phone_numbers.map { |item| @phone_numbers << PhoneNumber.new(item) }
169
+ end
170
+ end
171
+
172
+ class PhoneNumber
173
+ attr_accessor :number
174
+
175
+ def initialize(hash)
176
+ hash.map { |k, v| instance_variable_set("@#{k}", v) }
177
+ end
178
+ end
179
+
180
+ class RelatedLink
181
+ attr_accessor :data_url, :navigable_url, :title
182
+
183
+ def initialize(hash)
184
+ hash.map { |k, v| instance_variable_set("@#{k}", v) }
185
+ end
186
+ end
187
+
188
+ class CategoryData
189
+ attr_accessor :title, :absolute_path
190
+
191
+ def initialize(hash)
192
+ hash.map { |k, v| instance_variable_set("@#{k}", v) }
193
+ end
194
+ end
195
+
196
+ class UsageStatistic
197
+ attr_accessor :time_range_months, :time_range_days, :rank_value, :rank_delta, :reach_rank_value, :reach_rank_delta,
198
+ :reach_per_million_value, :reach_per_million_delta, :reach_page_views_per_million_value, :reach_page_views_per_million_delta,
199
+ :reach_page_views_rank_value, :reach_page_views_rank_delta, :reach_page_views_per_user_value, :reach_page_views_per_user_delta
200
+
201
+ def initialize(hash)
202
+ hash.map { |k, v| instance_variable_set("@#{k}", v) }
203
+ end
204
+ end
205
+ end
206
+ end
@@ -0,0 +1,11 @@
1
+ module Awis
2
+ module Utils
3
+ module Extra
4
+ def camelize(string)
5
+ string.split("_").map { |w| w.capitalize }.join
6
+ end
7
+
8
+ module_function :camelize
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,34 @@
1
+ module Awis
2
+ module Utils
3
+ class XML
4
+ def initialize(data)
5
+ @data = data
6
+ end
7
+
8
+ def each_node(attributes_in_path = false)
9
+ reader = Nokogiri::XML::Reader(@data)
10
+ nodes = ['']
11
+
12
+ reader.each do |node|
13
+ if node.node_type == Nokogiri::XML::Reader::TYPE_ELEMENT
14
+ if attributes_in_path && node.attributes.size > 0
15
+ attributes = []
16
+
17
+ node.attributes.sort.each do |name, value|
18
+ attributes << "@#{name}=#{value}"
19
+ end
20
+ nodes << "#{node.name}/#{attributes.join('/')}"
21
+ else
22
+ nodes << node.name
23
+ end
24
+ path = nodes.join('/')
25
+
26
+ yield node, path
27
+ end
28
+
29
+ nodes.pop if node.node_type == Nokogiri::XML::Reader::TYPE_END_ELEMENT || node.self_closing? # End tag
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ module Awis
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: awis-sdk-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Encore Shao
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2017-03-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: multi_xml
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.5.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.5.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: faraday
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 0.9.0
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.9.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: minitest
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: mocha
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: webmock
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: Ruby - Amazon Alexa Web Information Service Library (AWIS)
95
+ email:
96
+ - encore.shao@gmail.com
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files: []
100
+ files:
101
+ - .gitignore
102
+ - .travis.yml
103
+ - Gemfile
104
+ - README.md
105
+ - Rakefile
106
+ - awis.gemspec
107
+ - bin/console
108
+ - bin/setup
109
+ - lib/awis.rb
110
+ - lib/awis/api.rb
111
+ - lib/awis/api/base.rb
112
+ - lib/awis/api/category_browse.rb
113
+ - lib/awis/api/category_listings.rb
114
+ - lib/awis/api/sites_linking_in.rb
115
+ - lib/awis/api/traffic_history.rb
116
+ - lib/awis/api/url_info.rb
117
+ - lib/awis/client.rb
118
+ - lib/awis/config.rb
119
+ - lib/awis/connection.rb
120
+ - lib/awis/exceptions.rb
121
+ - lib/awis/hash.rb
122
+ - lib/awis/models.rb
123
+ - lib/awis/models/base.rb
124
+ - lib/awis/models/category_browse.rb
125
+ - lib/awis/models/category_listings.rb
126
+ - lib/awis/models/sites_linking_in.rb
127
+ - lib/awis/models/traffic_history.rb
128
+ - lib/awis/models/url_info.rb
129
+ - lib/awis/utils/extra.rb
130
+ - lib/awis/utils/xml.rb
131
+ - lib/awis/version.rb
132
+ homepage: https://github.com/encoreshao/awis
133
+ licenses: []
134
+ post_install_message:
135
+ rdoc_options: []
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ none: false
140
+ requirements:
141
+ - - ! '>='
142
+ - !ruby/object:Gem::Version
143
+ version: 1.9.3
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ segments:
151
+ - 0
152
+ hash: -314393393090401873
153
+ requirements: []
154
+ rubyforge_project:
155
+ rubygems_version: 1.8.23
156
+ signing_key:
157
+ specification_version: 3
158
+ summary: Ruby - Amazon Alexa Web Information Service Library (AWIS)
159
+ test_files: []