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.
Files changed (37) hide show
  1. data/.gitignore +18 -0
  2. data/.rspec +1 -0
  3. data/.rvmrc +1 -0
  4. data/Gemfile +4 -0
  5. data/Guardfile +11 -0
  6. data/LICENSE +22 -0
  7. data/README.md +71 -0
  8. data/Rakefile +7 -0
  9. data/lib/sqoot.rb +23 -0
  10. data/lib/sqoot/category.rb +11 -0
  11. data/lib/sqoot/click.rb +14 -0
  12. data/lib/sqoot/client.rb +58 -0
  13. data/lib/sqoot/commission.rb +15 -0
  14. data/lib/sqoot/offer.rb +16 -0
  15. data/lib/sqoot/provider.rb +11 -0
  16. data/lib/sqoot/request.rb +36 -0
  17. data/lib/sqoot/response/parse_gzip.rb +27 -0
  18. data/lib/sqoot/version.rb +3 -0
  19. data/spec/cassettes/Sqoot_Category/should_return_an_array_of_categories.yml +79 -0
  20. data/spec/cassettes/Sqoot_Category/should_return_mash_list_of_categories_without_passing_any_parameters.yml +80 -0
  21. data/spec/cassettes/Sqoot_Click/should_return_an_array_of_clicks.yml +61 -0
  22. data/spec/cassettes/Sqoot_Click/should_return_mash_list_of_clicks_without_passing_any_parameters.yml +61 -0
  23. data/spec/cassettes/Sqoot_Commission/should_return_an_array_of_commissions.yml +51 -0
  24. data/spec/cassettes/Sqoot_Commission/should_return_mash_list_of_commissions_without_passing_any_parameters.yml +51 -0
  25. data/spec/cassettes/Sqoot_Offer/should_return_a_list_of_offers_given_a_location_parameter.yml +75 -0
  26. data/spec/cassettes/Sqoot_Offer/should_return_an_array_of_offers.yml +141 -0
  27. data/spec/cassettes/Sqoot_Offer/should_return_mash_list_of_offers_without_passing_any_parameters.yml +142 -0
  28. data/spec/spec_helper.rb +42 -0
  29. data/spec/sqoot/category_spec.rb +15 -0
  30. data/spec/sqoot/click_spec.rb +15 -0
  31. data/spec/sqoot/client_spec.rb +12 -0
  32. data/spec/sqoot/commission_spec.rb +15 -0
  33. data/spec/sqoot/offer_spec.rb +21 -0
  34. data/spec/sqoot/provider_spec.rb +15 -0
  35. data/spec/sqoot_spec.rb +20 -0
  36. data/sqoot.gemspec +33 -0
  37. metadata +254 -0
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .DS_Store
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
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sqoot.gemspec
4
+ gemspec
@@ -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.
@@ -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
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require "rspec/core/rake_task"
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
@@ -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
@@ -0,0 +1,11 @@
1
+ module Sqoot
2
+ module Category
3
+
4
+ # Retrieve a list of categories base on the following parameters
5
+ #
6
+ # @return [Hashie::Mash] category list
7
+ def categories(options={})
8
+ get('/v1/categories', options)
9
+ end
10
+ end
11
+ end
@@ -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
@@ -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
@@ -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,11 @@
1
+ module Sqoot
2
+ module Provider
3
+
4
+ # Retrieve a list of providers base on the following parameters
5
+ #
6
+ # @return [Hashie::Mash]
7
+ def providers(options={})
8
+ get('/v1/providers', options)
9
+ end
10
+ end
11
+ 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,3 @@
1
+ module Sqoot
2
+ VERSION = "0.0.1"
3
+ 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+czL9375fpNRLU3lQkG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