google-map-static-image-generator 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/google_map_static_image/version.rb +1 -1
- data/lib/google_map_static_image.rb +19 -5
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 237094e6bc2d8572ccc0b6aec9683a40c10592c233ede43c3d29bfcd99d25be8
|
|
4
|
+
data.tar.gz: 9ac489db924458a8195803288c6e8a3c496d452b792a5313d14d085289b9f7b4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f3ecd4695ad402c2fef5c65d897d8dd043783f3b63707a56441836039d6e45a7c2b64c068428f2c25b112b231d6a5fb217aecc5c3c3ce7b38a17bef4825b32c3
|
|
7
|
+
data.tar.gz: 2a6226dd661996dabad1758070fc8c0ca3379941a6114a0882820af202474300a694e6bc2bbf16d59d5e5db11bb37463c2282dc5b3993afb2289254b1dd710ee
|
|
@@ -3,20 +3,34 @@ require_relative "google_map_static_image/version"
|
|
|
3
3
|
|
|
4
4
|
class GoogleMapStaticImage
|
|
5
5
|
STATIC_MAP_URL = "https://maps.googleapis.com/maps/api/staticmap"
|
|
6
|
+
VALID_MAP_TYPES = %w[roadmap satellite terrain hybrid].freeze
|
|
7
|
+
|
|
8
|
+
class ApiError < StandardError
|
|
9
|
+
attr_reader :status, :body
|
|
10
|
+
def initialize(status, body)
|
|
11
|
+
@status = status
|
|
12
|
+
@body = body
|
|
13
|
+
super("Google Maps Static API error #{status}: #{body}")
|
|
14
|
+
end
|
|
15
|
+
end
|
|
6
16
|
|
|
7
17
|
def get_response(api_key, markers, option = {})
|
|
8
18
|
query = {}
|
|
9
|
-
query[:
|
|
19
|
+
query[:key] = api_key
|
|
10
20
|
query[:size] = "1024x1024"
|
|
11
21
|
query[:scale] = 2
|
|
12
|
-
query[:
|
|
13
|
-
query[:
|
|
22
|
+
query[:center] = option[:center] unless option[:center].nil?
|
|
23
|
+
query[:zoom] = option[:zoom] unless option[:zoom].nil?
|
|
24
|
+
query[:maptype] = option[:map_type] if VALID_MAP_TYPES.include?(option[:map_type].to_s)
|
|
25
|
+
query[:style] = option[:style].map { |k, v| "#{k}:#{v}" }.join("|") unless option[:style].nil?
|
|
26
|
+
query[:path] = option[:path].map { |k, v| "#{k}:#{v}" }.join("|") unless option[:path].nil?
|
|
14
27
|
unless option[:location].nil?
|
|
15
|
-
query[:path] = [query[:path], option[:location].map { |
|
|
28
|
+
query[:path] = [query[:path], option[:location].map { |_k, v| v.to_s }.join("|")].join("|")
|
|
16
29
|
end
|
|
17
|
-
query[:markers] = option[:markers].map { |val| val.join("|") }
|
|
30
|
+
query[:markers] = option[:markers].map { |val| val.join("|") } unless option[:markers].nil?
|
|
18
31
|
|
|
19
32
|
response = HTTParty.get(STATIC_MAP_URL, query: query)
|
|
33
|
+
raise ApiError.new(response.code, response.body) unless response.code == 200
|
|
20
34
|
response.parsed_response
|
|
21
35
|
end
|
|
22
36
|
end
|