bike_reg 0.1.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 373b63787be2322e1239615604ab77a8c9801d1863d5c139e042e9032bed9a23
4
- data.tar.gz: caa5b4fbe34395309fc17b8e7e0c53b4f71361189593d25d6ac9b3a15b6790f3
3
+ metadata.gz: 4cd8ad9b4aac2357cff969a229f2767885512537138ec96dfa6c1165d6219f86
4
+ data.tar.gz: 6385894aa3816927105c74a994fab9e87a86a5817063e906d422514185aa25a5
5
5
  SHA512:
6
- metadata.gz: 30a304b66889d358c7ca50dbdbebc56dfcb8eadce801c96b4e200dcba1dfb831226eddbe8501c6f7e8580375178ffdf4af1139e8f82e8e2d94cd3537e1c90d06
7
- data.tar.gz: bd5a87f852845d9b46f2b0663852771edc75fa94b7f6ab7f270bbe1d2c024914cc7f8d9dbb0ffc5f21f4c086d78fb91facb40bdd2a407ed00dce0ec9691edbee
6
+ metadata.gz: '05000791b48b7a52ebfc4f49650e34c481b1f634f8a4c62d17d34f2014da6cba22ed1a144eb29f1240d757e35b9fbe7d5220c277bdfe84cc7f13e65a1c243ff9'
7
+ data.tar.gz: 064c37361c2e7ab7051db3bb580a4112df4467c10c7c7d2284f1494843ef355080e54cc3f2a07c78ce062ee5dde3b8f30f18d5632f448ec2a4256518d6cf8dfc
data/.rubocop.yml CHANGED
@@ -1,4 +1,7 @@
1
1
  AllCops:
2
+ NewCops: enable
3
+ Exclude:
4
+ - lib/bike_reg/scraper.rb
2
5
  TargetRubyVersion: 2.5
3
6
 
4
7
  Layout/LineLength:
data/CHANGELOG.md CHANGED
@@ -1,4 +1,18 @@
1
- ## [Unreleased]
1
+ ## [0.3.0] - 2021-11-14
2
+
3
+ - All the keys are now in snakecase
4
+
5
+ ## [0.2.1] - 2021-11-14
6
+
7
+ - Send date back in ISO via `event_date` and `event_end_date`
8
+
9
+ ## [0.2.0] - 2021-11-13
10
+
11
+ - Adds ability to scrape registrations
12
+
13
+ ## [0.1.1] - 2021-09-15
14
+
15
+ - Fixes Homepage URL to repo from rubygems.org
2
16
 
3
17
  ## [0.1.0] - 2021-09-12
4
18
 
data/Gemfile CHANGED
@@ -9,6 +9,9 @@ gem 'pry'
9
9
  gem 'pry-nav'
10
10
  gem 'rake', '~> 13.0'
11
11
  gem 'rspec', '~> 3.0'
12
- gem 'rubocop', '~> 1.7'
12
+ gem 'rubocop', '~> 1.22.3'
13
+ gem 'rubocop-discourse'
14
+ gem 'rubocop-rake'
15
+ gem 'rubocop-rspec'
13
16
  gem 'vcr'
14
17
  gem 'webmock'
data/Gemfile.lock CHANGED
@@ -1,21 +1,47 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bike_reg (0.1.0)
4
+ bike_reg (0.3.0)
5
5
  faraday (~> 1.7)
6
6
  faraday_middleware (~> 1.1)
7
+ kimurai (= 1.4)
7
8
 
8
9
  GEM
9
10
  remote: https://rubygems.org/
10
11
  specs:
12
+ activesupport (6.1.4.1)
13
+ concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ i18n (>= 1.6, < 2)
15
+ minitest (>= 5.1)
16
+ tzinfo (~> 2.0)
17
+ zeitwerk (~> 2.3)
11
18
  addressable (2.8.0)
12
19
  public_suffix (>= 2.0.2, < 5.0)
13
20
  ast (2.4.2)
21
+ capybara (3.36.0)
22
+ addressable
23
+ matrix
24
+ mini_mime (>= 0.1.3)
25
+ nokogiri (~> 1.8)
26
+ rack (>= 1.6.0)
27
+ rack-test (>= 0.6.3)
28
+ regexp_parser (>= 1.5, < 3.0)
29
+ xpath (~> 3.2)
30
+ capybara-mechanize (1.11.0)
31
+ capybara (>= 2.4.4, < 4)
32
+ mechanize (~> 2.7.0)
33
+ childprocess (4.1.0)
34
+ chronic (0.10.2)
35
+ cliver (0.3.2)
14
36
  coderay (1.1.3)
37
+ concurrent-ruby (1.1.9)
38
+ connection_pool (2.2.5)
15
39
  crack (0.4.5)
16
40
  rexml
17
41
  diff-lcs (1.4.4)
18
- faraday (1.7.1)
42
+ domain_name (0.5.20190701)
43
+ unf (>= 0.0.5, < 1.0.0)
44
+ faraday (1.8.0)
19
45
  faraday-em_http (~> 1.0)
20
46
  faraday-em_synchrony (~> 1.0)
21
47
  faraday-excon (~> 1.1)
@@ -34,22 +60,77 @@ GEM
34
60
  faraday-net_http_persistent (1.2.0)
35
61
  faraday-patron (1.0.0)
36
62
  faraday-rack (1.0.0)
37
- faraday_middleware (1.1.0)
63
+ faraday_middleware (1.2.0)
38
64
  faraday (~> 1.0)
39
65
  hashdiff (1.0.1)
66
+ headless (2.3.1)
67
+ http-cookie (1.0.4)
68
+ domain_name (~> 0.5)
69
+ i18n (1.8.11)
70
+ concurrent-ruby (~> 1.0)
71
+ kimurai (1.4.0)
72
+ activesupport
73
+ capybara (>= 2.15, < 4.0)
74
+ capybara-mechanize
75
+ cliver
76
+ headless
77
+ murmurhash3
78
+ nokogiri
79
+ pmap
80
+ poltergeist
81
+ pry
82
+ rbcat (~> 0.2)
83
+ selenium-webdriver
84
+ thor
85
+ whenever
86
+ matrix (0.4.2)
87
+ mechanize (2.7.7)
88
+ domain_name (~> 0.5, >= 0.5.1)
89
+ http-cookie (~> 1.0)
90
+ mime-types (>= 1.17.2)
91
+ net-http-digest_auth (~> 1.1, >= 1.1.1)
92
+ net-http-persistent (>= 2.5.2)
93
+ nokogiri (~> 1.6)
94
+ ntlm-http (~> 0.1, >= 0.1.1)
95
+ webrick (~> 1.7)
96
+ webrobots (>= 0.0.9, < 0.2)
40
97
  method_source (0.9.2)
98
+ mime-types (3.3.1)
99
+ mime-types-data (~> 3.2015)
100
+ mime-types-data (3.2021.0901)
101
+ mini_mime (1.1.2)
102
+ minitest (5.14.4)
41
103
  multipart-post (2.1.1)
42
- parallel (1.20.1)
104
+ murmurhash3 (0.1.6)
105
+ net-http-digest_auth (1.4.1)
106
+ net-http-persistent (4.0.1)
107
+ connection_pool (~> 2.2)
108
+ nokogiri (1.12.5-arm64-darwin)
109
+ racc (~> 1.4)
110
+ nokogiri (1.12.5-x86_64-linux)
111
+ racc (~> 1.4)
112
+ ntlm-http (0.1.1)
113
+ parallel (1.21.0)
43
114
  parser (3.0.2.0)
44
115
  ast (~> 2.4.1)
116
+ pmap (1.1.1)
117
+ poltergeist (1.18.1)
118
+ capybara (>= 2.1, < 4)
119
+ cliver (~> 0.3.1)
120
+ websocket-driver (>= 0.2.0)
45
121
  pry (0.12.2)
46
122
  coderay (~> 1.1.0)
47
123
  method_source (~> 0.9.0)
48
124
  pry-nav (0.3.0)
49
125
  pry (>= 0.9.10, < 0.13.0)
50
126
  public_suffix (4.0.6)
127
+ racc (1.6.0)
128
+ rack (2.2.3)
129
+ rack-test (1.1.0)
130
+ rack (>= 1.0, < 3)
51
131
  rainbow (3.0.0)
52
132
  rake (13.0.6)
133
+ rbcat (0.2.1)
53
134
  regexp_parser (2.1.1)
54
135
  rexml (3.2.5)
55
136
  rspec (3.10.0)
@@ -65,25 +146,53 @@ GEM
65
146
  diff-lcs (>= 1.2.0, < 2.0)
66
147
  rspec-support (~> 3.10.0)
67
148
  rspec-support (3.10.2)
68
- rubocop (1.20.0)
149
+ rubocop (1.22.3)
69
150
  parallel (~> 1.10)
70
151
  parser (>= 3.0.0.0)
71
152
  rainbow (>= 2.2.2, < 4.0)
72
153
  regexp_parser (>= 1.8, < 3.0)
73
154
  rexml
74
- rubocop-ast (>= 1.9.1, < 2.0)
155
+ rubocop-ast (>= 1.12.0, < 2.0)
75
156
  ruby-progressbar (~> 1.7)
76
157
  unicode-display_width (>= 1.4.0, < 3.0)
77
- rubocop-ast (1.11.0)
158
+ rubocop-ast (1.13.0)
78
159
  parser (>= 3.0.1.1)
160
+ rubocop-discourse (2.4.2)
161
+ rubocop (>= 1.1.0)
162
+ rubocop-rspec (>= 2.0.0)
163
+ rubocop-rake (0.6.0)
164
+ rubocop (~> 1.0)
165
+ rubocop-rspec (2.6.0)
166
+ rubocop (~> 1.19)
79
167
  ruby-progressbar (1.11.0)
80
168
  ruby2_keywords (0.0.5)
81
- unicode-display_width (2.0.0)
169
+ rubyzip (2.3.2)
170
+ selenium-webdriver (4.0.3)
171
+ childprocess (>= 0.5, < 5.0)
172
+ rexml (~> 3.2, >= 3.2.5)
173
+ rubyzip (>= 1.2.2)
174
+ thor (1.1.0)
175
+ tzinfo (2.0.4)
176
+ concurrent-ruby (~> 1.0)
177
+ unf (0.1.4)
178
+ unf_ext
179
+ unf_ext (0.0.8)
180
+ unicode-display_width (2.1.0)
82
181
  vcr (6.0.0)
83
182
  webmock (3.14.0)
84
183
  addressable (>= 2.8.0)
85
184
  crack (>= 0.3.2)
86
185
  hashdiff (>= 0.4.0, < 2.0.0)
186
+ webrick (1.7.0)
187
+ webrobots (0.1.2)
188
+ websocket-driver (0.7.5)
189
+ websocket-extensions (>= 0.1.0)
190
+ websocket-extensions (0.1.5)
191
+ whenever (1.0.0)
192
+ chronic (>= 0.6.3)
193
+ xpath (3.2.0)
194
+ nokogiri (~> 1.8)
195
+ zeitwerk (2.5.1)
87
196
 
88
197
  PLATFORMS
89
198
  arm64-darwin-20
@@ -95,9 +204,12 @@ DEPENDENCIES
95
204
  pry-nav
96
205
  rake (~> 13.0)
97
206
  rspec (~> 3.0)
98
- rubocop (~> 1.7)
207
+ rubocop (~> 1.22.3)
208
+ rubocop-discourse
209
+ rubocop-rake
210
+ rubocop-rspec
99
211
  vcr
100
212
  webmock
101
213
 
102
214
  BUNDLED WITH
103
- 2.2.19
215
+ 2.2.30
data/README.md CHANGED
@@ -25,8 +25,12 @@ Or install it yourself as:
25
25
 
26
26
  ```ruby
27
27
  client = BikeReg::Client.new
28
+ ```
29
+
30
+ ### Events
28
31
 
29
- events = client.event.search
32
+ ```ruby
33
+ events = client.event.search(states: 'IA', eventtype: 'cyclocross')
30
34
  #=> BikeReg::Collection
31
35
 
32
36
  events.total
@@ -34,7 +38,28 @@ events.total
34
38
 
35
39
  events.data
36
40
  #=> [#<BikeReg::Event>, #<BikeReg::Event>]
37
- ````
41
+
42
+ events.data[0].event_name
43
+ #=> 'The Grand'
44
+ ```
45
+
46
+ ### Registrations
47
+
48
+ You need both the event id and category id.
49
+
50
+ ```ruby
51
+ registrations = client.registrations.all(event_id: 123, category_id: 456)
52
+ #=> BikeReg::Collection
53
+
54
+ registrations.total
55
+ #=> 43
56
+
57
+ registrations.data
58
+ #=> [#<BikeReg::Registration>, #<BikeReg::Registration>]
59
+
60
+ registrations.data[0].name
61
+ #=> 'Lance Armstrong'
62
+ ```
38
63
 
39
64
  ## Development
40
65
 
data/bike_reg.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/bike_reg/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'bike_reg'
7
+ spec.version = BikeReg::VERSION
8
+ spec.authors = ['Scott Olsen']
9
+ spec.email = ['solsen300@gmail.com']
10
+ spec.homepage = 'https://github.com/scottolsen/bike_reg'
11
+ spec.summary = 'Gem to hit the BikeReg.com API'
12
+ spec.description = 'Gem to hit the BikeReg.com API. BikeReg API docs here https://www.bikereg.com/api/EventSearchDoc.aspx'
13
+ spec.license = 'MIT'
14
+
15
+ # Specify which files should be added to the gem when it is released.
16
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
17
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
18
+ `git ls-files -z`.split("\x0").reject do |f|
19
+ (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
20
+ end
21
+ end
22
+ spec.bindir = 'exe'
23
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ['lib']
25
+
26
+ spec.required_ruby_version = '>= 2.5'
27
+
28
+ spec.add_dependency 'faraday', '~> 1.7'
29
+ spec.add_dependency 'faraday_middleware', '~> 1.1'
30
+ spec.add_dependency 'kimurai', '1.4'
31
+ end
@@ -8,6 +8,10 @@ module BikeReg
8
8
  EventResource.new(self)
9
9
  end
10
10
 
11
+ def registrations
12
+ RegistrationResource.new(self)
13
+ end
14
+
11
15
  def connection
12
16
  @connection ||= Faraday.new(BASE_URL) do |conn|
13
17
  conn.request :json
@@ -11,12 +11,26 @@ module BikeReg
11
11
  def to_ostruct(obj)
12
12
  case obj
13
13
  when Hash
14
- OpenStruct.new(obj.transform_values { |val| to_ostruct(val) })
14
+ new_obj = obj.transform_keys { |key| underscore(key) }
15
+ OpenStruct.new(new_obj.transform_values { |val| to_ostruct(val) })
15
16
  when Array
16
17
  obj.map { |o| to_ostruct(o) }
17
18
  else # Assumed to be a primitive value
18
19
  obj
19
20
  end
20
21
  end
22
+
23
+ private
24
+
25
+ def underscore(camel_cased_word)
26
+ return camel_cased_word.to_s unless /[A-Z-]|::/.match?(camel_cased_word)
27
+
28
+ word = camel_cased_word.to_s.gsub('::', '/')
29
+ # word.gsub!(inflections.acronyms_underscore_regex) { "#{$1 && '_' }#{$2.downcase}" }
30
+ word.gsub!(/([A-Z]+)(?=[A-Z][a-z])|([a-z\d])(?=[A-Z])/) { (Regexp.last_match(1) || Regexp.last_match(2)) << '_' }
31
+ word.tr!('-', '_')
32
+ word.downcase!
33
+ word
34
+ end
21
35
  end
22
36
  end
@@ -2,5 +2,35 @@
2
2
 
3
3
  module BikeReg
4
4
  class Event < Object
5
+ # "/Date(1637384400000-0500)/"
6
+ def event_starts_at
7
+ ConvertDate
8
+ .new(event_date)
9
+ .utc_date
10
+ .to_s
11
+ end
12
+
13
+ def event_ends_at
14
+ ConvertDate
15
+ .new(event_end_date)
16
+ .utc_date
17
+ .to_s
18
+ end
19
+ end
20
+
21
+ class ConvertDate
22
+ def initialize(date)
23
+ @date = date
24
+ end
25
+
26
+ def utc_date
27
+ Time.at(epoch).getutc.to_date
28
+ end
29
+
30
+ private
31
+
32
+ def epoch
33
+ @date.split('(')[1].split('-')[0].to_i / 1000
34
+ end
5
35
  end
6
36
  end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BikeReg
4
+ class Registration < Object
5
+ end
6
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BikeReg
4
+ class RegistrationResource < Resource
5
+ def all(**params)
6
+ reg_url = "https://www.bikereg.com/Registration/ConfirmedSingleRace.aspx?eid=&team=&RaceRecID=#{params[:category_id]}&EventID=#{params[:event_id]}"
7
+
8
+ response = Scraper.parse!(:parse, url: reg_url)
9
+
10
+ Collection.from_response(response, key: 'riders', type: Registration, start_page: params[:startpage])
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'kimurai'
4
+ class Scraper < Kimurai::Base
5
+ @name = 'github_spider'
6
+ @engine = :mechanize
7
+ @start_urls = ["https://example.com/"]
8
+
9
+ def parse(response, url: '', data: {})
10
+ riders = []
11
+ trs = response.css('tr.event-participant')
12
+ trs.each do |tr|
13
+ state = tr.css('.state').text
14
+ last_name = tr.css('.lastname').text
15
+ name = "#{tr.css('#tdFirstName').text} #{last_name}"
16
+ team = tr.css('.team div').text.gsub("\r", '').gsub("\n", '').strip
17
+ riders << { name: name, team: team, state: state }
18
+ end
19
+
20
+ OpenStruct
21
+ .new(
22
+ body: {
23
+ riders: riders,
24
+ ResultCount: riders.count
25
+ }.with_indifferent_access
26
+ )
27
+ end
28
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BikeReg
4
- VERSION = '0.1.0'
4
+ VERSION = '0.3.0'
5
5
  end
data/lib/bike_reg.rb CHANGED
@@ -10,8 +10,11 @@ module BikeReg
10
10
  autoload :Error, 'bike_reg/error'
11
11
  autoload :Object, 'bike_reg/object'
12
12
  autoload :Resource, 'bike_reg/resource'
13
+ autoload :Scraper, 'bike_reg/scraper'
13
14
 
14
15
  autoload :EventResource, 'bike_reg/resources/event_resource'
16
+ autoload :RegistrationResource, 'bike_reg/resources/registration_resource'
15
17
 
16
18
  autoload :Event, 'bike_reg/objects/event'
19
+ autoload :Registration, 'bike_reg/objects/registration'
17
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bike_reg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Olsen
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-09-14 00:00:00.000000000 Z
11
+ date: 2021-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: kimurai
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: '1.4'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: '1.4'
41
55
  description: Gem to hit the BikeReg.com API. BikeReg API docs here https://www.bikereg.com/api/EventSearchDoc.aspx
42
56
  email:
43
57
  - solsen300@gmail.com
@@ -53,6 +67,7 @@ files:
53
67
  - LICENSE.txt
54
68
  - README.md
55
69
  - Rakefile
70
+ - bike_reg.gemspec
56
71
  - bin/console
57
72
  - bin/setup
58
73
  - lib/bike_reg.rb
@@ -61,14 +76,17 @@ files:
61
76
  - lib/bike_reg/error.rb
62
77
  - lib/bike_reg/object.rb
63
78
  - lib/bike_reg/objects/event.rb
79
+ - lib/bike_reg/objects/registration.rb
64
80
  - lib/bike_reg/resource.rb
65
81
  - lib/bike_reg/resources/event_resource.rb
82
+ - lib/bike_reg/resources/registration_resource.rb
83
+ - lib/bike_reg/scraper.rb
66
84
  - lib/bike_reg/version.rb
67
- homepage: https://github.com/scottolsen/bike-reg
85
+ homepage: https://github.com/scottolsen/bike_reg
68
86
  licenses:
69
87
  - MIT
70
88
  metadata: {}
71
- post_install_message:
89
+ post_install_message:
72
90
  rdoc_options: []
73
91
  require_paths:
74
92
  - lib
@@ -83,8 +101,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
101
  - !ruby/object:Gem::Version
84
102
  version: '0'
85
103
  requirements: []
86
- rubygems_version: 3.1.6
87
- signing_key:
104
+ rubygems_version: 3.2.31
105
+ signing_key:
88
106
  specification_version: 4
89
107
  summary: Gem to hit the BikeReg.com API
90
108
  test_files: []