sqoot 0.0.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.
- data/.gitignore +18 -0
- data/.rspec +1 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/Guardfile +11 -0
- data/LICENSE +22 -0
- data/README.md +71 -0
- data/Rakefile +7 -0
- data/lib/sqoot.rb +23 -0
- data/lib/sqoot/category.rb +11 -0
- data/lib/sqoot/click.rb +14 -0
- data/lib/sqoot/client.rb +58 -0
- data/lib/sqoot/commission.rb +15 -0
- data/lib/sqoot/offer.rb +16 -0
- data/lib/sqoot/provider.rb +11 -0
- data/lib/sqoot/request.rb +36 -0
- data/lib/sqoot/response/parse_gzip.rb +27 -0
- data/lib/sqoot/version.rb +3 -0
- data/spec/cassettes/Sqoot_Category/should_return_an_array_of_categories.yml +79 -0
- data/spec/cassettes/Sqoot_Category/should_return_mash_list_of_categories_without_passing_any_parameters.yml +80 -0
- data/spec/cassettes/Sqoot_Click/should_return_an_array_of_clicks.yml +61 -0
- data/spec/cassettes/Sqoot_Click/should_return_mash_list_of_clicks_without_passing_any_parameters.yml +61 -0
- data/spec/cassettes/Sqoot_Commission/should_return_an_array_of_commissions.yml +51 -0
- data/spec/cassettes/Sqoot_Commission/should_return_mash_list_of_commissions_without_passing_any_parameters.yml +51 -0
- data/spec/cassettes/Sqoot_Offer/should_return_a_list_of_offers_given_a_location_parameter.yml +75 -0
- data/spec/cassettes/Sqoot_Offer/should_return_an_array_of_offers.yml +141 -0
- data/spec/cassettes/Sqoot_Offer/should_return_mash_list_of_offers_without_passing_any_parameters.yml +142 -0
- data/spec/spec_helper.rb +42 -0
- data/spec/sqoot/category_spec.rb +15 -0
- data/spec/sqoot/click_spec.rb +15 -0
- data/spec/sqoot/client_spec.rb +12 -0
- data/spec/sqoot/commission_spec.rb +15 -0
- data/spec/sqoot/offer_spec.rb +21 -0
- data/spec/sqoot/provider_spec.rb +15 -0
- data/spec/sqoot_spec.rb +20 -0
- data/sqoot.gemspec +33 -0
- metadata +254 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 1.9.3@sqoot --create
|
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard 'rspec', :version => 2 do
|
5
|
+
|
6
|
+
watch(%r{^spec/.+_spec\.rb$})
|
7
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
8
|
+
watch('spec/spec_helper.rb') { "spec" }
|
9
|
+
|
10
|
+
end
|
11
|
+
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Cause Metric LLC
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# Sqoot
|
2
|
+
|
3
|
+
Wrapper for [Sqoot](http://www.sqoot.com) [API](http://www.sqoot.com/docs/api). Highly inspired by [Gowalla](https://github.com/pengwynn/gowalla) gem.
|
4
|
+
Built using [Faraday](https://github.com/technoweenie/faraday) and [Faraday Middleware](https://github.com/pengwynn/faraday_middleware).
|
5
|
+
|
6
|
+
To get the list of available parameters kindly check out [API](http://www.sqoot.com/docs/search)
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'sqoot'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install sqoot
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Sqoot.configure do |config|
|
25
|
+
config.affiliate_token = "YOUR AFFILIATE TOKEN"
|
26
|
+
config.authentication_token = "YOUR AUTHENTICATION TOKEN"
|
27
|
+
end
|
28
|
+
|
29
|
+
sqoot = Sqoot::Client.new
|
30
|
+
|
31
|
+
# http://api.sqoot.com/v1/offers?affiliate_token=yadayada
|
32
|
+
sqoot.offers
|
33
|
+
#=> returns a list of offers
|
34
|
+
|
35
|
+
# http://api.sqoot.com/v1/offers?affiliate_token=yadayada&location=Chicago
|
36
|
+
sqoot.offers(:location => 'Chicago')
|
37
|
+
|
38
|
+
# http://api.sqoot.com/v1/offers?affiliate_token=yadayada&location=Chicago&per_page=10
|
39
|
+
sqoot.offers(:location => 'Chicago', :per_page => 10)
|
40
|
+
|
41
|
+
# http://api.sqoot.com/v1/offers?affiliate_token=yadayada&categories=health-beauty&location=&page=2
|
42
|
+
sqoot.offers(:location => 'Chicago', :per_page => 10, :categories => 'health-beauty', :page => 2)
|
43
|
+
|
44
|
+
# http://api.sqoot.com/v1/offers?affiliate_token=yadayada&order=commission&per_page=250&price_at_least=10
|
45
|
+
sqoot.offers(:price_at_least => 10, :order => commission)
|
46
|
+
|
47
|
+
# http://api.sqoot.com/v1/providers?affiliate_token=yadayada
|
48
|
+
sqoot.providers
|
49
|
+
|
50
|
+
# http://api.sqoot.com/v1/commissions?authentication_token=tokenawesome
|
51
|
+
sqoot.commissions
|
52
|
+
# => returns current month commissions
|
53
|
+
|
54
|
+
sqoot.commissions(:to => '2012-01-01', :from => '2012-01-20')
|
55
|
+
# => returns commissions using date_range :to & :from
|
56
|
+
|
57
|
+
# http://api.sqoot.com/v1/clicks?authentication_token=tokenawesome
|
58
|
+
sqoot.clicks
|
59
|
+
# => returns real-time clicks from the event request limit of 1000
|
60
|
+
|
61
|
+
sqoot.clicks(:to => '2012-01-01', :from => '2012-01-20')
|
62
|
+
# => returns clicks using date_range :to & :from
|
63
|
+
|
64
|
+
|
65
|
+
## Contributing
|
66
|
+
|
67
|
+
1. Fork it
|
68
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
69
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
70
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
71
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/sqoot.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require "faraday"
|
2
|
+
require "faraday_middleware"
|
3
|
+
require "sqoot/version"
|
4
|
+
require "sqoot/client"
|
5
|
+
|
6
|
+
directory = File.expand_path(File.dirname(__FILE__))
|
7
|
+
|
8
|
+
module Sqoot
|
9
|
+
|
10
|
+
class << self
|
11
|
+
attr_accessor :affiliate_token, :authentication_token
|
12
|
+
|
13
|
+
# Configure default credentials easily
|
14
|
+
#
|
15
|
+
# @yield [affiliate_key, authentication_token]
|
16
|
+
def configure
|
17
|
+
yield self
|
18
|
+
true
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/lib/sqoot/click.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
module Sqoot
|
2
|
+
module Click
|
3
|
+
|
4
|
+
# Retrieve a list of clicks based on the following parameters
|
5
|
+
#
|
6
|
+
# @param [String] :to Start date
|
7
|
+
# @param [String] :from End date
|
8
|
+
#
|
9
|
+
# @return [Hashie::Mash]
|
10
|
+
def clicks(options={})
|
11
|
+
get('/v1/clicks', options)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/sqoot/client.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require "forwardable"
|
2
|
+
require "sqoot/offer"
|
3
|
+
require "sqoot/category"
|
4
|
+
require "sqoot/provider"
|
5
|
+
require "sqoot/commission"
|
6
|
+
require "sqoot/click"
|
7
|
+
require "sqoot/request"
|
8
|
+
require "sqoot/response/parse_gzip"
|
9
|
+
|
10
|
+
module Sqoot
|
11
|
+
class Client
|
12
|
+
extend Forwardable
|
13
|
+
|
14
|
+
include Offer
|
15
|
+
include Category
|
16
|
+
include Provider
|
17
|
+
include Commission
|
18
|
+
include Click
|
19
|
+
include Request
|
20
|
+
|
21
|
+
attr_reader :affiliate_token, :authentication_token
|
22
|
+
|
23
|
+
def initialize(options={})
|
24
|
+
@affiliate_token = options[:affiliate_token] || Sqoot.affiliate_token
|
25
|
+
@authentication_token = options[:authentication_token] || Sqoot.authentication_token
|
26
|
+
end
|
27
|
+
|
28
|
+
# Provides the URL for accessing the API
|
29
|
+
#
|
30
|
+
# @return [String]
|
31
|
+
def api_url
|
32
|
+
"http://api.sqoot.com"
|
33
|
+
end
|
34
|
+
|
35
|
+
# Raw HTTP connection with Faraday::Connection
|
36
|
+
#
|
37
|
+
# @return [Faraday::Connection]
|
38
|
+
def connection
|
39
|
+
params = {}
|
40
|
+
@connection = Faraday.new(:url => api_url, :params => params, :headers => default_headers) do |builder|
|
41
|
+
builder.use Faraday::Response::ParseGzip
|
42
|
+
builder.adapter Faraday.default_adapter
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def default_headers
|
49
|
+
headers = {
|
50
|
+
:authorization => @authentication_token,
|
51
|
+
:accept => '*/*',
|
52
|
+
:accept_encoding => 'gzip',
|
53
|
+
:user_agent => 'Ruby gem'
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Sqoot
|
2
|
+
module Commission
|
3
|
+
|
4
|
+
# Retrieve information of commissions based on the following parameters
|
5
|
+
#
|
6
|
+
# @param [String] :to Start date
|
7
|
+
# @param [String] :from End date
|
8
|
+
#
|
9
|
+
# @return [Hashie::Mash]
|
10
|
+
def commissions(options={})
|
11
|
+
get('/v1/commissions', options)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
data/lib/sqoot/offer.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
module Sqoot
|
2
|
+
module Offer
|
3
|
+
|
4
|
+
# Retrieve a list of offers based on the following parameters
|
5
|
+
#
|
6
|
+
# @param [String] location (What geography do you want deals from? It can be anything: a city, zip code, address, intersection or even a latitude/longitude)
|
7
|
+
# @param [String] categories (You can specify just one (e.g., restaurants), or whole bunch by separating their slugs with commas (e.g., "restaurants,jewish")
|
8
|
+
# @param [Integer] per_page Number of results to be displayed
|
9
|
+
#
|
10
|
+
# @return [Hashie::Mash] offers list
|
11
|
+
def offers(options={})
|
12
|
+
get('/v1/offers', options)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Sqoot
|
2
|
+
module Request
|
3
|
+
|
4
|
+
def get(path, options)
|
5
|
+
request(:get, path, convert_params(path, options))
|
6
|
+
end
|
7
|
+
|
8
|
+
def convert_params(path, data={})
|
9
|
+
auth_endpoints = ['commissions', 'clicks']
|
10
|
+
|
11
|
+
if auth_endpoints.include? path.split('/')[2]
|
12
|
+
data['authentication_token'] = authentication_token
|
13
|
+
else
|
14
|
+
data['affiliate_token'] = affiliate_token
|
15
|
+
end
|
16
|
+
|
17
|
+
data
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
def request(method, path, options)
|
22
|
+
response = connection.send(method) do |request|
|
23
|
+
case method
|
24
|
+
when :delete, :get
|
25
|
+
request.url(path, options)
|
26
|
+
when :post, :put
|
27
|
+
request.path = path
|
28
|
+
request.body = MultiJson.encode(options) unless options.empty?
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
response.body
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "faraday"
|
2
|
+
|
3
|
+
module Faraday
|
4
|
+
class Response::ParseGzip < Response::Middleware
|
5
|
+
class << self
|
6
|
+
attr_accessor :mash_class
|
7
|
+
end
|
8
|
+
|
9
|
+
dependency do
|
10
|
+
require 'json'
|
11
|
+
require 'hashie/mash'
|
12
|
+
self.mash_class = ::Hashie::Mash
|
13
|
+
end
|
14
|
+
|
15
|
+
def parse(body)
|
16
|
+
sio = StringIO.new(body)
|
17
|
+
begin
|
18
|
+
gz = Zlib::GzipReader.new(sio)
|
19
|
+
self.class.mash_class.new(JSON.parse(gz.read()))
|
20
|
+
rescue
|
21
|
+
self.class.mash_class.new JSON.parse body
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: AFFILIATE_TOKEN
|
6
|
+
body: ''
|
7
|
+
headers:
|
8
|
+
authorization: AUTHENTICATION_TOKEN
|
9
|
+
accept:
|
10
|
+
- ! '*/*'
|
11
|
+
accept-encoding:
|
12
|
+
- gzip
|
13
|
+
user-agent:
|
14
|
+
- Ruby gem
|
15
|
+
connection:
|
16
|
+
- close
|
17
|
+
response:
|
18
|
+
status:
|
19
|
+
code: 200
|
20
|
+
message: OK
|
21
|
+
headers:
|
22
|
+
server:
|
23
|
+
- nginx
|
24
|
+
date:
|
25
|
+
- Fri, 24 Feb 2012 15:05:46 GMT
|
26
|
+
content-type:
|
27
|
+
- text/javascript; charset=utf-8
|
28
|
+
transfer-encoding:
|
29
|
+
- chunked
|
30
|
+
connection:
|
31
|
+
- close
|
32
|
+
etag:
|
33
|
+
- ! '"74309e2e331a650863970752eb0878eb"'
|
34
|
+
cache-control:
|
35
|
+
- max-age=0, private, must-revalidate
|
36
|
+
x-ua-compatible:
|
37
|
+
- IE=Edge,chrome=1
|
38
|
+
x-runtime:
|
39
|
+
- '0.063788'
|
40
|
+
x-varnish:
|
41
|
+
- '839843809'
|
42
|
+
age:
|
43
|
+
- '0'
|
44
|
+
via:
|
45
|
+
- 1.1 varnish
|
46
|
+
content-encoding:
|
47
|
+
- gzip
|
48
|
+
body: !binary |-
|
49
|
+
H4sIAAAAAAAAA7yWTW+cMBCG7/0V1h5yClIWNmzTW7JJ99ZLq156qIwZWEvG
|
50
|
+
XtlmKxTlv9fQ7VLBZNoI6AUk2+/wMOP5eH7H2EpwD6WxEtzqA/sWVhh77p79
|
51
|
+
XhN2fq+FVc0rCCure+HlSfqgZFfs6QTau9V1f8wUBVj3XZha+3A8Tde3f+w6
|
52
|
+
VZetEX4xEsEvE+czL9375fpNRLU3lQkGgX0Ge5ICKKJ4gwJdbEQOsXHkFjr1
|
53
|
+
yoLnUvWHJnA/8KwhQNfvEc5soOnB3BGE5CqS2oMF56eR2Ta6O1VnlCuTNEUR
|
54
|
+
rYvEUNqD5lJLXUZalgevZAGTQI3xbMerI+XHdINRBmUkBsoespBeg5sWXvND
|
55
|
+
hR+lkgPlGql6qlnT5sHKnCvKcViiZCPVMldwd5DWHG37x4JijLHgilfEPeoB
|
56
|
+
uPKHKIOQ+M0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