rsqoot 0.2.2 → 0.3.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,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: db6629abd6587c3672911e89bb6686b648e13d0e
4
- data.tar.gz: 93dd7b2d00e771f81bc89821a4f5ce0166f9edb9
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OTA2NTI1OGNiM2VkN2NmMTM5ODRiMDE3NTI5Y2Q5NjYxMGNiYjBiMQ==
5
+ data.tar.gz: !binary |-
6
+ ZWU5MmJjNjU2NzJiZGJhZDMzYTJjZWViMjNiMGQ4N2RhZWExNTkyMA==
5
7
  SHA512:
6
- metadata.gz: ef941d492eb2cb23deab2cfdf17692bd055d3634af1930e5eb49d6b8fbfd7c521d703a50b85c1cc3cc62e8996752057868940f33cf5de8e9d45678aa2c91c13f
7
- data.tar.gz: 4d34799a2d1b2320e24e497815f6983af1b0e7ade53798308828645b20b4e6f8a7cba9badcebd4a47f4a130bba62641603a02e610a687bffc9d6ebd8bd691a31
8
+ metadata.gz: !binary |-
9
+ MTA4NGM0MjI0YTk0MGMyZjRlZjA3NjI5YWE5MzhkNTA3NWU0ZmVjMzQyZWY0
10
+ YWMzODFhZGFkMzdjODc4MDZmNmQyNThjNTJmNTJjNTAzNTg2MWQ3MTBiNTQy
11
+ ZTRmOTk0NzdkNzhhOGNhMGJjMTAwNTQ2ZWZiNjE4MmJiOTc1OTM=
12
+ data.tar.gz: !binary |-
13
+ YzQ1OTI4NDNkMDI3NzBhYjhiYTY1MDRkYTI3OGI0MWRjNWNjMTQyZWU0MWI5
14
+ NTQxZTdiYzg0NmM1MDE4Y2MwMWNiNGQ2M2U3MTY3YmZjMWU3ZDEyMTAxNzYw
15
+ NTRiOGRmMjA3YzExMTk1NjRhYTI4MWY4OTVkYzkzY2VkZDJjYzU=
@@ -5,7 +5,11 @@ module RSqoot
5
5
  #
6
6
  # @return [Hashie::Mash] category list
7
7
  def categories(options={})
8
- get('categories', options)
8
+ if categories_not_latest?(options)
9
+ @rsqoot_categories = get('categories', options)
10
+ @rsqoot_categories = @rsqoot_categories.categories if @rsqoot_categories
11
+ end
12
+ @rsqoot_categories
9
13
  end
10
14
  end
11
15
  end
data/lib/rsqoot/click.rb CHANGED
@@ -8,7 +8,7 @@ module RSqoot
8
8
  #
9
9
  # @return [Hashie::Mash]
10
10
  def clicks(options={})
11
- get('clicks', options)
11
+ get('clicks', options).clicks
12
12
  end
13
13
  end
14
14
  end
data/lib/rsqoot/client.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require "rsqoot/helper"
1
2
  require "rsqoot/merchant"
2
3
  require "rsqoot/category"
3
4
  require "rsqoot/provider"
@@ -8,6 +9,7 @@ require "rsqoot/request"
8
9
 
9
10
  module RSqoot
10
11
  class Client
12
+ include Helper
11
13
  include Category
12
14
  include Click
13
15
  include Commission
@@ -8,7 +8,7 @@ module RSqoot
8
8
  #
9
9
  # @return [Hashie::Mash]
10
10
  def commissions(options={})
11
- get('commissions', options)
11
+ get('commissions', options).commissions
12
12
  end
13
13
 
14
14
  end
data/lib/rsqoot/deal.rb CHANGED
@@ -9,21 +9,25 @@ module RSqoot
9
9
  # @param [Integer] page (Which page of result to return. Default to 1.)
10
10
  # @param [Integer] per_page (Number of results to return at once. Defaults to 10.)
11
11
  def deals(options={})
12
- get('deals', options)
12
+ if deals_not_latest?(options)
13
+ @rsqoot_deals = get('deals', options) || []
14
+ @rsqoot_deals = @rsqoot_deals.deals.map(&:deal) if !@rsqoot_deals.empty?
15
+ end
16
+ @rsqoot_deals
13
17
  end
14
18
 
15
19
  # Retrieve a deal by id
16
20
  #
17
21
  def deal(id, options={})
18
- get("deals/#{id}", options)
22
+ if deal_not_latest?(id)
23
+ @rsqoot_deal = get("deals/#{id}", options)
24
+ @rsqoot_deal = @rsqoot_deal.deal if @rsqoot_deal
25
+ end
26
+ @rsqoot_deal
19
27
  end
20
28
 
21
- def deal_click(id, options={})
22
- get("deals/#{id}/click", options, parse = false)
23
- end
24
-
25
- def deal_impression(id, options={})
26
- get("deals/#{id}/image", options, parse = false)
29
+ def impression(deal_id, options={})
30
+ url_generator("deals/#{deal_id}/image", options, require_key = true).first.to_s
27
31
  end
28
32
 
29
33
  end
@@ -0,0 +1,15 @@
1
+ module RSqoot
2
+ module Helper
3
+ def self.included(base)
4
+ ['deals', 'deal', 'categories', 'providers', 'merchant'].each do |name|
5
+ attr_reader ('rsqoot_' + name).to_sym
6
+ attr_accessor (name + '_options').to_sym
7
+ base.send :define_method, (name + '_not_latest?').to_sym do |opt|
8
+ result = method(name + '_options').call == opt ? false : true
9
+ method(name + '_options=').call opt if result
10
+ result
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -7,7 +7,11 @@ module RSqoot
7
7
  # @param [String] namespace (One of the supported namespaces. Factual, Foursquare, Facebook, Google, CitySearch, Yelp.)
8
8
 
9
9
  def merchant(id, options={})
10
- get("merchants/#{id}", options)
10
+ if merchant_not_latest?(id)
11
+ @rsqoot_merchant = get("merchants/#{id}", options)
12
+ @rsqoot_merchant = @rsqoot_merchant.merchant if @rsqoot_merchant
13
+ end
14
+ @rsqoot_merchant
11
15
  end
12
16
  end
13
17
  end
@@ -4,7 +4,11 @@ module RSqoot
4
4
  #
5
5
  # @return [Hashie::Mash]
6
6
  def providers(options={})
7
- get('providers', options)
7
+ if providers_not_latest?(options)
8
+ @rsqoot_providers = get('providers', options)
9
+ @rsqoot_providers = @rsqoot_providers.providers if @rsqoot_providers
10
+ end
11
+ @rsqoot_providers
8
12
  end
9
13
  end
10
14
  end
@@ -5,28 +5,31 @@ require 'json'
5
5
  module RSqoot
6
6
  module Request
7
7
 
8
- def get(path, opts = {}, parse = true)
9
- uri = URI.parse base_api_url
10
- uri.path = '/v2/' + path
11
- headers = {read_timeout: read_timeout}
12
- query = options_parser opts
13
- endpoint = path.split('/')[0]
8
+ def get(path, opts = {})
9
+ uri, headers = url_generator(path, opts)
10
+ begin
11
+ json = JSON.parse uri.open(headers).read
12
+ ::Hashie::Mash.new json
13
+ rescue
14
+ nil
15
+ end
16
+ end
17
+
18
+ def url_generator(path, opts = {}, require_key = false)
19
+ uri = URI.parse base_api_url
20
+ headers = {read_timeout: read_timeout}
21
+ uri.path = '/v2/' + path
22
+ query = options_parser opts
23
+ endpoint = path.split('/')[0]
14
24
  case authentication_method
15
25
  when :header
16
26
  headers.merge! h = {"Authorization" => "api_key #{api_key(endpoint)}"}
17
- query = query + "&api_key=#{api_key(endpoint)}" if !parse
27
+ query = query + "&api_key=#{api_key(endpoint)}" if require_key
18
28
  when :parameter
19
29
  query = query + "&api_key=#{api_key(endpoint)}"
20
30
  end
21
31
  uri.query = query
22
- if parse
23
- begin
24
- json = JSON.parse uri.open(headers).read
25
- ::Hashie::Mash.new json
26
- end
27
- else
28
- uri.to_s
29
- end
32
+ [uri, headers]
30
33
  end
31
34
 
32
35
  private
@@ -1,3 +1,3 @@
1
1
  module RSqoot
2
- VERSION = '0.2.2'
2
+ VERSION = '0.3.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rsqoot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felix Liu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-30 00:00:00.000000000 Z
11
+ date: 2013-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie
@@ -60,6 +60,7 @@ files:
60
60
  - lib/rsqoot/client.rb
61
61
  - lib/rsqoot/commission.rb
62
62
  - lib/rsqoot/deal.rb
63
+ - lib/rsqoot/helper.rb
63
64
  - lib/rsqoot/merchant.rb
64
65
  - lib/rsqoot/provider.rb
65
66
  - lib/rsqoot/request.rb
@@ -75,17 +76,17 @@ require_paths:
75
76
  - lib
76
77
  required_ruby_version: !ruby/object:Gem::Requirement
77
78
  requirements:
78
- - - '>='
79
+ - - ! '>='
79
80
  - !ruby/object:Gem::Version
80
81
  version: '0'
81
82
  required_rubygems_version: !ruby/object:Gem::Requirement
82
83
  requirements:
83
- - - '>='
84
+ - - ! '>='
84
85
  - !ruby/object:Gem::Version
85
86
  version: '0'
86
87
  requirements: []
87
88
  rubyforge_project:
88
- rubygems_version: 2.0.6
89
+ rubygems_version: 2.1.10
89
90
  signing_key:
90
91
  specification_version: 4
91
92
  summary: Wrapper for Sqoot API V2