rsqoot 0.4.2 → 0.5.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 +8 -8
- data/README.md +53 -41
- data/lib/generators/rsqoot/templates/rsqoot_config.rb +5 -5
- data/lib/rsqoot/category.rb +2 -2
- data/lib/rsqoot/click.rb +2 -2
- data/lib/rsqoot/commission.rb +2 -2
- data/lib/rsqoot/deal.rb +2 -2
- data/lib/rsqoot/helper.rb +12 -0
- data/lib/rsqoot/merchant.rb +1 -1
- data/lib/rsqoot/provider.rb +2 -2
- data/lib/rsqoot/request.rb +2 -3
- data/lib/rsqoot/version.rb +1 -1
- data/lib/rsqoot.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NzEwOThmZTFmMzUyMjI2ZjE3YzUwMDAwNWQ0YmY5NjUwNWE4ZGFmYQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MmJmNzM4Njc3OGEzMTY3NDE4ZTc3YjMyODQyMmU1MmQ0NTRmMDI2Mw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
M2Y3YjljNmZhNTU4MDMyMDgzNTUzMjE1NDNjNWUwYTlmODkwMzA4NzNlZGY0
|
10
|
+
ODEwYzJlNWYxMGIwMGIyZDliMmJjYzc0MDYzYTY5Y2FkMjc3MzhlNjRjZjJh
|
11
|
+
M2QxMGQ4NzYzZTExYTRmYjA2MzBkYzgwYjFkYmRhNjRmMmUwMjc=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
M2QxNzE1NTRhNDI3M2RkNWM0YzQ3ZjAwYWQwZTVlZDNiYmNiZjQ0ODU1Y2Nk
|
14
|
+
NTlkNzYwMzJjY2JmZTUzM2EzOGIzYzcyZWQ4ODJkYjk1YjI0NjhhNmM4ZDdi
|
15
|
+
MmZkNTI2OWQ0NTcwZmFjMTNmYzI0ZWNhNmJiNTk5MGQ2ZGY1M2Q=
|
data/README.md
CHANGED
@@ -9,7 +9,9 @@ To get the list of available parameters kindly check out [API V2](http://docs.sq
|
|
9
9
|
|
10
10
|
Add this line to your application's Gemfile:
|
11
11
|
|
12
|
-
|
12
|
+
```ruby
|
13
|
+
gem 'rsqoot'
|
14
|
+
```
|
13
15
|
|
14
16
|
And then execute:
|
15
17
|
|
@@ -27,7 +29,7 @@ Or install it yourself as:
|
|
27
29
|
private_api_key # YOUR PRIVATE API KEY
|
28
30
|
base_api_url # 'https://api.sqoot.com' by default
|
29
31
|
authentication_method # :header by default
|
30
|
-
read_timeout #
|
32
|
+
read_timeout # 60.seconds by default
|
31
33
|
expired_in # 1.hour by default
|
32
34
|
|
33
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.
|
@@ -36,58 +38,64 @@ There’s a handy generator that generates the default configuration file into c
|
|
36
38
|
|
37
39
|
Then, you should be able to use `SqootClient` to search deals. For example:
|
38
40
|
|
39
|
-
|
41
|
+
```ruby
|
42
|
+
SqootClient.deals(query: 'Home')
|
43
|
+
```
|
40
44
|
|
41
45
|
You can also change your configuration in your own instance, such as below:
|
42
46
|
|
43
|
-
|
47
|
+
```ruby
|
48
|
+
sqoot ||= RSqoot::Client.new(public_api_key: "YOUR PUBLIC API KEY", private_api_key: 'YOUR PRIVATE API KEY')
|
49
|
+
```
|
44
50
|
|
45
51
|
#### Basic Usages
|
46
52
|
|
47
|
-
|
53
|
+
```ruby
|
54
|
+
sqoot ||= RSqoot::Client.new
|
48
55
|
|
49
|
-
|
50
|
-
|
56
|
+
sqoot.deals
|
57
|
+
#=> returns a list of deals
|
51
58
|
|
52
|
-
|
59
|
+
sqoot.deals(query: 'travel')
|
53
60
|
|
54
|
-
|
61
|
+
sqoot.deals(location: 'Chicago')
|
55
62
|
|
56
|
-
|
63
|
+
sqoot.deals(location: 'Chicago', per_page: 10)
|
57
64
|
|
58
|
-
|
65
|
+
sqoot.deals(location: 'Chicago', per_page: 10, categories: 'health-beauty', page: 2)
|
59
66
|
|
60
|
-
|
67
|
+
sqoot.deals(price_at_least: 10, order: :commission_desc)
|
61
68
|
|
62
|
-
|
63
|
-
|
69
|
+
sqoot.impression(1555288, geometry: '250x250C')
|
70
|
+
# => return deal_id 1555288's image url which size is 250x250
|
64
71
|
|
65
|
-
|
66
|
-
|
72
|
+
sqoot.deal(1555288).url
|
73
|
+
# => return a click url which will redirect to another url
|
67
74
|
|
68
|
-
|
69
|
-
|
75
|
+
sqoot.providers
|
76
|
+
# => returns a list of providers
|
70
77
|
|
71
|
-
|
78
|
+
sqoot.providers(query: 'Groupon')
|
72
79
|
|
73
|
-
|
74
|
-
|
80
|
+
sqoot.categories
|
81
|
+
# => returns a list of categories
|
75
82
|
|
76
|
-
|
77
|
-
|
78
|
-
|
83
|
+
sqoot.categories(query: 'home')
|
84
|
+
sqoot.categories(query: 'home&health')
|
85
|
+
sqoot.categories(query: 'home,health')
|
79
86
|
|
80
|
-
|
81
|
-
|
87
|
+
sqoot.commissions
|
88
|
+
# => returns current month commissions
|
82
89
|
|
83
|
-
|
84
|
-
|
90
|
+
sqoot.commissions(to: '2012-01-01', from: '2012-01-20')
|
91
|
+
# => returns commissions using date_range :to & :from
|
85
92
|
|
86
|
-
|
87
|
-
|
93
|
+
sqoot.clicks
|
94
|
+
# => returns real-time clicks from the event request limit of 1000
|
88
95
|
|
89
|
-
|
90
|
-
|
96
|
+
sqoot.clicks(to: '2012-01-01', from: '2012-01-20')
|
97
|
+
# => returns clicks using date_range :to & :from
|
98
|
+
```
|
91
99
|
|
92
100
|
#### Auto Cache
|
93
101
|
|
@@ -95,22 +103,26 @@ Please notice that each query with above methods will automaticlly cache the res
|
|
95
103
|
|
96
104
|
If you want to fetch the newest records each time, you can do as below:
|
97
105
|
|
98
|
-
|
106
|
+
```ruby
|
107
|
+
sqoot.deals(location: 'Chicago', expired_in: 1.second)
|
108
|
+
```
|
99
109
|
|
100
110
|
By this, it will update the cache by each query.
|
101
111
|
|
102
112
|
#### Auto increment for deals
|
103
113
|
|
104
|
-
|
105
|
-
|
114
|
+
```ruby
|
115
|
+
sqoot.total_sqoot_deals(query: 'Home', page: 2, category_slugs: 'US')
|
116
|
+
# 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
117
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
118
|
+
# For example:
|
119
|
+
sqoot.total_sqoot_deals(query: 'Home', page: 1, per_page: 20, category_slugs: 'US').count
|
120
|
+
# => 20 records
|
121
|
+
sqoot.total_sqoot_deals(query: 'Home', page: 2, per_page: 20, category_slugs: 'US').count
|
122
|
+
# => 40 records
|
112
123
|
|
113
|
-
|
124
|
+
# But once you change your query options, it will re-cache the records.
|
125
|
+
```
|
114
126
|
|
115
127
|
|
116
128
|
## Contributing
|
@@ -1,10 +1,10 @@
|
|
1
1
|
RSqoot.configure do |config|
|
2
|
-
# config.public_api_key
|
3
|
-
# config.private_api_key
|
4
|
-
# config.base_api_url
|
2
|
+
# config.public_api_key = 'YOUR PUBLIC API KEY'
|
3
|
+
# config.private_api_key = 'YOUR PRIVATE API KEY'
|
4
|
+
# config.base_api_url = 'https://api.sqoot.com'
|
5
5
|
# config.authentication_method = :header
|
6
|
-
# config.read_timeout
|
7
|
-
# config.expired_in
|
6
|
+
# config.read_timeout = 60.seconds
|
7
|
+
# config.expired_in = 1.hour
|
8
8
|
end
|
9
9
|
|
10
10
|
SqootClient ||= RSqoot::Client.new
|
data/lib/rsqoot/category.rb
CHANGED
@@ -3,12 +3,12 @@ module RSqoot
|
|
3
3
|
|
4
4
|
# Retrieve a list of categories base on the following parameters
|
5
5
|
#
|
6
|
-
# @return [
|
6
|
+
# @return [RSqoot::SqootCategory] category list
|
7
7
|
def categories(options={})
|
8
8
|
options = update_by_expire_time options
|
9
9
|
query = options.delete(:query)
|
10
10
|
if categories_not_latest?(options)
|
11
|
-
@rsqoot_categories = get('categories', options)
|
11
|
+
@rsqoot_categories = get('categories', options, SqootCategory)
|
12
12
|
@rsqoot_categories = @rsqoot_categories.categories.map(&:category) if @rsqoot_categories
|
13
13
|
end
|
14
14
|
query.present? ? query_categories(query) : @rsqoot_categories
|
data/lib/rsqoot/click.rb
CHANGED
@@ -6,11 +6,11 @@ module RSqoot
|
|
6
6
|
# @param [String] :to Start date
|
7
7
|
# @param [String] :from End date
|
8
8
|
#
|
9
|
-
# @return [
|
9
|
+
# @return [RSqoot::SqootClick]
|
10
10
|
def clicks(options={})
|
11
11
|
options = update_by_expire_time options
|
12
12
|
if clicks_not_latest?(options)
|
13
|
-
@rsqoot_clicks = get('clicks', options)
|
13
|
+
@rsqoot_clicks = get('clicks', options, SqootClick)
|
14
14
|
@rsqoot_clicks = @rsqoot_clicks.clicks if @rsqoot_clicks
|
15
15
|
end
|
16
16
|
@rsqoot_clicks
|
data/lib/rsqoot/commission.rb
CHANGED
@@ -6,11 +6,11 @@ module RSqoot
|
|
6
6
|
# @param [String] :to Start date
|
7
7
|
# @param [String] :from End date
|
8
8
|
#
|
9
|
-
# @return [
|
9
|
+
# @return [RSqoot::SqootCommission]
|
10
10
|
def commissions(options={})
|
11
11
|
options = update_by_expire_time options
|
12
12
|
if commissions_not_latest?(options)
|
13
|
-
@rsqoot_commissions = get('commissions', options)
|
13
|
+
@rsqoot_commissions = get('commissions', options, SqootCommission)
|
14
14
|
@rsqoot_commissions = @rsqoot_commissions.commissions if @rsqoot_commissions
|
15
15
|
end
|
16
16
|
@rsqoot_commissions
|
data/lib/rsqoot/deal.rb
CHANGED
@@ -12,7 +12,7 @@ module RSqoot
|
|
12
12
|
options = update_by_expire_time options
|
13
13
|
if deals_not_latest?(options)
|
14
14
|
uniq = !!options.delete(:uniq)
|
15
|
-
@rsqoot_deals = get('deals', options) || []
|
15
|
+
@rsqoot_deals = get('deals', options, SqootDeal) || []
|
16
16
|
@rsqoot_deals = @rsqoot_deals.deals.map(&:deal) if !@rsqoot_deals.empty?
|
17
17
|
@rsqoot_deals = uniq_deals(@rsqoot_deals) if uniq
|
18
18
|
end
|
@@ -24,7 +24,7 @@ module RSqoot
|
|
24
24
|
def deal(id, options={})
|
25
25
|
options = update_by_expire_time options
|
26
26
|
if deal_not_latest?(id)
|
27
|
-
@rsqoot_deal = get("deals/#{id}", options)
|
27
|
+
@rsqoot_deal = get("deals/#{id}", options, SqootDeal)
|
28
28
|
@rsqoot_deal = @rsqoot_deal.deal if @rsqoot_deal
|
29
29
|
end
|
30
30
|
@rsqoot_deal
|
data/lib/rsqoot/helper.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'hashie/mash'
|
1
2
|
module RSqoot
|
2
3
|
module Helper
|
3
4
|
|
@@ -39,6 +40,17 @@ module RSqoot
|
|
39
40
|
end
|
40
41
|
base.class_eval { private ('query_' + name).to_sym }
|
41
42
|
end
|
43
|
+
|
44
|
+
# Add Wrappers: Deal, Category, Commission, Merchant, Provider, Click
|
45
|
+
[ 'SqootDeal',
|
46
|
+
'SqootCategory',
|
47
|
+
'SqootCommission',
|
48
|
+
'SqootMerchant',
|
49
|
+
'SqootProvider',
|
50
|
+
'SqootClick'].each do |class_name|
|
51
|
+
new_class = Class.new(::Hashie::Mash)
|
52
|
+
RSqoot.const_set class_name, new_class
|
53
|
+
end
|
42
54
|
end
|
43
55
|
|
44
56
|
# Add expired time functionality to this gem
|
data/lib/rsqoot/merchant.rb
CHANGED
@@ -9,7 +9,7 @@ module RSqoot
|
|
9
9
|
def merchant(id, options={})
|
10
10
|
options = update_by_expire_time options
|
11
11
|
if merchant_not_latest?(id)
|
12
|
-
@rsqoot_merchant = get("merchants/#{id}", options)
|
12
|
+
@rsqoot_merchant = get("merchants/#{id}", options, SqootMerchant)
|
13
13
|
@rsqoot_merchant = @rsqoot_merchant.merchant if @rsqoot_merchant
|
14
14
|
end
|
15
15
|
@rsqoot_merchant
|
data/lib/rsqoot/provider.rb
CHANGED
@@ -2,12 +2,12 @@ module RSqoot
|
|
2
2
|
module Provider
|
3
3
|
# Retrieve a list of providers base on the following parameters
|
4
4
|
#
|
5
|
-
# @return [
|
5
|
+
# @return [RSqoot::SqootProvider]
|
6
6
|
def providers(options={})
|
7
7
|
options = update_by_expire_time options
|
8
8
|
query = options.delete(:query)
|
9
9
|
if providers_not_latest?(options)
|
10
|
-
@rsqoot_providers = get('providers', options)
|
10
|
+
@rsqoot_providers = get('providers', options, SqootProvider)
|
11
11
|
@rsqoot_providers = @rsqoot_providers.providers.map(&:provider) if @rsqoot_providers
|
12
12
|
end
|
13
13
|
query.present? ? query_providers(query) : @rsqoot_providers
|
data/lib/rsqoot/request.rb
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
require 'open-uri'
|
2
|
-
require 'hashie/mash'
|
3
2
|
require 'json'
|
4
3
|
|
5
4
|
module RSqoot
|
6
5
|
module Request
|
7
6
|
|
8
|
-
def get(path, opts = {})
|
7
|
+
def get(path, opts = {}, wrapper = ::Hashie::Mash)
|
9
8
|
uri, headers = url_generator(path, opts)
|
10
9
|
begin
|
11
10
|
json = JSON.parse uri.open(headers).read
|
12
|
-
result =
|
11
|
+
result = wrapper.new json
|
13
12
|
@query_options = result.query
|
14
13
|
result
|
15
14
|
rescue
|
data/lib/rsqoot/version.rb
CHANGED
data/lib/rsqoot.rb
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.5.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-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashie
|