groupon_api 0.1.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.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +71 -0
- data/Rakefile +2 -0
- data/lib/groupon_api.rb +9 -0
- data/lib/groupon_api/config.rb +26 -0
- data/lib/groupon_api/deals.rb +11 -0
- data/lib/groupon_api/request.rb +30 -0
- data/lib/groupon_api/version.rb +3 -0
- data/spec/groupon_api_spec.rb +65 -0
- data/spec/spec_helper.rb +8 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 36abbb1658aa07d35134e1f59fa33d6a87aed2b2
|
4
|
+
data.tar.gz: be136abc6dd392f36a7de3692bab249a860767af
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 33be32dd150a0511157b3eb839442b149fe8fb684ddceebd6dd2beafab96ea1df20f242e1e32772e8909717e99e45cf600934d9eff69f2f6301e0e42126c43b8
|
7
|
+
data.tar.gz: 6aafe81ad1e0b42f0c1d35c3a4ca0edbdedb886da4ee18fde8b074eac243371365f22eab4e83c232ea0c1f8e0932f6a57a7c6feb7b0e4230eacf265770148d62
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Bryan Liff
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# GrouponApi
|
2
|
+
|
3
|
+
Groupon API gem
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'groupon_api'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install groupon_api
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
### Authorization
|
24
|
+
|
25
|
+
You must have an active partner account to use this gem.
|
26
|
+
|
27
|
+
Apply here: https://partner.groupon.com
|
28
|
+
|
29
|
+
### Configuration
|
30
|
+
|
31
|
+
For most method calls GrouponApi must be configured with your partner tsToken, which you can set as such:
|
32
|
+
|
33
|
+
GrouponApi.configure do |config|
|
34
|
+
config.ts_token = 'US_AFF_0_201236_212556_0'
|
35
|
+
end
|
36
|
+
|
37
|
+
Additionally you can set default params per API call
|
38
|
+
|
39
|
+
GrouponApi.configure do |config|
|
40
|
+
config.deals = {show: 'name,lat,lng', hide: 'areas,timezone,timezoneOffsetInSeconds'}
|
41
|
+
end
|
42
|
+
|
43
|
+
Ad hoc configuration can be done with the ```.config``` method:
|
44
|
+
|
45
|
+
GrouponApi.config.use_ssl = true #default, will use https instead of http
|
46
|
+
|
47
|
+
### Deals
|
48
|
+
Find Groupon deals with the ```.deals``` method.
|
49
|
+
|
50
|
+
deals = GrouponApi.deals(params)
|
51
|
+
deals[0] #HashWithIndifferentAccess
|
52
|
+
|
53
|
+
Your ```:ts_token``` will be automatically applied as well as any other default params set in ```config.deals```
|
54
|
+
|
55
|
+
A full list of parameters may be found here: https://partner-api.groupon.com/help/deal-api
|
56
|
+
|
57
|
+
## Testing
|
58
|
+
|
59
|
+
Since Groupon does not provide a test API enpoint / account, you must use your partner account
|
60
|
+
for testing.
|
61
|
+
|
62
|
+
Simply change the return value of ```#your_ts_token``` in ```spec/spec_helper.rb```
|
63
|
+
|
64
|
+
## Contributing
|
65
|
+
|
66
|
+
1. Fork it ( https://github.com/minerva-group/groupon_api/fork )
|
67
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
68
|
+
3. Add needed specs & code implementation
|
69
|
+
4. Commit your changes (`git commit -am 'Add some feature'`)
|
70
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
71
|
+
6. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/groupon_api.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'active_support/configurable'
|
2
|
+
|
3
|
+
module GrouponApi
|
4
|
+
# configure GrouponApi global settings
|
5
|
+
# GrouponApi.configure do |config|
|
6
|
+
# config.ts_token = 'US_AFF_0_201236_212556_0'
|
7
|
+
# end
|
8
|
+
def self.configure &block
|
9
|
+
yield @config ||= GrouponApi::Configuration.new
|
10
|
+
end
|
11
|
+
|
12
|
+
# GrouponApi global settings
|
13
|
+
def self.config
|
14
|
+
@config ||= GrouponApi::Configuration.new
|
15
|
+
end
|
16
|
+
|
17
|
+
class Configuration
|
18
|
+
include ActiveSupport::Configurable
|
19
|
+
|
20
|
+
config_accessor(:ts_token){ nil }
|
21
|
+
config_accessor(:use_ssl){ true }
|
22
|
+
|
23
|
+
#deals
|
24
|
+
config_accessor(:deals){ {} }
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module GrouponApi
|
2
|
+
def self.deals(params)
|
3
|
+
raise ::ArgumentError, 'param :ts_token cannot be nil' if GrouponApi.config.ts_token.nil?
|
4
|
+
raise ::ArgumentError, 'param :ts_token must match /US_AFF_0_\d+_212556_0/' unless GrouponApi.config.ts_token.match(API_KEY_FORMAT)
|
5
|
+
|
6
|
+
params.merge!(GrouponApi.config.deals)
|
7
|
+
params.merge!(tsToken: GrouponApi.config.ts_token)
|
8
|
+
|
9
|
+
GrouponApi::Request.call('deals', params)
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "net/http"
|
2
|
+
require "uri"
|
3
|
+
require 'json'
|
4
|
+
require 'active_support/core_ext/hash/indifferent_access'
|
5
|
+
|
6
|
+
module GrouponApi
|
7
|
+
class Request
|
8
|
+
def self.call(endpoint, params)
|
9
|
+
# format query string
|
10
|
+
query_arr = []
|
11
|
+
params.each_pair do |key,val|
|
12
|
+
query_arr << "#{key}=#{val}"
|
13
|
+
end
|
14
|
+
|
15
|
+
# Call API with config.use_ssl
|
16
|
+
protocol = GrouponApi.config.use_ssl ? 'https' : 'http'
|
17
|
+
url_str = "#{protocol}://#{API_BASE}/#{endpoint}.json?#{query_arr.join('&')}"
|
18
|
+
begin
|
19
|
+
result = Net::HTTP.get(URI.parse(url_str))
|
20
|
+
rescue => e
|
21
|
+
puts '[RESCUE]: ' + e.to_s
|
22
|
+
return []
|
23
|
+
end
|
24
|
+
|
25
|
+
# return result as Array of HashWithIndifferentAccess
|
26
|
+
json = JSON.parse(result)
|
27
|
+
json['deals'].collect{|deal| HashWithIndifferentAccess.new(deal)}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe GrouponApi do
|
4
|
+
|
5
|
+
shared_context :without_api_key do
|
6
|
+
before do
|
7
|
+
GrouponApi.config.ts_token = nil
|
8
|
+
end
|
9
|
+
end
|
10
|
+
shared_context :invalid_api_key do
|
11
|
+
before do
|
12
|
+
GrouponApi.config.ts_token = 42
|
13
|
+
end
|
14
|
+
end
|
15
|
+
shared_context :valid_api_key do
|
16
|
+
before do
|
17
|
+
GrouponApi.config.ts_token = your_ts_token
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '.deals' do
|
22
|
+
let(:valid_params){
|
23
|
+
{
|
24
|
+
lat: 40.704235,
|
25
|
+
lng: -73.986797,
|
26
|
+
radius: 10
|
27
|
+
}
|
28
|
+
}
|
29
|
+
context 'without API key' do
|
30
|
+
include_context :without_api_key
|
31
|
+
it "throws an exception" do
|
32
|
+
expect{described_class.deals(valid_params)}.to raise_error(ArgumentError, 'param :ts_token cannot be nil')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
context 'with invalid API key' do
|
36
|
+
include_context :invalid_api_key
|
37
|
+
it 'throws an exception' do
|
38
|
+
expect{described_class.deals(valid_params)}.to raise_error
|
39
|
+
end
|
40
|
+
end
|
41
|
+
context 'with valid API key' do
|
42
|
+
include_context :valid_api_key
|
43
|
+
context 'without results' do
|
44
|
+
it 'returns an empty Array' do
|
45
|
+
params = valid_params.merge(limit: 0, offset: 0)
|
46
|
+
result = described_class.deals(params)
|
47
|
+
expect(result).to be_a(Array)
|
48
|
+
expect(result.size).to eq(0)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
context 'with results' do
|
52
|
+
it "returns an Array of Hashes" do
|
53
|
+
result = described_class.deals(valid_params)
|
54
|
+
expect(result).to be_a(Array)
|
55
|
+
expect(result.first).to be_a(HashWithIndifferentAccess)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end #deals
|
60
|
+
|
61
|
+
describe '.divisions' do
|
62
|
+
pending
|
63
|
+
end #divisions
|
64
|
+
|
65
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: groupon_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bryan Liff
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.7'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.2'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.2'
|
69
|
+
description: Provides a Ruby gem wrapper for the Groupon API
|
70
|
+
email:
|
71
|
+
- bliff@minerva-group.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- Gemfile
|
77
|
+
- LICENSE.txt
|
78
|
+
- README.md
|
79
|
+
- Rakefile
|
80
|
+
- lib/groupon_api.rb
|
81
|
+
- lib/groupon_api/config.rb
|
82
|
+
- lib/groupon_api/deals.rb
|
83
|
+
- lib/groupon_api/request.rb
|
84
|
+
- lib/groupon_api/version.rb
|
85
|
+
- spec/groupon_api_spec.rb
|
86
|
+
- spec/spec_helper.rb
|
87
|
+
homepage: https://github.com/minerva-group/groupon_api
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.4.6
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: Groupon API gem
|
111
|
+
test_files:
|
112
|
+
- spec/groupon_api_spec.rb
|
113
|
+
- spec/spec_helper.rb
|