groupon2 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,9 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ *.swp
6
+ *.swo
7
+ coverage
8
+ doc
9
+ .yardoc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in groupon.gemspec
4
+ gemspec
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,34 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "groupon/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "groupon2"
7
+ s.version = Groupon::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Josh Deeden"]
10
+ s.email = ["jdeeden@gmail.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{A wrapper for the Groupon v2 API}
13
+ s.description = %q{A wrapper for the Groupon v2 API}
14
+
15
+ s.rubyforge_project = "groupon2"
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
@@ -0,0 +1,5 @@
1
+ class Array
2
+ def extract_options!
3
+ last.is_a?(::Hash) ? pop : {}
4
+ end
5
+ end
@@ -0,0 +1,85 @@
1
+ require 'faraday'
2
+ require 'faraday_middleware'
3
+ require 'core_ext/array'
4
+ require 'yajl'
5
+
6
+ module Groupon
7
+ class Client
8
+ attr_reader :api_key, :conn
9
+
10
+ # Initialize the client.
11
+ # TODO: Document.
12
+ def initialize(*args)
13
+ options = args.extract_options!
14
+ @api_key = args[0]
15
+ @conn = Faraday.new(:url => "http://api.groupon.com/") do |builder|
16
+ builder.adapter Faraday.default_adapter
17
+ builder.adapter :logger if options[:debug] == true
18
+ builder.use Faraday::Response::ParseJson
19
+ builder.use Faraday::Response::Mashify
20
+ end
21
+ end
22
+
23
+ # @overload deals(options={})
24
+ # Search for Deals
25
+ # @param [Hash] options A customizable set of options
26
+ # @option options [String] :lat Latitude of point to to sort deals by proximity to. Use with lon. Uses radius.
27
+ # @option options [String] :lon Longitude of point to to sort deals by proximity to. Use with lat. Uses radius.
28
+ # @option options [Fixnum] :radius Maximum distance of radius in miles to deal location from center point. Defaults to 10. Requires lat and lon
29
+ # @option options [String] :divisions One or more division slugs (comma separated). See Divisions API for more details.
30
+ # @option options [String] :source One or more source slugs (comma separated). See Sources API for more details.
31
+ # @option options [String] :phone Deals available at a business matching one of the phone numbers. See Businesses API for more details.
32
+ # @option options [String] :tag One or more tag slugs (comma separated). See Tags API for more details. Note: Specifying multiple tags returns deals matching any one of the tags, NOT all of them
33
+ # @option options [Boolean] :paid Shows deals filtered on paid status. Defaults to false. Set to true if you would like to see all deals.
34
+ # @return [Array] An array of Hashie::Mash objects representing Groupon deals
35
+ # @example Search deals by latitude and longitude
36
+ # client.deals(:lat => "-37.74", :lon => "-76.00")
37
+ # @example Search deals within a 2 miles radius of latitude and longitude
38
+ # client.deals(:lat => "-37.74", :lon => "-76.00", :radius => 2)
39
+ # @example Search deals from Groupon
40
+ # client.deals(:source => "Groupon")
41
+ # @example Search deals based on phone number
42
+ # client.deals(:phone => "7185551212")
43
+ # @example Search deals based on tags
44
+ # client.deals(:tag => "restaurants,spa")
45
+ # @example Search deals based on paid status. (Defaults to false)
46
+ # client.deals(:paid => true)
47
+ # @overload deals(deal_id)
48
+ # Get deal details
49
+ # @param [Fixnum] deal_id A Deal Id
50
+ # @return [Hashie::Mash] A Hashie::Mash object representing a Groupon deal
51
+ def deals(*args)
52
+ super
53
+ end
54
+
55
+ # @overload sources(options={})
56
+ # Search for sources
57
+ # @param [Hash] options A customizable set of options
58
+ # @option options [String] :division One or more division slugs. See Divisions API for more details. Note: Specifying multiple divisions returns sources that exist in either of the divisions, NOT all of them.
59
+ # @option options [String] :paid When paid is true, only paid sources are returned. Defaults to false.
60
+ # @overload sources(source_id)
61
+ # Get source details
62
+ # @param [String] slug A source slug
63
+ # @return [Hashie::Mash] A Hashie::Mash object representing a Groupon Deal Source
64
+ def sources(*args)
65
+ super
66
+ end
67
+
68
+ # @overload tags(options={})
69
+ # This method returns a list of all tags. There are no parameters specific to tags.
70
+ # @param [Hash] options A customizable set of options
71
+ # @return [Array] An array of Hashie::Mash objects representing Groupon tags.
72
+ def tags(*args)
73
+ super
74
+ end
75
+ def divisions(*args)
76
+ super
77
+ end
78
+
79
+ def method_missing(sym, *args, &block)
80
+ options = args.extract_options!.merge(:client_id => api_key)
81
+ response = conn.get("/v2/#{sym.to_s}/#{args[0]}") { |req| req.params = options }
82
+ args[0].nil? ? response.body.send(sym) : response.body.send(sym.to_s.chop)
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,3 @@
1
+ module Groupon
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,9 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+ describe Groupon::Client do
3
+ context "api" do
4
+ before(:all) do
5
+ api_key="39666de32f9626a0241f676db703795a9b0277cc"
6
+ @client = Groupon::Client.new(api_key)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,63 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe Groupon::Client do
4
+ context "api" do
5
+ before(:all) do
6
+ @client = Groupon::Client.new(API_KEY)
7
+ end
8
+ context "deals" do
9
+ context "search" do
10
+ context "with no args" do
11
+ use_vcr_cassette
12
+ before(:all) do
13
+ @deals = @client.deals
14
+ end
15
+ subject { @deals }
16
+ it { should_not be_nil }
17
+ it { should be_an(Array) }
18
+ it { should have_at_least(1).items }
19
+ end
20
+ context "with Brooklyn, NY lat/long" do
21
+ before(:all) do
22
+ @deals = @client.deals(:lat => "40.7325859", :lng => "-73.9568557")
23
+ end
24
+ subject { @deals }
25
+ it { should_not be_nil }
26
+ subject { @deals.first.division.name }
27
+ it { should eql "New York City" }
28
+ subject { @deals.last.division.name }
29
+ it { should eql "New York City" }
30
+ end
31
+ # TODO: Better test.
32
+ context "with Brooklyn, NY lat/long, scoped to a 10 mile radius" do
33
+ before(:all) do
34
+ @deals = @client.deals(:lat => "40.7325859", :lng => "-73.9568557", :radius => 10)
35
+ end
36
+ subject { @deals }
37
+ it { should_not be_nil }
38
+ subject { @deals.first.division.name }
39
+ it { should eql "New York City" }
40
+ subject { @deals.last.division.name }
41
+ it { should eql "New York City" }
42
+ end
43
+ end
44
+ context "details" do
45
+ before(:all) do
46
+ @deal = @client.deals("museum-of-modern-art")
47
+ puts "deal: #{@deal.inspect}"
48
+ end
49
+ subject { @deal }
50
+ it { should_not be_nil }
51
+ it { should be_a(Hashie::Mash) }
52
+ it { should respond_to(:id) }
53
+ it { should respond_to(:title) }
54
+ it { should respond_to(:merchant) }
55
+ it { should respond_to(:endAt) }
56
+ it { should respond_to(:type) }
57
+ it { should respond_to(:areas) }
58
+ # etc...
59
+ end
60
+ end
61
+ end
62
+ end
63
+
@@ -0,0 +1,25 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe Groupon::Client do
4
+ context "api" do
5
+ before(:all) do
6
+ @client = Groupon::Client.new(API_KEY)
7
+ end
8
+ context "divisions" do
9
+ context "search divisions" do
10
+ # use_vcr_cassette
11
+ context "all" do
12
+ before(:all) do
13
+ @divisions = @client.divisions
14
+ puts @divisions.inspect
15
+ end
16
+ context "the results" do
17
+ subject { @divisions }
18
+ specify { should_not be_nil }
19
+ specify { should have_at_least(1).items }
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,23 @@
1
+ require 'simplecov'
2
+
3
+ SimpleCov.start do
4
+ add_group 'Groupon', 'lib/groupon'
5
+ add_group 'Specs', 'spec'
6
+ end
7
+
8
+ require File.expand_path('../../lib/groupon', __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
22
+
23
+ API_KEY="39666de32f9626a0241f676db703795a9b0277cc"
metadata ADDED
@@ -0,0 +1,212 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: groupon2
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-29 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 Groupon v2 API
160
+ email:
161
+ - jdeeden@gmail.com
162
+ executables: []
163
+
164
+ extensions: []
165
+
166
+ extra_rdoc_files: []
167
+
168
+ files:
169
+ - .gitignore
170
+ - Gemfile
171
+ - Rakefile
172
+ - groupon2.gemspec
173
+ - lib/core_ext/array.rb
174
+ - lib/groupon.rb
175
+ - lib/groupon/version.rb
176
+ - spec/client/client_spec.rb
177
+ - spec/deals/deals_spec.rb
178
+ - spec/divisions/divisions_spec.rb
179
+ - spec/spec_helper.rb
180
+ has_rdoc: true
181
+ homepage: ""
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: groupon2
204
+ rubygems_version: 1.6.2
205
+ signing_key:
206
+ specification_version: 3
207
+ summary: A wrapper for the Groupon v2 API
208
+ test_files:
209
+ - spec/client/client_spec.rb
210
+ - spec/deals/deals_spec.rb
211
+ - spec/divisions/divisions_spec.rb
212
+ - spec/spec_helper.rb