awis-sdk-ruby_ 1.1.1p1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rubocop.yml +87 -0
- data/.travis.yml +12 -0
- data/Gemfile +8 -0
- data/README.md +179 -0
- data/Rakefile +13 -0
- data/awis.gemspec +35 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/awis.rb +22 -0
- data/lib/awis/api.rb +12 -0
- data/lib/awis/api/base.rb +54 -0
- data/lib/awis/api/category_browse.rb +43 -0
- data/lib/awis/api/category_listings.rb +58 -0
- data/lib/awis/api/sites_linking_in.rb +39 -0
- data/lib/awis/api/traffic_history.rb +43 -0
- data/lib/awis/api/url_info.rb +39 -0
- data/lib/awis/client.rb +46 -0
- data/lib/awis/config.rb +17 -0
- data/lib/awis/connection.rb +110 -0
- data/lib/awis/exceptions.rb +16 -0
- data/lib/awis/hash.rb +15 -0
- data/lib/awis/models.rb +13 -0
- data/lib/awis/models/base.rb +32 -0
- data/lib/awis/models/base_entity.rb +13 -0
- data/lib/awis/models/category_browse.rb +120 -0
- data/lib/awis/models/category_listings.rb +52 -0
- data/lib/awis/models/sites_linking_in.rb +39 -0
- data/lib/awis/models/traffic_history.rb +62 -0
- data/lib/awis/models/url_info.rb +392 -0
- data/lib/awis/utils.rb +10 -0
- data/lib/awis/utils/extra.rb +13 -0
- data/lib/awis/utils/hash.rb +11 -0
- data/lib/awis/utils/variable.rb +15 -0
- data/lib/awis/utils/xml.rb +38 -0
- data/lib/awis/version.rb +5 -0
- metadata +190 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 820841628f9886a0dd31e6729757b845a85aab18b7c299605db60b9465dd4f4d
|
4
|
+
data.tar.gz: 1f5f504d1ff3e2ef0ba25beb3fe7f381d36099cd6317acbf95681c85ddccadea
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a2cb847891bd5bc07e815ddf25c36a5348b28c7649b9beb146412da3fd8c7317806abf80b53e7bb9157ff3efc588d6790e7338592812846d04d321811227f9fd
|
7
|
+
data.tar.gz: 331a8f2566a9cdcf17b41cc140cb8fb9bea1a84cf52c04f9156ab795ebbbfa3c327249a332605efeff10dfec0348a4ed62e9c3ffea29fa60fa83ca7cae42e5b2
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
AllCops:
|
2
|
+
DisplayCopNames: true
|
3
|
+
TargetRubyVersion: 2.4
|
4
|
+
Exclude:
|
5
|
+
- '**/*.yml'
|
6
|
+
- 'test/**/*'
|
7
|
+
- 'pkg/*'
|
8
|
+
- 'tmp/*'
|
9
|
+
|
10
|
+
Style/StringLiterals:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
Documentation:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Style/RegexpLiteral:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Layout/SpaceInsideHashLiteralBraces:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
Metrics/LineLength:
|
23
|
+
Max: 160
|
24
|
+
|
25
|
+
Metrics/ModuleLength:
|
26
|
+
Max: 500
|
27
|
+
|
28
|
+
Metrics/BlockLength:
|
29
|
+
Exclude:
|
30
|
+
- 'test/**/*'
|
31
|
+
|
32
|
+
Layout/DotPosition:
|
33
|
+
EnforcedStyle: trailing
|
34
|
+
|
35
|
+
Style/RedundantFreeze:
|
36
|
+
Enabled: false
|
37
|
+
|
38
|
+
Style/FormatString:
|
39
|
+
Enabled: false
|
40
|
+
|
41
|
+
Metrics/ClassLength:
|
42
|
+
Enabled: false
|
43
|
+
|
44
|
+
Lint/AssignmentInCondition:
|
45
|
+
Enabled: false
|
46
|
+
|
47
|
+
Layout/EmptyLinesAroundAccessModifier:
|
48
|
+
Enabled: false
|
49
|
+
|
50
|
+
Style/SingleLineBlockParams:
|
51
|
+
Enabled: false
|
52
|
+
|
53
|
+
Style/NumericLiterals:
|
54
|
+
Exclude:
|
55
|
+
- 'spec/**/*'
|
56
|
+
|
57
|
+
Style/StringLiteralsInInterpolation:
|
58
|
+
Enabled: false
|
59
|
+
|
60
|
+
Metrics/MethodLength:
|
61
|
+
Max: 30
|
62
|
+
|
63
|
+
Layout/CaseIndentation:
|
64
|
+
# Valid values are: case, end
|
65
|
+
EnforcedStyle: end
|
66
|
+
IndentOneStep: false
|
67
|
+
|
68
|
+
Metrics/AbcSize:
|
69
|
+
Max: 40
|
70
|
+
|
71
|
+
Metrics/CyclomaticComplexity:
|
72
|
+
Max: 10
|
73
|
+
|
74
|
+
Metrics/PerceivedComplexity:
|
75
|
+
Max: 15
|
76
|
+
|
77
|
+
Metrics/ParameterLists:
|
78
|
+
Max: 10
|
79
|
+
|
80
|
+
Lint/UselessAssignment:
|
81
|
+
Enabled: false
|
82
|
+
|
83
|
+
Style/NumericLiterals:
|
84
|
+
Enabled: false
|
85
|
+
|
86
|
+
Rails:
|
87
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,179 @@
|
|
1
|
+
## Amazon - Alexa Web Information Service (AWIS)
|
2
|
+
Ruby Library for AWIS REST API - See: [Alexa Docs](http://docs.amazonwebservices.com/AlexaWebInfoService/latest/)
|
3
|
+
|
4
|
+
### How to installation
|
5
|
+
|
6
|
+
```
|
7
|
+
gem install awis-sdk-ruby
|
8
|
+
```
|
9
|
+
|
10
|
+
### How to usage
|
11
|
+
|
12
|
+
##### Configure your amazon certificate
|
13
|
+
|
14
|
+
```
|
15
|
+
require 'awis'
|
16
|
+
|
17
|
+
AWIS_CONFIG = YAML.load(File.read('awis.yml'))
|
18
|
+
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
|
26
|
+
end
|
27
|
+
```
|
28
|
+
|
29
|
+
##### Get UrlInfo Information
|
30
|
+
|
31
|
+
``` ruby
|
32
|
+
client = Awis::Client.new
|
33
|
+
url_info = client.url_info(url: "site.com")
|
34
|
+
```
|
35
|
+
|
36
|
+
If you looking for the API request URI:
|
37
|
+
|
38
|
+
* Awis::API::UrlInfo.new.load_request_uri(url: 'site.com')
|
39
|
+
|
40
|
+
|
41
|
+
Returns object that contains attributes:
|
42
|
+
|
43
|
+
* data_url
|
44
|
+
* rank
|
45
|
+
* asin
|
46
|
+
* xml
|
47
|
+
|
48
|
+
Returns object that contains relationships:
|
49
|
+
|
50
|
+
* contact_info [:data_url, :owner_name, :email, :physical_address, :company_stock_ticker, :phone_numbers]
|
51
|
+
* content_data [:data_url, :site_title, :site_description, :speed_median_load_time, :speed_percentile, :adult_content, :language_locale, :links_in_count, :owned_domains]
|
52
|
+
* usage_statistics [:time_range_months, :time_range_days, :rank_value, :rank_delta, :reach_rank_value, :reach_rank_delta,
|
53
|
+
:reach_per_million_value, :reach_per_million_delta, :reach_page_views_per_million_value, :reach_page_views_per_million_delta,
|
54
|
+
:reach_page_views_rank_value, :reach_page_views_rank_delta, :reach_page_views_per_user_value, :reach_page_views_per_user_delta]
|
55
|
+
- add two methods: [range_type, range_count]
|
56
|
+
* related_links [:data_url, :navigable_url, :title]
|
57
|
+
* categories [:title, :absolute_path]
|
58
|
+
|
59
|
+
New methods:
|
60
|
+
|
61
|
+
* is_404?
|
62
|
+
|
63
|
+
You can specify options:
|
64
|
+
|
65
|
+
* url
|
66
|
+
* response_group - which data to include in response (i.e. ["rank", "contact_info", "content_data"]) - defaults to all available
|
67
|
+
|
68
|
+
##### Get Sites Linking In
|
69
|
+
|
70
|
+
``` ruby
|
71
|
+
client = Awis::Client.new
|
72
|
+
sites_linking_in = client.sites_linking_in(url: "site.com")
|
73
|
+
```
|
74
|
+
|
75
|
+
If you looking for the API request URI:
|
76
|
+
|
77
|
+
* Awis::API::SitesLinkingIn.new.load_request_uri(url: 'site.com')
|
78
|
+
|
79
|
+
Returns object that contains relationships:
|
80
|
+
|
81
|
+
* sites [:title, :url]
|
82
|
+
|
83
|
+
You can specify options:
|
84
|
+
|
85
|
+
* url
|
86
|
+
* count - how many results to retrieve - defaults to max value that is 20
|
87
|
+
* start - offset of results - defaults to 0
|
88
|
+
|
89
|
+
##### Get Traffic History
|
90
|
+
|
91
|
+
``` ruby
|
92
|
+
client = Awis::Client.new
|
93
|
+
traffic_history = client.traffic_history(url: "site.com")
|
94
|
+
```
|
95
|
+
|
96
|
+
If you looking for the API request URI:
|
97
|
+
|
98
|
+
* Awis::API::TrafficHistory.new.load_request_uri(url: 'site.com')
|
99
|
+
|
100
|
+
Returns object that contains methods:
|
101
|
+
|
102
|
+
* range
|
103
|
+
* site
|
104
|
+
* start
|
105
|
+
|
106
|
+
Returns object that contains relationships:
|
107
|
+
|
108
|
+
* historical_data [:date, :page_views_per_million, :page_views_per_user, :rank, :reach_per_million]
|
109
|
+
|
110
|
+
You can specify options:
|
111
|
+
|
112
|
+
* url
|
113
|
+
* range - how many days to retrieve - defaults to max value 31
|
114
|
+
* start - start date (i.e. "20120120", 4.days.ago) - defaults to range number days ago
|
115
|
+
|
116
|
+
##### Get Category Listings
|
117
|
+
|
118
|
+
``` ruby
|
119
|
+
client = Awis::Client.new
|
120
|
+
category_listings = client.category_listings(path: "Top/Arts")
|
121
|
+
```
|
122
|
+
|
123
|
+
If you looking for the API request URI:
|
124
|
+
|
125
|
+
* Awis::API::CategoryListings.new.load_request_uri(path: "Top/Games/Card_Games")
|
126
|
+
|
127
|
+
Returns object that contains methods:
|
128
|
+
|
129
|
+
* count
|
130
|
+
* recursive_count
|
131
|
+
|
132
|
+
Returns object that contains relationships:
|
133
|
+
|
134
|
+
* listings [:data_url, :title, :popularity_rank, :description]
|
135
|
+
|
136
|
+
##### Get Category Browse
|
137
|
+
|
138
|
+
``` ruby
|
139
|
+
client = Awis::Client.new
|
140
|
+
category_browses = client.category_browse(path: "Top/Arts")
|
141
|
+
```
|
142
|
+
|
143
|
+
If you looking for the API request URI:
|
144
|
+
|
145
|
+
* Awis::API::CategoryBrowse.new.load_request_uri(path: "Top/Games/Card_Games")
|
146
|
+
|
147
|
+
Returns object that contains methods:
|
148
|
+
|
149
|
+
* categories [:path, :title, :sub_category_count, :total_listing_count]
|
150
|
+
* language_categories [:path, :title, :sub_category_count, :total_listing_count]
|
151
|
+
* related_categories [:path, :title, :sub_category_count, :total_listing_count]
|
152
|
+
* letter_bars [:path, :title, :sub_category_count, :total_listing_count]
|
153
|
+
|
154
|
+
Returns object that contains relationships:
|
155
|
+
|
156
|
+
* listings [:data_url, :title, :popularity_rank, :description]
|
157
|
+
|
158
|
+
##### How to run test
|
159
|
+
|
160
|
+
* rake test
|
161
|
+
|
162
|
+
##### Request ID and Status Code
|
163
|
+
|
164
|
+
You can retrieve status code and requestID
|
165
|
+
|
166
|
+
* request_id
|
167
|
+
* status_code
|
168
|
+
|
169
|
+
### Parsers
|
170
|
+
|
171
|
+
Awis is using `nokogiri` to parse XML documents.
|
172
|
+
|
173
|
+
### Contributors
|
174
|
+
|
175
|
+
* [Encore Shao](https://github.com/encoreshao)
|
176
|
+
|
177
|
+
### Copyright
|
178
|
+
|
179
|
+
Copyright (c) Encore Shao. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/gem_tasks'
|
5
|
+
|
6
|
+
require 'rake/testtask'
|
7
|
+
Rake::TestTask.new(:test) do |test|
|
8
|
+
test.libs << 'lib' << 'test'
|
9
|
+
test.pattern = 'test/**/*_test.rb'
|
10
|
+
test.verbose = true
|
11
|
+
end
|
12
|
+
|
13
|
+
task default: :test
|
data/awis.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'awis/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'awis-sdk-ruby_'
|
9
|
+
spec.version = Awis::VERSION
|
10
|
+
spec.authors = ['Encore Shao']
|
11
|
+
spec.email = ['encore.shao@gmail.com']
|
12
|
+
|
13
|
+
spec.summary = 'Ruby - Amazon Alexa Web Information Service Library (AWIS)'
|
14
|
+
spec.description = 'Ruby - Amazon Alexa Web Information Service Library (AWIS)'
|
15
|
+
spec.homepage = 'https://github.com/encoreshao/amazon-awis'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = 'exe'
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ['lib']
|
23
|
+
|
24
|
+
# spec.required_ruby_version = '>= 1.9.3'
|
25
|
+
|
26
|
+
spec.add_dependency 'aws-sigv4'
|
27
|
+
spec.add_dependency 'multi_xml'
|
28
|
+
spec.add_dependency 'nokogiri'
|
29
|
+
|
30
|
+
spec.add_development_dependency 'minitest'
|
31
|
+
spec.add_development_dependency 'mocha'
|
32
|
+
spec.add_development_dependency 'pry'
|
33
|
+
spec.add_development_dependency 'rubocop'
|
34
|
+
spec.add_development_dependency 'webmock'
|
35
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'awis'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/awis.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'multi_xml'
|
4
|
+
require 'nokogiri'
|
5
|
+
require 'aws-sigv4'
|
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'
|
16
|
+
|
17
|
+
module Awis
|
18
|
+
SERVICE_PATH = 'api'
|
19
|
+
SERVICE_NAME = 'awis'
|
20
|
+
SERVICE_REGION = 'us-west-1'
|
21
|
+
SERVICE_HOST = "#{SERVICE_NAME}.#{SERVICE_REGION}.amazonaws.com"
|
22
|
+
end
|
data/lib/awis/api.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Awis
|
4
|
+
module API
|
5
|
+
autoload :Base, 'awis/api/base'
|
6
|
+
autoload :UrlInfo, 'awis/api/url_info'
|
7
|
+
autoload :TrafficHistory, 'awis/api/traffic_history'
|
8
|
+
autoload :SitesLinkingIn, 'awis/api/sites_linking_in'
|
9
|
+
autoload :CategoryListings, 'awis/api/category_listings'
|
10
|
+
autoload :CategoryBrowse, 'awis/api/category_browse'
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Awis
|
4
|
+
module API
|
5
|
+
class Base
|
6
|
+
include Utils::Extra
|
7
|
+
attr_reader :arguments, :response_body
|
8
|
+
|
9
|
+
def fetch(arguments = {})
|
10
|
+
validation_arguments!(arguments)
|
11
|
+
|
12
|
+
loading_response_body
|
13
|
+
self
|
14
|
+
end
|
15
|
+
|
16
|
+
def request_description_params
|
17
|
+
arguments[:descriptions].to_s.capitalize
|
18
|
+
end
|
19
|
+
|
20
|
+
def parsed_body
|
21
|
+
@parsed_body ||= MultiXml.parse(response_body)
|
22
|
+
end
|
23
|
+
|
24
|
+
def loading_response_body
|
25
|
+
@response_body = Awis::Connection.new.get(params)
|
26
|
+
end
|
27
|
+
|
28
|
+
def root_node_name
|
29
|
+
"#{action_name}Response"
|
30
|
+
end
|
31
|
+
|
32
|
+
def action_name
|
33
|
+
self.class.name.split(/\:\:/)[-1]
|
34
|
+
end
|
35
|
+
|
36
|
+
def load_request_uri(params)
|
37
|
+
collection = Awis::Connection.new
|
38
|
+
collection.setup_params(params)
|
39
|
+
collection.uri
|
40
|
+
end
|
41
|
+
|
42
|
+
def before_validation_arguments(arguments)
|
43
|
+
raise ArgumentError, "Invalid arguments. should be like { url: 'site.com' }" unless arguments.is_a?(Hash)
|
44
|
+
raise ArgumentError, 'Invalid arguments. the url must be configured.' unless arguments.key?(:url)
|
45
|
+
end
|
46
|
+
|
47
|
+
class << self
|
48
|
+
def loading_data_from_xml(xml_file_path)
|
49
|
+
MultiXml.parse(File.new(xml_file_path))
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|