rsqoot 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +18 -1
- data/lib/generators/rsqoot/templates/rsqoot_config.rb +1 -0
- data/lib/rsqoot/category.rb +5 -2
- data/lib/rsqoot/click.rb +2 -0
- data/lib/rsqoot/client.rb +6 -5
- data/lib/rsqoot/commission.rb +1 -0
- data/lib/rsqoot/deal.rb +17 -0
- data/lib/rsqoot/helper.rb +23 -0
- data/lib/rsqoot/merchant.rb +2 -0
- data/lib/rsqoot/provider.rb +5 -2
- data/lib/rsqoot/request.rb +3 -1
- data/lib/rsqoot/version.rb +1 -1
- data/lib/rsqoot.rb +3 -8
- data/rsqoot.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NDQ0NmYzYTJhMWVjODg4NjVhM2M4ZTZhNTkyNzU1NDI4OGM1Mjc2Ng==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NzFmOTMzNWJjOWY1OGQyYTEyZDVmZjEwMTEwZDFiZjVkN2YyM2I5Zg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NDdjZTFhYjQ3ZjliNGI3NWQ3MTliYzIyZWNhMTdhMjliMDM0MmQzOThkMjA2
|
10
|
+
ZjI0NTM0NTYxZDNlNjk1MjZiZGMzM2UyNzVhNTZkMGJjZTM3YjhjNTI3MjBh
|
11
|
+
ZGE1MDlkYjdlMmZkMjM3MDdkZTA0ZDgwOTVkODJmZDUzZjdmNmU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NzIzMzE3ZTEwYmQ1MTRhNzhlMGZkZTZjMTc4ZjcxNDIxMDBkYzg3MDkxNTNi
|
14
|
+
ZjhlMDhhYTk3NzM3ODcyZWI2MWU2M2E3MjkzNDkxMGM0NTEwNGM5MjJiYzA3
|
15
|
+
ZWNlZDFkNzRmZDlmNTYyZTRjZDI4ZGM5NjQyY2NjYmRkYjJmNzg=
|
data/README.md
CHANGED
@@ -30,6 +30,7 @@ Or install it yourself as:
|
|
30
30
|
base_api_url # 'https://api.sqoot.com' by default
|
31
31
|
authentication_method # :header by default
|
32
32
|
read_timeout # 20 by default
|
33
|
+
expired_in # 1.hour by default
|
33
34
|
|
34
35
|
There’s a handy generator that generates the default configuration file into config/initializers directory. Run the following generator command, then edit the generated file.
|
35
36
|
|
@@ -46,6 +47,8 @@ You can also change your configuration in your instance, such as below:
|
|
46
47
|
sqoot.deals
|
47
48
|
#=> returns a list of deals
|
48
49
|
|
50
|
+
sqoot.deals(query: 'travel')
|
51
|
+
|
49
52
|
sqoot.deals(location: 'Chicago')
|
50
53
|
|
51
54
|
sqoot.deals(location: 'Chicago', per_page: 10)
|
@@ -63,6 +66,15 @@ You can also change your configuration in your instance, such as below:
|
|
63
66
|
sqoot.providers
|
64
67
|
# => returns a list of providers
|
65
68
|
|
69
|
+
sqoot.providers(query: 'Groupon')
|
70
|
+
|
71
|
+
sqoot.categories
|
72
|
+
# => returns a list of categories
|
73
|
+
|
74
|
+
sqoot.categories(query: 'home')
|
75
|
+
sqoot.categories(query: 'home&health')
|
76
|
+
sqoot.categories(query: 'home,health')
|
77
|
+
|
66
78
|
sqoot.commissions
|
67
79
|
# => returns current month commissions
|
68
80
|
|
@@ -81,10 +93,15 @@ Please notice that each query with above methods will automaticlly cache the res
|
|
81
93
|
|
82
94
|
If you want to fetch the newest records each time, you can do as below:
|
83
95
|
|
84
|
-
sqoot.deals(location: 'Chicago',
|
96
|
+
sqoot.deals(location: 'Chicago', expired_in: 1.second)
|
85
97
|
|
86
98
|
By this, it will update the cache by each query.
|
87
99
|
|
100
|
+
## TODO
|
101
|
+
|
102
|
+
+ Add auto-caching in config file
|
103
|
+
+ Add cache expire time in config file
|
104
|
+
|
88
105
|
## Contributing
|
89
106
|
|
90
107
|
1. Fork it
|
data/lib/rsqoot/category.rb
CHANGED
@@ -5,11 +5,14 @@ module RSqoot
|
|
5
5
|
#
|
6
6
|
# @return [Hashie::Mash] category list
|
7
7
|
def categories(options={})
|
8
|
+
updated_by options
|
9
|
+
query = options.delete(:query)
|
8
10
|
if categories_not_latest?(options)
|
9
11
|
@rsqoot_categories = get('categories', options)
|
10
|
-
@rsqoot_categories = @rsqoot_categories.categories if @rsqoot_categories
|
12
|
+
@rsqoot_categories = @rsqoot_categories.categories.map(&:category) if @rsqoot_categories
|
11
13
|
end
|
12
|
-
@rsqoot_categories
|
14
|
+
query.present? ? query_categories(query) : @rsqoot_categories
|
13
15
|
end
|
16
|
+
|
14
17
|
end
|
15
18
|
end
|
data/lib/rsqoot/click.rb
CHANGED
@@ -8,11 +8,13 @@ module RSqoot
|
|
8
8
|
#
|
9
9
|
# @return [Hashie::Mash]
|
10
10
|
def clicks(options={})
|
11
|
+
updated_by options
|
11
12
|
if clicks_not_latest?(options)
|
12
13
|
@rsqoot_clicks = get('clicks', options)
|
13
14
|
@rsqoot_clicks = @rsqoot_clicks.clicks if @rsqoot_clicks
|
14
15
|
end
|
15
16
|
@rsqoot_clicks
|
16
17
|
end
|
18
|
+
|
17
19
|
end
|
18
20
|
end
|
data/lib/rsqoot/client.rb
CHANGED
@@ -18,14 +18,15 @@ module RSqoot
|
|
18
18
|
include Provider
|
19
19
|
include Request
|
20
20
|
|
21
|
-
attr_reader :public_api_key, :private_api_key, :base_api_url, :authentication_method, :read_timeout
|
21
|
+
attr_reader :public_api_key, :private_api_key, :base_api_url, :authentication_method, :read_timeout, :query_options, :expired_in
|
22
22
|
|
23
23
|
def initialize(options={})
|
24
|
-
@public_api_key = options[:public_api_key]
|
25
|
-
@private_api_key = options[:private_api_key]
|
26
|
-
@base_api_url = options[:base_api_url]
|
24
|
+
@public_api_key = options[:public_api_key] || RSqoot.public_api_key
|
25
|
+
@private_api_key = options[:private_api_key] || RSqoot.private_api_key
|
26
|
+
@base_api_url = options[:base_api_url] || RSqoot.base_api_url
|
27
27
|
@authentication_method = options[:authentication_method] || RSqoot.authentication_method
|
28
|
-
@read_timeout = options[:read_timeout]
|
28
|
+
@read_timeout = options[:read_timeout] || RSqoot.read_timeout
|
29
|
+
@expired_in = options[:expired_in] || RSqoot.expired_in
|
29
30
|
end
|
30
31
|
|
31
32
|
end
|
data/lib/rsqoot/commission.rb
CHANGED
@@ -8,6 +8,7 @@ module RSqoot
|
|
8
8
|
#
|
9
9
|
# @return [Hashie::Mash]
|
10
10
|
def commissions(options={})
|
11
|
+
updated_by options
|
11
12
|
if commissions_not_latest?(options)
|
12
13
|
@rsqoot_commissions = get('commissions', options)
|
13
14
|
@rsqoot_commissions = @rsqoot_commissions.commissions if @rsqoot_commissions
|
data/lib/rsqoot/deal.rb
CHANGED
@@ -9,9 +9,12 @@ 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
|
+
updated_by options
|
12
13
|
if deals_not_latest?(options)
|
14
|
+
uniq = !!options.delete(:uniq)
|
13
15
|
@rsqoot_deals = get('deals', options) || []
|
14
16
|
@rsqoot_deals = @rsqoot_deals.deals.map(&:deal) if !@rsqoot_deals.empty?
|
17
|
+
@rsqoot_deals = uniq_deals(@rsqoot_deals) if uniq
|
15
18
|
end
|
16
19
|
@rsqoot_deals
|
17
20
|
end
|
@@ -19,6 +22,7 @@ module RSqoot
|
|
19
22
|
# Retrieve a deal by id
|
20
23
|
#
|
21
24
|
def deal(id, options={})
|
25
|
+
updated_by options
|
22
26
|
if deal_not_latest?(id)
|
23
27
|
@rsqoot_deal = get("deals/#{id}", options)
|
24
28
|
@rsqoot_deal = @rsqoot_deal.deal if @rsqoot_deal
|
@@ -30,5 +34,18 @@ module RSqoot
|
|
30
34
|
url_generator("deals/#{deal_id}/image", options, require_key = true).first.to_s
|
31
35
|
end
|
32
36
|
|
37
|
+
private
|
38
|
+
|
39
|
+
def uniq_deals(deals = [])
|
40
|
+
titles = deals.map(&:title).uniq
|
41
|
+
titles.map do |title|
|
42
|
+
deals.map do |deal|
|
43
|
+
if deal.try(:title) == title
|
44
|
+
deal
|
45
|
+
end
|
46
|
+
end.compact.last
|
47
|
+
end.flatten
|
48
|
+
end
|
49
|
+
|
33
50
|
end
|
34
51
|
end
|
data/lib/rsqoot/helper.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
module RSqoot
|
2
2
|
module Helper
|
3
|
+
|
3
4
|
def self.included(base)
|
4
5
|
[ 'deals',
|
5
6
|
'deal',
|
@@ -16,6 +17,28 @@ module RSqoot
|
|
16
17
|
result
|
17
18
|
end
|
18
19
|
end
|
20
|
+
|
21
|
+
[ 'categories',
|
22
|
+
'providers' ].each do |name|
|
23
|
+
base.send :define_method, ('query_' + name).to_sym do |q|
|
24
|
+
queries = q.downcase.scan(/[A-Za-z]+|\d+/)
|
25
|
+
if queries.present?
|
26
|
+
queries.map do |q|
|
27
|
+
instance_variable_get('@rsqoot_'+name).dup.keep_if do |c|
|
28
|
+
c.slug =~ Regexp.new(q)
|
29
|
+
end
|
30
|
+
end.flatten.compact.uniq
|
31
|
+
end
|
32
|
+
end
|
33
|
+
base.class_eval { private ('query_' + name).to_sym }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def updated_by(options = {})
|
38
|
+
@expired_in = options[:expired_in] if options[:expired_in].present?
|
39
|
+
time = Time.now.to_i / expired_in.to_i
|
40
|
+
options.merge!({expired_in: time})
|
19
41
|
end
|
42
|
+
|
20
43
|
end
|
21
44
|
end
|
data/lib/rsqoot/merchant.rb
CHANGED
@@ -7,11 +7,13 @@ 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
11
|
if merchant_not_latest?(id)
|
11
12
|
@rsqoot_merchant = get("merchants/#{id}", options)
|
12
13
|
@rsqoot_merchant = @rsqoot_merchant.merchant if @rsqoot_merchant
|
13
14
|
end
|
14
15
|
@rsqoot_merchant
|
15
16
|
end
|
17
|
+
|
16
18
|
end
|
17
19
|
end
|
data/lib/rsqoot/provider.rb
CHANGED
@@ -4,11 +4,14 @@ module RSqoot
|
|
4
4
|
#
|
5
5
|
# @return [Hashie::Mash]
|
6
6
|
def providers(options={})
|
7
|
+
updated_by options
|
8
|
+
query = options.delete(:query)
|
7
9
|
if providers_not_latest?(options)
|
8
10
|
@rsqoot_providers = get('providers', options)
|
9
|
-
@rsqoot_providers = @rsqoot_providers.providers if @rsqoot_providers
|
11
|
+
@rsqoot_providers = @rsqoot_providers.providers.map(&:provider) if @rsqoot_providers
|
10
12
|
end
|
11
|
-
@rsqoot_providers
|
13
|
+
query.present? ? query_providers(query) : @rsqoot_providers
|
12
14
|
end
|
15
|
+
|
13
16
|
end
|
14
17
|
end
|
data/lib/rsqoot/request.rb
CHANGED
data/lib/rsqoot/version.rb
CHANGED
data/lib/rsqoot.rb
CHANGED
@@ -1,16 +1,10 @@
|
|
1
|
+
require "active_support/core_ext"
|
1
2
|
require "rsqoot/client"
|
2
3
|
|
3
|
-
# load Rails/Railtie
|
4
|
-
begin
|
5
|
-
require 'rails'
|
6
|
-
rescue LoadError
|
7
|
-
#do nothing
|
8
|
-
end
|
9
|
-
|
10
4
|
module RSqoot
|
11
5
|
|
12
6
|
class << self
|
13
|
-
attr_accessor :public_api_key, :private_api_key, :base_api_url, :authentication_method, :read_timeout
|
7
|
+
attr_accessor :public_api_key, :private_api_key, :base_api_url, :authentication_method, :read_timeout, :expired_in
|
14
8
|
|
15
9
|
# Configure default credentials easily
|
16
10
|
#
|
@@ -28,6 +22,7 @@ module RSqoot
|
|
28
22
|
self.base_api_url ||= "https://api.sqoot.com"
|
29
23
|
self.authentication_method = :header
|
30
24
|
self.read_timeout = 60
|
25
|
+
self.expired_in = 1.hour
|
31
26
|
end
|
32
27
|
|
33
28
|
private
|
data/rsqoot.gemspec
CHANGED
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
|
+
version: 0.4.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-11-
|
11
|
+
date: 2013-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashie
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 1.7.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activesupport
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.0.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.0.0
|
41
55
|
description: A Ruby Wrapper for Sqoot API V2.
|
42
56
|
email:
|
43
57
|
- lyfeyaj@gmail.com
|