drivenow 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md ADDED
File without changes
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2011 Simon Woker
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,53 @@
1
+ module Drivenow
2
+ class Agent
3
+ require 'open-uri'
4
+ require 'json'
5
+ $KCODE = "U"
6
+
7
+ attr_reader :cars
8
+
9
+ # Creates a new instance of the Drivenow::Agent.
10
+ # options:
11
+ # :city => The City you want to get all for. e.g. :berlin
12
+ # :uri => The URI can be changed in case you want to test locally or anything else
13
+ #--
14
+ # TODO: Option for the Xpath for cars-array inside the JSON
15
+ def initialize(options = {})
16
+ options = { :uri => 'https://www.drive-now.com/php/metropolis/vehicle_filter' }.merge(options)
17
+ cities = Agent.cities
18
+
19
+ page = open(options[:uri]).read
20
+ cars = JSON(page)["rec"]["vehicles"]["vehicles"]
21
+ unless options[:city].nil?
22
+ cars = cars.select { |item| item["cit"] == cities[options[:city]] }
23
+ end
24
+ cities = cities.invert
25
+ cars.each { |item| item["cit"] = cities[item["cit"]] }
26
+ cars.map! { |item| Car.new(item) }
27
+ @cars = cars
28
+ end
29
+
30
+ def inspect
31
+ @cars.inspect
32
+ end
33
+
34
+ # Gets all cities that are available at the moment, currently
35
+ # * Berlin
36
+ # * Düsseldorf
37
+ # * München
38
+ # * Unterhaching (part of M�nchen)
39
+ # Can easily be overridden if there are more cities available in the future
40
+ #--
41
+ # TODO: Unterhaching, Oberding and Korschenbroich are part of other cities... needs to be an array instead of one string
42
+ def self.cities
43
+ {
44
+ :duesseldorf => "1293",
45
+ :berlin => "6099",
46
+ :muenchen => "4604",
47
+ #:unterhaching => "7590",
48
+ #:oberding => "7591",
49
+ #:korschenbroich => "1294"
50
+ }
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,81 @@
1
+ module Drivenow
2
+ class Car
3
+ attr_reader :json
4
+
5
+ # initialize a new Car from a Hash that's returned from the drive-now API.
6
+ # Example:
7
+ # {"position":{
8
+ # "latitude":"48.164372777778",
9
+ # "longitude":"11.594320833333",
10
+ # "address":"Biedersteiner Straße 29, 80802 München"},
11
+ # "auto":"N",
12
+ # "carName":"Barbi",
13
+ # "cit":"4604",
14
+ # "color":"MIDNIGHT BLACK",
15
+ # "fuelState":"40",
16
+ # "group":"MINI",
17
+ # "innerCleanliness":"CLEAN",
18
+ # "licensePlate":"M -I 7396",
19
+ # "model":"MINI Cooper",
20
+ # "personalName":"MINI Cooper: Barbi"}
21
+ def initialize(hash)
22
+ raise ArgumentError, 'hash must be a valid Hash with keys' if hash.nil? || hash.class != {}.class || hash.keys.count == 0
23
+
24
+ @json = hash
25
+ end
26
+
27
+ # Gets the personal Name and color of the car
28
+ # Example: "MINI Cooper: Barbi (MIDNIGHT BLACK)"
29
+ def name
30
+ @name ||= "#{json['personalName']} (#{color})"
31
+ end
32
+
33
+ # Gets the current address
34
+ # Example: "Biedersteiner Straße 29, 80802 München"
35
+ def address
36
+ @address ||= json['position']['address']
37
+ end
38
+
39
+ # Gets if it's an automatic car or manual
40
+ def automatic?
41
+ @automatic ||= json['auto'] == 'Y'
42
+ end
43
+
44
+ def color
45
+ @color ||= json['color'].capitalize
46
+ end
47
+
48
+ # Gets the car's city
49
+ # Example: "Berlin"
50
+ def city
51
+ @city ||= json["cit"].to_s.capitalize
52
+ end
53
+
54
+ # Gets the car's license plate (e.g. "M-I 7396")
55
+ def license_plate
56
+ @license ||= json['licensePlate'].gsub(' ', '')
57
+ end
58
+
59
+ # Gets the car's model (e.g. "MINI COOPER")
60
+ def model
61
+ @model ||= json['model']
62
+ end
63
+
64
+ # Gets the car's current position
65
+ # Example: {:latitude => '00.0000', :longitude => '00.000', :address => 'Musterstraße 01234 Berlin'}
66
+ def position
67
+ @position ||= json['position']
68
+ end
69
+
70
+ # Gets the car's fuel state in percent
71
+ # Example: "40%"
72
+ def fuel_state
73
+ @fuel_state ||= "#{json['fuelState']}%"
74
+ end
75
+
76
+ # Gets the car's cleanliness state. "CLEAN" normally
77
+ def clean
78
+ @clean ||= json['innerCleanliness']
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,3 @@
1
+ module Drivenow
2
+ VERSION = "0.1.0"
3
+ end
data/lib/drivenow.rb ADDED
@@ -0,0 +1,3 @@
1
+ $KCODE = 'U'
2
+ require 'drivenow/drivenow_car'
3
+ require 'drivenow/drivenow_agent'
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: drivenow
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Simon Woker
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-03-11 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: json
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 1
31
+ - 6
32
+ version: "1.6"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rake
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :development
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: rspec
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ hash: 19
58
+ segments:
59
+ - 2
60
+ - 8
61
+ version: "2.8"
62
+ type: :development
63
+ version_requirements: *id003
64
+ description: Wraps the DriveNow JSON to use it nicely in your own environment. You can use this Gem to read all cars that are available.
65
+ email: stastny@101ideas.cz
66
+ executables: []
67
+
68
+ extensions: []
69
+
70
+ extra_rdoc_files: []
71
+
72
+ files:
73
+ - lib/drivenow.rb
74
+ - lib/drivenow/drivenow_car.rb
75
+ - lib/drivenow/version.rb
76
+ - lib/drivenow/drivenow_agent.rb
77
+ - LICENSE
78
+ - CHANGELOG.md
79
+ homepage: https://github.com/swoker/DriveNow-Wrapper
80
+ licenses: []
81
+
82
+ post_install_message:
83
+ rdoc_options: []
84
+
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ hash: 3
93
+ segments:
94
+ - 0
95
+ version: "0"
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ hash: 23
102
+ segments:
103
+ - 1
104
+ - 3
105
+ - 6
106
+ version: 1.3.6
107
+ requirements: []
108
+
109
+ rubyforge_project:
110
+ rubygems_version: 1.8.17
111
+ signing_key:
112
+ specification_version: 3
113
+ summary: Wrapper for the DriveNow API
114
+ test_files: []
115
+