get_the_distance 0.0.1 → 0.0.2

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.
Files changed (2) hide show
  1. data/lib/get_the_distance.rb +18 -2
  2. metadata +1 -1
@@ -1,5 +1,21 @@
1
+ # encoding: UTF-8
2
+ require "httparty"
3
+
1
4
  class GetTheDistance
2
- def self.hi
3
- puts "Hello world!"
5
+ def initialize(key)
6
+ @key = key
7
+ end
8
+
9
+ def calculate(origin, destination)
10
+ result = HTTParty.get("https://maps.googleapis.com/maps/api/distancematrix/json?origins=" + origin + "&destinations=" + destination + "&key=" + @key)
11
+ if result.code == 200
12
+ return {
13
+ origin: result["origin_addresses"][0],
14
+ destination: result["destination_addresses"][0],
15
+ distance: result["rows"][0]["elements"][0]["distance"]["value"]
16
+ }
17
+ else
18
+ return nil
19
+ end
4
20
  end
5
21
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: get_the_distance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: