rsqoot 0.4.0 → 0.4.1

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
- NDQ0NmYzYTJhMWVjODg4NjVhM2M4ZTZhNTkyNzU1NDI4OGM1Mjc2Ng==
4
+ YjcwZDMzOTM2ZWI4NWNlYzRiY2I4ZjcxNmU0Y2Y0Nzk1YmFkZTVhNw==
5
5
  data.tar.gz: !binary |-
6
- NzFmOTMzNWJjOWY1OGQyYTEyZDVmZjEwMTEwZDFiZjVkN2YyM2I5Zg==
6
+ NzViOTRlN2I2N2JjNDYzMWE0MGZlYzU1OWY4ZTZmOTBmMThiY2Q3MQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NDdjZTFhYjQ3ZjliNGI3NWQ3MTliYzIyZWNhMTdhMjliMDM0MmQzOThkMjA2
10
- ZjI0NTM0NTYxZDNlNjk1MjZiZGMzM2UyNzVhNTZkMGJjZTM3YjhjNTI3MjBh
11
- ZGE1MDlkYjdlMmZkMjM3MDdkZTA0ZDgwOTVkODJmZDUzZjdmNmU=
9
+ MmVhOTYyM2M3NDk1ZTU3NmJkM2JhM2NkM2QyNzIyZjM1YWY5NTcyMjNmNjZi
10
+ YjNhYjFiODk4ZDliZTUyNTJmYWIxNWUyMjQ0NDcwMGRjYzUyNWRiMjVlZGU3
11
+ N2Q5ZDc5ZjFkMmZiZjcxOGI3MTNlZDdkYzg5MDExNTY3MGU3Yjk=
12
12
  data.tar.gz: !binary |-
13
- NzIzMzE3ZTEwYmQ1MTRhNzhlMGZkZTZjMTc4ZjcxNDIxMDBkYzg3MDkxNTNi
14
- ZjhlMDhhYTk3NzM3ODcyZWI2MWU2M2E3MjkzNDkxMGM0NTEwNGM5MjJiYzA3
15
- ZWNlZDFkNzRmZDlmNTYyZTRjZDI4ZGM5NjQyY2NjYmRkYjJmNzg=
13
+ N2ViOGI5MTk1NmE0ZDk2NDRjNGQyYjUyZDdiN2JiMmY2MGM3MzNjNDQ3ZGU0
14
+ YzM2OWZlNjgzNjhhNWMwZDE5OGExNTY5NGVjZjQyMTRmMWZiOTgzN2EyYTBi
15
+ YzQ5YzNkNjkwZWUzN2Y3OWE5NmM5Nzg4ZTZmYWViYWU1NGRiZjk=
data/README.md CHANGED
@@ -1,9 +1,7 @@
1
1
  RSqoot
2
2
  ======
3
3
 
4
- A Ruby Wrapper For Sqoot API V2
5
-
6
- 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).
7
5
 
8
6
  To get the list of available parameters kindly check out [API V2](http://docs.sqoot.com/v2/overview.html)
9
7
 
@@ -97,11 +95,6 @@ If you want to fetch the newest records each time, you can do as below:
97
95
 
98
96
  By this, it will update the cache by each query.
99
97
 
100
- ## TODO
101
-
102
- + Add auto-caching in config file
103
- + Add cache expire time in config file
104
-
105
98
  ## Contributing
106
99
 
107
100
  1. Fork it
data/lib/rsqoot/deal.rb CHANGED
@@ -34,8 +34,24 @@ module RSqoot
34
34
  url_generator("deals/#{deal_id}/image", options, require_key = true).first.to_s
35
35
  end
36
36
 
37
+ def total_sqoot_deals(options = {})
38
+ @total_deals ||= []
39
+ @cached_pages ||= []
40
+ page = options[:page] || 1
41
+ check_query_change options
42
+ if !page_cached? page
43
+ @total_deals += deals(options)
44
+ @total_deals.uniq!
45
+ @cached_pages << page.to_s
46
+ @cached_pages.uniq!
47
+ end
48
+ @total_deals
49
+ end
50
+
37
51
  private
38
52
 
53
+ attr_reader :cached_pages, :total_deals, :last_deals_query
54
+
39
55
  def uniq_deals(deals = [])
40
56
  titles = deals.map(&:title).uniq
41
57
  titles.map do |title|
@@ -47,5 +63,19 @@ module RSqoot
47
63
  end.flatten
48
64
  end
49
65
 
66
+ def check_query_change(options = {})
67
+ @last_deals_query ||= ''
68
+ current_query = options[:query].to_s + options[:category_slugs].to_s
69
+ if @last_deals_query != current_query
70
+ @last_deals_query = current_query
71
+ @total_deals = []
72
+ @cached_pages = []
73
+ end
74
+ end
75
+
76
+ def page_cached?(page = 1)
77
+ cached_pages.include? page.to_s
78
+ end
79
+
50
80
  end
51
81
  end
@@ -1,3 +1,3 @@
1
1
  module RSqoot
2
- VERSION = '0.4.0'
2
+ VERSION = '0.4.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rsqoot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felix Liu