multicity 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6e4451487126120de05aac29c91a0ee2e87cc2e9
4
+ data.tar.gz: c69226cbb56a34e4a1dff833bd97489790d4ba04
5
+ SHA512:
6
+ metadata.gz: 1464e6127f64d88b1c3f018872e467d655435fb546569097c32208de098220ec4fd1bd985cc1090509a433c1fe36d506af40b25171af9ad9099ffbbf46969959
7
+ data.tar.gz: aec034fa1d2ac2725ed1a09cdff4efe19dd9d27dbeeab45f86d0433f97af90a44a3ef0c56c2bc896e761e92cde117434e4ae50133aa51ff1c48801c037854582
data/CHANGELOG.md CHANGED
@@ -0,0 +1,6 @@
1
+ 1.4.0
2
+ ====
3
+
4
+ - Area of Operation fix => new url
5
+ - new prices
6
+ - corrected headers on get request
data/README.md CHANGED
@@ -23,6 +23,8 @@ Example
23
23
  # get operation area
24
24
  agent.get_operation_area # => array of lat/lon coordinates "[[52.464874, 13.405852], [52.466625, 13.425508], [52.467854, 13.435678],...]"
25
25
 
26
+ # get loading spots
27
+ agent.get_loading_spots
26
28
 
27
29
  Contribute
28
30
  =
@@ -1,88 +1,87 @@
1
1
  module Multicity
2
- class Agent
3
-
4
- @@options = {
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
- :url_area => 'https://www.multicity-carsharing.de/wp-content/plugins/multicity_map/geschaeftsbereich.kml',
7
- :url_load_stations => 'https://www.multicity-carsharing.de/rwe/json.php'
8
- }
9
-
10
- # Set the user agent
11
- def self.user_agent=val
12
- @@user_agent = val
13
- end
14
-
15
- def initialize
16
- @agent = Mechanize.new
17
- @agent.user_agent = @@user_agent ||= "Multicity Rubygem"
18
- end
19
-
20
- # Gets all cars in Berlin
21
- # Returns an array of Multicity:Car
22
- def get_cars
23
- data = @agent.get(@@options[:url_list], headers).body
24
- marker = data.scan(/"marker":\[(.*?)\],"/).first.join
25
- marker = marker.to_s.gsub(' ', ' ')
26
- marker = JSON.parse("[#{marker}]")
27
- marker.map! { |item| Car.new(item) }
28
- marker.select { |item| item.valid? }
29
- end
30
-
31
- # Gets the Operation Area for Berlin
32
- # Returns an Array of coordinate-Arrays that creates a Polygon
33
- # Example: [ [13.405852,52.464874], [13.425508,52.466625], ... ]
34
- def get_operation_area
35
- data = @agent.get(@@options[:url_area], headers).body
36
- data = XmlSimple.xml_in(data)
37
- coordinates = data["Document"].first["Placemark"].first["Polygon"].first["outerBoundaryIs"].first["LinearRing"].first["coordinates"].first
38
- coords = []
39
- coordinates.strip.split("\n").each do |coordinate|
40
- coordinate = coordinate.split ","
41
- coords << [ coordinate[1].to_f, coordinate[0].to_f ]
42
- end
43
-
44
- coords
45
- end
46
-
47
- def get_loading_spots
48
- data = @agent.get(@@options[:url_load_stations]).body
49
- data = encode data
50
- marker = JSON.parse(data)
51
- marker["marker"].map! {|item| Spot.new(item)}
52
- end
53
-
54
- def self.price duration, rate = :starter
55
- duration = duration.to_f
56
- rate = rate == :vielnutzer ? 2.0 : 2.5
57
- if duration > 1440.0
58
- price = (duration / 1440.0).floor * 39.00
59
- price += (duration % 1440.0) / 10.0 * rate
60
- else
61
- price = (duration / 10.0).ceil * rate
62
- end
63
-
64
- {:price => price.to_f.round(2), :unit => 'EUR', :rate => rate }
65
- end
66
-
67
- private
68
-
69
- def headers
70
- {
71
- "content-type" => "application/x-www-form-urlencoded;charset=utf-8",
72
- "accept-charset" => "utf-8"
73
- }
74
- end
75
-
76
- #######################################################
77
- private
78
- #######################################################
79
-
80
- def encode str
81
- if str.respond_to? :encode
82
- str.force_encoding("iso-8859-1").encode("utf-8")
83
- else
84
- Iconv.conv("utf-8", "iso-8859-1", str)
85
- end
86
- end
87
- end
2
+ class Agent
3
+
4
+ @@options = {
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
+ :url_area => 'https://www.multicity-carsharing.de/wp-content/plugins/multicity_map/geschaeftsbereich_neu.kml',
7
+ :url_load_stations => 'https://www.multicity-carsharing.de/rwe/json.php'
8
+ }
9
+
10
+ # Set the user agent
11
+ def self.user_agent=val
12
+ @@user_agent = val
13
+ end
14
+
15
+ def initialize
16
+ @agent = Mechanize.new
17
+ @agent.user_agent = @@user_agent ||= "Multicity Rubygem"
18
+ end
19
+
20
+ # Gets all cars in Berlin
21
+ # Returns an array of Multicity:Car
22
+ def get_cars
23
+ data = @agent.get(@@options[:url_list], {}, nil, headers).body
24
+ marker = data.scan(/"marker":\[(.*?)\],"/).first.join
25
+ marker = marker.to_s.gsub('&nbsp;', ' ')
26
+ marker = JSON.parse("[#{marker}]")
27
+ marker.map! { |item| Car.new(item) }
28
+ marker.select { |item| item.valid? }
29
+ end
30
+
31
+ # Gets the Operation Area for Berlin
32
+ # Returns an Array of coordinate-Arrays that creates a Polygon
33
+ # Example: [ [13.405852,52.464874], [13.425508,52.466625], ... ]
34
+ def get_operation_area
35
+ data = @agent.get(@@options[:url_area], {}, nil, headers).body
36
+ data = XmlSimple.xml_in(data)
37
+ coordinates = data["Document"].first["Placemark"].first["Polygon"].first["outerBoundaryIs"].first["LinearRing"].first["coordinates"].first
38
+ coords = []
39
+ coordinates.strip.split("\n").each do |coordinate|
40
+ coordinate = coordinate.split ","
41
+ coords << [ coordinate[1].to_f, coordinate[0].to_f ]
42
+ end
43
+
44
+ coords
45
+ end
46
+
47
+ def get_loading_spots
48
+ data = @agent.get(@@options[:url_load_stations], {}, nil, headers).body
49
+ data = encode data
50
+ marker = JSON.parse(data)
51
+ marker["marker"].map! {|item| Spot.new(item)}
52
+ end
53
+
54
+ def self.price minutes
55
+ price = minutes.to_f * 0.28
56
+ price = 39.0 if price > 39.0 && minutes < 1440
57
+
58
+ if minutes > 1440
59
+ price = 39.0 * (minutes/1440)
60
+ price += 0.28 * (minutes%1440)
61
+ end
62
+
63
+ {:price => price.round(2), :unit => 'EUR' }
64
+ end
65
+
66
+ private
67
+
68
+ def headers
69
+ {
70
+ "content-type" => "application/x-www-form-urlencoded;charset=utf-8",
71
+ "accept-charset" => "utf-8"
72
+ }
73
+ end
74
+
75
+ #######################################################
76
+ private
77
+ #######################################################
78
+
79
+ def encode str
80
+ if str.respond_to? :encode
81
+ str.force_encoding("iso-8859-1").encode("utf-8")
82
+ else
83
+ Iconv.conv("utf-8", "iso-8859-1", str)
84
+ end
85
+ end
86
+ end
88
87
  end
@@ -1,3 +1,3 @@
1
1
  module Multicity
2
- VERSION = "1.3.0"
2
+ VERSION = "1.4.0"
3
3
  end
metadata CHANGED
@@ -1,60 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multicity
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
5
- prerelease:
4
+ version: 1.4.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Simon Woker
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-03-15 00:00:00.000000000 Z
11
+ date: 2013-04-02 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: json
16
- requirement: &13282000 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
21
19
  version: '1.6'
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *13282000
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
25
27
  - !ruby/object:Gem::Dependency
26
28
  name: mechanize
27
- requirement: &13281620 !ruby/object:Gem::Requirement
28
- none: false
29
+ requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
- - - ! '>='
31
+ - - '>='
31
32
  - !ruby/object:Gem::Version
32
33
  version: '0'
33
34
  type: :runtime
34
35
  prerelease: false
35
- version_requirements: *13281620
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
36
41
  - !ruby/object:Gem::Dependency
37
42
  name: xml-simple
38
- requirement: &13281160 !ruby/object:Gem::Requirement
39
- none: false
43
+ requirement: !ruby/object:Gem::Requirement
40
44
  requirements:
41
- - - ! '>='
45
+ - - '>='
42
46
  - !ruby/object:Gem::Version
43
47
  version: '0'
44
48
  type: :runtime
45
49
  prerelease: false
46
- version_requirements: *13281160
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
47
55
  - !ruby/object:Gem::Dependency
48
56
  name: rake
49
- requirement: &13280640 !ruby/object:Gem::Requirement
50
- none: false
57
+ requirement: !ruby/object:Gem::Requirement
51
58
  requirements:
52
- - - ! '>='
59
+ - - '>='
53
60
  - !ruby/object:Gem::Version
54
61
  version: '0'
55
62
  type: :development
56
63
  prerelease: false
57
- version_requirements: *13280640
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
58
69
  description: Wraps the Multicity JSON to use it nicely in your own environment. You
59
70
  can use this Gem to read all cars that are available.
60
71
  email: github@simonwoker.de
@@ -72,29 +83,25 @@ files:
72
83
  - README.md
73
84
  homepage: https://github.com/swoker/multicity-ruby
74
85
  licenses: []
86
+ metadata: {}
75
87
  post_install_message:
76
88
  rdoc_options: []
77
89
  require_paths:
78
90
  - lib
79
91
  required_ruby_version: !ruby/object:Gem::Requirement
80
- none: false
81
92
  requirements:
82
- - - ! '>='
93
+ - - '>='
83
94
  - !ruby/object:Gem::Version
84
95
  version: '0'
85
- segments:
86
- - 0
87
- hash: -1799344324344999223
88
96
  required_rubygems_version: !ruby/object:Gem::Requirement
89
- none: false
90
97
  requirements:
91
- - - ! '>='
98
+ - - '>='
92
99
  - !ruby/object:Gem::Version
93
100
  version: 1.3.6
94
101
  requirements: []
95
102
  rubyforge_project:
96
- rubygems_version: 1.8.11
103
+ rubygems_version: 2.0.0
97
104
  signing_key:
98
- specification_version: 3
105
+ specification_version: 4
99
106
  summary: Wrapper for the Multicity API
100
107
  test_files: []