rqoot 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/README.md +4 -0
- data/Rakefile +0 -0
- data/lib/generators/rsqoot/config_generator.rb +16 -0
- data/lib/generators/rsqoot/templates/rsqoot_config.rb +7 -0
- data/lib/rsqoot.rb +30 -0
- data/lib/rsqoot/category.rb +11 -0
- data/lib/rsqoot/click.rb +14 -0
- data/lib/rsqoot/client.rb +30 -0
- data/lib/rsqoot/commission.rb +15 -0
- data/lib/rsqoot/deal.rb +30 -0
- data/lib/rsqoot/merchant.rb +13 -0
- data/lib/rsqoot/provider.rb +10 -0
- data/lib/rsqoot/request.rb +63 -0
- data/lib/rsqoot/version.rb +3 -0
- data/rsqoot.gemspec +24 -0
- metadata +91 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0c2f9085cf542d1279c58c97e975bbfe712ca140
|
4
|
+
data.tar.gz: aaea75921d775a4722a6e333a06f9630228ec756
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2078f4b01d91fdc1da517f0c9bb2ff0cfb370c25c7e1bf7057c2e210f799e91d049e41b173c16df47a6e8ff284117903b5b0a553f7277b551c01c4b294209a5d
|
7
|
+
data.tar.gz: bb20d55f01b3e1e67cf6f7f7a01b83b06eab8ff351cb3d7c4473982ed697ea65db1758fe7ca816f042419f529ecd45b598381bbbef84f02d95913d41ca36908c
|
data/.gitignore
ADDED
data/Gemfile
ADDED
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
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
|
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/lib/rsqoot/click.rb
ADDED
@@ -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
|
data/lib/rsqoot/deal.rb
ADDED
@@ -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,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
|
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 = "rqoot"
|
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: rqoot
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
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: []
|