google_geocode_api 0.1.0
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 +7 -0
- data/.rubocop.yml +18 -0
- data/CHANGELOG.md +4 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +51 -0
- data/LICENSE.txt +21 -0
- data/README.md +106 -0
- data/Rakefile +20 -0
- data/lib/google_geocode_api/address.rb +16 -0
- data/lib/google_geocode_api/client.rb +106 -0
- data/lib/google_geocode_api/error.rb +5 -0
- data/lib/google_geocode_api/object.rb +22 -0
- data/lib/google_geocode_api/response.rb +13 -0
- data/lib/google_geocode_api/version.rb +5 -0
- data/lib/google_geocode_api.rb +12 -0
- data/sig/google_geocode_api.rbs +4 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b84c44eacc710dc7807ae4af67dc8459a152983629a33c35ea37809c4a85f152
|
4
|
+
data.tar.gz: ecb4b85e1976ac0e0c342fb77ac8bdc0f9ac40dd212e22729078bc01f481642d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 97038a57c8b0bd3ec7d77bcbb954334206386b145f76b5d4831650a81ff54a75ebce0eae1af201ed7985f09181cbf18ce7fd4f3c862d246507f55b9decc07489
|
7
|
+
data.tar.gz: 6cdcc8b3f49d241ee523e6c303f45bcd4d70476fe88dae4db411ff6ea2e28601d99f6fa0992d64bac6b8f90028f6e32ccc18a861087a0ec0f83817f6a504f243
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.6
|
3
|
+
NewCops: enable
|
4
|
+
SuggestExtensions: false
|
5
|
+
|
6
|
+
Style/StringLiterals:
|
7
|
+
Enabled: true
|
8
|
+
EnforcedStyle: double_quotes
|
9
|
+
|
10
|
+
Style/StringLiteralsInInterpolation:
|
11
|
+
Enabled: true
|
12
|
+
EnforcedStyle: double_quotes
|
13
|
+
|
14
|
+
Layout/LineLength:
|
15
|
+
Max: 120
|
16
|
+
|
17
|
+
Lint/RedundantCopDisableDirective:
|
18
|
+
Enabled: false
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at sulman@hey.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
google_geocode_api (0.1.0)
|
5
|
+
faraday (~> 2.5)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ast (2.4.2)
|
11
|
+
faraday (2.5.2)
|
12
|
+
faraday-net_http (>= 2.0, < 3.1)
|
13
|
+
ruby2_keywords (>= 0.0.4)
|
14
|
+
faraday-net_http (3.0.0)
|
15
|
+
json (2.6.2)
|
16
|
+
minitest (5.16.3)
|
17
|
+
parallel (1.22.1)
|
18
|
+
parser (3.1.2.1)
|
19
|
+
ast (~> 2.4.1)
|
20
|
+
rainbow (3.1.1)
|
21
|
+
rake (13.0.6)
|
22
|
+
regexp_parser (2.5.0)
|
23
|
+
rexml (3.2.5)
|
24
|
+
rubocop (1.35.1)
|
25
|
+
json (~> 2.3)
|
26
|
+
parallel (~> 1.10)
|
27
|
+
parser (>= 3.1.2.1)
|
28
|
+
rainbow (>= 2.2.2, < 4.0)
|
29
|
+
regexp_parser (>= 1.8, < 3.0)
|
30
|
+
rexml (>= 3.2.5, < 4.0)
|
31
|
+
rubocop-ast (>= 1.20.1, < 2.0)
|
32
|
+
ruby-progressbar (~> 1.7)
|
33
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
34
|
+
rubocop-ast (1.21.0)
|
35
|
+
parser (>= 3.1.1.0)
|
36
|
+
ruby-progressbar (1.11.0)
|
37
|
+
ruby2_keywords (0.0.5)
|
38
|
+
unicode-display_width (2.2.0)
|
39
|
+
|
40
|
+
PLATFORMS
|
41
|
+
arm64-darwin-21
|
42
|
+
x86_64-linux
|
43
|
+
|
44
|
+
DEPENDENCIES
|
45
|
+
google_geocode_api!
|
46
|
+
minitest (~> 5.0)
|
47
|
+
rake (~> 13.0)
|
48
|
+
rubocop (~> 1.21)
|
49
|
+
|
50
|
+
BUNDLED WITH
|
51
|
+
2.3.21
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 Sulman Baig
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
# GoogleGeocodeApi
|
2
|
+
|
3
|
+
Google Geocode API is a light-weight Ruby wrapper for the Rubyists. It gives nice struct objects for adresses, even the raw responses are returned in nice open struct objects. It uses Faraday for HTTP requests.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Install the gem and add to the application's Gemfile by executing:
|
8
|
+
|
9
|
+
$ bundle add google_geocode_api
|
10
|
+
|
11
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
12
|
+
|
13
|
+
$ gem install google_geocode_api
|
14
|
+
|
15
|
+
---
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
### API Documentation
|
20
|
+
|
21
|
+
The API documentation can be found at [https://developers.google.com/maps/documentation/geocoding/start](https://developers.google.com/maps/documentation/geocoding/start).
|
22
|
+
|
23
|
+
### Get an API key
|
24
|
+
You can get API for the google by doing the following [here](https://developers.google.com/maps/documentation/geocoding/get-api-key#creating-api-keys).
|
25
|
+
|
26
|
+
### Configuration
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
require 'google_geocode_api'
|
30
|
+
client = GoogleGeocodeApi::Client.new(api_key: ENV['GOOGLE_API_KEY'])
|
31
|
+
```
|
32
|
+
Params:
|
33
|
+
- `api_key`: String - Required - The API key for the google geocode api.
|
34
|
+
|
35
|
+
Response:
|
36
|
+
```ruby
|
37
|
+
#<GoogleGeocodeApi::Client:0x00000001055fc318 @adapter=:net_http, @api_key="YOUR_API_KEY", @stubs=nil>
|
38
|
+
```
|
39
|
+
|
40
|
+
### Get place information provided place id
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
resp = GoogleGeocode::Client.new(api_key: "fake").find_place(place_id: "ChIJN1t_tDeuEmsRUsoyG83frY4")
|
44
|
+
```
|
45
|
+
Params:
|
46
|
+
- `place_id`: String - Required - The place id for the place you want to get information for.
|
47
|
+
|
48
|
+
Response:
|
49
|
+
```ruby
|
50
|
+
resp.results
|
51
|
+
=> #<GoogleGeocodeApi::Response:0x0000000109ec58b0 @results=[#<GoogleGeocodeApi::Address:0x000000010a197d40 @formatted_address="48 Pirrama Rd, Pyrmont NSW 2009, Australia", @latitude=-33.866489, @location_type="ROOFTOP", @longitude=151.1958561, @place_id="ChIJN1t_tDeuEmsRUsoyG83frY4">]>
|
52
|
+
```
|
53
|
+
|
54
|
+
> Also `raw_response` is available if you want the raw response from the API. This is useful if you want to do something with the raw response. Also that response is in OpenStruct Object which is a nice wrapper for the raw response and you can use 'dot' notation.
|
55
|
+
|
56
|
+
### Get address information provided address string
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
resp = GoogleGeocode::Client.new(api_key: "fake").find_address(address: "48 Pirrama Rd, Pyrmont NSW 2009, Australia")
|
60
|
+
```
|
61
|
+
Params:
|
62
|
+
- `address`: String - Required - The address you want to get information for.
|
63
|
+
|
64
|
+
Response:
|
65
|
+
```ruby
|
66
|
+
resp.results
|
67
|
+
=> #<GoogleGeocodeApi::Response:0x0000000109ec58b0 @results=[#<GoogleGeocodeApi::Address:0x000000010a197d40 @formatted_address="48 Pirrama Rd, Pyrmont NSW 2009, Australia", @latitude=-33.866489, @location_type="ROOFTOP", @longitude=151.1958561, @place_id="ChIJN1t_tDeuEmsRUsoyG83frY4">]>
|
68
|
+
```
|
69
|
+
> Also `raw_response` is available if you want the raw response from the API. This is useful if you want to do something with the raw response. Also that response is in OpenStruct Object which is a nice wrapper for the raw response and you can use 'dot' notation.
|
70
|
+
|
71
|
+
### Get address information provided latitute and longitude
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
resp = GoogleGeocode::Client.new(api_key: "fake").find_address(latitude: -33.866489, longitude: 151.1958561)
|
75
|
+
```
|
76
|
+
Params:
|
77
|
+
- `lat`: Float - Required - The latitude you want to get information for.
|
78
|
+
- `long`: Float - Required - The longitude you want to get information for.
|
79
|
+
|
80
|
+
Response:
|
81
|
+
```ruby
|
82
|
+
resp.results
|
83
|
+
=> #<GoogleGeocodeApi::Response:0x0000000109ec58b0 @results=[#<GoogleGeocodeApi::Address:0x000000010a197d40 @formatted_address="48 Pirrama Rd, Pyrmont NSW 2009, Australia", @latitude=-33.866489, @location_type="ROOFTOP", @longitude=151.1958561, @place_id="ChIJN1t_tDeuEmsRUsoyG83frY4">]>
|
84
|
+
```
|
85
|
+
|
86
|
+
> Also `raw_response` is available if you want the raw response from the API. This is useful if you want to do something with the raw response. Also that response is in OpenStruct Object which is a nice wrapper for the raw response and you can use 'dot' notation.
|
87
|
+
|
88
|
+
---
|
89
|
+
|
90
|
+
## Development
|
91
|
+
|
92
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
93
|
+
|
94
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
95
|
+
|
96
|
+
## Contributing
|
97
|
+
|
98
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/google_geocode_api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/google_geocode_api/blob/main/CODE_OF_CONDUCT.md).
|
99
|
+
|
100
|
+
## License
|
101
|
+
|
102
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
103
|
+
|
104
|
+
## Code of Conduct
|
105
|
+
|
106
|
+
Everyone interacting in the GoogleGeocodeApi project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/google_geocode_api/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rake/testtask"
|
5
|
+
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs << "test"
|
8
|
+
t.libs << "lib"
|
9
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
10
|
+
end
|
11
|
+
|
12
|
+
require "rubocop/rake_task"
|
13
|
+
|
14
|
+
RuboCop::RakeTask.new
|
15
|
+
|
16
|
+
task :console do
|
17
|
+
exec "irb -I lib -r currency_layer_api.rb"
|
18
|
+
end
|
19
|
+
|
20
|
+
task default: %i[test rubocop]
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GoogleGeocodeApi
|
4
|
+
# Address object
|
5
|
+
class Address
|
6
|
+
attr_reader :formatted_address, :place_id, :longitude, :latitude, :location_type
|
7
|
+
|
8
|
+
def initialize(obj)
|
9
|
+
@formatted_address = obj.formatted_address
|
10
|
+
@place_id = obj.place_id
|
11
|
+
@latitude = obj.geometry.location.lat
|
12
|
+
@longitude = obj.geometry.location.lng
|
13
|
+
@location_type = obj.geometry.location_type
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GoogleGeocodeApi
|
4
|
+
# Client having API methods and api_key
|
5
|
+
class Client
|
6
|
+
# Documentation: https://developers.google.com/maps/documentation/geocoding
|
7
|
+
BASE_URL = "https://maps.googleapis.com/maps/api/geocode/json"
|
8
|
+
attr_reader :api_key, :adapter
|
9
|
+
|
10
|
+
# #### Params:
|
11
|
+
# api_key: String - Required - API key for Google Geocode API (https://developers.google.com/maps/documentation/geocoding/get-api-key#creating-api-keys)
|
12
|
+
# adapter: Symbol - Optional - Default: :net_http - Adapter for Faraday connection
|
13
|
+
# stubs: Faraday::Adapter::Test::Stubs - Optional - Default: nil - Stubs for Faraday connection
|
14
|
+
# #### Example:
|
15
|
+
# client = GoogleGeocodeApi::Client.new api_key: "test"
|
16
|
+
# #### Description:
|
17
|
+
# Client for Google Geocode API
|
18
|
+
def initialize(api_key:, adapter: Faraday.default_adapter, stubs: nil)
|
19
|
+
@api_key = api_key
|
20
|
+
@adapter = adapter
|
21
|
+
|
22
|
+
# Test stubs for requests
|
23
|
+
@stubs = stubs
|
24
|
+
end
|
25
|
+
|
26
|
+
# #### Params:
|
27
|
+
# place_id: String - Required - Place ID for Google Geocode API
|
28
|
+
# #### Example:
|
29
|
+
# GoogleGeocode::Client.new(api_key: "fake").find_place(place_id: "ChIJN1t_tDeuEmsRUsoyG83frY4")
|
30
|
+
# #### Response:
|
31
|
+
# #<GoogleGeocodeApi::Response:0x0000000109ec58b0
|
32
|
+
# @results=[
|
33
|
+
# #<GoogleGeocodeApi::Address:0x000000010a197d40
|
34
|
+
# @formatted_address="48 Pirrama Rd, Pyrmont NSW 2009, Australia",
|
35
|
+
# @latitude=-33.866489, @location_type="ROOFTOP", @longitude=151.1958561, @place_id="ChIJN1t_tDeuEmsRUsoyG83frY4">
|
36
|
+
# ]>
|
37
|
+
# #### Description:
|
38
|
+
# Find address by place_id
|
39
|
+
def find_place(place_id:)
|
40
|
+
Response.new get("", { place_id: place_id })
|
41
|
+
end
|
42
|
+
|
43
|
+
# #### Params:
|
44
|
+
# address: String - Required - Address String for Google Geocode API
|
45
|
+
# #### Example:
|
46
|
+
# GoogleGeocode::Client.new(api_key: "fake").find_address(address: "48 Pirrama Rd, Pyrmont NSW 2009, Australia")
|
47
|
+
# #### Response:
|
48
|
+
# #<GoogleGeocodeApi::Response:0x0000000109ec58b0
|
49
|
+
# @results=[
|
50
|
+
# #<GoogleGeocodeApi::Address:0x000000010a197d40
|
51
|
+
# @formatted_address="48 Pirrama Rd, Pyrmont NSW 2009, Australia",
|
52
|
+
# @latitude=-33.866489, @location_type="ROOFTOP", @longitude=151.1958561, @place_id="ChIJN1t_tDeuEmsRUsoyG83frY4">
|
53
|
+
# ]>
|
54
|
+
# #### Description:
|
55
|
+
# Find address by providing address string
|
56
|
+
def find_address(address:)
|
57
|
+
Response.new get("", { address: address })
|
58
|
+
end
|
59
|
+
|
60
|
+
# #### Params:
|
61
|
+
# lat: Float - Required - Latitude for Google Geocode API
|
62
|
+
# long: Float - Required - Longitude for Google Geocode API
|
63
|
+
# #### Example:
|
64
|
+
# GoogleGeocode::Client.new(api_key: "fake").find_lat_long(lat: -33.866489, long: 151.1958561)
|
65
|
+
# #### Response:
|
66
|
+
# #<GoogleGeocodeApi::Response:0x0000000109ec58b0
|
67
|
+
# @results=[
|
68
|
+
# #<GoogleGeocodeApi::Address:0x000000010a197d40
|
69
|
+
# @formatted_address="48 Pirrama Rd, Pyrmont NSW 2009, Australia",
|
70
|
+
# @latitude=-33.866489, @location_type="ROOFTOP", @longitude=151.1958561, @place_id="ChIJN1t_tDeuEmsRUsoyG83frY4">
|
71
|
+
# ]>
|
72
|
+
# #### Description:
|
73
|
+
# Find address by providing latitude and longitude values
|
74
|
+
def find_lat_long(lat:, long:)
|
75
|
+
Response.new get("", { latlng: "#{lat},#{long}" })
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
# makes a get request to the given path with params
|
81
|
+
def get(path, params = {})
|
82
|
+
handle_response connection.get(path, params)
|
83
|
+
end
|
84
|
+
|
85
|
+
# handles the response from the api and raises error if any
|
86
|
+
# returns the response if no error
|
87
|
+
# Error codes: https://developers.google.com/maps/documentation/geocoding/requests-geocoding#StatusCodes
|
88
|
+
# error.message: "INVALID_REQUEST: Invalid request. Invalid 'latlng' parameter"
|
89
|
+
def handle_response(response)
|
90
|
+
return response if %w[OK ZERO_RESULTS].include? response.body["status"]
|
91
|
+
|
92
|
+
raise Error, "#{response.body["status"]}: #{response.body["error_message"]}"
|
93
|
+
end
|
94
|
+
|
95
|
+
# creates a faraday connection with base url and api_key
|
96
|
+
def connection
|
97
|
+
@connection ||= Faraday.new(BASE_URL) do |conn|
|
98
|
+
conn.params["key"] = api_key
|
99
|
+
conn.request :url_encoded
|
100
|
+
|
101
|
+
conn.response :json, content_type: "application/json"
|
102
|
+
conn.adapter adapter, @stubs
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "ostruct"
|
4
|
+
|
5
|
+
module GoogleGeocodeApi
|
6
|
+
# OpenStruct object for Google Geocode API
|
7
|
+
class Object < OpenStruct # rubocop:disable Style/OpenStructUse
|
8
|
+
def initialize(attributes)
|
9
|
+
super to_ostruct(attributes)
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_ostruct(obj)
|
13
|
+
if obj.is_a?(Hash) # rubocop:disable Style/CaseLikeIf
|
14
|
+
OpenStruct.new(obj.map { |key, val| [key, to_ostruct(val)] }.to_h) # rubocop:disable Style/HashTransformValues, Style/OpenStructUse, Style/MapToHash
|
15
|
+
elsif obj.is_a?(Array)
|
16
|
+
obj.map { |o| to_ostruct(o) }
|
17
|
+
else # Assumed to be a primitive value
|
18
|
+
obj
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GoogleGeocodeApi
|
4
|
+
# Response object formatted from Google API response
|
5
|
+
class Response
|
6
|
+
attr_reader :raw_response, :results
|
7
|
+
|
8
|
+
def initialize(response)
|
9
|
+
@raw_response = Object.new response.body
|
10
|
+
@results = @raw_response.results.map { |result| Address.new result }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "google_geocode_api/version"
|
4
|
+
require "faraday"
|
5
|
+
|
6
|
+
module GoogleGeocodeApi
|
7
|
+
autoload :Error, "google_geocode_api/error"
|
8
|
+
autoload :Client, "google_geocode_api/client"
|
9
|
+
autoload :Object, "google_geocode_api/object"
|
10
|
+
autoload :Response, "google_geocode_api/response"
|
11
|
+
autoload :Address, "google_geocode_api/address"
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: google_geocode_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sulman Baig
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-09-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.5'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rubocop
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.35'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.35'
|
41
|
+
description: Google Geocode API is a light-weight Ruby wrapper for the Rubyists. It
|
42
|
+
gives nice struct objects for adresses, even the raw responses are returned in nice
|
43
|
+
open struct objects. It uses Faraday for HTTP requests.
|
44
|
+
email:
|
45
|
+
- sulman@hey.com
|
46
|
+
executables: []
|
47
|
+
extensions: []
|
48
|
+
extra_rdoc_files:
|
49
|
+
- README.md
|
50
|
+
files:
|
51
|
+
- ".rubocop.yml"
|
52
|
+
- CHANGELOG.md
|
53
|
+
- CODE_OF_CONDUCT.md
|
54
|
+
- Gemfile
|
55
|
+
- Gemfile.lock
|
56
|
+
- LICENSE.txt
|
57
|
+
- README.md
|
58
|
+
- Rakefile
|
59
|
+
- lib/google_geocode_api.rb
|
60
|
+
- lib/google_geocode_api/address.rb
|
61
|
+
- lib/google_geocode_api/client.rb
|
62
|
+
- lib/google_geocode_api/error.rb
|
63
|
+
- lib/google_geocode_api/object.rb
|
64
|
+
- lib/google_geocode_api/response.rb
|
65
|
+
- lib/google_geocode_api/version.rb
|
66
|
+
- sig/google_geocode_api.rbs
|
67
|
+
homepage: https://github.com/sulmanweb/google_geocode_api
|
68
|
+
licenses:
|
69
|
+
- MIT
|
70
|
+
metadata:
|
71
|
+
homepage_uri: https://github.com/sulmanweb/google_geocode_api
|
72
|
+
source_code_uri: https://github.com/sulmanweb/google_geocode_api
|
73
|
+
changelog_uri: https://github.com/sulmanweb/google_geocode_api/blob/main/CHANGELOG.md
|
74
|
+
rubygems_mfa_required: 'true'
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '2.6'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubygems_version: 3.3.21
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: Google Geocode API is a light-weight Ruby wrapper for the Rubyists.
|
94
|
+
test_files: []
|