diMLOrb 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec", "~> 2.3.0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.5.2"
12
+ gem "rcov", ">= 0"
13
+ end
14
+
15
+ gem 'nokogiri'
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 ariera
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = diMLOrb
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to diMLOrb
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 ariera. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,52 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "diMLOrb"
16
+ gem.homepage = "http://github.com/ariera/diMLOrb"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Ruby API for the diMLO web timetable service}
19
+ gem.description = %Q{This gem acts as an API to the MLO (Metro Ligero Oeste) public transportation of Madrid, allowing the user get ETA of the next 2 trains}
20
+ gem.email = "ariera@gmail.com"
21
+ gem.authors = ["ariera"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ gem.add_runtime_dependency 'nokogiri'
27
+ gem.add_development_dependency 'rspec', '~> 2.3.0'
28
+ end
29
+ Jeweler::RubygemsDotOrgTasks.new
30
+
31
+ require 'rspec/core'
32
+ require 'rspec/core/rake_task'
33
+ RSpec::Core::RakeTask.new(:spec) do |spec|
34
+ spec.pattern = FileList['spec/**/*_spec.rb']
35
+ end
36
+
37
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
38
+ spec.pattern = 'spec/**/*_spec.rb'
39
+ spec.rcov = true
40
+ end
41
+
42
+ task :default => :spec
43
+
44
+ require 'rake/rdoctask'
45
+ Rake::RDocTask.new do |rdoc|
46
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
47
+
48
+ rdoc.rdoc_dir = 'rdoc'
49
+ rdoc.title = "diMLOrb #{version}"
50
+ rdoc.rdoc_files.include('README*')
51
+ rdoc.rdoc_files.include('lib/**/*.rb')
52
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
data/lib/diMLOrb.rb ADDED
@@ -0,0 +1,78 @@
1
+ # encoding: UTF-8
2
+ require 'net/http'
3
+ require 'uri'
4
+ require 'nokogiri'
5
+
6
+ module DiMLOrb
7
+ class DiMLOrb
8
+ STATIONS = {:colonia_jardin => "Colonia Jardín|ECJ|ML2", :somosaguas_sur => "Somosaguas Sur|SSU|ML2"}
9
+ attr_accessor :uri, :http, :html, :viewstate, :eventvalidation, :proximo, :siguiente, :cookie, :data, :duracion, :from, :to
10
+ def initialize(from = STATIONS[:colonia_jardin], to = STATIONS[:somosaguas_sur])
11
+ @from, @to = from, to
12
+ @uri = URI.parse("http://www.dimlo.es/Informate/calc.aspx")
13
+ @http = Net::HTTP.new(@uri.host, @uri.port)
14
+ get_validations
15
+ get_times
16
+ end
17
+
18
+ def get_validations
19
+ resp = @http.get(@uri.path)
20
+ raise "HTTP Error: #{resp.code}" if resp.code.to_i != 200
21
+
22
+ @cookie = resp.response['set-cookie'].split('; ')[0]
23
+ doc = Nokogiri::HTML(resp.body)
24
+ @viewstate = doc.css('#__VIEWSTATE').attr('value').value
25
+ @eventvalidation = doc.css('#__EVENTVALIDATION').attr('value').value
26
+ end
27
+
28
+ def get_times
29
+ #@html = Net::HTTP.post_form(@uri, options)
30
+ req = Net::HTTP::Post.new(@uri.request_uri)
31
+ req.form_data = options
32
+ headers.each{ |k,v| req[k] = v }
33
+ @html = @http.start {|http| http.request(req) }
34
+ doc = Nokogiri::HTML(@html.body)
35
+ @proximo = doc.css('#ProximoTXT').inner_text
36
+ @siguiente = doc.css('#SiguienteTXT').inner_text
37
+ @duracion = doc.css('#DuracionTXT').inner_text
38
+ end
39
+
40
+ def options
41
+ {
42
+ 'origenDDL' => @from,
43
+ 'destinoDDL' => @to,
44
+ '__EVENTVALIDATION' => @eventvalidation,
45
+ '__VIEWSTATE' => @viewstate,
46
+ 'btnCalcular.x' => '48',
47
+ 'btnCalcular.y' =>'5'
48
+ }
49
+ end
50
+ def headers
51
+ {
52
+ 'Cookie' => @cookie,
53
+ 'Host' => "www.dimlo.es",
54
+ 'User-Agent' => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0) Gecko/20100101 Firefox/4.0",
55
+ # 'Accept' => "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
56
+ # 'Accept-Language' => "es-es,es;q=0.8,en-us;q=0.5,en;q=0.3",
57
+ # 'Accept-Encoding' => "gzip, deflate",
58
+ # 'Accept-Charset' => "ISO-8859-1,utf-8;q=0.7,*;q=0.7",
59
+ # 'Keep-Alive' => "115",
60
+ # 'Connection' => 'keep-alive',
61
+ 'Referer' => 'http://www.dimlo.es/Informate/calc.aspx'}
62
+ end
63
+
64
+ def to_file(file_name = 'dimlo.html')
65
+ f = File.new(file_name, "w+")
66
+ f.puts @html
67
+ `open #{file_name}`
68
+ end
69
+
70
+ def from
71
+ @from.split("|").first
72
+ end
73
+
74
+ def to
75
+ @to.split("|").first
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Dimlorb" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'diMLOrb'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,183 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: diMLOrb
3
+ version: !ruby/object:Gem::Version
4
+ hash: 31
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 0
10
+ version: 0.0.0
11
+ platform: ruby
12
+ authors:
13
+ - ariera
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-07-17 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ prerelease: false
23
+ type: :runtime
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ name: nokogiri
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ prerelease: false
37
+ type: :development
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 2
46
+ - 3
47
+ - 0
48
+ version: 2.3.0
49
+ name: rspec
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ prerelease: false
53
+ type: :development
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ hash: 23
60
+ segments:
61
+ - 1
62
+ - 0
63
+ - 0
64
+ version: 1.0.0
65
+ name: bundler
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ prerelease: false
69
+ type: :development
70
+ requirement: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ hash: 7
76
+ segments:
77
+ - 1
78
+ - 5
79
+ - 2
80
+ version: 1.5.2
81
+ name: jeweler
82
+ version_requirements: *id004
83
+ - !ruby/object:Gem::Dependency
84
+ prerelease: false
85
+ type: :development
86
+ requirement: &id005 !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ hash: 3
92
+ segments:
93
+ - 0
94
+ version: "0"
95
+ name: rcov
96
+ version_requirements: *id005
97
+ - !ruby/object:Gem::Dependency
98
+ prerelease: false
99
+ type: :runtime
100
+ requirement: &id006 !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ hash: 3
106
+ segments:
107
+ - 0
108
+ version: "0"
109
+ name: nokogiri
110
+ version_requirements: *id006
111
+ - !ruby/object:Gem::Dependency
112
+ prerelease: false
113
+ type: :development
114
+ requirement: &id007 !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ~>
118
+ - !ruby/object:Gem::Version
119
+ hash: 3
120
+ segments:
121
+ - 2
122
+ - 3
123
+ - 0
124
+ version: 2.3.0
125
+ name: rspec
126
+ version_requirements: *id007
127
+ description: This gem acts as an API to the MLO (Metro Ligero Oeste) public transportation of Madrid, allowing the user get ETA of the next 2 trains
128
+ email: ariera@gmail.com
129
+ executables: []
130
+
131
+ extensions: []
132
+
133
+ extra_rdoc_files:
134
+ - LICENSE.txt
135
+ - README.rdoc
136
+ files:
137
+ - .document
138
+ - .rspec
139
+ - Gemfile
140
+ - LICENSE.txt
141
+ - README.rdoc
142
+ - Rakefile
143
+ - VERSION
144
+ - lib/diMLOrb.rb
145
+ - spec/diMLOrb_spec.rb
146
+ - spec/spec_helper.rb
147
+ has_rdoc: true
148
+ homepage: http://github.com/ariera/diMLOrb
149
+ licenses:
150
+ - MIT
151
+ post_install_message:
152
+ rdoc_options: []
153
+
154
+ require_paths:
155
+ - lib
156
+ required_ruby_version: !ruby/object:Gem::Requirement
157
+ none: false
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ hash: 3
162
+ segments:
163
+ - 0
164
+ version: "0"
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
166
+ none: false
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ hash: 3
171
+ segments:
172
+ - 0
173
+ version: "0"
174
+ requirements: []
175
+
176
+ rubyforge_project:
177
+ rubygems_version: 1.6.2
178
+ signing_key:
179
+ specification_version: 3
180
+ summary: Ruby API for the diMLO web timetable service
181
+ test_files:
182
+ - spec/diMLOrb_spec.rb
183
+ - spec/spec_helper.rb