bike_reg 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 373b63787be2322e1239615604ab77a8c9801d1863d5c139e042e9032bed9a23
4
+ data.tar.gz: caa5b4fbe34395309fc17b8e7e0c53b4f71361189593d25d6ac9b3a15b6790f3
5
+ SHA512:
6
+ metadata.gz: 30a304b66889d358c7ca50dbdbebc56dfcb8eadce801c96b4e200dcba1dfb831226eddbe8501c6f7e8580375178ffdf4af1139e8f82e8e2d94cd3537e1c90d06
7
+ data.tar.gz: bd5a87f852845d9b46f2b0663852771edc75fa94b7f6ab7f270bbe1d2c024914cc7f8d9dbb0ffc5f21f4c086d78fb91facb40bdd2a407ed00dce0ec9691edbee
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format progress
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.5
3
+
4
+ Layout/LineLength:
5
+ Max: 120
6
+
7
+ Style/Documentation:
8
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-09-12
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in bike_reg.gemspec
6
+ gemspec
7
+
8
+ gem 'pry'
9
+ gem 'pry-nav'
10
+ gem 'rake', '~> 13.0'
11
+ gem 'rspec', '~> 3.0'
12
+ gem 'rubocop', '~> 1.7'
13
+ gem 'vcr'
14
+ gem 'webmock'
data/Gemfile.lock ADDED
@@ -0,0 +1,103 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bike_reg (0.1.0)
5
+ faraday (~> 1.7)
6
+ faraday_middleware (~> 1.1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.8.0)
12
+ public_suffix (>= 2.0.2, < 5.0)
13
+ ast (2.4.2)
14
+ coderay (1.1.3)
15
+ crack (0.4.5)
16
+ rexml
17
+ diff-lcs (1.4.4)
18
+ faraday (1.7.1)
19
+ faraday-em_http (~> 1.0)
20
+ faraday-em_synchrony (~> 1.0)
21
+ faraday-excon (~> 1.1)
22
+ faraday-httpclient (~> 1.0.1)
23
+ faraday-net_http (~> 1.0)
24
+ faraday-net_http_persistent (~> 1.1)
25
+ faraday-patron (~> 1.0)
26
+ faraday-rack (~> 1.0)
27
+ multipart-post (>= 1.2, < 3)
28
+ ruby2_keywords (>= 0.0.4)
29
+ faraday-em_http (1.0.0)
30
+ faraday-em_synchrony (1.0.0)
31
+ faraday-excon (1.1.0)
32
+ faraday-httpclient (1.0.1)
33
+ faraday-net_http (1.0.1)
34
+ faraday-net_http_persistent (1.2.0)
35
+ faraday-patron (1.0.0)
36
+ faraday-rack (1.0.0)
37
+ faraday_middleware (1.1.0)
38
+ faraday (~> 1.0)
39
+ hashdiff (1.0.1)
40
+ method_source (0.9.2)
41
+ multipart-post (2.1.1)
42
+ parallel (1.20.1)
43
+ parser (3.0.2.0)
44
+ ast (~> 2.4.1)
45
+ pry (0.12.2)
46
+ coderay (~> 1.1.0)
47
+ method_source (~> 0.9.0)
48
+ pry-nav (0.3.0)
49
+ pry (>= 0.9.10, < 0.13.0)
50
+ public_suffix (4.0.6)
51
+ rainbow (3.0.0)
52
+ rake (13.0.6)
53
+ regexp_parser (2.1.1)
54
+ rexml (3.2.5)
55
+ rspec (3.10.0)
56
+ rspec-core (~> 3.10.0)
57
+ rspec-expectations (~> 3.10.0)
58
+ rspec-mocks (~> 3.10.0)
59
+ rspec-core (3.10.1)
60
+ rspec-support (~> 3.10.0)
61
+ rspec-expectations (3.10.1)
62
+ diff-lcs (>= 1.2.0, < 2.0)
63
+ rspec-support (~> 3.10.0)
64
+ rspec-mocks (3.10.2)
65
+ diff-lcs (>= 1.2.0, < 2.0)
66
+ rspec-support (~> 3.10.0)
67
+ rspec-support (3.10.2)
68
+ rubocop (1.20.0)
69
+ parallel (~> 1.10)
70
+ parser (>= 3.0.0.0)
71
+ rainbow (>= 2.2.2, < 4.0)
72
+ regexp_parser (>= 1.8, < 3.0)
73
+ rexml
74
+ rubocop-ast (>= 1.9.1, < 2.0)
75
+ ruby-progressbar (~> 1.7)
76
+ unicode-display_width (>= 1.4.0, < 3.0)
77
+ rubocop-ast (1.11.0)
78
+ parser (>= 3.0.1.1)
79
+ ruby-progressbar (1.11.0)
80
+ ruby2_keywords (0.0.5)
81
+ unicode-display_width (2.0.0)
82
+ vcr (6.0.0)
83
+ webmock (3.14.0)
84
+ addressable (>= 2.8.0)
85
+ crack (>= 0.3.2)
86
+ hashdiff (>= 0.4.0, < 2.0.0)
87
+
88
+ PLATFORMS
89
+ arm64-darwin-20
90
+ x86_64-linux
91
+
92
+ DEPENDENCIES
93
+ bike_reg!
94
+ pry
95
+ pry-nav
96
+ rake (~> 13.0)
97
+ rspec (~> 3.0)
98
+ rubocop (~> 1.7)
99
+ vcr
100
+ webmock
101
+
102
+ BUNDLED WITH
103
+ 2.2.19
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Scott Olsen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # BikeReg API Rubygem
2
+
3
+ [![Build Status](https://github.com/scottolsen/bike_reg/workflows/Specs/badge.svg)](https://github.com/scottolsen/bike_reg/actions)
4
+
5
+ Simple gem to hit the [BikeReg
6
+ API](https://www.bikereg.com/api/EventSearchDoc.aspx) to search for events.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'bike_reg'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle install
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install bike_reg
23
+
24
+ ## Usage
25
+
26
+ ```ruby
27
+ client = BikeReg::Client.new
28
+
29
+ events = client.event.search
30
+ #=> BikeReg::Collection
31
+
32
+ events.total
33
+ #=> 61
34
+
35
+ events.data
36
+ #=> [#<BikeReg::Event>, #<BikeReg::Event>]
37
+ ````
38
+
39
+ ## Development
40
+
41
+ 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.
42
+
43
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
44
+
45
+ ## Contributing
46
+
47
+ Bug reports and pull requests are welcome on GitHub at https://github.com/scottolsen/bike_reg.
48
+
49
+ ## License
50
+
51
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require 'rubocop/rake_task'
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'bike_reg'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -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,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BikeReg
4
+ class Client
5
+ BASE_URL = 'https://www.BikeReg.com/api'
6
+
7
+ def event
8
+ EventResource.new(self)
9
+ end
10
+
11
+ def connection
12
+ @connection ||= Faraday.new(BASE_URL) do |conn|
13
+ conn.request :json
14
+ conn.response :json, content_type: 'application/json'
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BikeReg
4
+ class Collection
5
+ attr_reader :data, :total, :next_page, :prev_page
6
+
7
+ def self.from_response(response, key:, type:, start_page:)
8
+ body = response.body
9
+ new(
10
+ data: body[key].map { |attrs| type.new(attrs) },
11
+ total: body['ResultCount'],
12
+ start_page: start_page
13
+ )
14
+ end
15
+
16
+ def initialize(data:, total:, start_page:)
17
+ @data = data
18
+ @total = total
19
+ @next_page = start_page.nil? ? 1 : start_page + 1
20
+ @prev_page = start_page.nil? ? 0 : start_page - 1
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BikeReg
4
+ class Error < StandardError
5
+ end
6
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ostruct'
4
+
5
+ module BikeReg
6
+ class Object < OpenStruct
7
+ def initialize(attributes)
8
+ super(to_ostruct(attributes))
9
+ end
10
+
11
+ def to_ostruct(obj)
12
+ case obj
13
+ when Hash
14
+ OpenStruct.new(obj.transform_values { |val| to_ostruct(val) })
15
+ when Array
16
+ obj.map { |o| to_ostruct(o) }
17
+ else # Assumed to be a primitive value
18
+ obj
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BikeReg
4
+ class Event < Object
5
+ end
6
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BikeReg
4
+ class Resource
5
+ attr_reader :client
6
+
7
+ def initialize(client)
8
+ @client = client
9
+ end
10
+
11
+ private
12
+
13
+ def get_request(url, params: {}, headers: {})
14
+ handle_response client.connection.get(url, params, headers)
15
+ end
16
+
17
+ # rubocop:disable Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength
18
+ def handle_response(response)
19
+ case response.status
20
+ when 400
21
+ raise Error, "Your request was malformed. #{response.body['error']}"
22
+ when 401
23
+ raise Error, "You did not supply valid authentication credentials. #{response.body['error']}"
24
+ when 403
25
+ raise Error, "You are not allowed to perform that action. #{response.body['error']}"
26
+ when 404
27
+ raise Error, "No results were found for your request. #{response.body['error']}"
28
+ when 429
29
+ raise Error, "Your request exceeded the API rate limit. #{response.body['error']}"
30
+ when 500
31
+ raise Error, "We were unable to perform the request due to server-side problems. #{response.body['error']}"
32
+ when 503
33
+ raise Error,
34
+ "The server is currently unable to handle the request due to a temporary overloading or maintenance of the
35
+ server. #{response.body['error']}"
36
+ end
37
+
38
+ response
39
+ end
40
+ # rubocop:enable Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength
41
+ end
42
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BikeReg
4
+ class EventResource < Resource
5
+ def search(**params)
6
+ response = get_request('search', params: params)
7
+ Collection.from_response(response, key: 'MatchingEvents', type: Event, start_page: params[:startpage])
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BikeReg
4
+ VERSION = '0.1.0'
5
+ end
data/lib/bike_reg.rb ADDED
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ require 'faraday_middleware'
5
+ require 'bike_reg/version'
6
+
7
+ module BikeReg
8
+ autoload :Client, 'bike_reg/client'
9
+ autoload :Collection, 'bike_reg/collection'
10
+ autoload :Error, 'bike_reg/error'
11
+ autoload :Object, 'bike_reg/object'
12
+ autoload :Resource, 'bike_reg/resource'
13
+
14
+ autoload :EventResource, 'bike_reg/resources/event_resource'
15
+
16
+ autoload :Event, 'bike_reg/objects/event'
17
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bike_reg
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Scott Olsen
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-09-14 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: '1.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.1'
41
+ description: Gem to hit the BikeReg.com API. BikeReg API docs here https://www.bikereg.com/api/EventSearchDoc.aspx
42
+ email:
43
+ - solsen300@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".rspec"
49
+ - ".rubocop.yml"
50
+ - CHANGELOG.md
51
+ - Gemfile
52
+ - Gemfile.lock
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - bin/console
57
+ - bin/setup
58
+ - lib/bike_reg.rb
59
+ - lib/bike_reg/client.rb
60
+ - lib/bike_reg/collection.rb
61
+ - lib/bike_reg/error.rb
62
+ - lib/bike_reg/object.rb
63
+ - lib/bike_reg/objects/event.rb
64
+ - lib/bike_reg/resource.rb
65
+ - lib/bike_reg/resources/event_resource.rb
66
+ - lib/bike_reg/version.rb
67
+ homepage: https://github.com/scottolsen/bike-reg
68
+ licenses:
69
+ - MIT
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '2.5'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubygems_version: 3.1.6
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: Gem to hit the BikeReg.com API
90
+ test_files: []