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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dd7cf0d91c5296a1352f60e6989066ffc156431d5956e7ce52599f5c7d66e2f2
4
- data.tar.gz: 9ca9c456a6a84d9083c1f81325305cd98eb907fc76adce18de79ca52d6ff519d
3
+ metadata.gz: 237094e6bc2d8572ccc0b6aec9683a40c10592c233ede43c3d29bfcd99d25be8
4
+ data.tar.gz: 9ac489db924458a8195803288c6e8a3c496d452b792a5313d14d085289b9f7b4
5
5
  SHA512:
6
- metadata.gz: 11676470fad2e0a0f43f8b9e8350f4efdb41415b9ae4baa0c31a3c606771c754ab3d0345801476ed33dc0d3720fa60b3bb8178b3c9765c8dc0080f022e726fed
7
- data.tar.gz: f020ffdfcc0ec13cbc8155205b027c9bd2fd2a99f1ca4d4840a93d67b78b32c9c72599a37f58748044f771dd8ae4b8f136ab51fce90b08e86718b1b1e0b0715c
6
+ metadata.gz: f3ecd4695ad402c2fef5c65d897d8dd043783f3b63707a56441836039d6e45a7c2b64c068428f2c25b112b231d6a5fb217aecc5c3c3ce7b38a17bef4825b32c3
7
+ data.tar.gz: 2a6226dd661996dabad1758070fc8c0ca3379941a6114a0882820af202474300a694e6bc2bbf16d59d5e5db11bb37463c2282dc5b3993afb2289254b1dd710ee
@@ -1,3 +1,3 @@
1
1
  class GoogleMapStaticImage
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -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[:api_key] = api_key
19
+ query[:key] = api_key
10
20
  query[:size] = "1024x1024"
11
21
  query[:scale] = 2
12
- query[:style] = option[:style].map { |key, val| "#{key}:#{val}" }.join("|") unless option[:style].nil?
13
- query[:path] = option[:path].map { |key, val| "#{key}:#{val}" }.join("|") unless option[:path].nil?
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 { |_key, val| val.to_s }.join("|")].join("|")
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("|") } unless option[:markers].nil?
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-map-static-image-generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abhishek Sharma