supreme_golf 0.0.2
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/.gitignore +23 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +49 -0
- data/Rakefile +2 -0
- data/lib/supreme_golf/base.rb +14 -0
- data/lib/supreme_golf/course.rb +56 -0
- data/lib/supreme_golf/tee_time.rb +35 -0
- data/lib/supreme_golf/version.rb +3 -0
- data/lib/supreme_golf.rb +37 -0
- data/supreme_golf.gemspec +29 -0
- data/test/fixtures/course_find.yml +58 -0
- data/test/fixtures/courses_near.yml +796 -0
- data/test/fixtures/tee_time_at.yml +85 -0
- data/test/fixtures/tee_time_invalid.yml +48 -0
- data/test/fixtures/tee_time_valid.yml +54 -0
- data/test/supreme_golf/course_test.rb +102 -0
- data/test/supreme_golf/supreme_golf_test.rb +16 -0
- data/test/supreme_golf/tee_time_test.rb +68 -0
- data/test/test_helper.rb +10 -0
- metadata +171 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 3d8034d9b3c8a36628cab31faea0a239335ae566
|
|
4
|
+
data.tar.gz: 22a00ed433bd8fe552f8ca1a1769c619c07ed705
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: ac9c7a1f05359937d6931471152b1069a0536ea998d08b0a1d52f6949c225de9df28d35aa13dcc2c7ca6f89a7aad9714d957a8cde6bd99ca87bdfb5244f75642
|
|
7
|
+
data.tar.gz: 01047920917e098fcf81d1f03afdc0d9226861cad6cf90f8ccb9c54ac08c895f70f1e44ff7c0b58ea37c228f481affe2beb31ceb751265076502558830eb000c
|
data/.gitignore
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
*.gem
|
|
2
|
+
*.rbc
|
|
3
|
+
.bundle
|
|
4
|
+
.config
|
|
5
|
+
.yardoc
|
|
6
|
+
Gemfile.lock
|
|
7
|
+
InstalledFiles
|
|
8
|
+
_yardoc
|
|
9
|
+
coverage
|
|
10
|
+
doc/
|
|
11
|
+
lib/bundler/man
|
|
12
|
+
pkg
|
|
13
|
+
rdoc
|
|
14
|
+
spec/reports
|
|
15
|
+
test/tmp
|
|
16
|
+
test/version_tmp
|
|
17
|
+
tmp
|
|
18
|
+
*.bundle
|
|
19
|
+
*.so
|
|
20
|
+
*.swp
|
|
21
|
+
*.o
|
|
22
|
+
*.a
|
|
23
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2015 Kyle Peyton
|
|
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,49 @@
|
|
|
1
|
+
# SupremeGolf
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
|
|
5
|
+
Add this line to your application's Gemfile:
|
|
6
|
+
|
|
7
|
+
gem 'supreme-golf'
|
|
8
|
+
|
|
9
|
+
And then execute:
|
|
10
|
+
|
|
11
|
+
$ bundle
|
|
12
|
+
|
|
13
|
+
Or install it yourself as:
|
|
14
|
+
|
|
15
|
+
$ gem install supreme-golf
|
|
16
|
+
|
|
17
|
+
## Official docs
|
|
18
|
+
|
|
19
|
+
https://supremegolf.com/api/docs/
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
The "params" passed to the API methods are simply the parameters defined in the official documentation listed above.
|
|
24
|
+
|
|
25
|
+
# Require the gem
|
|
26
|
+
require 'supreme_golf'
|
|
27
|
+
|
|
28
|
+
# Get all courses near a lat/lon
|
|
29
|
+
SupremeGolf::Course.near(params: {lat: 33.4677096, lon: -117.1318014, limit: 1})
|
|
30
|
+
|
|
31
|
+
# Get one course from an id
|
|
32
|
+
SupremeGolf::Course.find(3003)
|
|
33
|
+
|
|
34
|
+
# Get tee times for a course_id
|
|
35
|
+
SupremeGolf::TeeTime.at(3003)
|
|
36
|
+
|
|
37
|
+
# Get reservation url for a specific tee time for 2 people. Returning nil means invalid, returning string is reservation url
|
|
38
|
+
SupremeGolf::TeeTime.valid(30923902, params: {qty: 2})
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
## Contributing
|
|
42
|
+
|
|
43
|
+
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
|
+
|
|
45
|
+
1. Fork it ( https://github.com/[my-github-username]/supreme-golf/fork )
|
|
46
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
47
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
48
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
49
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module SupremeGolf
|
|
2
|
+
class Base
|
|
3
|
+
def initialize attributes = {}
|
|
4
|
+
(self.class::ATTRS.map(&:to_s) & attributes.keys).each do |attr|
|
|
5
|
+
self.send("#{attr}=", attributes[attr])
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def self.response_from_api url, params = {}
|
|
10
|
+
conn = Faraday.get url, params, SupremeGolf.configuration.http_headers
|
|
11
|
+
JSON.parse(conn.body)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
module SupremeGolf
|
|
2
|
+
class Course < SupremeGolf::Base
|
|
3
|
+
FIND_URL = "#{SupremeGolf::API_BASE_URL}/courses"
|
|
4
|
+
NEAR_URL = "#{SupremeGolf::API_BASE_URL}/courses/near"
|
|
5
|
+
|
|
6
|
+
ATTRS = [:id,
|
|
7
|
+
:slug,
|
|
8
|
+
:name,
|
|
9
|
+
:description,
|
|
10
|
+
:address_1,
|
|
11
|
+
:address_2,
|
|
12
|
+
:address_3,
|
|
13
|
+
:address_city,
|
|
14
|
+
:address_state,
|
|
15
|
+
:address_zipcode,
|
|
16
|
+
:address_country,
|
|
17
|
+
:phone,
|
|
18
|
+
:url,
|
|
19
|
+
:time_zone,
|
|
20
|
+
:latitude,
|
|
21
|
+
:longitude,
|
|
22
|
+
:rating,
|
|
23
|
+
:rounded_rating,
|
|
24
|
+
:rating_count,
|
|
25
|
+
:rough_tee_time_count,
|
|
26
|
+
:avg_rate,
|
|
27
|
+
:avg_regular_rate,
|
|
28
|
+
:min_rate,
|
|
29
|
+
:min_regular_rate,
|
|
30
|
+
:max_rate,
|
|
31
|
+
:max_regular_rate,
|
|
32
|
+
:distance,
|
|
33
|
+
:course_url,
|
|
34
|
+
:course_reviews_url,
|
|
35
|
+
:photo_thumb_url,
|
|
36
|
+
:photo_medium_url,
|
|
37
|
+
:photo_large_url
|
|
38
|
+
]
|
|
39
|
+
attr_accessor *ATTRS
|
|
40
|
+
|
|
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
|
+
def self.near params: {}
|
|
49
|
+
response = self.response_from_api NEAR_URL, params
|
|
50
|
+
|
|
51
|
+
response['courses'].map do |course_params|
|
|
52
|
+
new(course_params)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module SupremeGolf
|
|
2
|
+
class TeeTime < SupremeGolf::Base
|
|
3
|
+
AT_URL = "#{SupremeGolf::API_BASE_URL}/tee_times/at"
|
|
4
|
+
VALID_URL = "#{SupremeGolf::API_BASE_URL}/tee_times"
|
|
5
|
+
|
|
6
|
+
ATTRS = [:id,
|
|
7
|
+
:course_id,
|
|
8
|
+
:currency,
|
|
9
|
+
:players,
|
|
10
|
+
:rate,
|
|
11
|
+
:regular_rate,
|
|
12
|
+
:savings_pct,
|
|
13
|
+
:savings_amount,
|
|
14
|
+
:tee_off_at_formatted,
|
|
15
|
+
:tee_off_at_iso8601,
|
|
16
|
+
:amenities,
|
|
17
|
+
:provider
|
|
18
|
+
]
|
|
19
|
+
attr_accessor *ATTRS
|
|
20
|
+
|
|
21
|
+
def self.at course_id, params: {}
|
|
22
|
+
response = self.response_from_api "#{AT_URL}/#{course_id}", params
|
|
23
|
+
|
|
24
|
+
response['tee_times'].map do |tee_time_params|
|
|
25
|
+
new(tee_time_params)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def self.valid id, params: {}
|
|
30
|
+
response = self.response_from_api "#{VALID_URL}/#{id}/valid", params
|
|
31
|
+
|
|
32
|
+
response['reservation_url']
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
data/lib/supreme_golf.rb
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require 'faraday'
|
|
2
|
+
require 'json'
|
|
3
|
+
|
|
4
|
+
module SupremeGolf
|
|
5
|
+
API_VERSION = 4
|
|
6
|
+
API_BASE_URL = "https://supremegolf.com:443/api/v#{API_VERSION}"
|
|
7
|
+
|
|
8
|
+
class << self
|
|
9
|
+
attr_accessor :configuration
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def self.configure
|
|
13
|
+
self.configuration ||= Configuration.new
|
|
14
|
+
yield(configuration) if block_given?
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
class Configuration
|
|
18
|
+
attr_accessor :x_api_key
|
|
19
|
+
|
|
20
|
+
def initialize
|
|
21
|
+
@x_api_key = nil
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def http_headers
|
|
25
|
+
headers = {}
|
|
26
|
+
headers['X-Api-Key'] = @x_api_key if @x_api_key
|
|
27
|
+
headers
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
configure
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
require 'supreme_golf/base'
|
|
35
|
+
require 'supreme_golf/version'
|
|
36
|
+
require 'supreme_golf/course'
|
|
37
|
+
require 'supreme_golf/tee_time'
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'supreme_golf/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = 'supreme_golf'
|
|
8
|
+
spec.version = SupremeGolf::VERSION
|
|
9
|
+
spec.authors = ['Kyle Peyton']
|
|
10
|
+
spec.email = ['kylepeyton@gmail.com']
|
|
11
|
+
spec.summary = %q{Gem to wrap supremegolf.com API}
|
|
12
|
+
spec.description = %q{Gem to wrap supremegolf.com API}
|
|
13
|
+
spec.homepage = 'https://github.com/weexpectedTHIS/supreme_golf'
|
|
14
|
+
spec.license = 'MIT'
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
+
spec.require_paths = ['lib']
|
|
20
|
+
|
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
|
22
|
+
spec.add_development_dependency 'minitest'
|
|
23
|
+
spec.add_development_dependency 'vcr'
|
|
24
|
+
spec.add_development_dependency 'webmock'
|
|
25
|
+
spec.add_development_dependency 'mocha'
|
|
26
|
+
|
|
27
|
+
spec.add_dependency 'faraday'
|
|
28
|
+
spec.add_dependency 'json'
|
|
29
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
---
|
|
2
|
+
http_interactions:
|
|
3
|
+
- request:
|
|
4
|
+
method: get
|
|
5
|
+
uri: https://supremegolf.com/api/v4/courses/3002
|
|
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
|
+
Transfer-Encoding:
|
|
24
|
+
- chunked
|
|
25
|
+
Connection:
|
|
26
|
+
- close
|
|
27
|
+
Vary:
|
|
28
|
+
- Accept-Encoding
|
|
29
|
+
- Origin
|
|
30
|
+
Status:
|
|
31
|
+
- 200 OK
|
|
32
|
+
X-Api-Version:
|
|
33
|
+
- 4.1.7
|
|
34
|
+
Access-Control-Allow-Origin:
|
|
35
|
+
- "*"
|
|
36
|
+
Cache-Control:
|
|
37
|
+
- max-age=0, private, must-revalidate
|
|
38
|
+
X-Request-Id:
|
|
39
|
+
- 6922416c-dd74-4cc9-97d6-3a04c46aff47
|
|
40
|
+
X-Runtime:
|
|
41
|
+
- '0.011657'
|
|
42
|
+
X-Powered-By:
|
|
43
|
+
- Phusion Passenger 4.0.59
|
|
44
|
+
Date:
|
|
45
|
+
- Sun, 31 May 2015 04:17:22 GMT
|
|
46
|
+
Server:
|
|
47
|
+
- nginx + Phusion Passenger 4.0.59
|
|
48
|
+
body:
|
|
49
|
+
encoding: UTF-8
|
|
50
|
+
string: '{"course":{"id":3002,"slug":"temecula-creek-inn-oaks-course-california","name":"Temecula
|
|
51
|
+
Creek Inn - Oaks Course","description":"The 9-hole \"Oaks\" course at the
|
|
52
|
+
Temecula Creek Inn facility in Temecula, California features 3,436 yards of
|
|
53
|
+
golf from the longest tees for a par of 36. Designed by Ted Robinson, ASGCA,
|
|
54
|
+
the Oaks golf course opened in 1969.","address_1":"44501 Rainbow Canyon Rd","address_2":null,"address_3":null,"address_city":"Temecula","address_state":"CA","address_zipcode":"92592-5988","address_country":"United
|
|
55
|
+
States of America","phone":"855.685.9299","url":"http://www.temeculacreekinn.com/","time_zone":"America/Los_Angeles","latitude":33.46898,"longitude":-117.128529,"rating":3.0,"rounded_rating":3.0,"rating_count":3,"rough_tee_time_count":0,"avg_rate":"22.0","avg_regular_rate":"22.0","min_rate":"22.0","min_regular_rate":"22.0","max_rate":"22.0","max_regular_rate":"22.0","course_url":"https://supremegolf.com/tee-times/at/temecula-creek-inn-oaks-course-california","course_reviews_url":"https://supremegolf.com/tee-times/at/temecula-creek-inn-oaks-course-california/reviews","photo_thumb_url":"https://supremegolf.s3.amazonaws.com/assets/courses/3002/thumb.jpg?1420237939","photo_medium_url":"https://supremegolf.s3.amazonaws.com/assets/courses/3002/medium.jpg?1420237939","photo_large_url":"https://supremegolf.s3.amazonaws.com/assets/courses/3002/large.jpg?1420237939"}}'
|
|
56
|
+
http_version:
|
|
57
|
+
recorded_at: Sun, 31 May 2015 04:17:22 GMT
|
|
58
|
+
recorded_with: VCR 2.9.3
|