ratis 2.5.2.5 → 2.5.2.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +48 -33
- data/lib/ratis/request.rb +3 -0
- data/lib/ratis/timetable.rb +10 -5
- data/lib/ratis/timetable/stop.rb +2 -1
- data/lib/ratis/timetable/trip.rb +1 -1
- data/lib/ratis/version.rb +2 -1
- metadata +4 -4
data/README.md
CHANGED
@@ -19,19 +19,19 @@ Currently Supports Ruby `1.8.7` and `1.9.3`
|
|
19
19
|
|
20
20
|
Gem installation
|
21
21
|
-------------------
|
22
|
-
1. Ensure that an SSH identity with permission for the *authoritylabs*
|
22
|
+
1. Ensure that an SSH identity with permission for the *authoritylabs* organization on github is available to Bundler.
|
23
23
|
1. Include the gem in your Gemfile thus:
|
24
24
|
|
25
|
-
gem 'ratis',
|
25
|
+
gem 'ratis', '[VERSION]'
|
26
26
|
|
27
|
-
1. Add the following
|
27
|
+
1. Add the following configuration block.
|
28
28
|
|
29
29
|
This must happen before Ratis is `require`d (before `Rails::Initializer.run` in a Rails app).
|
30
30
|
|
31
31
|
require 'ratis/config'
|
32
32
|
Ratis.configure do |config|
|
33
|
-
config.endpoint = 'http://
|
34
|
-
config.namespace = '
|
33
|
+
config.endpoint = 'http://(YOUR ENDPOINT URL)'
|
34
|
+
config.namespace = '(YOUR NAMESPACE)'
|
35
35
|
config.proxy = 'http://localhost:8080'
|
36
36
|
config.timeout = 5
|
37
37
|
end
|
@@ -39,43 +39,59 @@ Gem installation
|
|
39
39
|
If Ratis is `require`d prior to this config being set you will get a `RuntimeError` informing you so.
|
40
40
|
If the provided `endpoint` is invalid an `ArgumentError: Invalid URL: bad URI` will be thrown, but only when a request is made.
|
41
41
|
|
42
|
-
|
42
|
+
NOTE ABOUT VERSIONS
|
43
43
|
-------------------
|
44
|
+
The versioning strategy for Ratis gem is the major, minor, and build components are set to match the ATIS version you are running. At the time of this edit, ATIS version 2.5.2 is matched with Ratis gem version 2.5.2.x. The last component is the patch version of the gem. This is the number that increases as we add feature from a particular ATIS version.
|
44
45
|
|
45
|
-
|
46
|
-
|
46
|
+
1. Add the following configuration block.
|
47
|
+
|
48
|
+
This must happen before Ratis is `require`d (before `Rails::Initializer.run` in a Rails app).
|
49
|
+
|
50
|
+
require 'ratis/config'
|
51
|
+
Ratis.configure do |config|
|
52
|
+
config.endpoint = 'http://(YOUR ENDPOINT URL)'
|
53
|
+
config.namespace = '(YOUR NAMESPACE)'
|
54
|
+
config.proxy = 'http://localhost:8080'
|
55
|
+
config.timeout = 5
|
56
|
+
end
|
57
|
+
|
58
|
+
If Ratis is `require`d prior to this config being set you will get a `RuntimeError` informing you so.
|
59
|
+
If the provided `endpoint` is invalid an `ArgumentError: Invalid URL: bad URI` will be thrown, but only when a request is made.
|
47
60
|
|
48
|
-
|
61
|
+
Gem usage
|
62
|
+
-------------------
|
49
63
|
|
50
|
-
|
64
|
+
### Classes
|
65
|
+
All the classes should be named to match the ATIS method:
|
51
66
|
|
52
|
-
|
67
|
+
Itinerary, Landmark, ScheduleNearby, ...
|
53
68
|
|
54
|
-
|
55
|
-
=> [AtisLandmark]
|
69
|
+
Notable exceptions:
|
56
70
|
|
71
|
+
Routes contains Allroutes method with the thinking that this might be extened for other routes methods, but is probably not necessary and should be renamed
|
72
|
+
|
57
73
|
### Queries
|
58
74
|
By convention most provide either an `all` or `where` class method (following [Active Record's hash conditions syntax](http://guides.rubyonrails.org/active_record_querying.html#hash-conditions)), which will return an array of objects which wrap the response, e.g:
|
59
75
|
|
60
|
-
>> all_landmarks =
|
76
|
+
>> all_landmarks = Landmark.where :type => :all
|
61
77
|
>> all_landmarks.count
|
62
78
|
=> 1510
|
63
79
|
>> all_landmarks.first
|
64
|
-
=> #<
|
80
|
+
=> #<Landmark:0x10d263190 @locality="N", @type="AIRPT", @location="4800 E. FALCON DR.", @verbose="FALCON FIELD AIRPORT">
|
65
81
|
|
66
82
|
### Errors
|
67
83
|
The `where` methods will try to sanity check your conditions before making a call to the SOAP server:
|
68
84
|
|
69
|
-
>>
|
85
|
+
>> Landmark.where({})
|
70
86
|
ArgumentError: You must provide a type
|
71
87
|
|
72
|
-
>>
|
88
|
+
>> Landmark.where :type => :all, :foo => 1
|
73
89
|
ArgumentError: Conditions not used by this class: [:foo]
|
74
90
|
|
75
|
-
When something goes wrong with the SOAP transaction an `
|
91
|
+
When something goes wrong with the SOAP transaction an `Error` will be raised:
|
76
92
|
|
77
|
-
>>
|
78
|
-
#<
|
93
|
+
>> NextBus.where :stop_id => 123456
|
94
|
+
#<Error: #10222--Unknown stop>
|
79
95
|
|
80
96
|
|
81
97
|
Development
|
@@ -87,20 +103,23 @@ Development
|
|
87
103
|
|
88
104
|
### Usage
|
89
105
|
|
90
|
-
1. For development Ratis is hard coded to use a local proxy server on port 8080:
|
91
|
-
|
92
|
-
ssh -i ~/.ssh/authoritylabs.pem -L 8080:localhost:3128 ubuntu@codingsanctum.com
|
93
|
-
|
94
106
|
1. Run the test suite with `rake`
|
95
107
|
1. Test it out with `irb -I lib/ -r rubygems -r ratis`
|
108
|
+
2. After irb is open with above step, paste in your application's connection config settings. Example:
|
109
|
+
|
110
|
+
Ratis.configure do |config|
|
111
|
+
config.endpoint = 'http://(YOUR ENDPOINT URL)'
|
112
|
+
config.namespace = '(YOUR NAMESPACE)'
|
113
|
+
config.timeout = 5
|
114
|
+
end
|
96
115
|
|
97
116
|
### Extending
|
98
117
|
|
99
|
-
The `
|
118
|
+
The `Landmark` class is a simple one to look at for reference, and will be referred to below:
|
100
119
|
|
101
120
|
#### Testing
|
102
121
|
|
103
|
-
You can see the spec for it in `spec/ratis/
|
122
|
+
You can see the spec for it in `spec/ratis/landmark_spec.rb`, it uses helper methods defined in `spec/spec_helper.rb`:
|
104
123
|
|
105
124
|
1. `stub_atis_request` tells `Webmock` to stub a `POST` to the ATIS SOAP server, any request which hasn't been explicitly allowed will trigger an exception.
|
106
125
|
|
@@ -125,16 +144,12 @@ You can see the spec for it in `spec/ratis/atis_landmark_spec.rb`, it uses helpe
|
|
125
144
|
|
126
145
|
#### Implementing
|
127
146
|
|
128
|
-
To ease interaction with the ATIS SOAP server the `AtisModel` module is available. Any class which makes requests to the server should:
|
129
|
-
|
130
|
-
require 'ratis/atis_model'
|
131
|
-
extend AtisModel
|
132
|
-
|
133
147
|
You get the following:
|
134
148
|
|
135
|
-
1. `atis_request` should be used to make request to the ATIS SOAP server. It ensures the request is built in a way which the ATIS SOAP server expects, provides a version check against responses and returns a `Savon::Response`:
|
136
149
|
|
137
|
-
|
150
|
+
1. `Request` should be used to make request to the ATIS SOAP server. It ensures the request is built in a way which the ATIS SOAP server expects, provides a version check against responses and returns a `Savon::Response`:
|
151
|
+
|
152
|
+
Request.get 'Getlandmarks', {'Type' => type}
|
138
153
|
|
139
154
|
The method and parameter names should be given as described by the ATIS SOAP Interface reference, with the first character uppercase and all others lowercase.
|
140
155
|
|
data/lib/ratis/request.rb
CHANGED
@@ -7,6 +7,7 @@ module Ratis
|
|
7
7
|
def initialize(config = nil)
|
8
8
|
config = Ratis.config if config.nil?
|
9
9
|
raise Errors::ConfigError('It appears that Ratis.configure has not been called') unless config.valid?
|
10
|
+
|
10
11
|
self.class.client do
|
11
12
|
wsdl.endpoint = Ratis.config.endpoint
|
12
13
|
wsdl.namespace = Ratis.config.namespace
|
@@ -31,6 +32,8 @@ module Ratis
|
|
31
32
|
raise Errno::ECONNREFUSED.new 'Refused request to ATIS SOAP server'
|
32
33
|
rescue Savon::SOAP::Fault => e
|
33
34
|
raise Errors::SoapError.new e
|
35
|
+
rescue Timeout::Error => e
|
36
|
+
raise "TIMEOUT!"
|
34
37
|
end
|
35
38
|
end
|
36
39
|
|
data/lib/ratis/timetable.rb
CHANGED
@@ -4,6 +4,7 @@ module Ratis
|
|
4
4
|
|
5
5
|
attr_accessor :route_short_name, :direction, :service_type, :operator, :effective, :timepoints, :trips
|
6
6
|
|
7
|
+
#Ratis::Timetable.where( :route_short_name => "460", :direction => "E", :service_type => 'W')
|
7
8
|
def self.where(conditions)
|
8
9
|
short_name = conditions.delete :route_short_name
|
9
10
|
direction = conditions.delete :direction
|
@@ -12,7 +13,7 @@ module Ratis
|
|
12
13
|
|
13
14
|
raise ArgumentError.new('You must provide a route_short_name') unless short_name
|
14
15
|
raise ArgumentError.new('You must provide a direction') unless direction
|
15
|
-
raise ArgumentError.new('You must provide either date or service_type')
|
16
|
+
raise ArgumentError.new('You must provide either date or service_type') if date.blank? && service_type.blank?
|
16
17
|
Ratis.all_conditions_used? conditions
|
17
18
|
|
18
19
|
request_params = { 'Route' => short_name, 'Direction' => direction }
|
@@ -29,14 +30,18 @@ module Ratis
|
|
29
30
|
timetable.operator = headway[:operator]
|
30
31
|
timetable.effective = headway[:effective]
|
31
32
|
|
32
|
-
|
33
|
-
|
33
|
+
timepoints_array = []
|
34
|
+
headway[:timepoints][:stop].each_with_index{|tp, i| timepoints_array.push(Timetable::Stop.new(i, tp[:stopid], tp[:description], tp[:area]) )} rescue []
|
35
|
+
timetable.timepoints = timepoints_array
|
34
36
|
|
35
|
-
|
36
|
-
|
37
|
+
trips_array = []
|
38
|
+
headway[:times][:trip].each_with_index{|t,i| trips_array.push(Timetable::Trip.new(i, t[:time], t[:comment]))} rescue []
|
39
|
+
timetable.trips = trips_array
|
37
40
|
|
38
41
|
timetable
|
39
42
|
end
|
43
|
+
|
44
|
+
|
40
45
|
|
41
46
|
end
|
42
47
|
|
data/lib/ratis/timetable/stop.rb
CHANGED
data/lib/ratis/timetable/trip.rb
CHANGED
data/lib/ratis/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ratis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 67
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 5
|
9
9
|
- 2
|
10
|
-
-
|
11
|
-
version: 2.5.2.
|
10
|
+
- 6
|
11
|
+
version: 2.5.2.6
|
12
12
|
platform: ruby
|
13
13
|
authors:
|
14
14
|
- AuthorityLabs
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2013-
|
19
|
+
date: 2013-02-15 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: savon
|