next_buses 0.0.6 → 0.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7b5b53421a0137f6f2da8153c2385d667a8bbbfa
4
- data.tar.gz: 111eae7bb5ea6a8ffc5689c3bfd9a2ef6aa81812
3
+ metadata.gz: 5c2165baa127709118d694b0eb725a4460a0ccd8
4
+ data.tar.gz: b8ca6336bdf7f06c29b20f7e13779844abc409d4
5
5
  SHA512:
6
- metadata.gz: c5570a5c96282069b3fd89d8a8bfa156ce6988a71cd636a22084546c4405e30570dc49703b97cdeb50f0d2bf547d36287a0e594b1b18f8d988f38c4aa723acfb
7
- data.tar.gz: e65fb98dedefce3cef31801a2f1badaa5a1d23e9ea81ee1e273e84ffcdff311b36232e3c6954c5fb4b28879242c0514dfce690a41e832488ea49b2da88b6894b
6
+ metadata.gz: 6d362edb0c0ffa35887ea1cc20d44e7e0f4f9d7cfe5e4d118578226e8274387e0c0162bb86236a9e336c33f6991198e8310fa923f5142d6f7dd9db1280176fdd
7
+ data.tar.gz: dd12aa6b38c83443dfe7f698ad10d680fbdb87b749667e1c45267ab515cec9564b68b1923685a3336e37334d8bef6004bbb0cfc05f89fe1535605dab09cde18e
@@ -0,0 +1,3 @@
1
+ To copy a SimpleForm initializer to your Rails App, with some configuration values, just do:
2
+
3
+ rails generate simple_form:install
@@ -0,0 +1,41 @@
1
+ module SimpleForm
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ desc "Copy SimpleForm default files"
5
+ source_root File.expand_path('../templates', __FILE__)
6
+ class_option :template_engine, desc: 'Template engine to be invoked (erb, haml or slim).'
7
+ class_option :bootstrap, type: :boolean, desc: 'Add the Twitter Bootstrap wrappers to the SimpleForm initializer.'
8
+ class_option :foundation, type: :boolean, desc: 'Add the Zurb Foundation 3 wrappers to the SimpleForm initializer.'
9
+
10
+ def info_bootstrap
11
+ return if options.bootstrap? || options.foundation?
12
+ puts "SimpleForm 2 supports Twitter Bootstrap and Zurb Foundation 3. If you want "\
13
+ "a configuration that is compatible with one of these frameworks, then please " \
14
+ "re-run this generator with --bootstrap or --foundation as an option."
15
+ end
16
+
17
+ def copy_config
18
+ template "config/initializers/simple_form.rb"
19
+
20
+ if options[:bootstrap]
21
+ template "config/initializers/simple_form_bootstrap.rb"
22
+ elsif options[:foundation]
23
+ template "config/initializers/simple_form_foundation.rb"
24
+ end
25
+
26
+ directory 'config/locales'
27
+ end
28
+
29
+ def copy_scaffold_template
30
+ engine = options[:template_engine]
31
+ copy_file "_form.html.#{engine}", "lib/templates/#{engine}/scaffold/_form.html.#{engine}"
32
+ end
33
+
34
+ def show_readme
35
+ if behavior == :invoke && options.bootstrap?
36
+ readme "README"
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,12 @@
1
+ ===============================================================================
2
+
3
+ Be sure to have a copy of the Bootstrap stylesheet available on your
4
+ application, you can get it on http://twitter.github.com/bootstrap.
5
+
6
+ Inside your views, use the 'simple_form_for' with one of the Bootstrap form
7
+ classes, '.form-horizontal', '.form-inline', '.form-search' or
8
+ '.form-vertical', as the following:
9
+
10
+ = simple_form_for(@user, html: {class: 'form-horizontal' }) do |form|
11
+
12
+ ===============================================================================
@@ -0,0 +1,13 @@
1
+ <%%= simple_form_for(@<%= singular_table_name %>) do |f| %>
2
+ <%%= f.error_notification %>
3
+
4
+ <div class="form-inputs">
5
+ <%- attributes.each do |attribute| -%>
6
+ <%%= f.<%= attribute.reference? ? :association : :input %> :<%= attribute.name %> %>
7
+ <%- end -%>
8
+ </div>
9
+
10
+ <div class="form-actions">
11
+ <%%= f.button :submit %>
12
+ </div>
13
+ <%% end %>
@@ -0,0 +1,10 @@
1
+ = simple_form_for(@<%= singular_table_name %>) do |f|
2
+ = f.error_notification
3
+
4
+ .form-inputs
5
+ <%- attributes.each do |attribute| -%>
6
+ = f.<%= attribute.reference? ? :association : :input %> :<%= attribute.name %>
7
+ <%- end -%>
8
+
9
+ .form-actions
10
+ = f.button :submit
@@ -0,0 +1,10 @@
1
+ = simple_form_for(@<%= singular_table_name %>) do |f|
2
+ = f.error_notification
3
+
4
+ .form-inputs
5
+ <%- attributes.each do |attribute| -%>
6
+ = f.<%= attribute.reference? ? :association : :input %> :<%= attribute.name %>
7
+ <%- end -%>
8
+
9
+ .form-actions
10
+ = f.button :submit
@@ -0,0 +1,145 @@
1
+ # Use this setup block to configure all options available in SimpleForm.
2
+ SimpleForm.setup do |config|
3
+ # Wrappers are used by the form builder to generate a
4
+ # complete input. You can remove any component from the
5
+ # wrapper, change the order or even add your own to the
6
+ # stack. The options given below are used to wrap the
7
+ # whole input.
8
+ config.wrappers :default, class: :input,
9
+ hint_class: :field_with_hint, error_class: :field_with_errors do |b|
10
+ ## Extensions enabled by default
11
+ # Any of these extensions can be disabled for a
12
+ # given input by passing: `f.input EXTENSION_NAME => false`.
13
+ # You can make any of these extensions optional by
14
+ # renaming `b.use` to `b.optional`.
15
+
16
+ # Determines whether to use HTML5 (:email, :url, ...)
17
+ # and required attributes
18
+ b.use :html5
19
+
20
+ # Calculates placeholders automatically from I18n
21
+ # You can also pass a string as f.input placeholder: "Placeholder"
22
+ b.use :placeholder
23
+
24
+ ## Optional extensions
25
+ # They are disabled unless you pass `f.input EXTENSION_NAME => :lookup`
26
+ # to the input. If so, they will retrieve the values from the model
27
+ # if any exists. If you want to enable the lookup for any of those
28
+ # extensions by default, you can change `b.optional` to `b.use`.
29
+
30
+ # Calculates maxlength from length validations for string inputs
31
+ b.optional :maxlength
32
+
33
+ # Calculates pattern from format validations for string inputs
34
+ b.optional :pattern
35
+
36
+ # Calculates min and max from length validations for numeric inputs
37
+ b.optional :min_max
38
+
39
+ # Calculates readonly automatically from readonly attributes
40
+ b.optional :readonly
41
+
42
+ ## Inputs
43
+ b.use :label_input
44
+ b.use :hint, wrap_with: { tag: :span, class: :hint }
45
+ b.use :error, wrap_with: { tag: :span, class: :error }
46
+ end
47
+
48
+ # The default wrapper to be used by the FormBuilder.
49
+ config.default_wrapper = :default
50
+
51
+ # Define the way to render check boxes / radio buttons with labels.
52
+ # Defaults to :nested for bootstrap config.
53
+ # inline: input + label
54
+ # nested: label > input
55
+ config.boolean_style = :nested
56
+
57
+ # Default class for buttons
58
+ config.button_class = 'btn'
59
+
60
+ # Method used to tidy up errors. Specify any Rails Array method.
61
+ # :first lists the first message for each field.
62
+ # Use :to_sentence to list all errors for each field.
63
+ # config.error_method = :first
64
+
65
+ # Default tag used for error notification helper.
66
+ config.error_notification_tag = :div
67
+
68
+ # CSS class to add for error notification helper.
69
+ config.error_notification_class = 'alert alert-error'
70
+
71
+ # ID to add for error notification helper.
72
+ # config.error_notification_id = nil
73
+
74
+ # Series of attempts to detect a default label method for collection.
75
+ # config.collection_label_methods = [ :to_label, :name, :title, :to_s ]
76
+
77
+ # Series of attempts to detect a default value method for collection.
78
+ # config.collection_value_methods = [ :id, :to_s ]
79
+
80
+ # You can wrap a collection of radio/check boxes in a pre-defined tag, defaulting to none.
81
+ # config.collection_wrapper_tag = nil
82
+
83
+ # You can define the class to use on all collection wrappers. Defaulting to none.
84
+ # config.collection_wrapper_class = nil
85
+
86
+ # You can wrap each item in a collection of radio/check boxes with a tag,
87
+ # defaulting to :span. Please note that when using :boolean_style = :nested,
88
+ # SimpleForm will force this option to be a label.
89
+ # config.item_wrapper_tag = :span
90
+
91
+ # You can define a class to use in all item wrappers. Defaulting to none.
92
+ # config.item_wrapper_class = nil
93
+
94
+ # How the label text should be generated altogether with the required text.
95
+ # config.label_text = lambda { |label, required| "#{required} #{label}" }
96
+
97
+ # You can define the class to use on all labels. Default is nil.
98
+ config.label_class = 'control-label'
99
+
100
+ # You can define the class to use on all forms. Default is simple_form.
101
+ # config.form_class = :simple_form
102
+
103
+ # You can define which elements should obtain additional classes
104
+ # config.generate_additional_classes_for = [:wrapper, :label, :input]
105
+
106
+ # Whether attributes are required by default (or not). Default is true.
107
+ # config.required_by_default = true
108
+
109
+ # Tell browsers whether to use the native HTML5 validations (novalidate form option).
110
+ # These validations are enabled in SimpleForm's internal config but disabled by default
111
+ # in this configuration, which is recommended due to some quirks from different browsers.
112
+ # To stop SimpleForm from generating the novalidate option, enabling the HTML5 validations,
113
+ # change this configuration to true.
114
+ config.browser_validations = false
115
+
116
+ # Collection of methods to detect if a file type was given.
117
+ # config.file_methods = [ :mounted_as, :file?, :public_filename ]
118
+
119
+ # Custom mappings for input types. This should be a hash containing a regexp
120
+ # to match as key, and the input type that will be used when the field name
121
+ # matches the regexp as value.
122
+ # config.input_mappings = { /count/ => :integer }
123
+
124
+ # Custom wrappers for input types. This should be a hash containing an input
125
+ # type as key and the wrapper that will be used for all inputs with specified type.
126
+ # config.wrapper_mappings = { string: :prepend }
127
+
128
+ # Default priority for time_zone inputs.
129
+ # config.time_zone_priority = nil
130
+
131
+ # Default priority for country inputs.
132
+ # config.country_priority = nil
133
+
134
+ # When false, do not use translations for labels.
135
+ # config.translate_labels = true
136
+
137
+ # Automatically discover new inputs in Rails' autoload path.
138
+ # config.inputs_discovery = true
139
+
140
+ # Cache SimpleForm inputs discovery
141
+ # config.cache_discovery = !Rails.env.development?
142
+
143
+ # Default class for inputs
144
+ # config.input_class = nil
145
+ end
@@ -0,0 +1,45 @@
1
+ # Use this setup block to configure all options available in SimpleForm.
2
+ SimpleForm.setup do |config|
3
+ config.wrappers :bootstrap, tag: 'div', class: 'control-group', error_class: 'error' do |b|
4
+ b.use :html5
5
+ b.use :placeholder
6
+ b.use :label
7
+ b.wrapper tag: 'div', class: 'controls' do |ba|
8
+ ba.use :input
9
+ ba.use :error, wrap_with: { tag: 'span', class: 'help-inline' }
10
+ ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
11
+ end
12
+ end
13
+
14
+ config.wrappers :prepend, tag: 'div', class: "control-group", error_class: 'error' do |b|
15
+ b.use :html5
16
+ b.use :placeholder
17
+ b.use :label
18
+ b.wrapper tag: 'div', class: 'controls' do |input|
19
+ input.wrapper tag: 'div', class: 'input-prepend' do |prepend|
20
+ prepend.use :input
21
+ end
22
+ input.use :hint, wrap_with: { tag: 'span', class: 'help-block' }
23
+ input.use :error, wrap_with: { tag: 'span', class: 'help-inline' }
24
+ end
25
+ end
26
+
27
+ config.wrappers :append, tag: 'div', class: "control-group", error_class: 'error' do |b|
28
+ b.use :html5
29
+ b.use :placeholder
30
+ b.use :label
31
+ b.wrapper tag: 'div', class: 'controls' do |input|
32
+ input.wrapper tag: 'div', class: 'input-append' do |append|
33
+ append.use :input
34
+ end
35
+ input.use :hint, wrap_with: { tag: 'span', class: 'help-block' }
36
+ input.use :error, wrap_with: { tag: 'span', class: 'help-inline' }
37
+ end
38
+ end
39
+
40
+ # Wrappers for forms and inputs using the Twitter Bootstrap toolkit.
41
+ # Check the Bootstrap docs (http://twitter.github.com/bootstrap)
42
+ # to learn about the different styles for forms and inputs,
43
+ # buttons and other elements.
44
+ config.default_wrapper = :bootstrap
45
+ end
@@ -0,0 +1,26 @@
1
+ # Use this setup block to configure all options available in SimpleForm.
2
+ SimpleForm.setup do |config|
3
+ config.wrappers :foundation, class: :input, hint_class: :field_with_hint, error_class: :error do |b|
4
+ b.use :html5
5
+ b.use :placeholder
6
+ b.optional :maxlength
7
+ b.optional :pattern
8
+ b.optional :min_max
9
+ b.optional :readonly
10
+ b.use :label_input
11
+ b.use :error, wrap_with: { tag: :small }
12
+
13
+ # Uncomment the following line to enable hints. The line is commented out by default since Foundation
14
+ # does't provide styles for hints. You will need to provide your own CSS styles for hints.
15
+ # b.use :hint, wrap_with: { tag: :span, class: :hint }
16
+ end
17
+
18
+ # CSS class for buttons
19
+ config.button_class = 'button'
20
+
21
+ # CSS class to add for error notification helper.
22
+ config.error_notification_class = 'alert-box alert'
23
+
24
+ # The default wrapper to be used by the FormBuilder.
25
+ config.default_wrapper = :foundation
26
+ end
@@ -0,0 +1,26 @@
1
+ en:
2
+ simple_form:
3
+ "yes": 'Yes'
4
+ "no": 'No'
5
+ required:
6
+ text: 'required'
7
+ mark: '*'
8
+ # You can uncomment the line below if you need to overwrite the whole required html.
9
+ # When using html, text and mark won't be used.
10
+ # html: '<abbr title="required">*</abbr>'
11
+ error_notification:
12
+ default_message: "Please review the problems below:"
13
+ # Labels and hints examples
14
+ # labels:
15
+ # defaults:
16
+ # password: 'Password'
17
+ # user:
18
+ # new:
19
+ # email: 'E-mail to sign in.'
20
+ # edit:
21
+ # email: 'E-mail.'
22
+ # hints:
23
+ # defaults:
24
+ # username: 'User name to sign in.'
25
+ # password: 'No special characters, please.'
26
+
@@ -5,25 +5,30 @@ module NextBuses
5
5
  class Request
6
6
  API_URL_STRING = "http://nextbus.mxdata.co.uk/nextbuses/1.0/1"
7
7
 
8
+ attr_accessor :stop_code, :username, :password
9
+
8
10
  def initialize(stop_code, username=nil, password=nil)
9
11
  @stop_code = stop_code
10
12
  @username = username == nil ? NextBuses.configuration.username : username
11
13
  @password = password == nil ? NextBuses.configuration.password : password
12
- @timestamp = Time.now.to_s
13
14
  end
14
15
 
15
16
  def execute
17
+ raise NoStopCodeError, 'A stop_code is required' if @stop_code.nil? || @stop_code.empty?
18
+ raise InvalidCredentialsError, 'A username is required' if @username.nil? || @username.empty?
19
+ raise InvalidCredentialsError, 'A password is required' if @password.nil? || @password.empty?
20
+
16
21
  response = HTTParty.post(API_URL_STRING, basic_auth: auth_hash, body: http_body)
17
22
 
18
23
  services = Array.new
19
24
  response['Siri']['ServiceDelivery']['StopMonitoringDelivery']['MonitoredStopVisit'].each do |visit|
20
- services.push Service.new do |service|
21
- service.vehicle_mode = visit['MonitoredVehicleJourney']['VehicleMode']
22
- service.published_line_name = visit['MonitoredVehicleJourney']['PublishedLineName']
23
- service.direction_name = visit['MonitoredVehicleJourney']['DirectionName']
24
- service.operator_ref = visit['MonitoredVehicleJourney']['OperatorRef']
25
- service.aimed_departure_time = visit['MonitoredVehicleJourney']['MonitoredCall']['AimedDepartureTime']
26
- end
25
+ service = Service.new
26
+ service.vehicle_mode = visit['MonitoredVehicleJourney']['VehicleMode']
27
+ service.published_line_name = visit['MonitoredVehicleJourney']['PublishedLineName']
28
+ service.direction_name = visit['MonitoredVehicleJourney']['DirectionName']
29
+ service.operator_ref = visit['MonitoredVehicleJourney']['OperatorRef']
30
+ service.aimed_departure_time = visit['MonitoredVehicleJourney']['MonitoredCall']['AimedDepartureTime']
31
+ services.push service
27
32
  end
28
33
 
29
34
  services
@@ -36,18 +41,25 @@ module NextBuses
36
41
  end
37
42
 
38
43
  def http_body
44
+ timestamp = Time.now.to_s
39
45
  xml = Builder::XmlMarkup.new(indent: 2)
40
46
  xml.instruct! :xml, version: '1.0', encoding: 'UTF-8', standalone: 'yes'
41
47
  xml.Siri version: '1.0', xmlns: 'http://www.siri.org.uk/' do
42
48
  xml.ServiceRequest do |sr|
43
- sr.RequestTimestamp @timestamp
49
+ sr.RequestTimestamp timestamp
44
50
  sr.RequestorRef @username
45
51
  sr.StopMonitoringRequest version: 1.0 do
46
- sr.RequestTimestamp @timestamp
52
+ sr.RequestTimestamp timestamp
47
53
  sr.MonitoringRef @stop_code
48
54
  end
49
55
  end
50
56
  end
51
57
  end
52
58
  end
59
+
60
+ class NoStopCodeError < StandardError
61
+ end
62
+
63
+ class InvalidCredentialsError < StandardError
64
+ end
53
65
  end
@@ -1,3 +1,3 @@
1
1
  module NextBuses
2
- VERSION = "0.0.6"
2
+ VERSION = "0.1.0"
3
3
  end
data/next_buses.gemspec CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
13
13
  spec.homepage = "http://www.githib.com/cfothergill/next_buses"
14
14
  spec.license = "MIT"
15
15
 
16
- spec.files = `git ls-files`.split($/)
16
+ spec.files = [`git ls-files`.split($/)]
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: next_buses
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Fothergill
@@ -92,6 +92,16 @@ files:
92
92
  - LICENSE.txt
93
93
  - README.md
94
94
  - Rakefile
95
+ - lib/generators/simple_form/USAGE
96
+ - lib/generators/simple_form/install_generator.rb
97
+ - lib/generators/simple_form/templates/README
98
+ - lib/generators/simple_form/templates/_form.html.erb
99
+ - lib/generators/simple_form/templates/_form.html.haml
100
+ - lib/generators/simple_form/templates/_form.html.slim
101
+ - lib/generators/simple_form/templates/config/initializers/simple_form.rb
102
+ - lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb
103
+ - lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb
104
+ - lib/generators/simple_form/templates/config/locales/simple_form.en.yml
95
105
  - lib/next_buses.rb
96
106
  - lib/next_buses/configuration.rb
97
107
  - lib/next_buses/request.rb