supreme_golf 0.0.2 → 0.0.3
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 +4 -4
- data/Gemfile +1 -1
- data/README.md +9 -6
- data/Rakefile +7 -1
- data/lib/supreme_golf/base.rb +8 -0
- data/lib/supreme_golf/course.rb +5 -10
- data/lib/supreme_golf/tee_time.rb +7 -4
- data/lib/supreme_golf/version.rb +1 -1
- data/supreme_golf.gemspec +1 -0
- data/test/fixtures/find_tee_time.yml +55 -0
- data/test/supreme_golf/course_test.rb +1 -0
- data/test/supreme_golf/supreme_golf_test.rb +14 -1
- data/test/supreme_golf/tee_time_test.rb +37 -0
- metadata +18 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 866941e1cc02bf2d66290a4131d6ee4c50da178b
|
|
4
|
+
data.tar.gz: c02371f65c665575a3b376eadcc02daab791ac27
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a3501a060b56eaf6fb25b28b3d21ce71b47e4a08009bb7fdb17632a70d9720cd1812d7ba634fb9359508cb16e1c2a2c7661897010058f09865adfc7e62569e08
|
|
7
|
+
data.tar.gz: bca741f2149ef410a2269cfa23cf3db0849507a568a6ee99a510a4ace85f60046b3503d33560cd0d12b7e0162a72b87bad20ffe18fbec54704208a9fb908ed8e
|
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
Add this line to your application's Gemfile:
|
|
6
6
|
|
|
7
|
-
gem '
|
|
7
|
+
gem 'supreme_golf'
|
|
8
8
|
|
|
9
9
|
And then execute:
|
|
10
10
|
|
|
@@ -12,19 +12,22 @@ And then execute:
|
|
|
12
12
|
|
|
13
13
|
Or install it yourself as:
|
|
14
14
|
|
|
15
|
-
$ gem install
|
|
15
|
+
$ gem install supreme_golf
|
|
16
16
|
|
|
17
17
|
## Official docs
|
|
18
18
|
|
|
19
19
|
https://supremegolf.com/api/docs/
|
|
20
20
|
|
|
21
|
+
## Configuration
|
|
22
|
+
|
|
23
|
+
SupremeGolf.configure do |config|
|
|
24
|
+
config.x_api_key = 'your-api-key-here'
|
|
25
|
+
end
|
|
26
|
+
|
|
21
27
|
## Usage
|
|
22
28
|
|
|
23
29
|
The "params" passed to the API methods are simply the parameters defined in the official documentation listed above.
|
|
24
30
|
|
|
25
|
-
# Require the gem
|
|
26
|
-
require 'supreme_golf'
|
|
27
|
-
|
|
28
31
|
# Get all courses near a lat/lon
|
|
29
32
|
SupremeGolf::Course.near(params: {lat: 33.4677096, lon: -117.1318014, limit: 1})
|
|
30
33
|
|
|
@@ -42,7 +45,7 @@ The "params" passed to the API methods are simply the parameters defined in the
|
|
|
42
45
|
|
|
43
46
|
You're welcome to contribute and help flesh out the rest of the API. I only implemented the methods I needed for my specific case, but there are many more you can see from the official docs.
|
|
44
47
|
|
|
45
|
-
1. Fork it ( https://github.com/[my-github-username]/
|
|
48
|
+
1. Fork it ( https://github.com/[my-github-username]/supreme_golf/fork )
|
|
46
49
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
47
50
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
48
51
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/Rakefile
CHANGED
data/lib/supreme_golf/base.rb
CHANGED
|
@@ -10,5 +10,13 @@ module SupremeGolf
|
|
|
10
10
|
conn = Faraday.get url, params, SupremeGolf.configuration.http_headers
|
|
11
11
|
JSON.parse(conn.body)
|
|
12
12
|
end
|
|
13
|
+
|
|
14
|
+
def self.find id
|
|
15
|
+
response = self.response_from_api "#{self::API_URLS[:find]}/#{id}"
|
|
16
|
+
key = self.name.split('::').last.to_s.gsub(/(.)([A-Z])/, '\1_\2').downcase
|
|
17
|
+
|
|
18
|
+
raise 'RecordNotFound' unless response[key]
|
|
19
|
+
new(response[key])
|
|
20
|
+
end
|
|
13
21
|
end
|
|
14
22
|
end
|
data/lib/supreme_golf/course.rb
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
module SupremeGolf
|
|
2
2
|
class Course < SupremeGolf::Base
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
API_URLS = {
|
|
4
|
+
find: "#{SupremeGolf::API_BASE_URL}/courses",
|
|
5
|
+
near: "#{SupremeGolf::API_BASE_URL}/courses/near"
|
|
6
|
+
}
|
|
5
7
|
|
|
6
8
|
ATTRS = [:id,
|
|
7
9
|
:slug,
|
|
@@ -38,15 +40,8 @@ module SupremeGolf
|
|
|
38
40
|
]
|
|
39
41
|
attr_accessor *ATTRS
|
|
40
42
|
|
|
41
|
-
def self.find id
|
|
42
|
-
response = self.response_from_api "#{FIND_URL}/#{id}"
|
|
43
|
-
|
|
44
|
-
raise 'RecordNotFound' unless response['course']
|
|
45
|
-
new(response['course'])
|
|
46
|
-
end
|
|
47
|
-
|
|
48
43
|
def self.near params: {}
|
|
49
|
-
response = self.response_from_api
|
|
44
|
+
response = self.response_from_api API_URLS[:near], params
|
|
50
45
|
|
|
51
46
|
response['courses'].map do |course_params|
|
|
52
47
|
new(course_params)
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
module SupremeGolf
|
|
2
2
|
class TeeTime < SupremeGolf::Base
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
API_URLS = {
|
|
4
|
+
find: "#{SupremeGolf::API_BASE_URL}/tee_times",
|
|
5
|
+
at: "#{SupremeGolf::API_BASE_URL}/tee_times/at",
|
|
6
|
+
valid: "#{SupremeGolf::API_BASE_URL}/tee_times"
|
|
7
|
+
}
|
|
5
8
|
|
|
6
9
|
ATTRS = [:id,
|
|
7
10
|
:course_id,
|
|
@@ -19,7 +22,7 @@ module SupremeGolf
|
|
|
19
22
|
attr_accessor *ATTRS
|
|
20
23
|
|
|
21
24
|
def self.at course_id, params: {}
|
|
22
|
-
response = self.response_from_api "#{
|
|
25
|
+
response = self.response_from_api "#{API_URLS[:at]}/#{course_id}", params
|
|
23
26
|
|
|
24
27
|
response['tee_times'].map do |tee_time_params|
|
|
25
28
|
new(tee_time_params)
|
|
@@ -27,7 +30,7 @@ module SupremeGolf
|
|
|
27
30
|
end
|
|
28
31
|
|
|
29
32
|
def self.valid id, params: {}
|
|
30
|
-
response = self.response_from_api "#{
|
|
33
|
+
response = self.response_from_api "#{API_URLS[:valid]}/#{id}/valid", params
|
|
31
34
|
|
|
32
35
|
response['reservation_url']
|
|
33
36
|
end
|
data/lib/supreme_golf/version.rb
CHANGED
data/supreme_golf.gemspec
CHANGED
|
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
|
|
|
23
23
|
spec.add_development_dependency 'vcr'
|
|
24
24
|
spec.add_development_dependency 'webmock'
|
|
25
25
|
spec.add_development_dependency 'mocha'
|
|
26
|
+
spec.add_development_dependency 'rake'
|
|
26
27
|
|
|
27
28
|
spec.add_dependency 'faraday'
|
|
28
29
|
spec.add_dependency 'json'
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
---
|
|
2
|
+
http_interactions:
|
|
3
|
+
- request:
|
|
4
|
+
method: get
|
|
5
|
+
uri: https://supremegolf.com/api/v4/tee_times/367049106
|
|
6
|
+
body:
|
|
7
|
+
encoding: US-ASCII
|
|
8
|
+
string: ''
|
|
9
|
+
headers:
|
|
10
|
+
User-Agent:
|
|
11
|
+
- Faraday v0.9.1
|
|
12
|
+
Accept-Encoding:
|
|
13
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
|
14
|
+
Accept:
|
|
15
|
+
- "*/*"
|
|
16
|
+
response:
|
|
17
|
+
status:
|
|
18
|
+
code: 200
|
|
19
|
+
message: OK
|
|
20
|
+
headers:
|
|
21
|
+
Content-Type:
|
|
22
|
+
- application/json
|
|
23
|
+
Content-Length:
|
|
24
|
+
- '341'
|
|
25
|
+
Connection:
|
|
26
|
+
- close
|
|
27
|
+
Status:
|
|
28
|
+
- 200 OK
|
|
29
|
+
X-Api-Version:
|
|
30
|
+
- 4.1.7
|
|
31
|
+
Access-Control-Allow-Origin:
|
|
32
|
+
- "*"
|
|
33
|
+
Etag:
|
|
34
|
+
- W/"8ae4d3114a5b3c942f281d27d1491737"
|
|
35
|
+
Cache-Control:
|
|
36
|
+
- max-age=0, private, must-revalidate
|
|
37
|
+
X-Request-Id:
|
|
38
|
+
- f45acb24-7d10-4c9a-b409-6b5aead73382
|
|
39
|
+
X-Runtime:
|
|
40
|
+
- '0.013376'
|
|
41
|
+
Vary:
|
|
42
|
+
- Origin
|
|
43
|
+
X-Powered-By:
|
|
44
|
+
- Phusion Passenger 4.0.59
|
|
45
|
+
Date:
|
|
46
|
+
- Tue, 02 Jun 2015 17:06:51 GMT
|
|
47
|
+
Server:
|
|
48
|
+
- nginx + Phusion Passenger 4.0.59
|
|
49
|
+
body:
|
|
50
|
+
encoding: UTF-8
|
|
51
|
+
string: '{"tee_time":{"id":367049106,"course_id":3003,"currency":"USD","players":[1,2,3,4],"rate":"65.00","regular_rate":"80.52","savings_pct":19,"savings_amount":"15.52","tee_off_at_formatted":"10:10AM","tee_off_at_iso8601":"2015-06-02T10:10:00Z","amenities":["is_18_holes","is_riding"],"provider":{"code":"golf18_network","name":"Golf18
|
|
52
|
+
Network"}}}'
|
|
53
|
+
http_version:
|
|
54
|
+
recorded_at: Tue, 02 Jun 2015 17:06:51 GMT
|
|
55
|
+
recorded_with: VCR 2.9.3
|
|
@@ -8,8 +8,21 @@ class SupremeGolfTest < Minitest::Test
|
|
|
8
8
|
end
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
+
after do
|
|
12
|
+
SupremeGolf.configure do |config|
|
|
13
|
+
config.x_api_key = nil
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
11
17
|
it 'should use x_api_key in request header' do
|
|
12
|
-
Faraday.expects(:get).with("#{SupremeGolf::Course::
|
|
18
|
+
Faraday.expects(:get).with("#{SupremeGolf::Course::API_URLS[:find]}/3002", {}, {'X-Api-Key' => 'testkey'}).returns(stub(body: {course: {}}.to_json))
|
|
19
|
+
SupremeGolf::Course.find(3002)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
describe 'find' do
|
|
24
|
+
it 'should make request with API_URLS :find and id' do
|
|
25
|
+
Faraday.expects(:get).with("#{SupremeGolf::Course::API_URLS[:find]}/3002", {}, {}).returns(stub(body: {course: {}}.to_json))
|
|
13
26
|
SupremeGolf::Course.find(3002)
|
|
14
27
|
end
|
|
15
28
|
end
|
|
@@ -65,4 +65,41 @@ class SupremeGolfTeeTimeTest < Minitest::Test
|
|
|
65
65
|
end
|
|
66
66
|
end
|
|
67
67
|
end
|
|
68
|
+
|
|
69
|
+
describe 'find' do
|
|
70
|
+
it 'gives back expected info' do
|
|
71
|
+
VCR.use_cassette('find_tee_time') do
|
|
72
|
+
tee_time = SupremeGolf::TeeTime.find '367049106'
|
|
73
|
+
|
|
74
|
+
expected_values = {
|
|
75
|
+
id: 367049106,
|
|
76
|
+
course_id: 3003,
|
|
77
|
+
currency: "USD",
|
|
78
|
+
players: [
|
|
79
|
+
1,
|
|
80
|
+
2,
|
|
81
|
+
3,
|
|
82
|
+
4
|
|
83
|
+
],
|
|
84
|
+
rate: "65.00",
|
|
85
|
+
regular_rate: "80.52",
|
|
86
|
+
savings_pct: 19,
|
|
87
|
+
savings_amount: "15.52",
|
|
88
|
+
tee_off_at_formatted: "10:10AM",
|
|
89
|
+
tee_off_at_iso8601: "2015-06-02T10:10:00Z",
|
|
90
|
+
amenities: [
|
|
91
|
+
"is_18_holes",
|
|
92
|
+
"is_riding"
|
|
93
|
+
],
|
|
94
|
+
provider: {
|
|
95
|
+
"code" => "golf18_network",
|
|
96
|
+
"name" => "Golf18 Network"
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
expected_values.each do |attr, value|
|
|
100
|
+
assert_equal value, tee_time.send(attr), "#{attr} accesses value"
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
68
105
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: supreme_golf
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Kyle Peyton
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-
|
|
11
|
+
date: 2015-06-10 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -80,6 +80,20 @@ dependencies:
|
|
|
80
80
|
- - ">="
|
|
81
81
|
- !ruby/object:Gem::Version
|
|
82
82
|
version: '0'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: rake
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - ">="
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0'
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - ">="
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '0'
|
|
83
97
|
- !ruby/object:Gem::Dependency
|
|
84
98
|
name: faraday
|
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -128,6 +142,7 @@ files:
|
|
|
128
142
|
- supreme_golf.gemspec
|
|
129
143
|
- test/fixtures/course_find.yml
|
|
130
144
|
- test/fixtures/courses_near.yml
|
|
145
|
+
- test/fixtures/find_tee_time.yml
|
|
131
146
|
- test/fixtures/tee_time_at.yml
|
|
132
147
|
- test/fixtures/tee_time_invalid.yml
|
|
133
148
|
- test/fixtures/tee_time_valid.yml
|
|
@@ -162,6 +177,7 @@ summary: Gem to wrap supremegolf.com API
|
|
|
162
177
|
test_files:
|
|
163
178
|
- test/fixtures/course_find.yml
|
|
164
179
|
- test/fixtures/courses_near.yml
|
|
180
|
+
- test/fixtures/find_tee_time.yml
|
|
165
181
|
- test/fixtures/tee_time_at.yml
|
|
166
182
|
- test/fixtures/tee_time_invalid.yml
|
|
167
183
|
- test/fixtures/tee_time_valid.yml
|