rsqoot 0.4.1 → 0.4.2

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YjcwZDMzOTM2ZWI4NWNlYzRiY2I4ZjcxNmU0Y2Y0Nzk1YmFkZTVhNw==
4
+ NjMzNmUyNTgxOTMwOWMxYTEwZjgxMjI2ODZjNDcwYjE1NzFkNDdlYw==
5
5
  data.tar.gz: !binary |-
6
- NzViOTRlN2I2N2JjNDYzMWE0MGZlYzU1OWY4ZTZmOTBmMThiY2Q3MQ==
6
+ NzUyOWVhMzQ5ZWYyZWVhZGIzNTZhODQ2OTg4ODAwY2Y0ZmQ0NzdhOQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MmVhOTYyM2M3NDk1ZTU3NmJkM2JhM2NkM2QyNzIyZjM1YWY5NTcyMjNmNjZi
10
- YjNhYjFiODk4ZDliZTUyNTJmYWIxNWUyMjQ0NDcwMGRjYzUyNWRiMjVlZGU3
11
- N2Q5ZDc5ZjFkMmZiZjcxOGI3MTNlZDdkYzg5MDExNTY3MGU3Yjk=
9
+ YTBjNzA4MDY5ZWQ4M2FmNjNjODg2YzAxMjBhMTA4OWMxZjViMzUxZDgzYmMw
10
+ ZDEwNjQwNTJiMmQwYjcwOTQ5Y2M4OGZiYzgyMmIzNTI2Yjg5OTEzMGMwZmRj
11
+ ZmJkYWNkN2FjMzJiNDI1OWI0M2JkODM0N2E4ODA4N2NjYWM0YzY=
12
12
  data.tar.gz: !binary |-
13
- N2ViOGI5MTk1NmE0ZDk2NDRjNGQyYjUyZDdiN2JiMmY2MGM3MzNjNDQ3ZGU0
14
- YzM2OWZlNjgzNjhhNWMwZDE5OGExNTY5NGVjZjQyMTRmMWZiOTgzN2EyYTBi
15
- YzQ5YzNkNjkwZWUzN2Y3OWE5NmM5Nzg4ZTZmYWViYWU1NGRiZjk=
13
+ MTM0ZjBiN2VhOTIzMGMyYmJlMzUwZTQxMGM3ZWUxMDBiZjdlMzg3ODIyOTU4
14
+ MjY4ZjczNzY4NjE5YmQxYTFiZjk1MzcwYzk1ZjU0MWM2MTcwN2YzMDVlZDFh
15
+ NDM4YjUzYzZkNmFiMWRkYzkyNzU3NWUyZjNkYzBiM2Q4M2QxZjQ=
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  RSqoot
2
2
  ======
3
3
 
4
- A Ruby Wrapper for [Sqoot](http://www.sqoot.com) [API V2](http://docs.sqoot.com/v2/overview.html).
4
+ A Ruby Wrapper for [Sqoot](http://www.sqoot.com) [API V2](http://docs.sqoot.com/v2/overview.html). With Auto-caching for all APIS, and Auto-increment for deals.
5
5
 
6
6
  To get the list of available parameters kindly check out [API V2](http://docs.sqoot.com/v2/overview.html)
7
7
 
@@ -34,9 +34,13 @@ There’s a handy generator that generates the default configuration file into c
34
34
 
35
35
  rails g rsqoot:config
36
36
 
37
- You can also change your configuration in your instance, such as below:
37
+ Then, you should be able to use `SqootClient` to search deals. For example:
38
38
 
39
- sqoot ||= RSqoot::Client.new(public_api_key: "YOUR PUBLIC API KEY")
39
+ SqootClient.deals(query: 'Home')
40
+
41
+ You can also change your configuration in your own instance, such as below:
42
+
43
+ sqoot ||= RSqoot::Client.new(public_api_key: "YOUR PUBLIC API KEY", private_api_key: 'YOUR PRIVATE API KEY')
40
44
 
41
45
  #### Basic Usages
42
46
 
@@ -95,6 +99,20 @@ If you want to fetch the newest records each time, you can do as below:
95
99
 
96
100
  By this, it will update the cache by each query.
97
101
 
102
+ #### Auto increment for deals
103
+
104
+ sqoot.total_sqoot_deals(query: 'Home', page: 2, category_slugs: 'US')
105
+ # For this method, it will cache all the pages for current query options, the more you query the more it will store until reach the end.
106
+
107
+ # For example:
108
+ sqoot.total_sqoot_deals(query: 'Home', page: 1, per_page: 20, category_slugs: 'US').count
109
+ # => 20 records
110
+ sqoot.total_sqoot_deals(query: 'Home', page: 2, per_page: 20, category_slugs: 'US').count
111
+ # => 40 records
112
+
113
+ # But once you change your query options, it will re-cache the records.
114
+
115
+
98
116
  ## Contributing
99
117
 
100
118
  1. Fork it
@@ -5,4 +5,6 @@ RSqoot.configure do |config|
5
5
  # config.authentication_method = :header
6
6
  # config.read_timeout = 20
7
7
  # config.expired_in = 1.hour
8
- end
8
+ end
9
+
10
+ SqootClient ||= RSqoot::Client.new
@@ -5,7 +5,7 @@ module RSqoot
5
5
  #
6
6
  # @return [Hashie::Mash] category list
7
7
  def categories(options={})
8
- updated_by options
8
+ options = update_by_expire_time options
9
9
  query = options.delete(:query)
10
10
  if categories_not_latest?(options)
11
11
  @rsqoot_categories = get('categories', options)
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
- updated_by options
11
+ options = update_by_expire_time options
12
12
  if clicks_not_latest?(options)
13
13
  @rsqoot_clicks = get('clicks', options)
14
14
  @rsqoot_clicks = @rsqoot_clicks.clicks if @rsqoot_clicks
@@ -8,7 +8,7 @@ module RSqoot
8
8
  #
9
9
  # @return [Hashie::Mash]
10
10
  def commissions(options={})
11
- updated_by options
11
+ options = update_by_expire_time options
12
12
  if commissions_not_latest?(options)
13
13
  @rsqoot_commissions = get('commissions', options)
14
14
  @rsqoot_commissions = @rsqoot_commissions.commissions if @rsqoot_commissions
data/lib/rsqoot/deal.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  module RSqoot
2
2
  module Deal
3
-
4
3
  # Retrieve a list of deals based on the following parameters
5
4
  #
6
5
  # @param [String] query (Search deals by title, description, fine print, merchant name, provider, and category.)
@@ -8,8 +7,9 @@ module RSqoot
8
7
  # @param [Integer] radius (Measured in miles. Defaults to 10.)
9
8
  # @param [Integer] page (Which page of result to return. Default to 1.)
10
9
  # @param [Integer] per_page (Number of results to return at once. Defaults to 10.)
10
+ #
11
11
  def deals(options={})
12
- updated_by options
12
+ options = update_by_expire_time options
13
13
  if deals_not_latest?(options)
14
14
  uniq = !!options.delete(:uniq)
15
15
  @rsqoot_deals = get('deals', options) || []
@@ -22,7 +22,7 @@ module RSqoot
22
22
  # Retrieve a deal by id
23
23
  #
24
24
  def deal(id, options={})
25
- updated_by options
25
+ options = update_by_expire_time options
26
26
  if deal_not_latest?(id)
27
27
  @rsqoot_deal = get("deals/#{id}", options)
28
28
  @rsqoot_deal = @rsqoot_deal.deal if @rsqoot_deal
@@ -34,8 +34,9 @@ module RSqoot
34
34
  url_generator("deals/#{deal_id}/image", options, require_key = true).first.to_s
35
35
  end
36
36
 
37
+ # Auto Increment for deals query.
37
38
  def total_sqoot_deals(options = {})
38
- @total_deals ||= []
39
+ @total_deals ||= []
39
40
  @cached_pages ||= []
40
41
  page = options[:page] || 1
41
42
  check_query_change options
@@ -52,6 +53,10 @@ module RSqoot
52
53
 
53
54
  attr_reader :cached_pages, :total_deals, :last_deals_query
54
55
 
56
+ # Uniq deals from Sqoot, because there are some many duplicated deals
57
+ # with different ids
58
+ # Simplely distinguish them by their titles
59
+ #
55
60
  def uniq_deals(deals = [])
56
61
  titles = deals.map(&:title).uniq
57
62
  titles.map do |title|
@@ -63,16 +68,29 @@ module RSqoot
63
68
  end.flatten
64
69
  end
65
70
 
71
+ # A status checker for method :total_sqoot_deals
72
+ # If the query parameters changed, this will reset the cache
73
+ # else it will do nothing
74
+ #
66
75
  def check_query_change(options = {})
76
+ options = update_by_expire_time options
67
77
  @last_deals_query ||= ''
68
- current_query = options[:query].to_s + options[:category_slugs].to_s
78
+ current_query = options[:query].to_s
79
+ current_query += options[:category_slugs].to_s
80
+ current_query += options[:location].to_s
81
+ current_query += options[:radius].to_s
82
+ current_query += options[:online].to_s
83
+ current_query += options[:expired_in].to_s
84
+ current_query += options[:per_page].to_s
69
85
  if @last_deals_query != current_query
70
86
  @last_deals_query = current_query
71
- @total_deals = []
87
+ @total_deals = []
72
88
  @cached_pages = []
73
89
  end
74
90
  end
75
91
 
92
+ # Helper methods to detect which page is cached
93
+ #
76
94
  def page_cached?(page = 1)
77
95
  cached_pages.include? page.to_s
78
96
  end
data/lib/rsqoot/helper.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  module RSqoot
2
2
  module Helper
3
3
 
4
+ # Add auto-cache helper methods, instances to save the latest query
5
+ #
4
6
  def self.included(base)
5
7
  [ 'deals',
6
8
  'deal',
@@ -18,6 +20,11 @@ module RSqoot
18
20
  end
19
21
  end
20
22
 
23
+ # Add categories and providers query helpers
24
+ # Search categories and providers will be very easy
25
+ # Such as: query_categories('home&_visiter,friends')
26
+ # => search records like: home, visiter, friends
27
+ #
21
28
  [ 'categories',
22
29
  'providers' ].each do |name|
23
30
  base.send :define_method, ('query_' + name).to_sym do |q|
@@ -34,10 +41,13 @@ module RSqoot
34
41
  end
35
42
  end
36
43
 
37
- def updated_by(options = {})
44
+ # Add expired time functionality to this gem
45
+ # By default is 1.hour, and can be replaced anywhere
46
+ #
47
+ def update_by_expire_time(options = {})
38
48
  @expired_in = options[:expired_in] if options[:expired_in].present?
39
49
  time = Time.now.to_i / expired_in.to_i
40
- options.merge!({expired_in: time})
50
+ options.merge({expired_in: time})
41
51
  end
42
52
 
43
53
  end
@@ -7,7 +7,7 @@ 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
- updated_by options
10
+ options = update_by_expire_time options
11
11
  if merchant_not_latest?(id)
12
12
  @rsqoot_merchant = get("merchants/#{id}", options)
13
13
  @rsqoot_merchant = @rsqoot_merchant.merchant if @rsqoot_merchant
@@ -4,7 +4,7 @@ module RSqoot
4
4
  #
5
5
  # @return [Hashie::Mash]
6
6
  def providers(options={})
7
- updated_by options
7
+ options = update_by_expire_time options
8
8
  query = options.delete(:query)
9
9
  if providers_not_latest?(options)
10
10
  @rsqoot_providers = get('providers', options)
@@ -1,3 +1,3 @@
1
1
  module RSqoot
2
- VERSION = '0.4.1'
2
+ VERSION = '0.4.2'
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.4.1
4
+ version: 0.4.2
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-11-05 00:00:00.000000000 Z
11
+ date: 2013-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie