overpass-api-ruby 0.2 → 0.2.1

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
  SHA1:
3
- metadata.gz: 8ef9346aa556dd932264aaa04f016c2d86553a93
4
- data.tar.gz: f6366d26fa31b74b910400e11f92376996dd0204
3
+ metadata.gz: 869f0f15d223e2dba7f50b5aee38f229afecff1f
4
+ data.tar.gz: a51e2aa6cfc9c4cd9eb9ace840d9c48eabbbacb1
5
5
  SHA512:
6
- metadata.gz: 013cc225d04ad2f4fe501f2beb430ad837831ddc134e4630ac962d7f47518d34b9c9f796418d103862a2aca2a762f10be631a7db8a0b4abf252c9c16e5542f7a
7
- data.tar.gz: 05eb5f15ed2b487300124889ca2ce7ecf5fedaa86cd3ec1c281af66c226083ca80bde55831b76ea525ecf66cf553053f20d98e25645ebca149b796bca1d37e35
6
+ metadata.gz: dd3a55ea3765c2c07b842a420eae89edbcd3111338e4ad9b878a2f42b39a6de0cebb92bc4d3749d1303ffd96e351a6c9571e7ff0bf53781a60c7d733400acacb
7
+ data.tar.gz: 63ea5915cbd930c273759d3da28bd87a868b57af31e6aa5af2f9ecf23fe0fa5734b43391f1cd20836b06bb30af762a069748df96d0ab10211ea8010bb0565e94
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- Overpass API Ruby
1
+ Overpass API Ruby [![CircleCI](https://circleci.com/gh/BrunoSalerno/overpass-api-ruby.svg?style=svg)](https://circleci.com/gh/BrunoSalerno/overpass-api-ruby)
2
2
  =================
3
3
 
4
4
  A Ruby wrapper for OpenStreetMap Overpass API. Supports both QL and XML.
@@ -76,6 +76,10 @@ buid_query (<String query>) Returns a String containing the whole query.
76
76
  bounding_box (s,n,w,e) Defines the global bounding box.
77
77
  ```
78
78
 
79
+ Test
80
+ ----
81
+
82
+ Run `rake spec`
79
83
 
80
84
  License
81
85
  -------
data/Rakefile CHANGED
@@ -4,9 +4,10 @@ require 'bundler/gem_tasks'
4
4
  require 'rake'
5
5
  require 'rspec/core/rake_task'
6
6
 
7
- desc 'Run all examples'
7
+ desc 'Run all tests'
8
8
  RSpec::Core::RakeTask.new(:spec) do |t|
9
+ t.pattern = "spec/**/*_spec.rb"
9
10
  t.rspec_opts = %w(--color --warnings)
10
11
  end
11
12
 
12
- task default: [:spec]
13
+ task default: [:spec]
@@ -3,8 +3,6 @@ require 'open-uri'
3
3
  require 'json'
4
4
 
5
5
  module OverpassAPI
6
- VERSION='0.2'
7
-
8
6
  class Base
9
7
  DEFAULT_ENDPOINT='http://overpass-api.de/api/interpreter?data='
10
8
 
@@ -0,0 +1,3 @@
1
+ module OverpassAPI
2
+ VERSION='0.2.1'
3
+ end
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'overpass_api_ruby'
4
+ require 'version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "overpass-api-ruby"
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+ require 'overpass_api_ruby'
3
+
4
+ describe OverpassAPI::QL do
5
+ it "should return the right elements" do
6
+ options={:bbox => {:s => -34.705448, :n => -34.526562,
7
+ :w => -58.531471, :e => -58.335159},
8
+ :timeout => 900}
9
+
10
+ overpass = OverpassAPI::QL.new(options)
11
+
12
+ ba_query = "rel['route'='subway'];(._;>;);out body;"
13
+
14
+ expect(overpass.query(ba_query)[:elements]).to be_a(Array)
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+ require 'overpass_api_ruby'
3
+
4
+ describe OverpassAPI::XML do
5
+ it "should return the requested elements" do
6
+ options={:bbox => {:s => -34.705448, :n => -34.526562,
7
+ :w => -58.531471, :e => -58.335159},
8
+ :timeout => 900}
9
+
10
+ overpass = OverpassAPI::XML.new(options)
11
+
12
+ ba_query = "<union><query type='relation'><has-kv k='route' v='subway'/></query>" <<
13
+ "</union><union><item/><recurse type='down'/></union>"
14
+
15
+
16
+ expect(overpass.query(ba_query)[:elements]).to be_a(Array)
17
+ end
18
+ end
@@ -37,7 +37,7 @@ RSpec.configure do |config|
37
37
  # Prevents you from mocking or stubbing a method that does not exist on
38
38
  # a real object. This is generally recommended, and will default to
39
39
  # `true` in RSpec 4.
40
- mocks.verify_partial_doubles = true
40
+ mocks.verify_partial_doubles = false
41
41
  end
42
42
 
43
43
  # The settings below are suggested to provide a good initial experience
@@ -0,0 +1,83 @@
1
+ require 'spec_helper'
2
+ require 'overpass_api_ruby'
3
+ require 'httpi'
4
+
5
+ describe OverpassAPI::Base do
6
+ it "should return the default endpoint" do
7
+ expect(OverpassAPI::Base::DEFAULT_ENDPOINT).to eq "http://overpass-api.de/api/interpreter?data="
8
+ base = OverpassAPI::Base.new
9
+ expect(base.instance_variable_get("@endpoint")).to eq OverpassAPI::Base::DEFAULT_ENDPOINT
10
+ end
11
+
12
+ it "should set the right args" do
13
+ opts = {bbox: {s: 1, n: 2, w: 3, e: 4},
14
+ endpoint: "a.endpoint.com",
15
+ timeout: 1000,
16
+ maxsize: 333}
17
+
18
+ base = OverpassAPI::Base.new(opts)
19
+
20
+ expect(base.instance_variable_get("@bbox")).to eq "1,3,2,4"
21
+ expect(base.instance_variable_get("@endpoint")).to eq "a.endpoint.com"
22
+ expect(base.instance_variable_get("@timeout")).to eq 1000
23
+ expect(base.instance_variable_get("@maxsize")).to eq 333
24
+ end
25
+
26
+ it "should set the bounding box" do
27
+ base = OverpassAPI::Base.new
28
+ base.bounding_box(10,20,30,40)
29
+
30
+ expect(base.instance_variable_get("@bbox")).to eq "10,30,20,40"
31
+ end
32
+
33
+ it "should try to perform the query" do
34
+ base = OverpassAPI::Base.new
35
+
36
+ query = "a query"
37
+ built_query = "built_query"
38
+ expected_response = "a response"
39
+
40
+ allow(base).to receive(:perform).and_return(expected_response)
41
+ allow(base).to receive(:build_query).and_return(built_query)
42
+
43
+ expect(base).to receive(:build_query).with(query)
44
+ expect(base).to receive(:perform).with(built_query)
45
+
46
+ response = base.query(query)
47
+
48
+ expect(response).to eq expected_response
49
+ end
50
+
51
+ it "should try to perform a raw query" do
52
+ base = OverpassAPI::Base.new
53
+
54
+ query = "as query"
55
+ expected_response = "a response"
56
+
57
+ allow(base).to receive(:perform).and_return(expected_response)
58
+ expect(base).to receive(:perform).with(query)
59
+
60
+ response = base.raw_query(query)
61
+
62
+ expect(response).to eq expected_response
63
+ end
64
+
65
+ it "should try to perform an http request" do
66
+ base = OverpassAPI::Base.new
67
+
68
+ query = "a query"
69
+ request = "a request"
70
+ body = {key: "value"}
71
+
72
+ url = URI::encode("#{OverpassAPI::Base::DEFAULT_ENDPOINT}#{query}")
73
+
74
+ allow(HTTPI::Request).to receive(:new).and_return(request)
75
+ expect(HTTPI::Request).to receive(:new).with(url)
76
+
77
+ allow(HTTPI).to receive(:get).and_return(OpenStruct.new(body: body.to_json))
78
+ expect(HTTPI).to receive(:get).with(request)
79
+
80
+ response = base.raw_query(query)
81
+ expect(response).to eq body
82
+ end
83
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+ require 'overpass_api_ruby'
3
+
4
+ describe OverpassAPI::QL do
5
+ it "should return the right built query when no opts are passed" do
6
+ overpass = OverpassAPI::QL.new
7
+ built_query = overpass.build_query("a query")
8
+
9
+ expect(built_query).to eq "[out:json];a query"
10
+ end
11
+
12
+ it "should set the right opts" do
13
+ opts = {bbox: {s: 1, n: 2, w: 3, e: 4},
14
+ timeout: 1000,
15
+ maxsize: 333}
16
+
17
+ overpass = OverpassAPI::QL.new(opts)
18
+ built_query = overpass.build_query("a query")
19
+
20
+ expected_built_query = "[bbox:1,3,2,4][timeout:1000][maxsize:333][out:json];a query"
21
+ expect(built_query).to eq expected_built_query
22
+ end
23
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+ require 'overpass_api_ruby'
3
+
4
+ describe OverpassAPI::XML do
5
+ it "should return the right built query when no opts are passed" do
6
+ overpass = OverpassAPI::XML.new
7
+ built_query = overpass.build_query("a query")
8
+
9
+ expect(built_query).to eq "<osm-script output='json'>a query<print/></osm-script>"
10
+ end
11
+
12
+ it "should set the right opts" do
13
+ opts = {bbox: {s: 1, n: 2, w: 3, e: 4},
14
+ timeout: 1000,
15
+ maxsize: 333}
16
+
17
+ overpass = OverpassAPI::XML.new(opts)
18
+ built_query = overpass.build_query("a query")
19
+
20
+ expected_built_query = "<osm-script bbox='1,3,2,4' timeout='1000' maxsize='333' output='json'>" <<
21
+ "a query<print/></osm-script>"
22
+ expect(built_query).to eq expected_built_query
23
+ end
24
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: overpass-api-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bruno Salerno
@@ -98,10 +98,15 @@ files:
98
98
  - lib/base.rb
99
99
  - lib/overpass_api_ruby.rb
100
100
  - lib/ql.rb
101
+ - lib/version.rb
101
102
  - lib/xml.rb
102
103
  - overpass-api-ruby.gemspec
103
- - spec/overpass_api_ruby_spec.rb
104
+ - spec/integration/ql_spec.rb
105
+ - spec/integration/xml_spec.rb
104
106
  - spec/spec_helper.rb
107
+ - spec/unit/base_spec.rb
108
+ - spec/unit/ql_spec.rb
109
+ - spec/unit/xml_spec.rb
105
110
  homepage: https://github.com/BrunoSalerno/overpass-api-ruby
106
111
  licenses:
107
112
  - MIT
@@ -128,5 +133,9 @@ specification_version: 4
128
133
  summary: This gem will allow you to perform queries to OSM Overpass API using QL or
129
134
  XML
130
135
  test_files:
131
- - spec/overpass_api_ruby_spec.rb
136
+ - spec/integration/ql_spec.rb
137
+ - spec/integration/xml_spec.rb
132
138
  - spec/spec_helper.rb
139
+ - spec/unit/base_spec.rb
140
+ - spec/unit/ql_spec.rb
141
+ - spec/unit/xml_spec.rb
@@ -1,34 +0,0 @@
1
- require 'spec_helper'
2
- require 'overpass_api_ruby'
3
-
4
- describe OverpassAPI do
5
- describe OverpassAPI::XML do
6
- it "'s example works" do
7
- options={:bbox => {:s => -34.705448, :n => -34.526562,
8
- :w => -58.531471, :e => -58.335159},
9
- :timeout => 900}
10
-
11
- overpass = OverpassAPI::XML.new(options)
12
-
13
- ba_query = "<union><query type='relation'><has-kv k='route' v='subway'/></query>" <<
14
- "</union><union><item/><recurse type='down'/></union>"
15
-
16
-
17
- expect(overpass.query(ba_query)[:elements]).to be_a(Array)
18
- end
19
- end
20
-
21
- describe OverpassAPI::QL do
22
- it "'s example works" do
23
- options={:bbox => {:s => -34.705448, :n => -34.526562,
24
- :w => -58.531471, :e => -58.335159},
25
- :timeout => 900}
26
-
27
- overpass = OverpassAPI::QL.new(options)
28
-
29
- ba_query = "rel['route'='subway'];(._;>;);out body;"
30
-
31
- expect(overpass.query(ba_query)[:elements]).to be_a(Array)
32
- end
33
- end
34
- end