groupon 0.0.1 → 1.0.0
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.
- data/lib/groupon.rb +23 -21
- data/lib/groupon/client.rb +34 -11
- data/lib/groupon/version.rb +3 -0
- data/test/groupon_test.rb +6 -6
- data/test/helper.rb +1 -2
- metadata +140 -107
data/lib/groupon.rb
CHANGED
@@ -1,40 +1,43 @@
|
|
1
1
|
require 'httparty'
|
2
2
|
require 'hashie'
|
3
|
+
require 'groupon/client'
|
3
4
|
|
4
|
-
directory = File.expand_path(File.dirname(__FILE__))
|
5
5
|
|
6
6
|
Hash.send :include, Hashie::HashExtensions
|
7
7
|
|
8
8
|
module Groupon
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
|
10
|
+
# Returns a list of divisions - cities where Groupon is live.
|
11
|
+
# @see http://sites.google.com/site/grouponapi/divisions-api Groupon API docs
|
12
|
+
# @return [Array<Hashie::Mash>] an array of divisions
|
12
13
|
def self.divisions
|
13
14
|
Groupon::Client.new.divisions
|
14
15
|
end
|
15
|
-
|
16
|
-
def self.deals(options={})
|
17
|
-
Groupon::Client.new.deals(options)
|
18
|
-
end
|
19
16
|
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
# elsewhere
|
17
|
+
# Returns a list of deals.
|
18
|
+
# The API returns an ordered list of deals currently running for a given Division.
|
19
|
+
# Priority is based on position within the response (top deals are higher in priority).
|
20
|
+
#
|
21
|
+
# @see http://sites.google.com/site/grouponapi/divisions-api Groupon API docs
|
27
22
|
#
|
28
|
-
#
|
29
|
-
|
30
|
-
|
31
|
-
|
23
|
+
# @option options [String] :lat (Latitudinal coordinates based on IP of API request) Latitude of geolocation to find deals
|
24
|
+
# @option options [String] :lng (Longtitudinal coordinates based on IP of API request) Longitude of geolocation to find deals
|
25
|
+
# @return [Array<Hashie::Mash>] an array of deals
|
26
|
+
def self.deals(options={})
|
27
|
+
Groupon::Client.new.deals(options)
|
32
28
|
end
|
33
29
|
|
34
30
|
class << self
|
31
|
+
|
32
|
+
# Get/sets the required Groupon API token
|
33
|
+
# @see http://sites.google.com/site/grouponapi/home Groupon API docs
|
34
|
+
#
|
35
|
+
# @param [String]
|
36
|
+
# @return [String]
|
35
37
|
attr_accessor :api_key
|
36
38
|
end
|
37
|
-
|
39
|
+
|
40
|
+
# Contains information for errors returned by the API
|
38
41
|
class GrouponError < StandardError
|
39
42
|
attr_reader :data
|
40
43
|
|
@@ -45,4 +48,3 @@ module Groupon
|
|
45
48
|
end
|
46
49
|
end
|
47
50
|
|
48
|
-
require File.join(directory, 'groupon', 'client')
|
data/lib/groupon/client.rb
CHANGED
@@ -1,38 +1,61 @@
|
|
1
1
|
module Groupon
|
2
2
|
class Client
|
3
|
+
attr_accessor :api_key
|
3
4
|
include HTTParty
|
4
|
-
base_uri "http://
|
5
|
+
base_uri "http://api.groupon.com/v2"
|
5
6
|
format :json
|
6
7
|
|
8
|
+
# Initialize the Groupon client
|
9
|
+
#
|
10
|
+
# @option options [String] :api_key (Groupon.api_key) Your Groupon API token
|
11
|
+
|
7
12
|
def initialize(options={})
|
8
|
-
api_key = options[:api_key] || Groupon.api_key
|
9
|
-
self.class.headers({'X-GrouponToken' => api_key }) unless api_key.nil?
|
13
|
+
@api_key = options[:api_key] || Groupon.api_key
|
10
14
|
end
|
11
|
-
|
15
|
+
# Returns a list of divisions - cities where Groupon is live.
|
16
|
+
# @see http://sites.google.com/site/grouponapi/divisions-api Groupon API docs
|
17
|
+
#
|
18
|
+
# @return [Array<Hashie::Mash>] an array of divisions
|
12
19
|
def divisions
|
13
|
-
self.class.get("/divisions.json").divisions
|
20
|
+
self.class.get("/divisions.json",:query => { :client_id => @api_key }).divisions
|
14
21
|
end
|
15
|
-
|
22
|
+
|
23
|
+
# Returns a list of deals.
|
24
|
+
#
|
25
|
+
# The API returns an ordered list of deals currently running for a given Division.
|
26
|
+
#
|
27
|
+
# Priority is based on position within the response (top deals are higher in priority).
|
28
|
+
#
|
29
|
+
#
|
30
|
+
#
|
31
|
+
# @see http://sites.google.com/site/grouponapi/divisions-api Groupon API docs
|
32
|
+
#
|
33
|
+
#
|
34
|
+
#
|
35
|
+
# @option options [String] :lat (Latitudinal coordinates based on IP of API request) Latitude of geolocation to find deals
|
36
|
+
#
|
37
|
+
# @option options [String] :lng (Longtitudinal coordinates based on IP of API request) Longitude of geolocation to find deals
|
38
|
+
#
|
39
|
+
# @return [Array<Hashie::Mash>] an array of deals
|
16
40
|
def deals(query={})
|
17
41
|
division = query.delete(:division)
|
42
|
+
query.merge! :client_id => @api_key
|
18
43
|
path = division ? "/#{division}" : ""
|
19
44
|
path += "/deals.json"
|
20
45
|
self.class.get(path, :query => query).deals
|
21
46
|
end
|
22
47
|
|
23
|
-
|
24
48
|
def self.get(*args); handle_response super end
|
25
49
|
def self.post(*args); handle_response super end
|
26
|
-
|
50
|
+
|
27
51
|
def self.handle_response(response)
|
28
52
|
case response.code
|
29
53
|
when 500...600; raise GrouponError.new(Hashie::Mash.new(response).status)
|
30
54
|
else; response
|
31
55
|
end
|
32
|
-
|
56
|
+
|
33
57
|
Hashie::Mash.new(response)
|
34
|
-
|
58
|
+
|
35
59
|
end
|
36
|
-
|
37
60
|
end
|
38
61
|
end
|
data/test/groupon_test.rb
CHANGED
@@ -1,26 +1,26 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
class GrouponTest < Test::Unit::TestCase
|
4
|
-
|
4
|
+
|
5
5
|
context "Groupon API" do
|
6
6
|
|
7
7
|
should "return a list of divisions - cities where Groupon is live" do
|
8
|
-
stub_get("/divisions.json", "divisions.json")
|
8
|
+
stub_get("/divisions.json?client_id=", "divisions.json")
|
9
9
|
divisions = Groupon.divisions
|
10
10
|
divisions.size.should == 61
|
11
11
|
divisions.last.name.should == 'Wichita'
|
12
12
|
divisions.last.location.latitude.should == 37.6922
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
should "return a list of deals" do
|
16
|
-
stub_get("/deals.json?lat=32.781100000000002&lng=-96.9791", "deals.json")
|
16
|
+
stub_get("/deals.json?lat=32.781100000000002&lng=-96.9791&client_id=", "deals.json")
|
17
17
|
deals = Groupon.deals(:lat => "32.781100000000002", :lng => "-96.9791")
|
18
18
|
deals.size.should == 1
|
19
19
|
deals.first.discount_percent.should == 50
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
should "return a list of deals for a specified division" do
|
23
|
-
stub_get("/dallas/deals.json", "deals.json")
|
23
|
+
stub_get("/dallas/deals.json?client_id=", "deals.json")
|
24
24
|
deals = Groupon.deals(:division => :dallas)
|
25
25
|
deals.size.should == 1
|
26
26
|
deals.first.discount_percent.should == 50
|
data/test/helper.rb
CHANGED
@@ -2,7 +2,6 @@ require 'rubygems'
|
|
2
2
|
require 'test/unit'
|
3
3
|
require 'shoulda'
|
4
4
|
|
5
|
-
require 'redgreen'
|
6
5
|
require 'matchy'
|
7
6
|
require 'fakeweb'
|
8
7
|
|
@@ -25,7 +24,7 @@ def fixture_file(filename)
|
|
25
24
|
end
|
26
25
|
|
27
26
|
def groupon_url(url, options={})
|
28
|
-
url =~ /^http/ ? url : "http://
|
27
|
+
url =~ /^http/ ? url : "http://api.groupon.com/v2#{url}"
|
29
28
|
end
|
30
29
|
|
31
30
|
def stub_request(method, url, filename, status=nil)
|
metadata
CHANGED
@@ -1,147 +1,180 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: groupon
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
version: 0.0.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Wynn Netherland
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
dependencies:
|
20
|
-
- !ruby/object:Gem::Dependency
|
21
|
-
version_requirements: &id001 !ruby/object:Gem::Requirement
|
22
|
-
requirements:
|
23
|
-
- - ">="
|
24
|
-
- !ruby/object:Gem::Version
|
25
|
-
segments:
|
26
|
-
- 0
|
27
|
-
- 1
|
28
|
-
- 3
|
29
|
-
version: 0.1.3
|
12
|
+
date: 2010-05-23 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
30
15
|
name: hashie
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.1.3
|
22
|
+
type: :runtime
|
31
23
|
prerelease: false
|
32
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.1.3
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: httparty
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 0.1.0
|
33
38
|
type: :runtime
|
34
|
-
|
35
|
-
version_requirements:
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
- 0
|
41
|
-
- 1
|
42
|
-
- 0
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
43
45
|
version: 0.1.0
|
44
|
-
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: shoulda
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.10.1
|
54
|
+
type: :development
|
45
55
|
prerelease: false
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
- - ">="
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
segments:
|
54
|
-
- 2
|
55
|
-
- 10
|
56
|
-
- 1
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
57
61
|
version: 2.10.1
|
58
|
-
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: mg
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 0.0.8
|
70
|
+
type: :development
|
59
71
|
prerelease: false
|
60
|
-
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 0.0.8
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: redgreen
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
61
86
|
type: :development
|
62
|
-
- !ruby/object:Gem::Dependency
|
63
|
-
version_requirements: &id004 !ruby/object:Gem::Requirement
|
64
|
-
requirements:
|
65
|
-
- - "="
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
segments:
|
68
|
-
- 0
|
69
|
-
- 4
|
70
|
-
- 0
|
71
|
-
version: 0.4.0
|
72
|
-
name: matchy
|
73
87
|
prerelease: false
|
74
|
-
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: jnunemaker-matchy
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - '='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 0.4.0
|
75
102
|
type: :development
|
76
|
-
- !ruby/object:Gem::Dependency
|
77
|
-
version_requirements: &id005 !ruby/object:Gem::Requirement
|
78
|
-
requirements:
|
79
|
-
- - ">="
|
80
|
-
- !ruby/object:Gem::Version
|
81
|
-
segments:
|
82
|
-
- 1
|
83
|
-
- 2
|
84
|
-
- 5
|
85
|
-
version: 1.2.5
|
86
|
-
name: fakeweb
|
87
103
|
prerelease: false
|
88
|
-
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - '='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 0.4.0
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: fakeweb
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.2.5
|
89
118
|
type: :development
|
90
|
-
- !ruby/object:Gem::Dependency
|
91
|
-
version_requirements: &id006 !ruby/object:Gem::Requirement
|
92
|
-
requirements:
|
93
|
-
- - ">="
|
94
|
-
- !ruby/object:Gem::Version
|
95
|
-
segments:
|
96
|
-
- 0
|
97
|
-
version: "0"
|
98
|
-
name: yard
|
99
119
|
prerelease: false
|
100
|
-
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: 1.2.5
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: yard
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
101
134
|
type: :development
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
102
142
|
description: Wrapper for the Groupon API
|
103
143
|
email: wynn.netherland@gmail.com
|
104
144
|
executables: []
|
105
|
-
|
106
145
|
extensions: []
|
107
|
-
|
108
146
|
extra_rdoc_files: []
|
109
|
-
|
110
|
-
files:
|
147
|
+
files:
|
111
148
|
- lib/groupon/client.rb
|
149
|
+
- lib/groupon/version.rb
|
112
150
|
- lib/groupon.rb
|
113
|
-
|
151
|
+
- test/helper.rb
|
152
|
+
- test/groupon_test.rb
|
114
153
|
homepage: http://github.com/pengwynn/groupon
|
115
154
|
licenses: []
|
116
|
-
|
117
155
|
post_install_message:
|
118
156
|
rdoc_options: []
|
119
|
-
|
120
|
-
require_paths:
|
157
|
+
require_paths:
|
121
158
|
- lib
|
122
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
requirements:
|
131
|
-
- -
|
132
|
-
- !ruby/object:Gem::Version
|
133
|
-
segments:
|
134
|
-
- 1
|
135
|
-
- 3
|
136
|
-
- 6
|
159
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
160
|
+
none: false
|
161
|
+
requirements:
|
162
|
+
- - ! '>='
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: '0'
|
165
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
166
|
+
none: false
|
167
|
+
requirements:
|
168
|
+
- - ! '>='
|
169
|
+
- !ruby/object:Gem::Version
|
137
170
|
version: 1.3.6
|
138
171
|
requirements: []
|
139
|
-
|
140
172
|
rubyforge_project:
|
141
|
-
rubygems_version: 1.
|
173
|
+
rubygems_version: 1.8.23
|
142
174
|
signing_key:
|
143
175
|
specification_version: 3
|
144
176
|
summary: Wrapper for the Groupon API
|
145
|
-
test_files:
|
177
|
+
test_files:
|
146
178
|
- test/helper.rb
|
147
179
|
- test/groupon_test.rb
|
180
|
+
has_rdoc:
|