race_partner_registrations 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 829a089bdfa591b49c8ac0779fcec3e18317dd20
4
+ data.tar.gz: 3530b3c0562e2d8fcf72490b7f17755ea8950b1d
5
+ SHA512:
6
+ metadata.gz: 090adc25ca86353750f9470cd47817c0d8243faa23a496e4d6927b60adc7935ca42fe5b882e71cf7c995197cb8e3a2cbc7ed28977700aff5a8021e8725c07256
7
+ data.tar.gz: 0715201e670f578c3314daeb606205fc3bc07173cbf2882376f77eda7347624b5961c8af0ae4d438118383ee5a8f0f77f9b4dc4b7e4288eb9aa460ef98bd2c86
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,5 @@
1
+ --require spec_helper
2
+ --color true
3
+ --format documentation
4
+
5
+ --tag ~slow
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in race_partner_registrations.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Sean Devine
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.
@@ -0,0 +1,41 @@
1
+ # Race Partner Registrations
2
+
3
+ [Race Partner](http://www.racepartner.com) is a platform for registration, volunteer management, and marketing for road races and other endurance events.
4
+
5
+ [racepartner.com](http://www.racepartner.com) enables users to browse the registrations for a given event.
6
+
7
+ ![Race Partner Entrance List Screen Shot](./assets/images/entrance_list.jpg?raw=true)
8
+
9
+ `race_partner_registrations` enables you to extract these registration lists.
10
+
11
+ ## Usage
12
+
13
+ The `name` and `location` are extracted from the entrance list.
14
+
15
+ ### Examples
16
+
17
+ ```bash
18
+ $ gem install race_partner_registrations
19
+ $ irb
20
+ irb> require 'race_partner_registrations'
21
+ irb> url = "https://register.racepartner.com/falmouthroadrace/entrants"
22
+ irb> event = RacePartnerRegistrations::Event.new(url)
23
+ ```
24
+
25
+ An event can be converted to a CSV.
26
+ ```
27
+ irb> puts event.to_csv
28
+ name,location
29
+ Sean Devine,"Suffield, CT"
30
+ ```
31
+
32
+ You can also download the registrations and iterate through them directly.
33
+
34
+ ```bash
35
+ irb> event.download_registrations!
36
+ irb> registration = event.registrations.first
37
+ irb> registration.name
38
+ => "Sean Devine"
39
+ irb> registration.location
40
+ => "Suffield, CT"
41
+ ```
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'bundler' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('race_partner_registrations', 'bundler')
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'htmldiff' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('race_partner_registrations', 'htmldiff')
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'ldiff' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('race_partner_registrations', 'ldiff')
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'nokogiri' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('race_partner_registrations', 'nokogiri')
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rake' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('race_partner_registrations', 'rake')
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rspec' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rspec-core', 'rspec')
@@ -0,0 +1,11 @@
1
+ require "race_partner_registrations/version"
2
+
3
+ require "mechanize"
4
+ require "csv"
5
+
6
+ require "race_partner_registrations/event"
7
+ require "race_partner_registrations/registration"
8
+
9
+ module RacePartnerRegistrations
10
+ # Your code goes here...
11
+ end
@@ -0,0 +1,76 @@
1
+ module RacePartnerRegistrations
2
+ class Event
3
+ class InvalidUrlError < StandardError; end
4
+ class RegistrationsNotDownloadedError < StandardError; end
5
+
6
+ attr_reader :url
7
+
8
+ def initialize(url)
9
+ @url = url
10
+ end
11
+
12
+ def valid?
13
+ page.search("div#EntrantSearchForm").any?
14
+ end
15
+
16
+ def registrations
17
+ @registrations || raise(RegistrationsNotDownloadedError, "download_registrations! has not been sent to this event.")
18
+ end
19
+
20
+ def downloaded?
21
+ !!@registrations
22
+ end
23
+
24
+ def download_registrations!
25
+ raise InvalidUrlError unless valid?
26
+ @registrations = []
27
+ get_state_values(page).each do |state_value|
28
+ agent.get(single_page_url(state_value)).search("div#EntrantList tr").each do |row|
29
+ name_td, location_td = [0,1].collect { |n| row.search("td")[n] }
30
+ next unless name_td && location_td
31
+ @registrations << Registration.new(name_td.text.strip, location_td.text.strip)
32
+ end
33
+ end
34
+ @registrations
35
+ end
36
+
37
+ def to_csv
38
+ download_registrations! unless downloaded?
39
+ CSV.generate do |csv|
40
+ csv << ["name", "location"]
41
+ registrations.each do |registration|
42
+ csv << [:name, :location].collect { |attr| registration.send(attr) }
43
+ end
44
+ end
45
+ end
46
+
47
+ private
48
+
49
+ def page
50
+ @page ||= agent.get(url)
51
+ end
52
+
53
+ def agent
54
+ @agent = Mechanize.new
55
+ end
56
+
57
+ def get_form(page)
58
+ form_action = page.search("div#EntrantSearchForm form").first.attr("action")
59
+ page.form_with(action: form_action)
60
+ end
61
+
62
+ def get_state_values(page)
63
+ get_form(page).field_with(id: "state").options.collect do |state_option|
64
+ state_option.value
65
+ end.reject do |state_value|
66
+ state_value.length == 0
67
+ end
68
+ end
69
+
70
+ def single_page_url(state_value)
71
+ base_url = url.split("?")[0]
72
+ base_url + "?State=#{state_value}&PageSize=#{200_000_000}&PageIndex=1&Submitted=true"
73
+ end
74
+
75
+ end
76
+ end
@@ -0,0 +1,11 @@
1
+ module RacePartnerRegistrations
2
+ class Registration
3
+
4
+ attr_reader :name, :location
5
+
6
+ def initialize(name, location)
7
+ @name, @location = name, location
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module RacePartnerRegistrations
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'race_partner_registrations/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "race_partner_registrations"
8
+ spec.version = RacePartnerRegistrations::VERSION
9
+ spec.authors = ["Sean Devine"]
10
+ spec.email = ["barelyknown@icloud.com"]
11
+ spec.summary = "Download registration list from a Race Partner event."
12
+ spec.description = spec.summary
13
+ spec.homepage = ""
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.bindir = 'exec'
19
+ spec.test_files = spec.files.grep(%r{^(spec)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.6"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0.0"
25
+
26
+ spec.add_dependency "mechanize", "~> 2.7.3"
27
+ end
@@ -0,0 +1,83 @@
1
+ module RacePartnerRegistrations
2
+ describe Event do
3
+
4
+ subject do
5
+ described_class.new url
6
+ end
7
+
8
+ context "when initialized with a valid url" do
9
+ let :url do
10
+ "https://register.racepartner.com/falmouthroadrace/entrants"
11
+ end
12
+
13
+ it "sets and gets the url" do
14
+ expect(subject.url).to eq url
15
+ end
16
+
17
+ it "is valid" do
18
+ expect(subject).to be_valid
19
+ end
20
+
21
+ describe "#downloaded?" do
22
+ context "when the @registrations is not nil" do
23
+ before do
24
+ subject.instance_variable_set "@registrations", []
25
+ end
26
+ it "is downloaded" do
27
+ expect(subject).to be_downloaded
28
+ end
29
+ end
30
+ context "when the @registrations is nil" do
31
+ before do
32
+ subject.instance_variable_set "@registrations", nil
33
+ end
34
+ it "is not downloaded" do
35
+ expect(subject).to_not be_downloaded
36
+ end
37
+ end
38
+ end
39
+
40
+ describe "#download_registrations!" do
41
+ it "does not raise an exception", :slow do
42
+ expect{subject.download_registrations!}.to_not raise_error
43
+ end
44
+ it "sets the registrations", :slow do
45
+ subject.download_registrations!
46
+ expect(subject.registrations).to_not be_empty
47
+ end
48
+ end
49
+
50
+ describe "#to_csv" do
51
+ before do
52
+ allow(subject).to receive(:download_registrations!)
53
+ allow(subject).to receive(:registrations).and_return([Registration.new("Sean Devine", "Suffield, CT")])
54
+ end
55
+ it "generates the csv" do expect(subject.to_csv).to eq "name,location\nSean Devine,\"Suffield, CT\"\n"
56
+ end
57
+ end
58
+ end
59
+
60
+ context "when initialized with an invalid url" do
61
+ let :url do
62
+ "https://register.racepartner.com/falmouthroadrace"
63
+ end
64
+
65
+ it "is not valid" do
66
+ expect(subject).to_not be_valid
67
+ end
68
+
69
+ describe "#download_registrations!" do
70
+ it "raises an exception" do
71
+ expect{subject.download_registrations!}.to raise_error Event::InvalidUrlError
72
+ end
73
+ end
74
+
75
+ describe "#registrations" do
76
+ it "raises an exception" do
77
+ expect{subject.registrations}.to raise_error Event::RegistrationsNotDownloadedError
78
+ end
79
+ end
80
+ end
81
+
82
+ end
83
+ end
@@ -0,0 +1,31 @@
1
+ module RacePartnerRegistrations
2
+ describe Registration do
3
+
4
+ let :name do
5
+ "Sean Devine"
6
+ end
7
+
8
+ let :location do
9
+ "Suffield, CT"
10
+ end
11
+
12
+ context "when initialized with the name and location" do
13
+ subject do
14
+ described_class.new name, location
15
+ end
16
+ it "sets and gets the name" do
17
+ expect(subject.name).to eq name
18
+ end
19
+ it "sets and get the location" do
20
+ expect(subject.location).to eq location
21
+ end
22
+ end
23
+
24
+ context "when initialized without a name and location" do
25
+ it "raises an ArgumentError" do
26
+ expect{described_class.new}.to raise_error ArgumentError
27
+ end
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1 @@
1
+ require "race_partner_registrations"
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: race_partner_registrations
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sean Devine
8
+ autorequire:
9
+ bindir: exec
10
+ cert_chain: []
11
+ date: 2014-08-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.0.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.0.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: mechanize
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.7.3
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.7.3
69
+ description: Download registration list from a Race Partner event.
70
+ email:
71
+ - barelyknown@icloud.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - assets/images/entrance_list.jpg
83
+ - exec/bundler
84
+ - exec/htmldiff
85
+ - exec/ldiff
86
+ - exec/nokogiri
87
+ - exec/rake
88
+ - exec/rspec
89
+ - lib/race_partner_registrations.rb
90
+ - lib/race_partner_registrations/event.rb
91
+ - lib/race_partner_registrations/registration.rb
92
+ - lib/race_partner_registrations/version.rb
93
+ - race_partner_registrations.gemspec
94
+ - spec/lib/race_partner_registrations/event_spec.rb
95
+ - spec/lib/race_partner_registrations/registration_spec.rb
96
+ - spec/spec_helper.rb
97
+ homepage: ''
98
+ licenses:
99
+ - MIT
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.2.2
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: Download registration list from a Race Partner event.
121
+ test_files:
122
+ - spec/lib/race_partner_registrations/event_spec.rb
123
+ - spec/lib/race_partner_registrations/registration_spec.rb
124
+ - spec/spec_helper.rb
125
+ has_rdoc: