rsqoot 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ec628307ce0c636974f1302b34c42ba6e207e74c
4
+ data.tar.gz: 6cbdc7c584d68492fc0e6c128a3c88733ce3cd01
5
+ SHA512:
6
+ metadata.gz: f8781dbae0339b5eb534ed866de0e753e3bf90269b5cb026aa2ab73a9d2562b26eed030e95531e1a3ad4bda66f60309d62fe6234f03d5ac39b344518b75c2d7d
7
+ data.tar.gz: bfe98dc0764d75e32bf12d61125deb38963da7505ebfb85e734da73d326db624a45256c3bb758fca3417f6fbec33b298188ff3eeb83809ecd684b71a7e4a979e
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sqoot.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Felix Liu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,74 @@
1
+ Sqoot
2
+ ======
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).
7
+
8
+ To get the list of available parameters kindly check out [API V2](http://docs.sqoot.com/v2/overview.html)
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'rsqoot'
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install rsqoot
23
+
24
+ ## Usage
25
+
26
+ Sqoot.configure do |config|
27
+ # config.public_api_key = 'YOUR PUBLIC API KEY'
28
+ # config.private_api_key = 'YOUR PRIVATE API KEY'
29
+ # config.base_api_url = 'https://api.sqoot.com'
30
+ # config.authentication_method = :header
31
+ # config.read_timeout = 20
32
+ end
33
+
34
+ sqoot = Sqoot::Client.new
35
+
36
+ sqoot.deals
37
+ #=> returns a list of deals
38
+
39
+ sqoot.deals(:location => 'Chicago')
40
+
41
+ sqoot.deals(:location => 'Chicago', :per_page => 10)
42
+
43
+ sqoot.deals(:location => 'Chicago', :per_page => 10, :categories => 'health-beauty', :page => 2)
44
+
45
+ sqoot.deals(:price_at_least => 10, :order => commission)
46
+
47
+ sqoot.deal_impression(1555288, geometry: '250x250C')
48
+ # => return a image url which size is 250x250
49
+
50
+ sqoot.deal_click(1555288)
51
+ # => return a click url which will redirect to another url
52
+
53
+ sqoot.providers
54
+ # => returns a list of providers
55
+
56
+ sqoot.commissions
57
+ # => returns current month commissions
58
+
59
+ sqoot.commissions(:to => '2012-01-01', :from => '2012-01-20')
60
+ # => returns commissions using date_range :to & :from
61
+
62
+ sqoot.clicks
63
+ # => returns real-time clicks from the event request limit of 1000
64
+
65
+ sqoot.clicks(:to => '2012-01-01', :from => '2012-01-20')
66
+ # => returns clicks using date_range :to & :from
67
+
68
+ ## Contributing
69
+
70
+ 1. Fork it
71
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
72
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
73
+ 4. Push to the branch (`git push origin my-new-feature`)
74
+ 5. Create new Pull Request
data/Rakefile ADDED
File without changes
@@ -0,0 +1,16 @@
1
+ module RSqoot
2
+ module Generators
3
+ class ConfigGenerator < Rails::Generators::Base
4
+ source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
5
+
6
+ desc <<DESC
7
+ Description:
8
+ Copies RSqoot configuration file to your application's initializer directory.
9
+ DESC
10
+
11
+ def copy_config_file
12
+ template 'rsqoot_config.rb', 'config/initializers/rsqoot_config.rb'
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,7 @@
1
+ Sqoot.configure do |config|
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
+ # config.authentication_method = :header
6
+ # config.read_timeout = 20
7
+ end
@@ -0,0 +1,11 @@
1
+ module RSqoot
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('categories', options)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ module RSqoot
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('clicks', options)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,30 @@
1
+ require "rsqoot/merchant"
2
+ require "rsqoot/category"
3
+ require "rsqoot/provider"
4
+ require "rsqoot/commission"
5
+ require "rsqoot/click"
6
+ require "rsqoot/deal"
7
+ require "rsqoot/request"
8
+
9
+ module RSqoot
10
+ class Client
11
+ include Category
12
+ include Click
13
+ include Commission
14
+ include Deal
15
+ include Merchant
16
+ include Provider
17
+ include Request
18
+
19
+ attr_reader :public_api_key, :private_api_key, :base_api_url, :authentication_method, :read_timeout
20
+
21
+ def initialize(options={})
22
+ @public_api_key = options[:public_api_key] || RSqoot.public_api_key
23
+ @private_api_key = options[:private_api_key] || RSqoot.private_api_key
24
+ @base_api_url = options[:base_api_url] || RSqoot.base_api_url
25
+ @authentication_method = options[:authentication_method] || RSqoot.authentication_method
26
+ @read_timeout = options[:read_timeout] || RSqoot.read_timeout
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,15 @@
1
+ module RSqoot
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('commissions', options)
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,30 @@
1
+ module RSqoot
2
+ module Deal
3
+
4
+ # Retrieve a list of deals based on the following parameters
5
+ #
6
+ # @param [String] query (Search deals by title, description, fine print, merchant name, provider, and category.)
7
+ # @param [String] location (Limit results to a particular area. We'll resolve whatever you pass us (including an IP address) to coordinates and search near there.)
8
+ # @param [Integer] radius (Measured in miles. Defaults to 10.)
9
+ # @param [Integer] page (Which page of result to return. Default to 1.)
10
+ # @param [Integer] per_page (Number of results to return at once. Defaults to 10.)
11
+ def deals(options={})
12
+ get('deals', options)
13
+ end
14
+
15
+ # Retrieve a deal by id
16
+ #
17
+ def deal(id, options={})
18
+ get("deals/#{id}", options)
19
+ end
20
+
21
+ def deal_click(id, options={})
22
+ get("deals/#{id}/click", options, parse = false)
23
+ end
24
+
25
+ def deal_impression(id, options={})
26
+ get("deals/#{id}/image", options, parse = false)
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,13 @@
1
+ module RSqoot
2
+ module Merchant
3
+
4
+ # Retrieve a list of merchants base on the following parameters
5
+ #
6
+ # @param [String] id (The merchant's ID, Use the Sqoot ID or ID for any supported namespace. Must supply namespace if we don't use Sqoot)
7
+ # @param [String] namespace (One of the supported namespaces. Factual, Foursquare, Facebook, Google, CitySearch, Yelp.)
8
+
9
+ def merchant(id, options={})
10
+ get("merchants/#{id}", options)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,10 @@
1
+ module RSqoot
2
+ module Provider
3
+ # Retrieve a list of providers base on the following parameters
4
+ #
5
+ # @return [Hashie::Mash]
6
+ def providers(options={})
7
+ get('providers', options)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,63 @@
1
+ require 'open-uri'
2
+ require 'hashie/mash'
3
+ require 'json'
4
+
5
+ module RSqoot
6
+ module Request
7
+
8
+ def get(path, opts = {}, parse = true)
9
+ uri = URI.parse base_api_url
10
+ uri.path = '/v2/' + path
11
+ headers = {read_timeout: read_timeout}
12
+ query = options_parser opts
13
+ endpoint = path.split('/')[0]
14
+ case authentication_method
15
+ when :header
16
+ headers.merge! h = {"Authorization" => "api_key #{api_key(endpoint)}"}
17
+ query = query + "&api_key=#{api_key(endpoint)}" if !parse
18
+ when :parameter
19
+ query = query + "&api_key=#{api_key(endpoint)}"
20
+ end
21
+ uri.query = query
22
+ if parse
23
+ begin
24
+ json = JSON.parse uri.open(headers).read
25
+ ::Hashie::Mash.new json
26
+ end
27
+ else
28
+ uri.to_s
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def private_endpoints
35
+ %w(clicks commissions)
36
+ end
37
+
38
+ def public_endpoints
39
+ %w(categories deals merchants providers)
40
+ end
41
+
42
+ def api_key(endpoint='')
43
+ if private_endpoints.include? endpoint
44
+ private_api_key
45
+ elsif public_endpoints.include? endpoint
46
+ public_api_key
47
+ else
48
+ raise "No such endpoint #{endpoint} available."
49
+ end
50
+ end
51
+
52
+ # Example: options = {per_page: 10, page: 1}
53
+ # Options should be parsed as http query: per_page=10&page=1
54
+ #
55
+ # @return [String]
56
+ def options_parser(options = {})
57
+ options.map do |key, value|
58
+ [key, value].map(&:to_s).join('=')
59
+ end.join('&')
60
+ end
61
+
62
+ end
63
+ end
@@ -0,0 +1,3 @@
1
+ module RSqoot
2
+ VERSION = '0.1.1'
3
+ end
data/lib/rsqoot.rb ADDED
@@ -0,0 +1,30 @@
1
+ require "rsqoot/client"
2
+
3
+ module RSqoot
4
+
5
+ class << self
6
+ attr_accessor :public_api_key, :private_api_key, :base_api_url, :authentication_method, :read_timeout
7
+
8
+ # Configure default credentials easily
9
+ #
10
+ # @yield [Sqoot]
11
+ def configure
12
+ load_defaults
13
+ yield self
14
+ raise "Authentication method must be :header or :parameter ." if !AUTHENTICATION_METHODS.include? self.authentication_method
15
+ true
16
+ end
17
+
18
+ def load_defaults
19
+ self.base_api_url ||= "https://api.sqoot.com"
20
+ self.authentication_method = :header
21
+ self.read_timeout = 60
22
+ end
23
+
24
+ private
25
+
26
+ AUTHENTICATION_METHODS = [:header, :parameter]
27
+
28
+ end
29
+
30
+ end
data/rsqoot.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require 'rsqoot/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "rsqoot"
7
+ s.version = RSqoot::VERSION.dup
8
+ s.platform = Gem::Platform::RUBY
9
+ s.licenses = ['MIT']
10
+ s.summary = %q{Wrapper for Sqoot API V2}
11
+ s.email = ['lyfeyaj@gmail.com']
12
+ s.homepage = "https://github.com/lyfeyaj/rsqoot"
13
+ s.description = %q{A Ruby Wrapper for Sqoot API V2.}
14
+ s.authors = ['Felix Liu']
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.extra_rdoc_files = ['README.md']
19
+ s.require_paths = ['lib']
20
+
21
+ s.add_dependency "hashie", "~> 2.0.0"
22
+ s.add_dependency "json", "~> 1.7.0"
23
+
24
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rsqoot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Felix Liu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: hashie
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 2.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 2.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 1.7.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 1.7.0
41
+ description: A Ruby Wrapper for Sqoot API V2.
42
+ email:
43
+ - lyfeyaj@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files:
47
+ - README.md
48
+ files:
49
+ - .gitignore
50
+ - Gemfile
51
+ - LICENSE
52
+ - README.md
53
+ - Rakefile
54
+ - lib/generators/rsqoot/config_generator.rb
55
+ - lib/generators/rsqoot/templates/rsqoot_config.rb
56
+ - lib/rsqoot.rb
57
+ - lib/rsqoot/category.rb
58
+ - lib/rsqoot/click.rb
59
+ - lib/rsqoot/client.rb
60
+ - lib/rsqoot/commission.rb
61
+ - lib/rsqoot/deal.rb
62
+ - lib/rsqoot/merchant.rb
63
+ - lib/rsqoot/provider.rb
64
+ - lib/rsqoot/request.rb
65
+ - lib/rsqoot/version.rb
66
+ - rsqoot.gemspec
67
+ homepage: https://github.com/lyfeyaj/rsqoot
68
+ licenses:
69
+ - MIT
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 2.0.6
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: Wrapper for Sqoot API V2
91
+ test_files: []