multicity 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,17 +5,37 @@ module Multicity
5
5
  :url_list => 'https://kunden.multicity-carsharing.de/kundenbuchung/hal2ajax_process.php?zoom=10&lng1=&lat1=&lng2=&lat2=&stadtCache=&mapstation_id=&mapstadt_id=&verwaltungfirma=&centerLng=13.382322739257802&centerLat=52.50734843957503&searchmode=buchanfrage&with_staedte=false&buchungsanfrage=N&lat=52.50734843957503&lng=13.382322739257802&instant_access=J&open_end=J&objectname=multicitymarker&ignore_virtual_stations=J&before=null&after=null&ajxmod=hal2map&callee=getMarker',
6
6
  :url_area => 'https://www.multicity-carsharing.de/wp-content/plugins/multicity_map/geschaeftsbereich.kml'
7
7
  }
8
-
9
- def get_cars
10
- agent = Mechanize.new
11
-
12
- data = agent.get(@@options[:url_list], headers).body
8
+
9
+ def initialize
10
+ @agent = Mechanize.new
11
+ end
12
+
13
+ # Gets all cars in Berlin
14
+ # Returns an array of Multicity:Car
15
+ def get_cars
16
+ data = @agent.get(@@options[:url_list], headers).body
13
17
  marker = data.scan(/"marker":\[(.*?)\],"/).first
14
18
  marker = marker.to_s.gsub(' ', ' ')
15
19
  marker = JSON.parse("[#{marker}]")
16
20
  marker.map { |item| Car.new(item) }
17
21
  end
18
22
 
23
+ # Gets the Operation Area for Berlin
24
+ # Returns an Array of coordinate-Arrays that creates a Polygon
25
+ # Example: [ [13.405852,52.464874], [13.425508,52.466625], ... ]
26
+ def get_operation_area
27
+ data = @agent.get(@@options[:url_area], headers).body
28
+ data = XmlSimple.xml_in(data)
29
+ coordinates = data["Document"].first["Placemark"].first["Polygon"].first["outerBoundaryIs"].first["LinearRing"].first["coordinates"].first
30
+ coords = []
31
+ coordinates.strip.split("\n").each do |coordinate|
32
+ coordinate = coordinate.split ","
33
+ coords << [ coordinate[0].to_f, coordinate[1].to_f ]
34
+ end
35
+
36
+ coords
37
+ end
38
+
19
39
  private
20
40
 
21
41
  def headers
@@ -1,25 +1,55 @@
1
1
  module Multicity
2
+ # Multicity Car represents a has these attributes
3
+ # * position: Hash with Keys :lat and :lon with the coordinates
4
+ # * license_plate: License plate, e.g. B-MC 1234
5
+ # * id: internal id
6
+ # * model: normally "Citroen C-Zero"
2
7
  class Car
3
8
  attr_reader :json
4
9
  attr_accessor :position, :license_plate, :id, :model
5
10
 
11
+ # Creates a new Car object. The hash can be set to a value from the Multicity-API.
12
+ # If the hash is nil, the car will not have any data
6
13
  # Example hash
7
- # {"lat"=>"52.5359483", "hal2option"=>{"mouseout"=>"hideToolTip", "maxZoom"=>"", "clustername"=>"multicitycluster", "click"=>"showMarkerInfos", "id"=>"284964", "minZoom"=>"4", "tooltip"=>"'Citroën C-Zero (B-MC 1694)'", "bende"=>"1359122400", "StationInfoTyp"=>"HM_AUTO_INFO", "rclick"=>false, "dblclick"=>false, "objecttyp"=>"carpos", "objectname"=>"multicitymarker", "draggable"=>false, "mouseover"=>"showToolTip", "openinfo"=>"showMarkerInfos", "banfang"=>"1359118800"}, "iconName"=>"carIcon", "iconNameSelected"=>"carIconSelected", "lng"=>"13.4432250"}
8
- def initialize hash
14
+ # {
15
+ # "lat" => "52.5359483",
16
+ # "iconName" => "carIcon",
17
+ # "iconNameSelected" => "carIconSelected",
18
+ # "lng" => "13.4432250",
19
+ # "hal2option" => {
20
+ # "mouseout" => "hideToolTip",
21
+ # "maxZoom" => "",
22
+ # "clustername" => "multicitycluster",
23
+ # "click" => "showMarkerInfos",
24
+ # "id" => "284964",
25
+ # "minZoom" => "4",
26
+ # "tooltip" => "'Citroën C-Zero (B-MC 1694)'",
27
+ # "bende" => "1359122400",
28
+ # "StationInfoTyp" => "HM_AUTO_INFO",
29
+ # "rclick" => false,
30
+ # "dblclick" => false,
31
+ # "objecttyp" => "carpos",
32
+ # "objectname" => "multicitymarker",
33
+ # "draggable" => false,
34
+ # "mouseover" => "showToolTip",
35
+ # "openinfo" => "showMarkerInfos",
36
+ # "banfang" => "1359118800"
37
+ # }
38
+ # }
39
+ def initialize hash = nil
9
40
  @json = hash
10
-
11
- tooltip = json["hal2option"]["tooltip"].gsub "'", ""
12
- if tooltip != "false"
13
- self.position = { :lat => json["lat"], :lon => json["lng"] }
14
- self.id = json["hal2option"]["id"]
15
- tips = tooltip.split(" ")
16
- if (tips.count == 2)
17
- self.model = tips[0]
18
- self.license_plate = tips[1].to_s.gsub("(", "").gsub(")", "")
19
- else
20
- self.model = "Citroën C-Zero"
41
+ unless hash.nil?
42
+ tooltip = json["hal2option"]["tooltip"].gsub "'", ""
43
+ if tooltip != "false"
44
+ self.position = { :lat => json["lat"], :lon => json["lng"] }
45
+ self.id = json["hal2option"]["id"]
46
+ tips = tooltip.split(" ")
47
+ if (tips.count == 2)
48
+ self.model = tips[0]
49
+ self.license_plate = tips[1].to_s.gsub("(", "").gsub(")", "")
50
+ end
21
51
  end
22
- end
52
+ end
23
53
  end
24
54
  end
25
55
  end
@@ -1,3 +1,3 @@
1
1
  module Multicity
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
data/lib/multicity.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'mechanize'
3
3
  require 'json'
4
+ require 'xmlsimple'
4
5
 
5
6
  require 'multicity/multicity_car'
6
7
  require 'multicity/multicity_agent'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multicity
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
+ - 1
8
9
  - 0
9
- - 0
10
- version: 1.0.0
10
+ version: 1.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Simon Woker
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-01-25 00:00:00 Z
18
+ date: 2013-01-28 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  prerelease: false
@@ -48,7 +48,7 @@ dependencies:
48
48
  type: :runtime
49
49
  - !ruby/object:Gem::Dependency
50
50
  prerelease: false
51
- name: rake
51
+ name: xml-simple
52
52
  version_requirements: &id003 !ruby/object:Gem::Requirement
53
53
  none: false
54
54
  requirements:
@@ -59,6 +59,20 @@ dependencies:
59
59
  - 0
60
60
  version: "0"
61
61
  requirement: *id003
62
+ type: :runtime
63
+ - !ruby/object:Gem::Dependency
64
+ prerelease: false
65
+ name: rake
66
+ version_requirements: &id004 !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ requirement: *id004
62
76
  type: :development
63
77
  description: Wraps the Multicity JSON to use it nicely in your own environment. You can use this Gem to read all cars that are available.
64
78
  email: github@simonwoker.de