awis-sdk-ruby 0.0.6 → 0.0.7

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.
data/README.md CHANGED
@@ -44,9 +44,9 @@ Returns object that contains relationships:
44
44
 
45
45
  * contact_info [:data_url, :owner_name, :email, :physical_address, :company_stock_ticker, :phone_numbers]
46
46
  * content_data [:data_url, :site_title, :site_description, :speed_median_load_time, :speed_percentile, :adult_content, :language_locale, :links_in_count, :owned_domains]
47
- * usage_statistics [:time_range_months, :time_range_days, :rank_value, :rank_delta, :reach_rank_value, :reach_rank_delta,
47
+ * usage_statistics [:time_range_months, :time_range_days, :rank_value, :rank_delta, :reach_rank_value, :reach_rank_delta,
48
48
  :reach_per_million_value, :reach_per_million_delta, :reach_page_views_per_million_value, :reach_page_views_per_million_delta,
49
- :reach_page_views_rank_value, :reach_page_views_rank_delta, :reach_page_views_per_user_value, :reach_page_views_per_user_delta]
49
+ :reach_page_views_rank_value, :reach_page_views_rank_delta, :reach_page_views_per_user_value, :reach_page_views_per_user_delta]
50
50
  - add two methods: [range_type, range_count]
51
51
  * related_links [:data_url, :navigable_url, :title]
52
52
  * categories [:title, :absolute_path]
@@ -57,7 +57,7 @@ New methods:
57
57
 
58
58
  You can specify options:
59
59
 
60
- * url
60
+ * url
61
61
  * response_group - which data to include in response (i.e. ["rank", "contact_info", "content_data"]) - defaults to all available
62
62
 
63
63
  ##### Get Sites Linking In
@@ -20,4 +20,4 @@ module Awis
20
20
 
21
21
  class << self
22
22
  end
23
- end
23
+ end
@@ -4,10 +4,21 @@ module Awis
4
4
  include Utils::Extra
5
5
  attr_reader :arguments, :response_body
6
6
 
7
+ def fetch(arguments = {})
8
+ validation_arguments!(arguments)
9
+
10
+ loading_response_body
11
+ self
12
+ end
13
+
7
14
  def parsed_body
8
15
  @parsed_body ||= MultiXml.parse(response_body)
9
16
  end
10
17
 
18
+ def loading_response_body
19
+ @response_body = Awis::Connection.new.get(params)
20
+ end
21
+
11
22
  def root_node_name
12
23
  "#{action_name}Response"
13
24
  end
@@ -22,6 +33,11 @@ module Awis
22
33
  collection.uri
23
34
  end
24
35
 
36
+ def before_validation_arguments(arguments)
37
+ raise ArgumentError, "Invalid arguments. should be like { url: 'site.com' }" unless arguments.is_a?(Hash)
38
+ raise ArgumentError, "Invalid arguments. the url must be configured." unless arguments.has_key?(:url)
39
+ end
40
+
25
41
  class << self
26
42
  def loading_data_from_xml(xml_file_path)
27
43
  MultiXml.parse(File.new(xml_file_path))
@@ -3,14 +3,6 @@ module Awis
3
3
  class CategoryBrowse < Base
4
4
  DEFAULT_RESPONSE_GROUP = %w(categories related_categories language_categories letter_bars).freeze
5
5
 
6
- def fetch(arguments = {})
7
- raise ArgumentError.new("Valid category path (Top/Arts, Top/Business/Automotive)") unless arguments.has_key?(:path)
8
- validation_arguments!(arguments)
9
-
10
- @response_body = Awis::Connection.new.get(params)
11
- self
12
- end
13
-
14
6
  def load_request_uri(arguments = {})
15
7
  validation_arguments!(arguments)
16
8
 
@@ -18,9 +10,15 @@ module Awis
18
10
  end
19
11
 
20
12
  private
13
+ def before_validation_arguments(arguments)
14
+ raise ArgumentError, "Invalid arguments. should be like { path: 'Top/Arts' }" unless arguments.is_a?(Hash)
15
+ raise ArgumentError, "Invalid arguments. the path must be configured." unless arguments.has_key?(:path)
16
+ end
17
+
21
18
  def validation_arguments!(arguments)
22
- @arguments = arguments
19
+ before_validation_arguments(arguments)
23
20
 
21
+ @arguments = arguments
24
22
  @arguments[:response_group] = Array(arguments.fetch(:response_group, DEFAULT_RESPONSE_GROUP))
25
23
  @arguments[:descriptions] = arguments.fetch(:descriptions, true)
26
24
  end
@@ -1,13 +1,7 @@
1
1
  module Awis
2
2
  module API
3
3
  class CategoryListings < Base
4
- def fetch(arguments = {})
5
- raise ArgumentError, "You must provide a URL" unless arguments.has_key?(:path)
6
- validation_arguments!(arguments)
7
-
8
- @response_body = Awis::Connection.new.get(params)
9
- self
10
- end
4
+ DEFAULT_RESPONSE_GROUP = %w(listings).freeze
11
5
 
12
6
  def load_request_uri(arguments = {})
13
7
  validation_arguments!(arguments)
@@ -16,9 +10,15 @@ module Awis
16
10
  end
17
11
 
18
12
  private
13
+ def before_validation_arguments(arguments)
14
+ raise ArgumentError, "Invalid arguments. should be like { path: '/Top/Games/Card_Games' }" unless arguments.is_a?(Hash)
15
+ raise ArgumentError, "Invalid arguments. the path must be configured." unless arguments.has_key?(:path)
16
+ end
17
+
19
18
  def validation_arguments!(arguments)
20
- @arguments = arguments
19
+ before_validation_arguments(arguments)
21
20
 
21
+ @arguments = arguments
22
22
  @arguments[:sort_by] = arguments.fetch(:sort_by, "popularity")
23
23
  @arguments[:recursive] = arguments.fetch(:recursive, true)
24
24
  @arguments[:descriptions] = arguments.fetch(:descriptions, true)
@@ -29,7 +29,7 @@ module Awis
29
29
  def params
30
30
  {
31
31
  "Action" => "CategoryListings",
32
- "ResponseGroup" => "Listings",
32
+ "ResponseGroup" => DEFAULT_RESPONSE_GROUP[0],
33
33
  "Path" => arguments[:path],
34
34
  "Recursive" => recursive_param,
35
35
  "Descriptions" => descriptions_params,
@@ -1,15 +1,7 @@
1
1
  module Awis
2
2
  module API
3
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
- validation_arguments!(arguments)
9
-
10
- @response_body = Awis::Connection.new.get(params)
11
- self
12
- end
4
+ DEFAULT_RESPONSE_GROUP = %w(sites_linking_in).freeze
13
5
 
14
6
  def load_request_uri(arguments = {})
15
7
  validation_arguments!(arguments)
@@ -19,6 +11,8 @@ module Awis
19
11
 
20
12
  private
21
13
  def validation_arguments!(arguments)
14
+ before_validation_arguments(arguments)
15
+
22
16
  @arguments = arguments
23
17
  @arguments[:count] = arguments.fetch(:count, 20)
24
18
  @arguments[:start] = arguments.fetch(:start, 0)
@@ -28,7 +22,7 @@ module Awis
28
22
  {
29
23
  "Action" => "SitesLinkingIn",
30
24
  "Url" => arguments[:url],
31
- "ResponseGroup" => "SitesLinkingIn",
25
+ "ResponseGroup" => DEFAULT_RESPONSE_GROUP[0],
32
26
  "Count" => arguments[:count],
33
27
  "Start" => arguments[:start]
34
28
  }
@@ -1,14 +1,6 @@
1
1
  module Awis
2
2
  module API
3
3
  class TrafficHistory < Base
4
- def fetch(arguments = {})
5
- raise ArgumentError, "Any valid URL." unless arguments.has_key?(:url)
6
-
7
- validation_arguments!(arguments)
8
- @response_body = Awis::Connection.new.get(params)
9
- self
10
- end
11
-
12
4
  def load_request_uri(arguments = {})
13
5
  validation_arguments!(arguments)
14
6
 
@@ -27,8 +19,9 @@ module Awis
27
19
  end
28
20
 
29
21
  def validation_arguments!(arguments)
30
- @arguments = arguments
22
+ before_validation_arguments(arguments)
31
23
 
24
+ @arguments = arguments
32
25
  @arguments[:range] = arguments.fetch(:range, 31)
33
26
  @arguments[:start] = arguments.fetch(:start) { Time.now - (3600 * 24 * @arguments[:range].to_i) }
34
27
  end
@@ -3,14 +3,6 @@ module Awis
3
3
  class UrlInfo < Base
4
4
  DEFAULT_RESPONSE_GROUP = %w(related_links categories rank rank_by_country usage_stats adult_content speed language owned_domains links_in_count site_data).freeze
5
5
 
6
- def fetch(arguments = {})
7
- raise ArgumentError, "Any valid URL." unless arguments.has_key?(:url)
8
- validation_arguments!(arguments)
9
-
10
- @response_body = Awis::Connection.new.get(params)
11
- self
12
- end
13
-
14
6
  def load_request_uri(arguments = {})
15
7
  validation_arguments!(arguments)
16
8
 
@@ -19,6 +11,8 @@ module Awis
19
11
 
20
12
  private
21
13
  def validation_arguments!(arguments)
14
+ before_validation_arguments(arguments)
15
+
22
16
  @arguments = arguments
23
17
  @arguments[:response_group] = Array(arguments.fetch(:response_group, DEFAULT_RESPONSE_GROUP))
24
18
  end
@@ -1,6 +1,5 @@
1
1
  module Awis
2
2
  class Client
3
-
4
3
  def initialize
5
4
  raise CertificateError.new("Amazon access certificate is missing!") if Awis.config.access_key_id.nil? || Awis.config.secret_access_key.nil?
6
5
  end
@@ -41,4 +40,4 @@ module Awis
41
40
  end
42
41
  end
43
42
  end
44
- end
43
+ end
@@ -26,7 +26,7 @@ module Awis
26
26
 
27
27
  def get(params = {})
28
28
  setup_params(params)
29
-
29
+
30
30
  handle_response(request).body.force_encoding(Encoding::UTF_8)
31
31
  end
32
32
 
@@ -49,7 +49,7 @@ module Awis
49
49
 
50
50
  def request
51
51
  showing_request_uri
52
-
52
+
53
53
  Faraday.get(uri)
54
54
  end
55
55
 
@@ -1,8 +1,4 @@
1
1
  class Hash
2
- def deep_find(key)
3
- key?(key) ? self[key] : self.values.inject(nil) { |memo, v| memo ||= v.deep_find(key) if v.respond_to?(:deep_find) }
4
- end
5
-
6
2
  def array_slice_merge!(key, array, count)
7
3
  self[key] = array.each_slice(count).collect { |e| e.reduce({}, :merge) }
8
4
  end
@@ -8,4 +8,4 @@ module Awis
8
8
  autoload :CategoryListings, "awis/models/category_listings"
9
9
  autoload :CategoryBrowse, "awis/models/category_browse"
10
10
  end
11
- end
11
+ end
@@ -14,7 +14,7 @@ module Awis
14
14
  def action_name
15
15
  self.class.name.split(/\:\:/)[-1]
16
16
  end
17
-
17
+
18
18
  def relationship_collections(_object, items, items_count, kclass)
19
19
  return if items.empty?
20
20
 
@@ -8,7 +8,7 @@ module Awis
8
8
  @language_categories = []
9
9
  @related_categories = []
10
10
  @letter_bars = []
11
-
11
+
12
12
  setup_data! loading_response(response)
13
13
  end
14
14
 
@@ -10,7 +10,7 @@ module Awis
10
10
 
11
11
  def setup_data!(response)
12
12
  datas = []
13
-
13
+
14
14
  response.each_node do |node, path|
15
15
  text = node.inner_xml
16
16
  text = text.to_i if text.to_i.to_s === text
@@ -26,15 +26,13 @@ module Awis
26
26
  @site ||= text
27
27
  elsif node.name == 'aws:Start'
28
28
  @start ||= text
29
- elsif node.name == 'aws:Rank'
30
- @rank ||= text
31
29
  elsif node.name == 'aws:Date' && path == "#{base_node_name}/aws:Date"
32
30
  datas << { date: text }
33
31
  elsif node.name == 'aws:PerMillion' && path == "#{base_node_name}/aws:PageViews/aws:PerMillion"
34
32
  datas << { page_views_per_million: text }
35
33
  elsif node.name == 'aws:PerUser' && path == "#{base_node_name}/aws:PageViews/aws:PerUser"
36
34
  datas << { page_views_per_user: text }
37
- elsif node.name == 'aws:PerMillion' && path == "#{base_node_name}/aws:Rank"
35
+ elsif node.name == 'aws:Rank' && path == "#{base_node_name}/aws:Rank"
38
36
  datas << { rank: text }
39
37
  elsif node.name == 'aws:PerMillion' && path == "#{base_node_name}/aws:Reach/aws:PerMillion"
40
38
  datas << { reach_per_million: text }
@@ -7,15 +7,15 @@ module Awis
7
7
  @usage_statistics = []
8
8
  @related_links = []
9
9
  @categories = []
10
-
10
+
11
11
  setup_data! loading_response(response)
12
12
  end
13
13
 
14
14
  def setup_data!(response)
15
- content_data = {
15
+ content_data = {
16
16
  owned_domains: []
17
17
  }
18
- contact_info = {
18
+ contact_info = {
19
19
  phone_numbers: []
20
20
  }
21
21
  statistics = []
@@ -156,7 +156,7 @@ module Awis
156
156
  end
157
157
 
158
158
  class ContentData < BaseEntity
159
- attr_accessor :data_url, :site_title, :site_description, :online_since, :speed_median_load_time, :speed_percentile, :adult_content,
159
+ attr_accessor :data_url, :site_title, :site_description, :online_since, :speed_median_load_time, :speed_percentile, :adult_content,
160
160
  :language_locale, :links_in_count, :owned_domains
161
161
 
162
162
  def initialize(options)
@@ -207,7 +207,7 @@ module Awis
207
207
  end
208
208
 
209
209
  class UsageStatistic < BaseEntity
210
- attr_accessor :time_range_months, :time_range_days, :rank_value, :rank_delta, :reach_rank_value, :reach_rank_delta,
210
+ attr_accessor :time_range_months, :time_range_days, :rank_value, :rank_delta, :reach_rank_value, :reach_rank_delta,
211
211
  :reach_per_million_value, :reach_per_million_delta, :reach_page_views_per_million_value, :reach_page_views_per_million_delta,
212
212
  :reach_page_views_rank_value, :reach_page_views_rank_delta, :reach_page_views_per_user_value, :reach_page_views_per_user_delta
213
213
 
@@ -1,3 +1,3 @@
1
1
  module Awis
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awis-sdk-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -167,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
167
  version: '0'
168
168
  segments:
169
169
  - 0
170
- hash: -3875215359314092874
170
+ hash: 3226589619329212718
171
171
  requirements: []
172
172
  rubyforge_project:
173
173
  rubygems_version: 1.8.23