citibike_trips 0.0.1
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 +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +38 -0
- data/Rakefile +9 -0
- data/citibike_trips.gemspec +26 -0
- data/lib/citibike_trips/station.rb +37 -0
- data/lib/citibike_trips/stations.rb +21 -0
- data/lib/citibike_trips/trip.rb +12 -0
- data/lib/citibike_trips/trips.rb +33 -0
- data/lib/citibike_trips/version.rb +3 -0
- data/lib/citibike_trips.rb +18 -0
- data/test/samples/stations.json +1 -0
- data/test/samples/trips1.html +749 -0
- data/test/samples/trips15.html +419 -0
- data/test/samples/trips2.html +659 -0
- data/test/test_station.rb +41 -0
- data/test/test_stations.rb +25 -0
- data/test/test_trip.rb +20 -0
- data/test/test_trips.rb +38 -0
- metadata +143 -0
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'citibike_trips'
|
3
|
+
|
4
|
+
class StationTests < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@data = {
|
7
|
+
"id"=>72,
|
8
|
+
"stationName"=>"W 52 St & 11 Ave",
|
9
|
+
"availableDocks"=>35,
|
10
|
+
"totalDocks"=>37,
|
11
|
+
"latitude"=>40.76727216,
|
12
|
+
"longitude"=>-73.99392888,
|
13
|
+
"statusValue"=>"In Service",
|
14
|
+
"statusKey"=>1,
|
15
|
+
"availableBikes"=>1,
|
16
|
+
"stAddress1"=>"W 52 St & 11 Ave",
|
17
|
+
"stAddress2"=>"",
|
18
|
+
"city"=>"",
|
19
|
+
"postalCode"=>"",
|
20
|
+
"location"=>"",
|
21
|
+
"altitude"=>"",
|
22
|
+
"testStation"=>false,
|
23
|
+
"lastCommunicationTime"=>nil,
|
24
|
+
"landMark"=>""}
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_initialize
|
28
|
+
station = CitibikeTrips::Station.new(@data)
|
29
|
+
# Some regular fields
|
30
|
+
assert_equal 72, station.id
|
31
|
+
assert_equal 'W 52 St & 11 Ave', station.name
|
32
|
+
assert_equal false, station.test_station
|
33
|
+
# Test conversion of empty string values to nil
|
34
|
+
assert_nil station.location
|
35
|
+
# Test special handling of city
|
36
|
+
assert_equal 'New York', station.city
|
37
|
+
# Virtual fields
|
38
|
+
assert_equal ['W 52 St & 11 Ave'], station.street_address_array
|
39
|
+
assert_equal 'W 52 St & 11 Ave', station.street_address
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'mocha/test_unit'
|
3
|
+
require 'citibike_trips'
|
4
|
+
|
5
|
+
class StationsTests < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
page = Mechanize::Page.new
|
8
|
+
Mechanize.any_instance.stubs(:get).with(CitibikeTrips::Stations::STATIONS_URL).returns(page)
|
9
|
+
json = File.read("#{File.dirname(__FILE__)}/samples/stations.json")
|
10
|
+
page.stubs(:body).returns(json)
|
11
|
+
@stations = CitibikeTrips::Stations.new
|
12
|
+
end
|
13
|
+
def test_initialize
|
14
|
+
assert_equal 332, @stations.stations.length
|
15
|
+
@stations.stations.each do |k,v|
|
16
|
+
assert_kind_of CitibikeTrips::Station, v
|
17
|
+
end
|
18
|
+
assert_equal 'W 52 St & 11 Ave', @stations.stations[72].name
|
19
|
+
assert_equal 20, @stations.stations[3002].available_docks
|
20
|
+
end
|
21
|
+
def test_square_brackets
|
22
|
+
assert_equal 'W 52 St & 11 Ave', @stations[72].name
|
23
|
+
assert_equal 20, @stations[3002].available_docks
|
24
|
+
end
|
25
|
+
end
|
data/test/test_trip.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'citibike_trips'
|
3
|
+
|
4
|
+
class TripTests < Test::Unit::TestCase
|
5
|
+
def test_initialize
|
6
|
+
page = Mechanize::Page.new
|
7
|
+
Mechanize.any_instance.stubs(:get).with(CitibikeTrips::Stations::STATIONS_URL).returns(page)
|
8
|
+
json = File.read("#{File.dirname(__FILE__)}/samples/stations.json")
|
9
|
+
page.stubs(:body).returns(json)
|
10
|
+
|
11
|
+
trip = CitibikeTrips::Trip.new('trip-13150976', '151', '517', '1406760278', '1406761369')
|
12
|
+
assert_equal 'trip-13150976', trip.id
|
13
|
+
assert_kind_of CitibikeTrips::Station, trip.start_station
|
14
|
+
assert_equal 'Cleveland Pl & Spring St', trip.start_station.name
|
15
|
+
assert_kind_of CitibikeTrips::Station, trip.end_station
|
16
|
+
assert_equal 'E 41 St & Madison Ave', trip.end_station.name
|
17
|
+
assert_equal Time.at(1406760278), trip.start_timestamp
|
18
|
+
assert_equal Time.at(1406761369), trip.end_timestamp
|
19
|
+
end
|
20
|
+
end
|
data/test/test_trips.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'mocha/test_unit'
|
3
|
+
require 'citibike_trips'
|
4
|
+
|
5
|
+
class TripsTests < Test::Unit::TestCase
|
6
|
+
def test_initialize
|
7
|
+
agent = Mechanize.new
|
8
|
+
uri1 = 'https://www.citibikenyc.com/member/trips'
|
9
|
+
uri2 = 'https://www.citibikenyc.com/member/trips/2'
|
10
|
+
uri15 = 'https://www.citibikenyc.com/member/trips/15'
|
11
|
+
trips1 = File.read("#{File.dirname(__FILE__)}/samples/trips1.html")
|
12
|
+
trips2 = File.read("#{File.dirname(__FILE__)}/samples/trips2.html")
|
13
|
+
# Note trips2.html was modified to have trips15 as the next page
|
14
|
+
trips15 = File.read("#{File.dirname(__FILE__)}/samples/trips15.html")
|
15
|
+
# I just fiddled with the args here until it worked. Ugly.
|
16
|
+
page1 = Mechanize::Page.new(URI.parse(uri1), nil, trips1, nil, agent)
|
17
|
+
page2 = Mechanize::Page.new(URI.parse(uri2), nil, trips2, nil, agent)
|
18
|
+
page15 = Mechanize::Page.new(URI.parse(uri15), nil, trips15, nil, agent)
|
19
|
+
Mechanize.any_instance.stubs(:get).with(uri1).returns(page1)
|
20
|
+
Mechanize.any_instance.stubs(:get).with(uri2).returns(page2)
|
21
|
+
Mechanize.any_instance.stubs(:get).with(uri15).returns(page15)
|
22
|
+
|
23
|
+
page = Mechanize::Page.new
|
24
|
+
Mechanize.any_instance.stubs(:get).with(CitibikeTrips::Stations::STATIONS_URL).returns(page)
|
25
|
+
json = File.read("#{File.dirname(__FILE__)}/samples/stations.json")
|
26
|
+
page.stubs(:body).returns(json)
|
27
|
+
|
28
|
+
trips = CitibikeTrips::Trips.new
|
29
|
+
# 26+20+4
|
30
|
+
assert_equal 50, trips.trips.length
|
31
|
+
trips.trips.each do |t|
|
32
|
+
assert_kind_of CitibikeTrips::Trip, t
|
33
|
+
end
|
34
|
+
assert_equal 'trip-13150976', trips.trips.first.id
|
35
|
+
assert_equal Time.at(1369869537), trips.trips.last.start_timestamp
|
36
|
+
assert_equal 'Broadway & W 58 St', trips.trips.last.start_station.name
|
37
|
+
end
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: citibike_trips
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jason Heiss
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-01 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.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: mocha
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: highline
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: mechanize
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: ''
|
84
|
+
email:
|
85
|
+
- jheiss@aput.net
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- citibike_trips.gemspec
|
96
|
+
- lib/citibike_trips.rb
|
97
|
+
- lib/citibike_trips/station.rb
|
98
|
+
- lib/citibike_trips/stations.rb
|
99
|
+
- lib/citibike_trips/trip.rb
|
100
|
+
- lib/citibike_trips/trips.rb
|
101
|
+
- lib/citibike_trips/version.rb
|
102
|
+
- test/samples/stations.json
|
103
|
+
- test/samples/trips1.html
|
104
|
+
- test/samples/trips15.html
|
105
|
+
- test/samples/trips2.html
|
106
|
+
- test/test_station.rb
|
107
|
+
- test/test_stations.rb
|
108
|
+
- test/test_trip.rb
|
109
|
+
- test/test_trips.rb
|
110
|
+
homepage: https://github.com/jheiss/citibike_trips
|
111
|
+
licenses:
|
112
|
+
- MIT
|
113
|
+
metadata: {}
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options: []
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
requirements: []
|
129
|
+
rubyforge_project:
|
130
|
+
rubygems_version: 2.2.2
|
131
|
+
signing_key:
|
132
|
+
specification_version: 4
|
133
|
+
summary: Fetches your Citi Bike trip data
|
134
|
+
test_files:
|
135
|
+
- test/samples/stations.json
|
136
|
+
- test/samples/trips1.html
|
137
|
+
- test/samples/trips15.html
|
138
|
+
- test/samples/trips2.html
|
139
|
+
- test/test_station.rb
|
140
|
+
- test/test_stations.rb
|
141
|
+
- test/test_trip.rb
|
142
|
+
- test/test_trips.rb
|
143
|
+
has_rdoc:
|