colectivero 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in colectivero.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,50 @@
1
+ Copyright (c) 2012 Bruno Bonamin
2
+
3
+ Permission is hereby granted, free of charge, to any
4
+ person obtaining a copy of this software and associated
5
+ documentation files (the "Software"), to deal in the
6
+ Software without restriction, including without limitation
7
+ the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the
9
+ Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice
13
+ shall be included in all copies or substantial portions of
14
+ the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17
+ KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
19
+ PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
20
+ OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+
25
+ ----------------------------------------------------------
26
+
27
+ TRADUCCIÓN NO OFICIAL NI AUTORIZADA PARA SU USO COMO LICENCIA LEGAL
28
+ Copyright (c) 2012 Bruno Bonamin
29
+
30
+ Se autoriza por la presente, de forma gratuita, a cualquier
31
+ persona que haya obtenido una copia de este software y
32
+ archivos asociados de documentación (el "Software"), para tratar en el
33
+ Software sin restricción, incluyendo sin ninguna limitación en lo que concierne
34
+ los derechos para usar, copiar, modificar, fusionar, publicar,
35
+ distribuir, sublicenciar, y / o vender copias de este
36
+ Software, y para permitir a las personas a las que se les proporcione el Software para
37
+ hacer lo mismo, sujeto a las siguientes condiciones:
38
+
39
+ El aviso de copyright anterior y este aviso de permiso
40
+ tendrá que ser incluido en todas las copias o partes sustanciales de
41
+ este Software.
42
+
43
+ EL SOFTWARE SE ENTREGA "TAL CUAL", SIN GARANTÍA DE NINGÚN
44
+ TIPO, EXPRESA O IMPLÍCITA, INCLUYENDO PERO SIN LIMITARSE A GARANTÍAS DE
45
+ MERCANTIBILIDAD, CAPACIDAD DE HACER Y DE NO INFRACCIÓN DE COPYRIGHT. EN NINGÚN
46
+ CASO LOS AUTORES O TITULARES DEL COPYRIGHT SERÁN RESPONSABLES DE
47
+ NINGUNA RECLAMACIÓN, DAÑOS U OTRAS RESPONSABILIDADES,
48
+ YA SEA EN UN LITIGIO, AGRAVIO O DE OTRO MODO,
49
+ DERIVADAS DE, OCASIONADAS POR CULPA DE O EN CONEXION CON EL
50
+ SOFTWARE O SU USO U OTRO TIPO DE ACCIONES EN EL SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,35 @@
1
+ = Colectivero
2
+
3
+ Esta es una API no oficial para consultar el sistema de horarios de llegada de colectivos en la ciudad de Rosario, Argentina; del Ente de Transporte de Rosario.
4
+
5
+ Incluyo un par de ejemplos que detallan su uso.
6
+
7
+ == Instalación
8
+
9
+ La instalación es muy simple desde rubygems:
10
+ gem install colectivero
11
+
12
+ Y hacer un require:
13
+ require 'colectivero'
14
+
15
+ == Uso
16
+ Para conocer la lista de todos los colectivos disponibles:
17
+ Colectivero::Bus.list_all
18
+
19
+ Seleccionando algún elemento de la lista, se puede instanciar un colectivo para poder conocer sus calles e intersecciones para obtener un número de parada:
20
+ bus = Colectivero::Bus.new('153')
21
+ bus.streets
22
+ calle = bus.streets[5]
23
+ intersec = bus.intersections(calle).first
24
+ parada = Colectivero::BusStop.new(bus, calle, intersec)
25
+
26
+ Y finalmente, para consultar la llegada:
27
+ llegada = Colectivero::Arrival.new bus, parada
28
+ llegada.message # => "Linea 153R: 16min. 7434mts"
29
+
30
+ Alternativamente, también se puede consultar la llegada mandando la parada como un entero o un string:
31
+ llegada = Colectivero::Arrival.new bus, '4186'
32
+ llegada = Colectivero::Arrival.new bus, 4186
33
+
34
+ ==Licencia
35
+ Ver el archivo LICENSE para detalles.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "colectivero/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "colectivero"
7
+ s.version = Colectivero::VERSION
8
+ s.authors = ["Bruno Bonamin"]
9
+ s.email = ["bruno@bonamin.org"]
10
+ s.homepage = "http://github.com/bbonamin/colectivero"
11
+ s.summary = %q{API de Cuándo Llega Rosario}
12
+ s.description = %q{API Wrapper para el Cuándo Llega del Ente de Transporte de Rosario}
13
+
14
+ s.add_dependency('mechanize', '>= 1.0.0')
15
+ s.add_dependency('json', '>= 1.6.6')
16
+
17
+ s.add_development_dependency 'rspec', '~> 2.9'
18
+ s.rubyforge_project = "colectivero"
19
+
20
+ s.files = `git ls-files`.split("\n")
21
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
23
+ s.require_paths = ["lib"]
24
+
25
+ # specify any dependencies here; for example:
26
+ # s.add_development_dependency "rspec"
27
+ # s.add_runtime_dependency "rest-client"
28
+ end
@@ -0,0 +1,8 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require "colectivero/version"
3
+ require "colectivero/bus"
4
+ require "colectivero/bus_stop"
5
+ require "colectivero/arrival"
6
+
7
+ module Colectivero
8
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'mechanize'
3
+
4
+ module Colectivero
5
+ class Arrival
6
+ attr_reader :query_date_time, :message
7
+
8
+ def initialize(bus, bus_stop)
9
+ if bus_stop.is_a? Colectivero::BusStop
10
+ bus_stop_number = bus_stop.number
11
+ else
12
+ bus_stop_number = bus_stop.to_s
13
+ end
14
+
15
+ agent = Mechanize.new
16
+ agent.post("http://www.etr.gov.ar/getSmsResponse.php", {"parada" => "#{bus_stop_number}", "linea"=>"#{bus.value}"})
17
+ @message = agent.page.content
18
+ @query_date_time = Time.now
19
+
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,80 @@
1
+ # -*- encoding: utf-8 -*-
2
+ module Colectivero
3
+ class Bus
4
+ BUS_LINES = [ {:name => '101', :line_id => '1,2', :value => '101'},
5
+ {:name => '102', :line_id => '3,4', :value => '102'},
6
+ {:name => '103', :line_id => '5,6', :value => '103'},
7
+ {:name => '110', :line_id => '11', :value => '110'},
8
+ {:name => '112', :line_id=>'12,13', :value => '112'},
9
+ {:name => '113', :line_id => '14', :value => '113'},
10
+ {:name => '115', :line_id => '15', :value => '115'},
11
+ {:name => '116', :line_id => '16', :value => '116'},
12
+ {:name => '120', :line_id => '17', :value => '120'},
13
+ {:name => '121', :line_id => '18', :value => '121'},
14
+ {:name => '122', :line_id=>'19,20', :value => '122'},
15
+ {:name => '123', :line_id => '21', :value => '123'},
16
+ {:name => '125', :line_id => '22', :value => '125'},
17
+ {:name => '126', :line_id=>'23,24', :value => '126'},
18
+ {:name => '127', :line_id => '25', :value => '127'},
19
+ {:name => '128', :line_id=>'26,27', :value => '128'},
20
+ {:name => '129', :line_id => '28', :value => '129'},
21
+ {:name => '130', :line_id => '29', :value => '130'},
22
+ {:name => '131', :line_id => '30', :value => '131'},
23
+ {:name => '132', :line_id => '31', :value => '132'},
24
+ {:name => '133', :line_id=>'32,33', :value => '133'},
25
+ {:name => '134', :line_id => '34', :value => '134'},
26
+ {:name => '135', :line_id => '35', :value => '135'},
27
+ {:name => '136', :line_id => '36', :value => '136'},
28
+ {:name => '137', :line_id => '37', :value => '137'},
29
+ {:name => '138', :line_id=>'38,39', :value => '138'},
30
+ {:name => '139', :line_id=>'40,41', :value => '139'},
31
+ {:name => '140', :line_id => '43', :value => '140'},
32
+ {:name => '141', :line_id => '44', :value => '141'},
33
+ {:name => '142', :line_id => '45,46,47', :value => '142'},
34
+ {:name => '143', :line_id => '48,49', :value => '143'},
35
+ {:name => '144', :line_id => '50,51', :value => '144'},
36
+ {:name => '145', :line_id => '52,53', :value => '145'},
37
+ {:name => '146', :line_id => '54,55', :value => '146'},
38
+ {:name => '153', :line_id => '56,57,58', :value => '153'},
39
+ {:name => 'K', :line_id => '64', :value => 'K'},
40
+ {:name => 'Linea de la Costa', :line_id => '65', :value => 'LC'},
41
+ {:name => 'Ronda del Centro', :line_id => '66', :value => 'RC'} ]
42
+
43
+ attr_reader :name, :line_id, :value, :streets
44
+ def initialize bus_name
45
+ bus = BUS_LINES.select { |bus| bus[:name] == bus_name.to_s }.first
46
+ if bus.nil?
47
+ raise 'Nombre de colectivo no válido'
48
+ else
49
+ @name = bus[:name]
50
+ @line_id = bus[:line_id]
51
+ @value = bus[:value]
52
+
53
+ agent = Mechanize.new
54
+ agent.get("http://www.etr.gov.ar/getData.php?accion=getCalle&idLinea=#{line_id}")
55
+ @streets = JSON(agent.page.content)
56
+ end
57
+ end
58
+
59
+ def self.list_all
60
+ buses = []
61
+ BUS_LINES.each do |bus|
62
+ buses << bus[:name]
63
+ end
64
+ buses
65
+ end
66
+
67
+ def intersections(street)
68
+ agent = Mechanize.new
69
+ agent.get("http://www.etr.gov.ar/getData.php?accion=getInterseccion&idLinea=#{line_id}&idCalle=#{street['id']}")
70
+ JSON(agent.page.content)
71
+ end
72
+
73
+ # private
74
+ # def get_streets
75
+ # agent = Mechanize.new
76
+ # agent.get("http://www.etr.gov.ar/getData.php?accion=getCalle&idLinea=#{line_id}")
77
+ # JSON(agent.page.content)
78
+ # end
79
+ end
80
+ end
@@ -0,0 +1,15 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'mechanize'
3
+ require 'json'
4
+
5
+ module Colectivero
6
+ class BusStop
7
+
8
+ attr_reader :number
9
+ def initialize(bus,street,intersection)
10
+ agent = Mechanize.new
11
+ agent.get("http://www.etr.gov.ar/getData.php?accion=getInfoParadas&idLinea=#{bus.line_id}&idCalle=#{street['id']}&idInt=#{intersection['id']}")
12
+ @number = agent.page.links.first.text
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module Colectivero
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Arrival' do
4
+ it 'should return a string when called with object parameters' do
5
+ bus = Colectivero::Bus.new('110')
6
+ street = bus.streets.first
7
+ intersection = bus.intersections(street).first
8
+ bus_stop = Colectivero::BusStop.new(bus, street, intersection)
9
+
10
+ arrival = Colectivero::Arrival.new bus, bus_stop
11
+ arrival.message.should_not match "Disculpe\\*"
12
+ end
13
+
14
+ it 'should return a string when called with a bus stop number' do
15
+ bus = Colectivero::Bus.new('110')
16
+ valid_bus_stop = 7969
17
+
18
+ arrival = Colectivero::Arrival.new bus, valid_bus_stop
19
+ arrival.message.should_not match "Disculpe\\*"
20
+ end
21
+
22
+ it 'should return a Disculpe message when called with an invalid bus stop' do
23
+ bus = Colectivero::Bus.new('110')
24
+ street = bus.streets.first
25
+ intersection = bus.intersections(street).first
26
+ bus_stop = Colectivero::BusStop.new(bus, street, intersection)
27
+
28
+ arrival = Colectivero::Arrival.new bus, 9191
29
+ arrival.message.should match("Disculpe(.*)")
30
+ end
31
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Bus' do
4
+ before(:each) do
5
+ @bus = Colectivero::Bus.new('110')
6
+ end
7
+
8
+ context 'with a valid name' do
9
+ it 'should have an id' do
10
+ @bus.line_id.should_not be_nil
11
+ end
12
+
13
+ it 'should have a name' do
14
+ @bus.name.should_not be_nil
15
+ end
16
+
17
+ it 'should have a value' do
18
+ @bus.value.should_not be_nil
19
+ end
20
+ end
21
+
22
+ context 'with an invalid name' do
23
+ it 'should be raise an error' do
24
+ expect { Colectivero::Bus.new('xxx') }.should raise_error
25
+ end
26
+ end
27
+
28
+ it 'should have many streets' do
29
+ @bus.streets.should_not be_empty
30
+ end
31
+
32
+ context 'with a street as parameter' do
33
+ it 'should have many intersections' do
34
+ street = @bus.streets.first
35
+ @bus.intersections(street).should_not be_empty
36
+ end
37
+ end
38
+
39
+ it 'should raise an error when calling intersections without params' do
40
+ expect { @bus.intersections }.should raise_error
41
+ end
42
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'BusStop' do
4
+ it 'should return a bus_stop number when called with the correct parameters' do
5
+ bus = Colectivero::Bus.new('110')
6
+ street = bus.streets.first
7
+ intersection = bus.intersections(street).first
8
+ bus_stop = Colectivero::BusStop.new(bus, street, intersection)
9
+
10
+ bus_stop.should_not be_nil
11
+ end
12
+
13
+ it 'should return an error when called with no parameters' do
14
+ expect { Colectivero::BusStop.new}.should raise_error
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper.rb"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ Dir["../colectivero/lib/*.rb"].each {|file| require file }
8
+ require 'pry'
9
+
10
+ RSpec.configure do |config|
11
+ config.treat_symbols_as_metadata_keys_with_true_values = true
12
+ config.run_all_when_everything_filtered = true
13
+ config.filter_run :focus
14
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: colectivero
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Bruno Bonamin
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-27 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mechanize
16
+ requirement: &70176595056820 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70176595056820
25
+ - !ruby/object:Gem::Dependency
26
+ name: json
27
+ requirement: &70176595056300 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 1.6.6
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70176595056300
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &70176595044340 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '2.9'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70176595044340
47
+ description: API Wrapper para el Cuándo Llega del Ente de Transporte de Rosario
48
+ email:
49
+ - bruno@bonamin.org
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - .rspec
56
+ - Gemfile
57
+ - LICENSE
58
+ - README.rdoc
59
+ - Rakefile
60
+ - colectivero.gemspec
61
+ - lib/colectivero.rb
62
+ - lib/colectivero/arrival.rb
63
+ - lib/colectivero/bus.rb
64
+ - lib/colectivero/bus_stop.rb
65
+ - lib/colectivero/version.rb
66
+ - spec/colectivero/arrival_spec.rb
67
+ - spec/colectivero/bus_spec.rb
68
+ - spec/colectivero/bus_stop_spec.rb
69
+ - spec/spec_helper.rb
70
+ homepage: http://github.com/bbonamin/colectivero
71
+ licenses: []
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project: colectivero
90
+ rubygems_version: 1.8.10
91
+ signing_key:
92
+ specification_version: 3
93
+ summary: API de Cuándo Llega Rosario
94
+ test_files:
95
+ - spec/colectivero/arrival_spec.rb
96
+ - spec/colectivero/bus_spec.rb
97
+ - spec/colectivero/bus_stop_spec.rb
98
+ - spec/spec_helper.rb