ola_maps 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +217 -0
- data/lib/ola_maps/client.rb +76 -0
- data/lib/ola_maps/version.rb +3 -0
- data/lib/ola_maps.rb +7 -0
- metadata +149 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4ffdd3cbc975d235ec87c4484b194811bcba795b11662ff859b930085523b4ab
|
4
|
+
data.tar.gz: ea2ffbff4838dc8b9c6e6ff373d01ec4fbddd92f410f02e628dc1601bfbbbcae
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dd9b986b1a9ee6b9d0b61efc17d847c106f3b58fa923bca07c5d55c21281f02ccea3fdda8fab64482849fd1045a8213b4e8de82495deef929e01b7a88c4d254a
|
7
|
+
data.tar.gz: 29255ad6e54214869c9d4c362e4271b04b4278fa2ca9095416cae9c965eb608fc31faf47a90a51c38fb134f82cb19d07cdee2a521a0eea17d5742e5f3aded252
|
data/README.md
ADDED
@@ -0,0 +1,217 @@
|
|
1
|
+
# Ola Maps
|
2
|
+
|
3
|
+
A Ruby gem for interacting with the Ola Maps API, providing a simple interface for location-based services like autocomplete, geocoding, and reverse geocoding.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'ola_maps'
|
11
|
+
```
|
12
|
+
|
13
|
+
Then, execute:
|
14
|
+
|
15
|
+
`$ bundle install`
|
16
|
+
|
17
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
18
|
+
|
19
|
+
` $ gem install 'ola_maps'`
|
20
|
+
|
21
|
+
## Configuration
|
22
|
+
|
23
|
+
Before using the gem, set up your environment variables in a .env file:
|
24
|
+
|
25
|
+
```
|
26
|
+
API_KEY=your_api_key
|
27
|
+
CLIENT_ID=your_client_id
|
28
|
+
CLIENT_SECRET=your_client_secret
|
29
|
+
```
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
Here's how to use the `OlaMaps` gem:
|
34
|
+
|
35
|
+
```
|
36
|
+
require 'dotenv/load'
|
37
|
+
require 'ola_maps'
|
38
|
+
|
39
|
+
client = OlaMaps::Client.new(
|
40
|
+
api_key: ENV['API_KEY']
|
41
|
+
)
|
42
|
+
|
43
|
+
# Autocomplete
|
44
|
+
autocomplete_response = client.autocomplete('kempe')
|
45
|
+
puts autocomplete_response.body
|
46
|
+
|
47
|
+
# Geocode
|
48
|
+
geocode_response = client.geocode('Bangalore')
|
49
|
+
puts geocode_response.body
|
50
|
+
|
51
|
+
# Reverse Geocode
|
52
|
+
reverse_geocode_response = client.reverse_geocode('12.931316595874005,77.61649243443775')
|
53
|
+
puts reverse_geocode_response.body
|
54
|
+
|
55
|
+
```
|
56
|
+
|
57
|
+
## API Methods
|
58
|
+
|
59
|
+
### `#autocomplete(input, origin: nil, location: nil, radius: nil, strictbounds: nil)`
|
60
|
+
|
61
|
+
Returns autocomplete suggestions based on the input string.
|
62
|
+
|
63
|
+
- **Parameters:**
|
64
|
+
- `input`: The input string for autocomplete.
|
65
|
+
- `origin`: (Optional) The origin location.
|
66
|
+
- `location`: (Optional) The location to bias the results.
|
67
|
+
- `radius`: (Optional) The radius within which to return results.
|
68
|
+
- `strictbounds`: (Optional) If true, restrict results to the specified area.
|
69
|
+
|
70
|
+
### `#geocode(address, bounds: nil, language: 'English')`
|
71
|
+
|
72
|
+
Returns geocoded address information.
|
73
|
+
|
74
|
+
- **Parameters:**
|
75
|
+
- `address`: The address to geocode.
|
76
|
+
- `bounds`: (Optional) The bounds within which to search.
|
77
|
+
- `language`: (Optional) The language for the response (default is 'English').
|
78
|
+
|
79
|
+
### `#reverse_geocode(latlng)`
|
80
|
+
|
81
|
+
Returns reverse geocoded address information for a given latitude and longitude.
|
82
|
+
|
83
|
+
- **Parameters:**
|
84
|
+
- `latlng`: The latitude and longitude in the format `lat,lng`.
|
85
|
+
|
86
|
+
## Running Tests
|
87
|
+
|
88
|
+
To run the tests for this gem, ensure you have the required environment variables set in your .env file, then execute:
|
89
|
+
|
90
|
+
```
|
91
|
+
bundle exec rspec
|
92
|
+
```
|
93
|
+
|
94
|
+
## Contributing
|
95
|
+
|
96
|
+
Bug reports and pull requests are welcome on GitHub at [ola_maps](https://github.com/shobhit-shukla/ola_maps). 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/shobhit-shukla/ola_maps/blob/main/CODE_OF_CONDUCT.md).
|
97
|
+
|
98
|
+
## License
|
99
|
+
|
100
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
101
|
+
Here’s a template for your README file for the `OlaMaps` gem:
|
102
|
+
|
103
|
+
````markdown
|
104
|
+
# OlaMaps
|
105
|
+
|
106
|
+
A Ruby gem for interacting with the Ola Maps API, providing a simple interface for location-based services like autocomplete, geocoding, and reverse geocoding.
|
107
|
+
|
108
|
+
## Installation
|
109
|
+
|
110
|
+
Add this line to your application's Gemfile:
|
111
|
+
|
112
|
+
```ruby
|
113
|
+
gem 'ola_maps'
|
114
|
+
```
|
115
|
+
````
|
116
|
+
|
117
|
+
Then, execute:
|
118
|
+
|
119
|
+
```bash
|
120
|
+
bundle install
|
121
|
+
```
|
122
|
+
|
123
|
+
## Configuration
|
124
|
+
|
125
|
+
### Environment Variables
|
126
|
+
|
127
|
+
Before using the gem, set up your environment variables in a `.env` file:
|
128
|
+
|
129
|
+
```plaintext
|
130
|
+
API_KEY=your_api_key
|
131
|
+
CLIENT_ID=your_client_id
|
132
|
+
CLIENT_SECRET=your_client_secret
|
133
|
+
```
|
134
|
+
|
135
|
+
### Usage
|
136
|
+
|
137
|
+
Here's how to use the `OlaMaps` gem:
|
138
|
+
|
139
|
+
```ruby
|
140
|
+
require 'dotenv/load'
|
141
|
+
require 'ola_maps'
|
142
|
+
|
143
|
+
client = OlaMaps::Client.new(
|
144
|
+
api_key: ENV['API_KEY'],
|
145
|
+
client_id: ENV['CLIENT_ID'],
|
146
|
+
client_secret: ENV['CLIENT_SECRET']
|
147
|
+
)
|
148
|
+
|
149
|
+
# Autocomplete
|
150
|
+
autocomplete_response = client.autocomplete('kempe')
|
151
|
+
puts autocomplete_response.body
|
152
|
+
|
153
|
+
# Geocode
|
154
|
+
geocode_response = client.geocode('Bangalore')
|
155
|
+
puts geocode_response.body
|
156
|
+
|
157
|
+
# Reverse Geocode
|
158
|
+
reverse_geocode_response = client.reverse_geocode('12.931316595874005,77.61649243443775')
|
159
|
+
puts reverse_geocode_response.body
|
160
|
+
```
|
161
|
+
|
162
|
+
## API Methods
|
163
|
+
|
164
|
+
### `#autocomplete(input, origin: nil, location: nil, radius: nil, strictbounds: nil)`
|
165
|
+
|
166
|
+
Returns autocomplete suggestions based on the input string.
|
167
|
+
|
168
|
+
- **Parameters:**
|
169
|
+
- `input`: The input string for autocomplete.
|
170
|
+
- `origin`: (Optional) The origin location.
|
171
|
+
- `location`: (Optional) The location to bias the results.
|
172
|
+
- `radius`: (Optional) The radius within which to return results.
|
173
|
+
- `strictbounds`: (Optional) If true, restrict results to the specified area.
|
174
|
+
|
175
|
+
### `#geocode(address, bounds: nil, language: 'English')`
|
176
|
+
|
177
|
+
Returns geocoded address information.
|
178
|
+
|
179
|
+
- **Parameters:**
|
180
|
+
- `address`: The address to geocode.
|
181
|
+
- `bounds`: (Optional) The bounds within which to search.
|
182
|
+
- `language`: (Optional) The language for the response (default is 'English').
|
183
|
+
|
184
|
+
### `#reverse_geocode(latlng)`
|
185
|
+
|
186
|
+
Returns reverse geocoded address information for a given latitude and longitude.
|
187
|
+
|
188
|
+
- **Parameters:**
|
189
|
+
- `latlng`: The latitude and longitude in the format `lat,lng`.
|
190
|
+
|
191
|
+
## Running Tests
|
192
|
+
|
193
|
+
To run the tests for this gem, ensure you have the required environment variables set in your `.env` file, then execute:
|
194
|
+
|
195
|
+
```bash
|
196
|
+
bundle exec rspec
|
197
|
+
```
|
198
|
+
|
199
|
+
## Contributing
|
200
|
+
|
201
|
+
1. Fork it (https://github.com/yourusername/ola_maps/fork)
|
202
|
+
2. Create your feature branch (`git checkout -b feature/YourFeature`)
|
203
|
+
3. Commit your changes (`git commit -m 'Add some feature'`)
|
204
|
+
4. Push to the branch (`git push origin feature/YourFeature`)
|
205
|
+
5. Create a new Pull Request
|
206
|
+
|
207
|
+
## License
|
208
|
+
|
209
|
+
This gem is available as open-source under the terms of the MIT License.
|
210
|
+
|
211
|
+
### Customization
|
212
|
+
|
213
|
+
Feel free to modify sections like the installation instructions or API method descriptions to match your specific implementation details.
|
214
|
+
|
215
|
+
## Code of Conduct
|
216
|
+
|
217
|
+
Everyone interacting in the OlaMaps project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/ola_maps/blob/main/CODE_OF_CONDUCT.md).
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'securerandom'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module OlaMaps
|
6
|
+
class Client
|
7
|
+
BASE_URL = 'https://api.olamaps.io'
|
8
|
+
|
9
|
+
def initialize(api_key: nil, client_id: nil, client_secret: nil)
|
10
|
+
@api_key = api_key
|
11
|
+
@client_id = client_id
|
12
|
+
@client_secret = client_secret
|
13
|
+
end
|
14
|
+
|
15
|
+
def autocomplete(input, origin: nil, location: nil, radius: nil, strictbounds: nil)
|
16
|
+
query = { input: input, api_key: @api_key }
|
17
|
+
query[:origin] = origin if origin
|
18
|
+
query[:location] = location if location
|
19
|
+
query[:radius] = radius if radius
|
20
|
+
query[:strictbounds] = strictbounds if strictbounds
|
21
|
+
|
22
|
+
get('/places/v1/autocomplete', query)
|
23
|
+
end
|
24
|
+
|
25
|
+
def geocode(address, bounds: nil, language: 'English')
|
26
|
+
query = { address: address, api_key: @api_key }
|
27
|
+
query[:bounds] = bounds if bounds
|
28
|
+
query[:language] = language
|
29
|
+
|
30
|
+
get('/places/v1/geocode', query)
|
31
|
+
end
|
32
|
+
|
33
|
+
def reverse_geocode(latlng)
|
34
|
+
query = { latlng: latlng, api_key: @api_key }
|
35
|
+
|
36
|
+
get('/places/v1/reverse-geocode', query)
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def get(path, params)
|
42
|
+
connection.get(path, params) do |req|
|
43
|
+
req.headers = default_headers
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def connection
|
48
|
+
@connection ||= Faraday.new(url: BASE_URL) do |faraday|
|
49
|
+
faraday.request :url_encoded
|
50
|
+
faraday.response :json, content_type: /\bjson$/
|
51
|
+
faraday.adapter Faraday.default_adapter
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def default_headers
|
56
|
+
headers = {}
|
57
|
+
headers['X-Request-Id'] = SecureRandom.uuid
|
58
|
+
headers['X-Correlation-Id'] = SecureRandom.uuid
|
59
|
+
headers['Authorization'] = "Bearer #{get_token}" if @client_id && @client_secret
|
60
|
+
headers
|
61
|
+
end
|
62
|
+
|
63
|
+
def get_token
|
64
|
+
response = Faraday.post(
|
65
|
+
'https://account.olamaps.io/realms/olamaps/protocol/openid-connect/token',
|
66
|
+
{
|
67
|
+
grant_type: 'client_credentials',
|
68
|
+
client_id: @client_id,
|
69
|
+
client_secret: @client_secret,
|
70
|
+
scope: 'openid olamaps'
|
71
|
+
}
|
72
|
+
)
|
73
|
+
JSON.parse(response.body)['access_token']
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/lib/ola_maps.rb
ADDED
metadata
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ola_maps
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Shobhit
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-07-13 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.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: securerandom
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: dotenv
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.7'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.10'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.10'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: webmock
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.14'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.14'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: vcr
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '6.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '6.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.14.0
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.14.0
|
111
|
+
description: Provides an easy interface for interacting with the Ola Maps API.
|
112
|
+
email:
|
113
|
+
- shobits001@outlook.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- README.md
|
119
|
+
- lib/ola_maps.rb
|
120
|
+
- lib/ola_maps/client.rb
|
121
|
+
- lib/ola_maps/version.rb
|
122
|
+
homepage: https://github.com/shobhit-shukla/ola-maps-ruby
|
123
|
+
licenses:
|
124
|
+
- MIT
|
125
|
+
metadata:
|
126
|
+
allowed_push_host: https://rubygems.org
|
127
|
+
homepage_uri: https://github.com/shobhit-shukla/ola-maps-ruby
|
128
|
+
source_code_uri: https://github.com/shobhit-shukla/ola-maps-ruby
|
129
|
+
changelog_uri: https://github.com/shobhit-shukla/ola-maps-ruby
|
130
|
+
post_install_message:
|
131
|
+
rdoc_options: []
|
132
|
+
require_paths:
|
133
|
+
- lib
|
134
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 2.5.0
|
139
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
requirements: []
|
145
|
+
rubygems_version: 3.5.11
|
146
|
+
signing_key:
|
147
|
+
specification_version: 4
|
148
|
+
summary: A Ruby wrapper for the Ola Maps API.
|
149
|
+
test_files: []
|