mtb_project_api 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ee7bef301acbc81fa8a345e2f6cdfe7780138276
4
+ data.tar.gz: e2366f0e91e29c5187a1733de4d8a82db33b3ce2
5
+ SHA512:
6
+ metadata.gz: 5cba9682504991acc308a01a5048b5d08fd21980dc0c5ec6bfe5123e56088bb1e82b6a56aa1ba4ee752de939bea2a91c1c5c9799a42505fe8dca40bdf62ecd9b
7
+ data.tar.gz: 0023302dd1747d65f7cf022c7ec013c4e3ddf2aae21c5b8261b54acb71678a22974d781bc109d3f19aa8c43bf13f1432fd55083b2541a530a6a83acdef2f25d2
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in mtb_project_api.gemspec
4
+ gemspec
@@ -0,0 +1,55 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mtb_project_api (0.1.0)
5
+ faraday
6
+ oj
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.5.2)
12
+ public_suffix (>= 2.0.2, < 4.0)
13
+ byebug (10.0.2)
14
+ crack (0.4.3)
15
+ safe_yaml (~> 1.0.0)
16
+ diff-lcs (1.3)
17
+ faraday (0.15.2)
18
+ multipart-post (>= 1.2, < 3)
19
+ hashdiff (0.3.7)
20
+ multipart-post (2.0.0)
21
+ oj (3.6.5)
22
+ public_suffix (3.0.3)
23
+ rake (10.5.0)
24
+ rspec (3.8.0)
25
+ rspec-core (~> 3.8.0)
26
+ rspec-expectations (~> 3.8.0)
27
+ rspec-mocks (~> 3.8.0)
28
+ rspec-core (3.8.0)
29
+ rspec-support (~> 3.8.0)
30
+ rspec-expectations (3.8.1)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.8.0)
33
+ rspec-mocks (3.8.0)
34
+ diff-lcs (>= 1.2.0, < 2.0)
35
+ rspec-support (~> 3.8.0)
36
+ rspec-support (3.8.0)
37
+ safe_yaml (1.0.4)
38
+ webmock (3.0.1)
39
+ addressable (>= 2.3.6)
40
+ crack (>= 0.3.2)
41
+ hashdiff
42
+
43
+ PLATFORMS
44
+ ruby
45
+
46
+ DEPENDENCIES
47
+ bundler (~> 1.16)
48
+ byebug
49
+ mtb_project_api!
50
+ rake (~> 10.0)
51
+ rspec (~> 3.0)
52
+ webmock
53
+
54
+ BUNDLED WITH
55
+ 1.16.1
@@ -0,0 +1,105 @@
1
+ # MTB Project Api Wrapper Gem
2
+
3
+ A simple wrapper gem to access the [public endpoints provided by the MTB Project API](https://www.mtbproject.com/data).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'mtb_project_api'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install mtb_project_api
20
+
21
+ ## Usage
22
+
23
+ To initialize a `MtbProjectApi::Client`, you'll need your MTB Project login **email** and **private key** which you can find [in the right column here](https://www.mtbproject.com/data).
24
+
25
+ ```
26
+ require 'mtb_project_api'
27
+
28
+ mtb_project_client = MtbProjectApi::Client.new(email, mtb_project_key)
29
+ ```
30
+ Here are the following calls you can make:
31
+
32
+ **.get_local_trails**
33
+ ```
34
+ # Returns trails for a given query.
35
+ #
36
+ # Required Arguments:
37
+ # lat - Latitude for a given area
38
+ # lon - Longitude for a given area
39
+ #
40
+ # Optional Arguments:
41
+ # maxDistance - Max distance, in miles, from lat, lon. Default: 30. Max: 200.
42
+ # maxResults - Max number of trails to return. Default: 10. Max: 500.
43
+ # sort - Values can be 'quality', 'distance'. Default: quality.
44
+ # minLength - Min trail length, in miles. Default: 0 (no minimum).
45
+ # minStars - Min star rating, 0-4. Default: 0.
46
+
47
+ params = {
48
+ lat: 40.0274,
49
+ lon: -105.2519,
50
+ maxDistance: 10
51
+ }
52
+
53
+ mtb_project_client.get_local_trails(params)
54
+ ```
55
+
56
+ **.get_trails_by_id**
57
+ ```
58
+ # Returns trails for given trail IDs.
59
+ #
60
+ # Required Arguments:
61
+ # ids - one or array of trail IDs
62
+
63
+ params = {
64
+ ids: [343243, 5653463, 423426]
65
+ }
66
+
67
+ mtb_project_client.get_trails_by_id(params)
68
+ ```
69
+
70
+ **.get_conditions**
71
+ ```
72
+ # Returns conditions for given trail IDs.
73
+ #
74
+ # Required Arguments:
75
+ # ids - one or array of trail IDs
76
+
77
+ params = {
78
+ ids: [343243, 5653463, 423426]
79
+ }
80
+
81
+ mtb_project_client.get_conditions(params)
82
+ ```
83
+
84
+ **.get_to_dos**
85
+ ```
86
+ # Returns up to 200 of the user's to-do trail IDs.
87
+ #
88
+ # Optional Arguments:
89
+ # startPos - The starting index of the list to return. Defaults to 0.
90
+
91
+ params = {
92
+ startPos: 3
93
+ }
94
+ mtb_project_client.get_to_dos(params)
95
+ ```
96
+
97
+ ## Development
98
+
99
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
100
+
101
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
102
+
103
+ ## Contributing
104
+
105
+ Bug reports and pull requests are welcome on GitHub at https://github.com/tarnelope/mtb_project_api.
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "mtb_project_api"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ require "mtb_project_api/version"
2
+ require "mtb_project_api/client"
3
+
4
+ module MtbProjectApi
5
+ end
@@ -0,0 +1,102 @@
1
+ require 'faraday'
2
+ require 'oj'
3
+
4
+ module MtbProjectApi
5
+ class Client
6
+ API_ENDPOINT = 'https://www.mtbproject.com/data/'.freeze
7
+
8
+ def initialize(email, private_key)
9
+ @email = email
10
+ @private_key = private_key
11
+ end
12
+
13
+ # Returns trails for a given query.
14
+ #
15
+ # Required Arguments:
16
+ # lat - Latitude for a given area
17
+ # lon - Longitude for a given area
18
+ #
19
+ # Optional Arguments:
20
+ # maxDistance - Max distance, in miles, from lat, lon. Default: 30. Max: 200.
21
+ # maxResults - Max number of trails to return. Default: 10. Max: 500.
22
+ # sort - Values can be 'quality', 'distance'. Default: quality.
23
+ # minLength - Min trail length, in miles. Default: 0 (no minimum).
24
+ # minStars - Min star rating, 0-4. Default: 0.
25
+ def get_local_trails(params = {})
26
+ allowed_keys = [:lat, :lon, :maxDistance, :maxResults, :sort, :minLength, :minStars]
27
+ request_params = params.select { |k| allowed_keys.include?(k) }.merge(key: @private_key)
28
+
29
+ request(
30
+ http_method: :get,
31
+ endpoint: "get-trails",
32
+ params: request_params
33
+ )
34
+ end
35
+
36
+ # Returns trails for given trail IDs.
37
+ #
38
+ # Required Arguments:
39
+ # ids - one or array of trail IDs
40
+ def get_trails_by_id(params = {})
41
+ request_by_ids("get-trails-by-id", params)
42
+ end
43
+
44
+ # Returns conditions for given trail IDs.
45
+ #
46
+ # Required Arguments:
47
+ # ids - one or array of trail IDs
48
+ def get_conditions(params = {})
49
+ request_by_ids("get-conditions", params)
50
+ end
51
+
52
+ # Returns up to 200 of the user's to-do trail IDs.
53
+ #
54
+ # Optional Arguments:
55
+ # startPos - The starting index of the list to return. Defaults to 0.
56
+ def get_to_dos(params = {})
57
+ request_params = params.merge({
58
+ email: @email,
59
+ key: @private_key
60
+ })
61
+
62
+ request(
63
+ http_method: :get,
64
+ endpoint: "get-to-dos",
65
+ params: request_params
66
+ )
67
+ end
68
+
69
+ private
70
+
71
+ def client
72
+ @_client ||= Faraday.new(API_ENDPOINT) do |client|
73
+ client.request :url_encoded
74
+ client.adapter Faraday.default_adapter
75
+ end
76
+ end
77
+
78
+ def request(http_method:, endpoint:, params: {})
79
+ response = client.public_send(http_method, endpoint, params)
80
+ Oj.load(response.body)
81
+ end
82
+
83
+ def request_by_ids(endpoint, params)
84
+ request_params = request_by_ids_params(params)
85
+
86
+ request(
87
+ http_method: :get,
88
+ endpoint: endpoint,
89
+ params: request_params
90
+ )
91
+ end
92
+
93
+ def request_by_ids_params(params)
94
+ ids = Array(params[:ids]).join(',')
95
+
96
+ {
97
+ ids: ids,
98
+ key: @private_key
99
+ }
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,3 @@
1
+ module MtbProjectApi
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,31 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "mtb_project_api/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mtb_project_api"
8
+ spec.version = MtbProjectApi::VERSION
9
+ spec.authors = ["Teresa Tarn"]
10
+ spec.email = ["teresa.tarn@kapost.com"]
11
+ spec.license = "MIT"
12
+ spec.summary = "Easily access MTB Project's provided endpoints."
13
+ spec.description = "A wrapper gem for the public MTB Project API"
14
+ spec.homepage = "https://www.github.com/tarnelope/mtb_project_api"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "faraday", "~> 0.15"
24
+ spec.add_dependency "oj", "~> 3.6"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.16"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.0"
29
+ spec.add_development_dependency "webmock", "~> 3.4"
30
+ spec.add_development_dependency "byebug", "~> 10.0"
31
+ end
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mtb_project_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Teresa Tarn
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-09-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.15'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: oj
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.6'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.4'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.4'
97
+ - !ruby/object:Gem::Dependency
98
+ name: byebug
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '10.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '10.0'
111
+ description: A wrapper gem for the public MTB Project API
112
+ email:
113
+ - teresa.tarn@kapost.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".travis.yml"
121
+ - Gemfile
122
+ - Gemfile.lock
123
+ - README.md
124
+ - Rakefile
125
+ - bin/console
126
+ - bin/setup
127
+ - lib/mtb_project_api.rb
128
+ - lib/mtb_project_api/client.rb
129
+ - lib/mtb_project_api/version.rb
130
+ - mtb_project_api.gemspec
131
+ homepage: https://www.github.com/tarnelope/mtb_project_api
132
+ licenses:
133
+ - MIT
134
+ metadata: {}
135
+ post_install_message:
136
+ rdoc_options: []
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ requirements: []
150
+ rubyforge_project:
151
+ rubygems_version: 2.6.14
152
+ signing_key:
153
+ specification_version: 4
154
+ summary: Easily access MTB Project's provided endpoints.
155
+ test_files: []