open-elevation-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 +23 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +104 -0
- data/README.md +54 -0
- data/lib/open-elevation-api/configuration.rb +13 -0
- data/lib/open-elevation-api/get_elevations.rb +55 -0
- data/lib/open-elevation-api.rb +22 -0
- data/open-elevation-api.gemspec +22 -0
- data/spec/fixtures/vcr_cassettes/multiple_location.yml +45 -0
- data/spec/fixtures/vcr_cassettes/single_location.yml +45 -0
- data/spec/open-elevation-api/get_elevations_spec.rb +64 -0
- data/spec/spec_helper.rb +23 -0
- metadata +167 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 6b140920a500137c4eb837a745242868a0b2ef6448a0a3b96515f1e9e28b6d5d
|
|
4
|
+
data.tar.gz: f0ca081ab2bc0b434739c40b4c282945239d27707630f6e0ca694eb29b847a42
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: e14888ab9df8df14ac881880aa1c5f6ac96d8cbbb67fb54e4b7897110c177f9aaebf3b90f1ba84bf45fe7ffc733b73686bb0094e64370af67081a6dcd6d72130
|
|
7
|
+
data.tar.gz: 3bef980cee75a518fd70fc0d5b9de47cb9094fa2f8697ead6b8a2e942b1f68e4805d4c2c065f2027be590cfc71e06b80cff76ad498adaa7a4ac815a3ea89fa80
|
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require:
|
|
2
|
+
- rubocop-rspec
|
|
3
|
+
AllCops:
|
|
4
|
+
DisplayCopNames: true
|
|
5
|
+
NewCops: enable
|
|
6
|
+
TargetRubyVersion: 3.1
|
|
7
|
+
Style/Documentation:
|
|
8
|
+
Enabled: false
|
|
9
|
+
Style/FrozenStringLiteralComment:
|
|
10
|
+
Enabled: false
|
|
11
|
+
Metrics/MethodLength:
|
|
12
|
+
Max: 18
|
|
13
|
+
Metrics/BlockLength:
|
|
14
|
+
Max: 40
|
|
15
|
+
Gemspec/DevelopmentDependencies:
|
|
16
|
+
Enabled: false
|
|
17
|
+
RSpec/MultipleExpectations:
|
|
18
|
+
Enabled: false
|
|
19
|
+
RSpec/ExampleLength:
|
|
20
|
+
Max: 30
|
|
21
|
+
Layout/LineLength:
|
|
22
|
+
Exclude:
|
|
23
|
+
- spec/quelink_mg/resp/*_spec.rb
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
open-elevation-api (0.1.0)
|
|
5
|
+
activesupport (~> 7.0)
|
|
6
|
+
httparty
|
|
7
|
+
|
|
8
|
+
GEM
|
|
9
|
+
remote: https://rubygems.org/
|
|
10
|
+
specs:
|
|
11
|
+
activesupport (7.0.7.2)
|
|
12
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
13
|
+
i18n (>= 1.6, < 2)
|
|
14
|
+
minitest (>= 5.1)
|
|
15
|
+
tzinfo (~> 2.0)
|
|
16
|
+
addressable (2.8.6)
|
|
17
|
+
public_suffix (>= 2.0.2, < 6.0)
|
|
18
|
+
ast (2.4.2)
|
|
19
|
+
base64 (0.1.1)
|
|
20
|
+
coderay (1.1.3)
|
|
21
|
+
concurrent-ruby (1.2.2)
|
|
22
|
+
crack (0.4.5)
|
|
23
|
+
rexml
|
|
24
|
+
diff-lcs (1.5.0)
|
|
25
|
+
hashdiff (1.1.0)
|
|
26
|
+
httparty (0.21.0)
|
|
27
|
+
mini_mime (>= 1.0.0)
|
|
28
|
+
multi_xml (>= 0.5.2)
|
|
29
|
+
i18n (1.14.1)
|
|
30
|
+
concurrent-ruby (~> 1.0)
|
|
31
|
+
json (2.6.3)
|
|
32
|
+
language_server-protocol (3.17.0.3)
|
|
33
|
+
method_source (1.0.0)
|
|
34
|
+
mini_mime (1.1.5)
|
|
35
|
+
minitest (5.20.0)
|
|
36
|
+
multi_xml (0.6.0)
|
|
37
|
+
parallel (1.23.0)
|
|
38
|
+
parser (3.2.2.3)
|
|
39
|
+
ast (~> 2.4.1)
|
|
40
|
+
racc
|
|
41
|
+
pry (0.14.2)
|
|
42
|
+
coderay (~> 1.1)
|
|
43
|
+
method_source (~> 1.0)
|
|
44
|
+
public_suffix (5.0.4)
|
|
45
|
+
racc (1.7.1)
|
|
46
|
+
rainbow (3.1.1)
|
|
47
|
+
regexp_parser (2.8.1)
|
|
48
|
+
rexml (3.2.6)
|
|
49
|
+
rspec (3.12.0)
|
|
50
|
+
rspec-core (~> 3.12.0)
|
|
51
|
+
rspec-expectations (~> 3.12.0)
|
|
52
|
+
rspec-mocks (~> 3.12.0)
|
|
53
|
+
rspec-core (3.12.2)
|
|
54
|
+
rspec-support (~> 3.12.0)
|
|
55
|
+
rspec-expectations (3.12.3)
|
|
56
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
57
|
+
rspec-support (~> 3.12.0)
|
|
58
|
+
rspec-mocks (3.12.6)
|
|
59
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
60
|
+
rspec-support (~> 3.12.0)
|
|
61
|
+
rspec-support (3.12.1)
|
|
62
|
+
rubocop (1.56.0)
|
|
63
|
+
base64 (~> 0.1.1)
|
|
64
|
+
json (~> 2.3)
|
|
65
|
+
language_server-protocol (>= 3.17.0)
|
|
66
|
+
parallel (~> 1.10)
|
|
67
|
+
parser (>= 3.2.2.3)
|
|
68
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
69
|
+
regexp_parser (>= 1.8, < 3.0)
|
|
70
|
+
rexml (>= 3.2.5, < 4.0)
|
|
71
|
+
rubocop-ast (>= 1.28.1, < 2.0)
|
|
72
|
+
ruby-progressbar (~> 1.7)
|
|
73
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
|
74
|
+
rubocop-ast (1.29.0)
|
|
75
|
+
parser (>= 3.2.1.0)
|
|
76
|
+
rubocop-capybara (2.18.0)
|
|
77
|
+
rubocop (~> 1.41)
|
|
78
|
+
rubocop-rspec (2.21.0)
|
|
79
|
+
rubocop (~> 1.33)
|
|
80
|
+
rubocop-capybara (~> 2.17)
|
|
81
|
+
ruby-progressbar (1.13.0)
|
|
82
|
+
tzinfo (2.0.6)
|
|
83
|
+
concurrent-ruby (~> 1.0)
|
|
84
|
+
unicode-display_width (2.4.2)
|
|
85
|
+
vcr (6.1.0)
|
|
86
|
+
webmock (3.19.1)
|
|
87
|
+
addressable (>= 2.8.0)
|
|
88
|
+
crack (>= 0.3.2)
|
|
89
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
|
90
|
+
|
|
91
|
+
PLATFORMS
|
|
92
|
+
x86_64-linux
|
|
93
|
+
|
|
94
|
+
DEPENDENCIES
|
|
95
|
+
open-elevation-api!
|
|
96
|
+
pry (~> 0.13)
|
|
97
|
+
rspec (~> 3.9)
|
|
98
|
+
rubocop (~> 1.0)
|
|
99
|
+
rubocop-rspec (~> 2.2)
|
|
100
|
+
vcr (~> 6.0)
|
|
101
|
+
webmock (~> 3.0)
|
|
102
|
+
|
|
103
|
+
BUNDLED WITH
|
|
104
|
+
2.4.7
|
data/README.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# open-api-elevation
|
|
2
|
+
This gem is both for using official Open Elevation API https://open-elevation.com/ and the one you can serve on your own server https://github.com/Jorl17/open-elevation/blob/master/docs/host-your-own.md
|
|
3
|
+
I encourage you if you plan to use Open Elevation API to either host on your own (mind it requires to store a lot of data ~20GB) or donate for Open Elevation API servers to help the creator provide the service
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## Instalation
|
|
7
|
+
|
|
8
|
+
The open-api-elevation gem is available at rubygems.org. You can install with:
|
|
9
|
+
|
|
10
|
+
`gem install open-api-elevation`
|
|
11
|
+
|
|
12
|
+
Alternatively, you can install the gem with bundler:
|
|
13
|
+
|
|
14
|
+
## Gemfile
|
|
15
|
+
|
|
16
|
+
`gem 'open-api-elevation'`
|
|
17
|
+
|
|
18
|
+
After doing bundle install, you should have the gem installed in your bundle.
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
## Configuration
|
|
22
|
+
If you want to use public OpenElevation API you may omit this step
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
OpenElevation.configure do |config|
|
|
26
|
+
config.api_url = 'https://EXAMPLE_API_SERVER/api/v1/lookup'
|
|
27
|
+
end
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
You need to prepare collection that reponds to longitude and latitude methods
|
|
33
|
+
```
|
|
34
|
+
service = described_class.new(collection: ...)
|
|
35
|
+
service.call
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Results then may be obtained by
|
|
39
|
+
```
|
|
40
|
+
service.raw_response # as Hash
|
|
41
|
+
service.collection_with_result # as original collection with elevation filled (if possible)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
## Development
|
|
46
|
+
|
|
47
|
+
Building gem locally (you can change file name, ofc):
|
|
48
|
+
|
|
49
|
+
`gem build *.gemspec -o pkg/open-api-elevation.gem`
|
|
50
|
+
|
|
51
|
+
Installing:
|
|
52
|
+
`gem install pkg/open-api-elevation.gem`
|
|
53
|
+
|
|
54
|
+
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module OpenElevationApi
|
|
4
|
+
class Configuration
|
|
5
|
+
attr_accessor :api_url
|
|
6
|
+
|
|
7
|
+
OPEN_ELEVATION_API_URL = 'https://api.open-elevation.com/api/v1/lookup'
|
|
8
|
+
|
|
9
|
+
def initialize(api_url = nil)
|
|
10
|
+
@api_url = api_url || OPEN_ELEVATION_API_URL
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
require 'httparty'
|
|
2
|
+
|
|
3
|
+
module OpenElevationApi
|
|
4
|
+
InvalidCollection = Class.new(StandardError)
|
|
5
|
+
class GetElevations
|
|
6
|
+
attr_reader :raw_response, :collection_with_result
|
|
7
|
+
|
|
8
|
+
def initialize(collection:, longitude_method: :longitude, latitude_method: :latitude)
|
|
9
|
+
@collection = collection
|
|
10
|
+
@longitude_method = longitude_method
|
|
11
|
+
@latitude_method = latitude_method
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def call
|
|
15
|
+
raise InvalidCollection, 'Latitude or Longitude not provided' unless verify_collection
|
|
16
|
+
|
|
17
|
+
@raw_response = api_result
|
|
18
|
+
@collection_with_result = combined_results
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
def verify_collection
|
|
24
|
+
@collection.all? { |obj| obj.respond_to?(@longitude_method) && obj.respond_to?(@latitude_method) }
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def body
|
|
28
|
+
{
|
|
29
|
+
locations: @collection.map do |obj|
|
|
30
|
+
{ latitude: obj.send(@latitude_method), longitude: obj.send(@longitude_method) }
|
|
31
|
+
end
|
|
32
|
+
}.to_json
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def api_result
|
|
36
|
+
@api_result ||= HTTParty.post(
|
|
37
|
+
OpenElevationApi.configuration.api_url,
|
|
38
|
+
body:,
|
|
39
|
+
headers: { 'Content-Type': 'application/json', Accept: 'application/json' }
|
|
40
|
+
)['results']
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def combined_results
|
|
44
|
+
@collection.each do |obj|
|
|
45
|
+
result = api_result.find do |res|
|
|
46
|
+
res['latitude'] == obj.send(@latitude_method) && res['longitude'] == obj.send(@longitude_method)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
next if result.nil? || !obj.respond_to?(:elevation)
|
|
50
|
+
|
|
51
|
+
obj.elevation = result['elevation']
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'pry'
|
|
4
|
+
require 'date'
|
|
5
|
+
require 'active_support'
|
|
6
|
+
require 'active_support/time_with_zone'
|
|
7
|
+
require 'active_support/core_ext/time/zones'
|
|
8
|
+
|
|
9
|
+
require File.expand_path('open-elevation-api/get_elevations.rb', __dir__)
|
|
10
|
+
require File.expand_path('open-elevation-api/configuration.rb', __dir__)
|
|
11
|
+
|
|
12
|
+
module OpenElevationApi
|
|
13
|
+
class << self
|
|
14
|
+
def configuration
|
|
15
|
+
@configuration ||= Configuration.new
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def configure
|
|
19
|
+
yield(configuration)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Gem::Specification.new do |s|
|
|
2
|
+
s.name = 'open-elevation-api'
|
|
3
|
+
s.version = '0.1.0'
|
|
4
|
+
s.summary = 'Handles selecting elevation from Open Elevation API'
|
|
5
|
+
s.description = 'Works for both official API and self-hosted versions'
|
|
6
|
+
s.authors = ['Stanislaw Zawadzki']
|
|
7
|
+
s.email = 'st.zawadzki@gmail.com '
|
|
8
|
+
|
|
9
|
+
s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
|
10
|
+
s.require_paths = ['lib']
|
|
11
|
+
s.license = 'MIT'
|
|
12
|
+
s.required_ruby_version = '>= 3.1'
|
|
13
|
+
s.add_dependency 'activesupport', '~> 7.0'
|
|
14
|
+
s.add_dependency 'httparty'
|
|
15
|
+
s.add_development_dependency 'pry', '~> 0.13'
|
|
16
|
+
s.add_development_dependency 'rspec', '~> 3.9'
|
|
17
|
+
s.add_development_dependency 'rubocop', '~> 1.0'
|
|
18
|
+
s.add_development_dependency 'rubocop-rspec', '~> 2.2'
|
|
19
|
+
s.add_development_dependency 'vcr', '~> 6.0'
|
|
20
|
+
s.add_development_dependency 'webmock', '~> 3.0'
|
|
21
|
+
s.metadata['rubygems_mfa_required'] = 'false'
|
|
22
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
---
|
|
2
|
+
http_interactions:
|
|
3
|
+
- request:
|
|
4
|
+
method: post
|
|
5
|
+
uri: https://api.open-elevation.com/api/v1/lookup
|
|
6
|
+
body:
|
|
7
|
+
encoding: UTF-8
|
|
8
|
+
string: '{"locations":[{"latitude":51.01,"longitude":21.01},{"latitude":51.21,"longitude":21.06},{"latitude":51.51,"longitude":20.91}]}'
|
|
9
|
+
headers:
|
|
10
|
+
Content-Type:
|
|
11
|
+
- application/json
|
|
12
|
+
Accept:
|
|
13
|
+
- application/json
|
|
14
|
+
Accept-Encoding:
|
|
15
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
|
16
|
+
User-Agent:
|
|
17
|
+
- Ruby
|
|
18
|
+
response:
|
|
19
|
+
status:
|
|
20
|
+
code: 200
|
|
21
|
+
message: OK
|
|
22
|
+
headers:
|
|
23
|
+
Server:
|
|
24
|
+
- nginx/1.21.1
|
|
25
|
+
Date:
|
|
26
|
+
- Tue, 09 Jan 2024 18:59:59 GMT
|
|
27
|
+
Content-Type:
|
|
28
|
+
- application/json
|
|
29
|
+
Transfer-Encoding:
|
|
30
|
+
- chunked
|
|
31
|
+
Connection:
|
|
32
|
+
- keep-alive
|
|
33
|
+
Strict-Transport-Security:
|
|
34
|
+
- max-age=31536000; includeSubDomains
|
|
35
|
+
Access-Control-Allow-Origin:
|
|
36
|
+
- "*"
|
|
37
|
+
Access-Control-Allow-Methods:
|
|
38
|
+
- GET, POST, OPTIONS
|
|
39
|
+
Access-Control-Allow-Headers:
|
|
40
|
+
- DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Origin,Accept,Content-Type,X-Requested_with,X-CSRF-Token
|
|
41
|
+
body:
|
|
42
|
+
encoding: ASCII-8BIT
|
|
43
|
+
string: '{"results":[{"latitude":51.01,"longitude":21.01,"elevation":290.0},{"elevation":193.0,"longitude":21.06,"latitude":51.21},{"latitude":51.51,"longitude":20.91,"elevation":162.0}]}'
|
|
44
|
+
recorded_at: Tue, 09 Jan 2024 18:59:59 GMT
|
|
45
|
+
recorded_with: VCR 6.1.0
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
---
|
|
2
|
+
http_interactions:
|
|
3
|
+
- request:
|
|
4
|
+
method: post
|
|
5
|
+
uri: https://api.open-elevation.com/api/v1/lookup
|
|
6
|
+
body:
|
|
7
|
+
encoding: UTF-8
|
|
8
|
+
string: '{"locations":[{"latitude":51.01,"longitude":21.01}]}'
|
|
9
|
+
headers:
|
|
10
|
+
Content-Type:
|
|
11
|
+
- application/json
|
|
12
|
+
Accept:
|
|
13
|
+
- application/json
|
|
14
|
+
Accept-Encoding:
|
|
15
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
|
16
|
+
User-Agent:
|
|
17
|
+
- Ruby
|
|
18
|
+
response:
|
|
19
|
+
status:
|
|
20
|
+
code: 200
|
|
21
|
+
message: OK
|
|
22
|
+
headers:
|
|
23
|
+
Server:
|
|
24
|
+
- nginx/1.21.1
|
|
25
|
+
Date:
|
|
26
|
+
- Tue, 09 Jan 2024 18:21:25 GMT
|
|
27
|
+
Content-Type:
|
|
28
|
+
- application/json
|
|
29
|
+
Transfer-Encoding:
|
|
30
|
+
- chunked
|
|
31
|
+
Connection:
|
|
32
|
+
- keep-alive
|
|
33
|
+
Strict-Transport-Security:
|
|
34
|
+
- max-age=31536000; includeSubDomains
|
|
35
|
+
Access-Control-Allow-Origin:
|
|
36
|
+
- "*"
|
|
37
|
+
Access-Control-Allow-Methods:
|
|
38
|
+
- GET, POST, OPTIONS
|
|
39
|
+
Access-Control-Allow-Headers:
|
|
40
|
+
- DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Origin,Accept,Content-Type,X-Requested_with,X-CSRF-Token
|
|
41
|
+
body:
|
|
42
|
+
encoding: ASCII-8BIT
|
|
43
|
+
string: '{"results":[{"latitude":51.01,"longitude":21.01,"elevation":290.0}]}'
|
|
44
|
+
recorded_at: Tue, 09 Jan 2024 18:21:25 GMT
|
|
45
|
+
recorded_with: VCR 6.1.0
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe OpenElevationApi::GetElevations do
|
|
4
|
+
it 'returns error if longitude or latitude missing' do
|
|
5
|
+
elevation_stuct = OpenStruct.new(longitude: 21.01, elevation: nil)
|
|
6
|
+
|
|
7
|
+
service = described_class.new(collection: [elevation_stuct])
|
|
8
|
+
expect{service.call}.to raise_error OpenElevationApi::InvalidCollection
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it 'gets single elevation - and enhancing collection' do
|
|
12
|
+
VCR.use_cassette('single location') do
|
|
13
|
+
elevation_stuct = OpenStruct.new(longitude: 21.01, latitude: 51.01, elevation: nil)
|
|
14
|
+
|
|
15
|
+
service = described_class.new(collection: [elevation_stuct])
|
|
16
|
+
service.call
|
|
17
|
+
|
|
18
|
+
expect(service.raw_response).to eq [{ 'latitude' => 51.01, 'longitude' => 21.01, 'elevation' => 290.0 }]
|
|
19
|
+
expect(service.collection_with_result.first.elevation).to eq 290.0
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'gets single elevation - and enhancing collection, but with different method names' do
|
|
24
|
+
VCR.use_cassette('single location') do
|
|
25
|
+
elevation_stuct = OpenStruct.new(lon: 21.01, lat: 51.01, elevation: nil)
|
|
26
|
+
|
|
27
|
+
service = described_class.new(collection: [elevation_stuct], longitude_method: :lon, latitude_method: :lat)
|
|
28
|
+
service.call
|
|
29
|
+
|
|
30
|
+
expect(service.raw_response).to eq [{ 'latitude' => 51.01, 'longitude' => 21.01, 'elevation' => 290.0 }]
|
|
31
|
+
expect(service.collection_with_result.first.elevation).to eq 290.0
|
|
32
|
+
expect(service.collection_with_result.first.lat).to eq 51.01
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it 'gets single elevation - and enhancing collection' do
|
|
37
|
+
VCR.use_cassette('single location') do
|
|
38
|
+
ElevationImmutableStruct = Struct.new(:longitude, :latitude)
|
|
39
|
+
elevation_stuct = ElevationImmutableStruct.new(21.01, 51.01)
|
|
40
|
+
|
|
41
|
+
collection = [elevation_stuct]
|
|
42
|
+
service = described_class.new(collection:)
|
|
43
|
+
service.call
|
|
44
|
+
|
|
45
|
+
expect(service.raw_response).to eq [{ 'latitude' => 51.01, 'longitude' => 21.01, 'elevation' => 290.0 }]
|
|
46
|
+
expect(service.collection_with_result).to eq collection
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it 'gets multiple elevation - and enhancing collection' do
|
|
51
|
+
VCR.use_cassette('multiple location') do
|
|
52
|
+
elevation_stuct = OpenStruct.new(longitude: 21.01, latitude: 51.01, elevation: nil)
|
|
53
|
+
elevation_stuct_2 = OpenStruct.new(longitude: 21.06, latitude: 51.21, elevation: nil)
|
|
54
|
+
elevation_stuct_3 = OpenStruct.new(longitude: 20.91, latitude: 51.51, elevation: nil)
|
|
55
|
+
|
|
56
|
+
service = described_class.new(collection: [elevation_stuct, elevation_stuct_2, elevation_stuct_3])
|
|
57
|
+
service.call
|
|
58
|
+
|
|
59
|
+
expect(service.raw_response.map{|r| r['elevation']}).to eq [290.0, 193.0, 162.0]
|
|
60
|
+
expect(service.collection_with_result.first.elevation).to eq 290.0
|
|
61
|
+
expect(service.collection_with_result.last.elevation).to eq 162.0
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require 'vcr'
|
|
2
|
+
require_relative '../lib/open-elevation-api'
|
|
3
|
+
|
|
4
|
+
OpenElevationApi.configure do |config|
|
|
5
|
+
config.api_url = OpenElevationApi::Configuration::OPEN_ELEVATION_API_URL
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
RSpec.configure do |config|
|
|
9
|
+
config.expect_with :rspec do |expectations|
|
|
10
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
config.mock_with :rspec do |mocks|
|
|
14
|
+
mocks.verify_partial_doubles = true
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
VCR.configure do |config|
|
|
21
|
+
config.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
|
|
22
|
+
config.hook_into :webmock
|
|
23
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: open-elevation-api
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Stanislaw Zawadzki
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2024-01-09 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: activesupport
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '7.0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '7.0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: httparty
|
|
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: pry
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0.13'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0.13'
|
|
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.9'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '3.9'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rubocop
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '1.0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '1.0'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: rubocop-rspec
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - "~>"
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '2.2'
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - "~>"
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '2.2'
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: vcr
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - "~>"
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '6.0'
|
|
104
|
+
type: :development
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - "~>"
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '6.0'
|
|
111
|
+
- !ruby/object:Gem::Dependency
|
|
112
|
+
name: webmock
|
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
|
114
|
+
requirements:
|
|
115
|
+
- - "~>"
|
|
116
|
+
- !ruby/object:Gem::Version
|
|
117
|
+
version: '3.0'
|
|
118
|
+
type: :development
|
|
119
|
+
prerelease: false
|
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
121
|
+
requirements:
|
|
122
|
+
- - "~>"
|
|
123
|
+
- !ruby/object:Gem::Version
|
|
124
|
+
version: '3.0'
|
|
125
|
+
description: Works for both official API and self-hosted versions
|
|
126
|
+
email: 'st.zawadzki@gmail.com '
|
|
127
|
+
executables: []
|
|
128
|
+
extensions: []
|
|
129
|
+
extra_rdoc_files: []
|
|
130
|
+
files:
|
|
131
|
+
- ".rubocop.yml"
|
|
132
|
+
- Gemfile
|
|
133
|
+
- Gemfile.lock
|
|
134
|
+
- README.md
|
|
135
|
+
- lib/open-elevation-api.rb
|
|
136
|
+
- lib/open-elevation-api/configuration.rb
|
|
137
|
+
- lib/open-elevation-api/get_elevations.rb
|
|
138
|
+
- open-elevation-api.gemspec
|
|
139
|
+
- spec/fixtures/vcr_cassettes/multiple_location.yml
|
|
140
|
+
- spec/fixtures/vcr_cassettes/single_location.yml
|
|
141
|
+
- spec/open-elevation-api/get_elevations_spec.rb
|
|
142
|
+
- spec/spec_helper.rb
|
|
143
|
+
homepage:
|
|
144
|
+
licenses:
|
|
145
|
+
- MIT
|
|
146
|
+
metadata:
|
|
147
|
+
rubygems_mfa_required: 'false'
|
|
148
|
+
post_install_message:
|
|
149
|
+
rdoc_options: []
|
|
150
|
+
require_paths:
|
|
151
|
+
- lib
|
|
152
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
153
|
+
requirements:
|
|
154
|
+
- - ">="
|
|
155
|
+
- !ruby/object:Gem::Version
|
|
156
|
+
version: '3.1'
|
|
157
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
|
+
requirements:
|
|
159
|
+
- - ">="
|
|
160
|
+
- !ruby/object:Gem::Version
|
|
161
|
+
version: '0'
|
|
162
|
+
requirements: []
|
|
163
|
+
rubygems_version: 3.3.7
|
|
164
|
+
signing_key:
|
|
165
|
+
specification_version: 4
|
|
166
|
+
summary: Handles selecting elevation from Open Elevation API
|
|
167
|
+
test_files: []
|