actransit_rails 0.2.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
  SHA1:
3
- metadata.gz: ad3dd9f032df1c65da242f9b4508b68d7df4914a
4
- data.tar.gz: bef2da53560a6e943fd0366c44b711bc2cb6744d
3
+ metadata.gz: 6c5c5102c50ca3e92760dbdbb3b0950815dafdcc
4
+ data.tar.gz: db7de3713043287af01148e456be7bb2c919a62e
5
5
  SHA512:
6
- metadata.gz: 5ba2c8a1c8ab3f8020158d032867e67b7cc13724142d196c67444715c5839c1132363e534066a0e33becd1460d313dd90c20760d19563d51159c5501c51d9372
7
- data.tar.gz: 3ca3ccaca6c50d78d41e9a1567b73ddb08ef41e217784902015290c15cafecc51279043bce194252cf974c74c7e08c54db9551abd4e37073910a1687a93ac400
6
+ metadata.gz: 0caf0f1e2f28a0d507a95b6802c12fdf9997f183908eb0b11548c26cdd7b8c19e522fd1d97caad5975d72098edcc0b42ec14b6c2c51c19bfd9917dc791a6c44c
7
+ data.tar.gz: 89841a7986e13fa295de83ced14484e87d1f1497d5366fb026d1a3ab9d6f4fdc894584df7ec9043ce66b101a21f63292d7039b3e76c1577e88a6224db01f6080
@@ -1,8 +1,15 @@
1
1
  # ActransitRails Change Log
2
2
 
3
- # 07.20.15 - Version 0.2.0
3
+ # 07.20.15 - Version 0.2.x
4
4
 
5
- Added Error Handling based on the HTTP response codes.
5
+ ## Added Error Handling based on the HTTP response codes.
6
6
 
7
- ACTransitRails will raise an APIAccessError with a `message` and `code` attributes.
7
+ * ACTransitRails will raise an APIAccessError with a `message` and `code` attributes.
8
+ * You can `rescue_from` error messages by adding a callback in your ApplicationController like this:
8
9
 
10
+ ```ruby
11
+ rescue_from ACTransitRails::APIAccessError do |exception|
12
+ flash[:alert] = exception.message
13
+ redirect_to(request.referrer || root_path)
14
+ end
15
+ ```
data/README.md CHANGED
@@ -4,6 +4,8 @@ A gem for accessing the ACTransit API in Rails.
4
4
 
5
5
  Checkout the ACTransit [Documentation](http://api.actransit.org/transit/) for more info.
6
6
 
7
+ [Change Log](/CHANGELOG.md) details of each new version.
8
+
7
9
  ## Installation
8
10
 
9
11
  Add this line to your application's Gemfile:
@@ -22,6 +24,8 @@ Or install it yourself as:
22
24
 
23
25
  ## Usage
24
26
 
27
+ ### Setup
28
+
25
29
  1. Make sure you [register an application](http://api.actransit.org/transit/Account/Register) with ACTransit to get your access token.
26
30
 
27
31
  2. I'd recommend using a gem like [figaro](https://github.com/laserlemon/figaro) to safely store your ACTransit access token as an environment variable.
@@ -36,7 +40,9 @@ ACTransitRails.configure(ENV['ACTRANSIT_TOKEN'])
36
40
  ACTransitRails.configure("myactransittoken")
37
41
  ```
38
42
 
39
- 4. Once configured, you can use the helper methods to make requests from the api. Responses will be formatted as either a hash or an array of hashes depending on what you request.
43
+ ### Making Requests
44
+
45
+ * Once configured, you can use the helper methods to make requests from the api. Responses will be formatted as either a hash or an array of hashes depending on what you request.
40
46
 
41
47
  ```ruby
42
48
  # returns array of hashes
@@ -63,6 +69,17 @@ ACTransitRails.get_stops('E', 4119214)
63
69
 
64
70
  ```
65
71
 
72
+ ### Errors
73
+
74
+ * ACTransitRails will raise an APIAccessError with a `message` and `code` attributes.
75
+ * You can `rescue_from` error messages by adding a callback in your ApplicationController like this:
76
+
77
+ ```ruby
78
+ rescue_from ACTransitRails::APIAccessError do |exception|
79
+ flash[:alert] = exception.message
80
+ redirect_to(request.referrer || root_path)
81
+ end
82
+ ```
66
83
 
67
84
  ## Contributing
68
85
 
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "bundler/setup"
4
4
  require "actransit_rails"
5
+ require "net/http"
5
6
 
6
7
  # You can add fixtures and/or initialization code here to make experimenting
7
8
  # with your gem easier. You can also use a different console, if you like.
@@ -10,12 +10,15 @@ module ACTransitRails
10
10
  @actransit_token = actransit_token
11
11
  end
12
12
 
13
+ # ROUTES
14
+
13
15
  def self.get_all_routes
14
16
  uri = URI.parse(
15
17
  base_url +
16
- "routes/" +
18
+ "routes" +
17
19
  search_string +
18
- my_token
20
+ my_token +
21
+ response_format
19
22
  )
20
23
  return get_response(uri)
21
24
  end
@@ -24,9 +27,10 @@ module ACTransitRails
24
27
  uri = URI.parse(
25
28
  base_url +
26
29
  "route/" +
27
- "#{route_name}/" +
30
+ "#{route_name}" +
28
31
  search_string +
29
- my_token
32
+ my_token +
33
+ response_format
30
34
  )
31
35
  return get_response(uri)
32
36
  end
@@ -35,9 +39,10 @@ module ACTransitRails
35
39
  uri = URI.parse(
36
40
  base_url +
37
41
  "route/" +
38
- "#{route_name}/trips/" +
42
+ "#{route_name}/trips" +
39
43
  search_string +
40
- my_token
44
+ my_token +
45
+ response_format
41
46
  )
42
47
  return get_response(uri)
43
48
  end
@@ -46,20 +51,35 @@ module ACTransitRails
46
51
  uri = URI.parse(
47
52
  base_url +
48
53
  "route/" +
49
- "#{route_name}/directions/" +
54
+ "#{route_name}/directions" +
55
+ search_string +
56
+ my_token +
57
+ response_format
58
+ )
59
+ return get_response(uri)
60
+ end
61
+
62
+ def self.get_stops(route_name, trip_id = nil)
63
+ trip_id ||= get_trips(route_name)[0]["TripId"]
64
+ uri = URI.parse(
65
+ base_url +
66
+ "route/" +
67
+ "#{route_name}/trip/" +
68
+ "#{trip_id}/stops" +
50
69
  search_string +
51
- my_token
70
+ my_token +
71
+ response_format
52
72
  )
53
73
  return get_response(uri)
54
74
  end
55
75
 
56
- def self.get_stops(route_name, trip = nil)
57
- trip ||= get_trips(route_name)[0]["TripId"]
76
+ def self.get_route_pattern(route_name, trip_id = nil)
77
+ trip_id ||= get_trips(route_name)[0]["TripId"]
58
78
  uri = URI.parse(
59
79
  base_url +
60
80
  "route/" +
61
81
  "#{route_name}/trip/" +
62
- "#{trip}/stops/" +
82
+ "#{trip_id}/pattern" +
63
83
  search_string +
64
84
  my_token +
65
85
  response_format
@@ -67,6 +87,59 @@ module ACTransitRails
67
87
  return get_response(uri)
68
88
  end
69
89
 
90
+ # STOPS
91
+
92
+ def self.get_all_stops
93
+ uri = URI.parse(
94
+ base_url +
95
+ "stops" +
96
+ search_string +
97
+ my_token +
98
+ response_format
99
+ )
100
+ return get_response(uri)
101
+ end
102
+
103
+ # VEHICLES
104
+
105
+ def self.get_vehicle(vehicle_id)
106
+ uri = URI.parse(
107
+ base_url +
108
+ "vehicle/" +
109
+ "#{vehicle_id}" +
110
+ search_string +
111
+ my_token +
112
+ response_format
113
+ )
114
+ return get_response(uri)
115
+ end
116
+
117
+ # GTFS
118
+
119
+ def self.get_gtfs_info
120
+ uri = URI.parse(
121
+ base_url +
122
+ "gtfs" +
123
+ search_string +
124
+ my_token +
125
+ response_format
126
+ )
127
+ return get_response(uri)
128
+ end
129
+
130
+ # SERVICE NOTICES
131
+
132
+ def self.get_service_notices
133
+ uri = URI.parse(
134
+ base_url +
135
+ "servicenotices" +
136
+ search_string +
137
+ my_token +
138
+ response_format
139
+ )
140
+ return get_response(uri)
141
+ end
142
+
70
143
  private
71
144
 
72
145
  def self.base_url
@@ -101,6 +174,8 @@ module ACTransitRails
101
174
  message = http_response.body
102
175
  when '404'
103
176
  message = "Not found. No results for your query."
177
+ else
178
+ message = http_response.body
104
179
  end
105
180
  raise ACTransitRails::APIAccessError.new(message, code)
106
181
  end
@@ -1,3 +1,3 @@
1
1
  module ACTransitRails
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actransit_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sanjay Y Patel
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-07-20 00:00:00.000000000 Z
11
+ date: 2016-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json