adility 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/Rakefile +2 -0
- data/adility.gemspec +34 -0
- data/lib/adility/version.rb +3 -0
- data/lib/adility.rb +43 -0
- data/lib/core_ext/array.rb +5 -0
- data/lib/faraday/patch.rb +66 -0
- data/spec/offers/offers_spec.rb +31 -0
- data/spec/spec_helper.rb +21 -0
- metadata +210 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm 1.9.2@adility
|
data/Gemfile
ADDED
data/Rakefile
ADDED
data/adility.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "adility/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "adility"
|
7
|
+
s.version = Adility::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Josh Deeden"]
|
10
|
+
s.email = ["jdeeden@gmail.com"]
|
11
|
+
s.homepage = "http://github.com/gangster/adility"
|
12
|
+
s.summary = %q{A wrapper for the Adility API}
|
13
|
+
s.description = %q{A wrapper for the Adility API}
|
14
|
+
|
15
|
+
s.rubyforge_project = "adility"
|
16
|
+
s.add_development_dependency('rake', '~> 0.8')
|
17
|
+
s.add_development_dependency('rspec', '~> 2.5')
|
18
|
+
s.add_development_dependency('simplecov', '~> 0.4')
|
19
|
+
s.add_development_dependency('vcr', '~> 1.7.0')
|
20
|
+
s.add_development_dependency('fakeweb')
|
21
|
+
s.add_development_dependency('yard', '~> 0.6')
|
22
|
+
s.add_development_dependency('maruku', '~> 0.6')
|
23
|
+
s.add_runtime_dependency("faraday", '~> 0.5.7')
|
24
|
+
s.add_runtime_dependency("faraday_middleware", '~> 0.3.2')
|
25
|
+
s.add_runtime_dependency("typhoeus", '~> 0.2.4')
|
26
|
+
s.add_runtime_dependency('hashie', '~> 1.0.0')
|
27
|
+
s.add_runtime_dependency('yajl-ruby', '~> 0.8.1')
|
28
|
+
s.add_runtime_dependency('multi_json', '~> 0.0.5')
|
29
|
+
|
30
|
+
s.files = `git ls-files`.split("\n")
|
31
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
32
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
33
|
+
s.require_paths = ["lib"]
|
34
|
+
end
|
data/lib/adility.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'faraday_middleware'
|
3
|
+
require 'core_ext/array'
|
4
|
+
require 'faraday/patch'
|
5
|
+
require 'yajl'
|
6
|
+
|
7
|
+
module Adility
|
8
|
+
class Client
|
9
|
+
attr_reader :api_key, :conn
|
10
|
+
|
11
|
+
# Initialize the client.
|
12
|
+
# TODO: Document.
|
13
|
+
def initialize(*args)
|
14
|
+
options = args.extract_options!
|
15
|
+
@api_key = args[0]
|
16
|
+
@conn = Faraday.new(:url => "https://testapi.offersdb.com") do |builder|
|
17
|
+
builder.adapter Faraday.default_adapter
|
18
|
+
builder.adapter :logger #if options[:debug] == true
|
19
|
+
builder.use Faraday::Response::ParseJson
|
20
|
+
builder.use Faraday::Response::Mashify
|
21
|
+
end
|
22
|
+
end
|
23
|
+
def method_missing(sym, *args, &block)
|
24
|
+
options = args.extract_options!
|
25
|
+
if args[0]
|
26
|
+
url = "/distribution/beta/#{sym.to_s}/#{args[0]}.json"
|
27
|
+
else
|
28
|
+
url = "/distribution/beta/#{sym.to_s}.json"
|
29
|
+
end
|
30
|
+
response = conn.get(url) do |req|
|
31
|
+
req.headers['X-OFFERSDB-API-KEY'] = api_key
|
32
|
+
req.params = options
|
33
|
+
end
|
34
|
+
if args[0].nil?
|
35
|
+
ret = response.body.send sym
|
36
|
+
else
|
37
|
+
ret = response.body.send sym.to_s.chop
|
38
|
+
end
|
39
|
+
ret
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
module Faraday
|
3
|
+
class Adapter
|
4
|
+
class NetHttp < Faraday::Adapter
|
5
|
+
def call(env)
|
6
|
+
super
|
7
|
+
|
8
|
+
is_ssl = env[:url].scheme == 'https'
|
9
|
+
|
10
|
+
http = net_http_class(env).new(env[:url].host, env[:url].port || (is_ssl ? 443 : 80))
|
11
|
+
if http.use_ssl = is_ssl
|
12
|
+
ssl = env[:ssl]
|
13
|
+
if ssl[:verify] == false
|
14
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
15
|
+
else
|
16
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE # <= PATCH or HACK ssl[:verify]
|
17
|
+
end
|
18
|
+
http.cert = ssl[:client_cert] if ssl[:client_cert]
|
19
|
+
http.key = ssl[:client_key] if ssl[:client_key]
|
20
|
+
http.ca_file = ssl[:ca_file] if ssl[:ca_file]
|
21
|
+
end
|
22
|
+
req = env[:request]
|
23
|
+
http.read_timeout = net.open_timeout = req[:timeout] if req[:timeout]
|
24
|
+
http.open_timeout = req[:open_timeout] if req[:open_timeout]
|
25
|
+
|
26
|
+
full_path = full_path_for(env[:url].path, env[:url].query, env[:url].fragment)
|
27
|
+
http_req = Net::HTTPGenericRequest.new(
|
28
|
+
env[:method].to_s.upcase, # request method
|
29
|
+
(env[:body] ? true : false), # is there data
|
30
|
+
true, # does net/http love you, true or false?
|
31
|
+
full_path, # request uri path
|
32
|
+
env[:request_headers]) # request headers
|
33
|
+
|
34
|
+
if env[:body].respond_to?(:read)
|
35
|
+
http_req.body_stream = env[:body]
|
36
|
+
env[:body] = nil
|
37
|
+
end
|
38
|
+
|
39
|
+
http_resp = http.request http_req, env[:body]
|
40
|
+
|
41
|
+
resp_headers = {}
|
42
|
+
http_resp.each_header do |key, value|
|
43
|
+
resp_headers[key] = value
|
44
|
+
end
|
45
|
+
|
46
|
+
env.update \
|
47
|
+
:status => http_resp.code.to_i,
|
48
|
+
:response_headers => resp_headers,
|
49
|
+
:body => http_resp.body
|
50
|
+
|
51
|
+
@app.call env
|
52
|
+
rescue Errno::ECONNREFUSED
|
53
|
+
raise Error::ConnectionFailed.new(Errno::ECONNREFUSED)
|
54
|
+
end
|
55
|
+
|
56
|
+
def net_http_class(env)
|
57
|
+
if proxy = env[:request][:proxy]
|
58
|
+
Net::HTTP::Proxy(proxy[:uri].host, proxy[:uri].port, proxy[:user], proxy[:password])
|
59
|
+
else
|
60
|
+
Net::HTTP
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe Adility::Client do
|
4
|
+
context "api" do
|
5
|
+
before(:all) do
|
6
|
+
api_key=""
|
7
|
+
@client = Adility::Client.new(api_key)
|
8
|
+
end
|
9
|
+
context "offers" do
|
10
|
+
context "search" do
|
11
|
+
context "with zip" do
|
12
|
+
use_vcr_cassette
|
13
|
+
before(:all) do
|
14
|
+
@offers = @client.offers(:zip => "94117", :distance => "100", :sort_by => :title)
|
15
|
+
end
|
16
|
+
subject { @offers }
|
17
|
+
it { should_not be_nil }
|
18
|
+
it { should be_an(Array) }
|
19
|
+
it { should have_at_least(1).items }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
context "load individial" do
|
23
|
+
before(:all) do
|
24
|
+
@offer = @client.offers("1d5a5257286ec63669aa1c099f66c29e36e0424bc193914b04eb36607e833c04")
|
25
|
+
end
|
26
|
+
subject { @offer }
|
27
|
+
it { should_not be_nil }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
|
3
|
+
SimpleCov.start do
|
4
|
+
add_group 'Adility', 'lib/adility'
|
5
|
+
add_group 'Specs', 'spec'
|
6
|
+
end
|
7
|
+
|
8
|
+
require File.expand_path('../../lib/adility', __FILE__)
|
9
|
+
require 'rubygems'
|
10
|
+
require 'rspec'
|
11
|
+
require 'vcr'
|
12
|
+
|
13
|
+
VCR.config do |c|
|
14
|
+
c.cassette_library_dir = 'spec/cassettes'
|
15
|
+
c.stub_with :typhoeus
|
16
|
+
c.default_cassette_options = { :record => :new_episodes }
|
17
|
+
end
|
18
|
+
|
19
|
+
RSpec.configure do |c|
|
20
|
+
c.extend VCR::RSpec::Macros
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,210 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: adility
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Josh Deeden
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-03-22 00:00:00 -04:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: rake
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ~>
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: "0.8"
|
25
|
+
type: :development
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ~>
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: "2.5"
|
36
|
+
type: :development
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: simplecov
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0.4"
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: vcr
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ~>
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: 1.7.0
|
58
|
+
type: :development
|
59
|
+
version_requirements: *id004
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: fakeweb
|
62
|
+
prerelease: false
|
63
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "0"
|
69
|
+
type: :development
|
70
|
+
version_requirements: *id005
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: yard
|
73
|
+
prerelease: false
|
74
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ~>
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: "0.6"
|
80
|
+
type: :development
|
81
|
+
version_requirements: *id006
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
name: maruku
|
84
|
+
prerelease: false
|
85
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ~>
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: "0.6"
|
91
|
+
type: :development
|
92
|
+
version_requirements: *id007
|
93
|
+
- !ruby/object:Gem::Dependency
|
94
|
+
name: faraday
|
95
|
+
prerelease: false
|
96
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 0.5.7
|
102
|
+
type: :runtime
|
103
|
+
version_requirements: *id008
|
104
|
+
- !ruby/object:Gem::Dependency
|
105
|
+
name: faraday_middleware
|
106
|
+
prerelease: false
|
107
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
109
|
+
requirements:
|
110
|
+
- - ~>
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: 0.3.2
|
113
|
+
type: :runtime
|
114
|
+
version_requirements: *id009
|
115
|
+
- !ruby/object:Gem::Dependency
|
116
|
+
name: typhoeus
|
117
|
+
prerelease: false
|
118
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
119
|
+
none: false
|
120
|
+
requirements:
|
121
|
+
- - ~>
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: 0.2.4
|
124
|
+
type: :runtime
|
125
|
+
version_requirements: *id010
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: hashie
|
128
|
+
prerelease: false
|
129
|
+
requirement: &id011 !ruby/object:Gem::Requirement
|
130
|
+
none: false
|
131
|
+
requirements:
|
132
|
+
- - ~>
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: 1.0.0
|
135
|
+
type: :runtime
|
136
|
+
version_requirements: *id011
|
137
|
+
- !ruby/object:Gem::Dependency
|
138
|
+
name: yajl-ruby
|
139
|
+
prerelease: false
|
140
|
+
requirement: &id012 !ruby/object:Gem::Requirement
|
141
|
+
none: false
|
142
|
+
requirements:
|
143
|
+
- - ~>
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 0.8.1
|
146
|
+
type: :runtime
|
147
|
+
version_requirements: *id012
|
148
|
+
- !ruby/object:Gem::Dependency
|
149
|
+
name: multi_json
|
150
|
+
prerelease: false
|
151
|
+
requirement: &id013 !ruby/object:Gem::Requirement
|
152
|
+
none: false
|
153
|
+
requirements:
|
154
|
+
- - ~>
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: 0.0.5
|
157
|
+
type: :runtime
|
158
|
+
version_requirements: *id013
|
159
|
+
description: A wrapper for the Adility API
|
160
|
+
email:
|
161
|
+
- jdeeden@gmail.com
|
162
|
+
executables: []
|
163
|
+
|
164
|
+
extensions: []
|
165
|
+
|
166
|
+
extra_rdoc_files: []
|
167
|
+
|
168
|
+
files:
|
169
|
+
- .gitignore
|
170
|
+
- .rvmrc
|
171
|
+
- Gemfile
|
172
|
+
- Rakefile
|
173
|
+
- adility.gemspec
|
174
|
+
- lib/adility.rb
|
175
|
+
- lib/adility/version.rb
|
176
|
+
- lib/core_ext/array.rb
|
177
|
+
- lib/faraday/patch.rb
|
178
|
+
- spec/offers/offers_spec.rb
|
179
|
+
- spec/spec_helper.rb
|
180
|
+
has_rdoc: true
|
181
|
+
homepage: http://github.com/gangster/adility
|
182
|
+
licenses: []
|
183
|
+
|
184
|
+
post_install_message:
|
185
|
+
rdoc_options: []
|
186
|
+
|
187
|
+
require_paths:
|
188
|
+
- lib
|
189
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
190
|
+
none: false
|
191
|
+
requirements:
|
192
|
+
- - ">="
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: "0"
|
195
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
196
|
+
none: false
|
197
|
+
requirements:
|
198
|
+
- - ">="
|
199
|
+
- !ruby/object:Gem::Version
|
200
|
+
version: "0"
|
201
|
+
requirements: []
|
202
|
+
|
203
|
+
rubyforge_project: adility
|
204
|
+
rubygems_version: 1.6.2
|
205
|
+
signing_key:
|
206
|
+
specification_version: 3
|
207
|
+
summary: A wrapper for the Adility API
|
208
|
+
test_files:
|
209
|
+
- spec/offers/offers_spec.rb
|
210
|
+
- spec/spec_helper.rb
|