awis-sdk-ruby 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
11
+
12
+ .ruby-version
13
+ awis.yml
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ notifications:
2
+ disabled: true
3
+ bundler_args: --without extra
4
+ rvm:
5
+ - 1.9.3
6
+ - 2.0.0
7
+ - 2.1.1
8
+ env:
9
+ - XML_PARSER=nokogiri
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "https://rubygems.org"
2
+
3
+ group :extra do
4
+ gem "debugger"
5
+ end
6
+
7
+ gem "bundler"
8
+ gem "rake"
9
+
10
+ # XML parsers
11
+ gem "nokogiri", '~> 1.6.8'
12
+
13
+ gemspec
data/README.md ADDED
@@ -0,0 +1,149 @@
1
+ ## Amazon - Alexa Web Information Service (AWIS)
2
+ Ruby Library for AWSI API - [Amazon AWIS](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
+ AWIS_CONFIG = YAML.load(File.read('awis.yml'))
16
+
17
+ Awis.config do |c|
18
+ c.access_key_id = AWIS_CONFIG['access_key_id']
19
+ c.secret_access_key = AWIS_CONFIG['secret_access_key']
20
+ c.debug = AWIS_CONFIG['debug']
21
+ end
22
+ ```
23
+
24
+ ##### Get UrlInfo Information
25
+
26
+ ``` ruby
27
+ client = Awis::Client.new
28
+ url_info = client.url_info(url: "github.com")
29
+ ```
30
+
31
+ Returns object that contains attributes:
32
+
33
+ * data_url
34
+ * rank
35
+ * asin
36
+
37
+ Returns object that contains relationships:
38
+
39
+ * contact_info [:data_url, :owner_name, :email, :physical_address, :company_stock_ticker, :phone_numbers]
40
+ * content_data [:data_url, :site_title, :site_description, :speed_median_load_time, :speed_percentile, :adult_content, :language_locale, :links_in_count, :owned_domains]
41
+ * usage_statistics [:time_range_months, :time_range_days, :rank_value, :rank_delta, :reach_rank_value, :reach_rank_delta,
42
+ :reach_per_million_value, :reach_per_million_delta, :reach_page_views_per_million_value, :reach_page_views_per_million_delta,
43
+ :reach_page_views_rank_value, :reach_page_views_rank_delta, :reach_page_views_per_user_value, :reach_page_views_per_user_delta]
44
+ * related_links [:data_url, :navigable_url, :title]
45
+ * categories [:title, :absolute_path]
46
+
47
+ You can specify options:
48
+
49
+ * url
50
+ * response_group - which data to include in response (i.e. ["rank", "contact_info", "content_data"]) - defaults to all available
51
+
52
+ See: [Docs](http://docs.amazonwebservices.com/AlexaWebInfoService/latest/) for valid groups.
53
+
54
+ ##### Get Sites Linking In
55
+
56
+ ``` ruby
57
+ client = Awis::Client.new
58
+ sites_linking_in = client.sites_linking_in(url: "site.com")
59
+ ```
60
+
61
+ Returns object that contains relationships:
62
+
63
+ * sites [:title, :url]
64
+
65
+ You can specify options:
66
+
67
+ * url
68
+ * count - how many results to retrieve - defaults to max value that is 20
69
+ * start - offset of results - defaults to 0
70
+
71
+ ##### Get Traffic History
72
+
73
+ ``` ruby
74
+ client = Awis::Client.new
75
+ traffic_history = client.traffic_history(url: "site.com")
76
+ ```
77
+
78
+ Returns object that contains methods:
79
+
80
+ * range
81
+ * site
82
+ * start
83
+
84
+ Returns object that contains relationships:
85
+
86
+ * historical_data [:date, :page_views_per_million, :page_views_per_user, :rank, :reach_per_million]
87
+
88
+ You can specify options:
89
+
90
+ * url
91
+ * range - how many days to retrieve - defaults to max value 31
92
+ * start - start date (i.e. "20120120", 4.days.ago) - defaults to range number days ago
93
+
94
+ ##### Get Category Listings
95
+
96
+ ``` ruby
97
+ client = Awis::Client.new
98
+ category_listings = client.category_listings(path: "Top/Games/Card_Games")
99
+ ```
100
+
101
+ Returns object that contains methods:
102
+
103
+ * count
104
+ * recursive_count
105
+
106
+ Returns object that contains relationships:
107
+
108
+ * listings [:data_url, :title, :popularity_rank, :description]
109
+
110
+ ##### Get Category Browse
111
+
112
+ ``` ruby
113
+ client = Awis::Client.new
114
+ category_browses = client.category_browse(path: "Top/Games/Card_Games")
115
+ ```
116
+
117
+ Returns object that contains methods:
118
+
119
+ * categories [:path, :title, :sub_category_count, :total_listing_count]
120
+ * language_categories [:path, :title, :sub_category_count, :total_listing_count]
121
+ * related_categories [:path, :title, :sub_category_count, :total_listing_count]
122
+ * letter_bars [:path, :title, :sub_category_count, :total_listing_count]
123
+
124
+ Returns object that contains relationships:
125
+
126
+ * listings [:data_url, :title, :popularity_rank, :description]
127
+
128
+ ##### Request ID and Status Code
129
+
130
+ You can retrieve status code and request id
131
+
132
+ * request_id
133
+ * status_code
134
+
135
+ ### Parsers
136
+
137
+ Awis is using `nokogiri` to parse XML documents.
138
+
139
+ ### Contributors
140
+
141
+ * [Encore Shao](https://github.com/encoreshao)
142
+
143
+ ### Continuous Integration
144
+
145
+ [![Build Status](https://travis-ci.org/encoreshao/awis.svg?branch=master)](https://travis-ci.org/encoreshao/awis)
146
+
147
+ ### Copyright
148
+
149
+ Copyright (c) Encore Shao. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require "rake/testtask"
5
+ Rake::TestTask.new(:test) do |test|
6
+ test.libs << "lib" << "test"
7
+ test.pattern = "test/**/*_test.rb"
8
+ test.verbose = true
9
+ end
10
+
11
+ task :default => :test
data/awis.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'awis/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "awis-sdk-ruby"
8
+ spec.version = Awis::VERSION
9
+ spec.authors = ["Encore Shao"]
10
+ spec.email = ["encore.shao@gmail.com"]
11
+
12
+ spec.summary = %q{Ruby - Amazon Alexa Web Information Service Library (AWIS)}
13
+ spec.description = %q{Ruby - Amazon Alexa Web Information Service Library (AWIS)}
14
+ spec.homepage = "https://github.com/encoreshao/awis"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.required_ruby_version = ">= 1.9.3"
24
+
25
+ spec.add_dependency "multi_xml", ">= 0.5.0"
26
+ spec.add_dependency "faraday", "~> 0.9.0"
27
+
28
+ spec.add_development_dependency "minitest"
29
+ spec.add_development_dependency "mocha"
30
+ spec.add_development_dependency "webmock"
31
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "awis"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/awis.rb ADDED
@@ -0,0 +1,19 @@
1
+ require "multi_xml"
2
+
3
+ require "awis/version"
4
+ require "awis/hash"
5
+ require "awis/utils/xml"
6
+ require "awis/utils/extra"
7
+ require "awis/exceptions"
8
+ require "awis/connection"
9
+ require "awis/config"
10
+ require "awis/client"
11
+ require "awis/api"
12
+ require "awis/models"
13
+
14
+ module Awis
15
+ API_VERSION = "2005-07-11".freeze
16
+ API_HOST = "awis.amazonaws.com".freeze
17
+ class << self
18
+ end
19
+ end
data/lib/awis/api.rb ADDED
@@ -0,0 +1,10 @@
1
+ module Awis
2
+ module API
3
+ autoload :Base, "awis/api/base"
4
+ autoload :UrlInfo, "awis/api/url_info"
5
+ autoload :TrafficHistory, "awis/api/traffic_history"
6
+ autoload :SitesLinkingIn, "awis/api/sites_linking_in"
7
+ autoload :CategoryListings, "awis/api/category_listings"
8
+ autoload :CategoryBrowse, "awis/api/category_browse"
9
+ end
10
+ end
@@ -0,0 +1,26 @@
1
+ module Awis
2
+ module API
3
+ class Base
4
+ include Utils::Extra
5
+ attr_reader :arguments, :response_body
6
+
7
+ def parsed_body
8
+ @parsed_body ||= MultiXml.parse(response_body)
9
+ end
10
+
11
+ def root_node_name
12
+ "#{action_name}Response"
13
+ end
14
+
15
+ def action_name
16
+ self.class.name.split(/\:\:/)[-1]
17
+ end
18
+
19
+ class << self
20
+ def loading_data_from_xml(xml_file_path)
21
+ MultiXml.parse(File.new(xml_file_path))
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,36 @@
1
+ module Awis
2
+ module API
3
+ class CategoryBrowse < Base
4
+ DEFAULT_RESPONSE_GROUP = %w(categories related_categories language_categories letter_bars).freeze
5
+
6
+ def fetch(arguments = {})
7
+ raise ArgumentError.new("Valid category path (Top/Arts, Top/Business/Automotive)") unless arguments.has_key?(:path)
8
+ @arguments = arguments
9
+
10
+ @arguments[:response_group] = Array(arguments.fetch(:response_group, DEFAULT_RESPONSE_GROUP))
11
+ @arguments[:descriptions] = arguments.fetch(:descriptions, true)
12
+
13
+ @response_body = Awis::Connection.new.get(params)
14
+ self
15
+ end
16
+
17
+ private
18
+ def params
19
+ {
20
+ "Action" => action_name,
21
+ "ResponseGroup" => response_groups,
22
+ "Path" => arguments[:path],
23
+ "Descriptions" => descriptions_params
24
+ }
25
+ end
26
+
27
+ def response_groups
28
+ arguments[:response_group].sort.map { |group| camelize(group) }.join(",")
29
+ end
30
+
31
+ def descriptions_params
32
+ arguments[:descriptions].to_s.capitalize
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,45 @@
1
+ module Awis
2
+ module API
3
+ class CategoryListings < Base
4
+ def fetch(arguments = {})
5
+ raise ArgumentError, "You must provide a URL" unless arguments.has_key?(:path)
6
+ @arguments = arguments
7
+
8
+ @arguments[:sort_by] = arguments.fetch(:sort_by, "popularity")
9
+ @arguments[:recursive] = arguments.fetch(:recursive, true)
10
+ @arguments[:descriptions] = arguments.fetch(:descriptions, true)
11
+ @arguments[:start] = arguments.fetch(:start, 0)
12
+ @arguments[:count] = arguments.fetch(:count, 20)
13
+
14
+ @response_body = Awis::Connection.new.get(params)
15
+ self
16
+ end
17
+
18
+ private
19
+ def params
20
+ {
21
+ "Action" => "CategoryListings",
22
+ "ResponseGroup" => "Listings",
23
+ "Path" => arguments[:path],
24
+ "Recursive" => recursive_param,
25
+ "Descriptions" => descriptions_params,
26
+ "SortBy" => sort_by_param,
27
+ "Count" => arguments[:count],
28
+ "Start" => arguments[:start],
29
+ }
30
+ end
31
+
32
+ def recursive_param
33
+ arguments[:recursive].to_s.capitalize
34
+ end
35
+
36
+ def descriptions_params
37
+ arguments[:descriptions].to_s.capitalize
38
+ end
39
+
40
+ def sort_by_param
41
+ camelize(arguments[:sort_by])
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,29 @@
1
+ module Awis
2
+ module API
3
+ class SitesLinkingIn < Base
4
+ attr_accessor :sites
5
+
6
+ def fetch(arguments = {})
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)
12
+
13
+ @response_body = Awis::Connection.new.get(params)
14
+ self
15
+ end
16
+
17
+ private
18
+ def params
19
+ {
20
+ "Action" => "SitesLinkingIn",
21
+ "Url" => arguments[:url],
22
+ "ResponseGroup" => "SitesLinkingIn",
23
+ "Count" => arguments[:count],
24
+ "Start" => arguments[:start]
25
+ }
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,30 @@
1
+ module Awis
2
+ module API
3
+ class TrafficHistory < Base
4
+ def fetch(arguments = {})
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
+
11
+ @response_body = Awis::Connection.new.get(params)
12
+ self
13
+ end
14
+
15
+ def params
16
+ {
17
+ "Action" => "TrafficHistory",
18
+ "Url" => arguments[:url],
19
+ "ResponseGroup" => "History",
20
+ "Range" => arguments[:range],
21
+ "Start" => start_param,
22
+ }
23
+ end
24
+
25
+ def start_param
26
+ arguments[:start].respond_to?(:strftime) ? arguments[:start].strftime("%Y%m%d") : arguments[:start]
27
+ end
28
+ end
29
+ end
30
+ end