opencellid-client 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitgnore +3 -0
- data/.simplecov +3 -0
- data/Gemfile +4 -0
- data/License.txt +22 -0
- data/README.md +96 -0
- data/Rakefile +4 -0
- data/lib/opencellid.rb +7 -0
- data/lib/opencellid/bbox.rb +34 -0
- data/lib/opencellid/cell.rb +62 -0
- data/lib/opencellid/error.rb +30 -0
- data/lib/opencellid/measure.rb +42 -0
- data/lib/opencellid/opencellid.rb +108 -0
- data/lib/opencellid/response.rb +63 -0
- data/lib/opencellid/utils.rb +25 -0
- data/lib/opencellid/version.rb +5 -0
- data/opencellid-client.gemspec +27 -0
- data/spec/lib/bbox_spec.rb +47 -0
- data/spec/lib/cell_spec.rb +138 -0
- data/spec/lib/data/cell_not_found.xml +4 -0
- data/spec/lib/data/cell_with_measures.xml +10 -0
- data/spec/lib/data/measure_added.xml +4 -0
- data/spec/lib/data/measure_list.xml +5 -0
- data/spec/lib/data/one_cell.xml +4 -0
- data/spec/lib/error_spec.rb +58 -0
- data/spec/lib/measure_spec.rb +73 -0
- data/spec/lib/opencellid_spec.rb +242 -0
- data/spec/lib/response_spec.rb +134 -0
- data/spec/lib/utils_spec.rb +98 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/support/spec_utils.rb +3 -0
- metadata +122 -0
@@ -0,0 +1,134 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'opencellid'
|
3
|
+
|
4
|
+
module Opencellid
|
5
|
+
|
6
|
+
describe Response do
|
7
|
+
|
8
|
+
describe "from_xml" do
|
9
|
+
|
10
|
+
context "when passed nil" do
|
11
|
+
|
12
|
+
it "should raise error" do
|
13
|
+
expect{Response.from_xml(nil)}.to raise_error RuntimeError
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
context "when passing a document not containing a valid root element" do
|
19
|
+
|
20
|
+
it "should raise a RuntimeError" do
|
21
|
+
expect{Response.from_xml("<a>This is not a valid response</a>")}.to raise_error RuntimeError
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
context "when passing a valid measure list" do
|
27
|
+
|
28
|
+
before do
|
29
|
+
@response = Response.from_xml data_file_as_string("measure_list.xml")
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should contain measures" do
|
33
|
+
@response.should be_a Response
|
34
|
+
@response.measures.count.should == 2
|
35
|
+
@response.measures[0].lat.should == 60.5
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should be an_ok response" do
|
39
|
+
@response.should be_ok
|
40
|
+
@response.should_not be_failed
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should not have an error" do
|
44
|
+
@response.error.should be_nil
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should not contain cell sub-elements" do
|
48
|
+
@response.cells.should be_empty
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
context "when passing a valid response" do
|
54
|
+
|
55
|
+
context "and response has ok status" do
|
56
|
+
|
57
|
+
before do
|
58
|
+
@response = Response.from_xml data_file_as_string("one_cell.xml")
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should be an ok response" do
|
62
|
+
@response.should be_ok
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should contain the cell sub-elements" do
|
66
|
+
@response.cells.count.should == 1
|
67
|
+
@response.cells[0].id.should == 118135
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should not have an error" do
|
71
|
+
@response.error.should be_nil
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should not contain measures" do
|
75
|
+
@response.measures.should be_empty
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
context "and response has a failure status" do
|
81
|
+
|
82
|
+
before do
|
83
|
+
@response = Response.from_xml data_file_as_string("cell_not_found.xml")
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should be a failed response" do
|
87
|
+
@response.should_not be_ok
|
88
|
+
@response.should be_failed
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should not contain cell sub-elements" do
|
92
|
+
@response.cells.should be_empty
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should not contain measures" do
|
96
|
+
@response.measures.should be_empty
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should have the correct error" do
|
100
|
+
@response.error.should_not be_nil
|
101
|
+
@response.error.code.should == 1
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
context "and response contains a result field" do
|
107
|
+
|
108
|
+
before do
|
109
|
+
@response = Response.from_xml data_file_as_string("measure_added.xml")
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should have a result" do
|
113
|
+
@response.result.should match /^Measure added/
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should have a cell id" do
|
117
|
+
@response.cell_id.should == 1252312
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should have a measure_id" do
|
121
|
+
@response.measure_id.should == 56216401
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
|
132
|
+
|
133
|
+
|
134
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'opencellid'
|
3
|
+
|
4
|
+
module Opencellid
|
5
|
+
|
6
|
+
describe "to_i_or_nil" do
|
7
|
+
|
8
|
+
context "when passed nil" do
|
9
|
+
|
10
|
+
it "should return nil" do
|
11
|
+
::Opencellid.to_i_or_nil(nil).should be_nil
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
context "when passed an empty string" do
|
17
|
+
|
18
|
+
it "should return nil" do
|
19
|
+
::Opencellid.to_i_or_nil("").should be_nil
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
context "when passed a non-empty string" do
|
25
|
+
|
26
|
+
it "should invoke to_i on the string and return the result" do
|
27
|
+
string = double(:length => 1)
|
28
|
+
string.should_receive(:to_i).and_return 5
|
29
|
+
::Opencellid.to_i_or_nil(string).should == 5
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "to_f_or_nil" do
|
37
|
+
|
38
|
+
context "when passed nil" do
|
39
|
+
|
40
|
+
it "should return nil" do
|
41
|
+
::Opencellid.to_f_or_nil(nil).should be_nil
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
context "when passed an empty string" do
|
47
|
+
|
48
|
+
it "should return nil" do
|
49
|
+
::Opencellid.to_f_or_nil("").should be_nil
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
context "when passed a non-empty string" do
|
55
|
+
|
56
|
+
it "should invoke to_f on the string and return the result" do
|
57
|
+
string = double(:length => 1)
|
58
|
+
string.should_receive(:to_f).and_return 5.567
|
59
|
+
::Opencellid.to_f_or_nil(string).should == 5.567
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "to_datetime_or_nil" do
|
67
|
+
|
68
|
+
context "when passed nil" do
|
69
|
+
|
70
|
+
it "should return nil" do
|
71
|
+
::Opencellid.to_datetime_or_nil(nil,"format").should be_nil
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
context "when passed an empty string" do
|
77
|
+
|
78
|
+
it "should return nil" do
|
79
|
+
::Opencellid.to_datetime_or_nil("","format").should be_nil
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
context "when passed a non-empty string" do
|
85
|
+
|
86
|
+
it "should invoke strptime on the DateTime and return the result" do
|
87
|
+
now = DateTime.now
|
88
|
+
string = double(:length => 1)
|
89
|
+
DateTime.should_receive(:strptime).with(string,"format").and_return(now)
|
90
|
+
::Opencellid.to_datetime_or_nil(string,"format").should == now
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
require 'rspec'
|
3
|
+
require 'webmock/rspec'
|
4
|
+
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.color_enabled = true
|
12
|
+
config.formatter = 'documentation'
|
13
|
+
end
|
14
|
+
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: opencellid-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Marco Sandrini
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-02-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &70230512618500 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70230512618500
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: webmock
|
27
|
+
requirement: &70230512617380 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70230512617380
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: simplecov
|
38
|
+
requirement: &70230512616100 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70230512616100
|
47
|
+
description: A Ruby client for OpenCellID API
|
48
|
+
email:
|
49
|
+
- nessche@gmail.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- .gitgnore
|
55
|
+
- .simplecov
|
56
|
+
- Gemfile
|
57
|
+
- License.txt
|
58
|
+
- README.md
|
59
|
+
- Rakefile
|
60
|
+
- lib/opencellid.rb
|
61
|
+
- lib/opencellid/bbox.rb
|
62
|
+
- lib/opencellid/cell.rb
|
63
|
+
- lib/opencellid/error.rb
|
64
|
+
- lib/opencellid/measure.rb
|
65
|
+
- lib/opencellid/opencellid.rb
|
66
|
+
- lib/opencellid/response.rb
|
67
|
+
- lib/opencellid/utils.rb
|
68
|
+
- lib/opencellid/version.rb
|
69
|
+
- opencellid-client.gemspec
|
70
|
+
- spec/lib/bbox_spec.rb
|
71
|
+
- spec/lib/cell_spec.rb
|
72
|
+
- spec/lib/data/cell_not_found.xml
|
73
|
+
- spec/lib/data/cell_with_measures.xml
|
74
|
+
- spec/lib/data/measure_added.xml
|
75
|
+
- spec/lib/data/measure_list.xml
|
76
|
+
- spec/lib/data/one_cell.xml
|
77
|
+
- spec/lib/error_spec.rb
|
78
|
+
- spec/lib/measure_spec.rb
|
79
|
+
- spec/lib/opencellid_spec.rb
|
80
|
+
- spec/lib/response_spec.rb
|
81
|
+
- spec/lib/utils_spec.rb
|
82
|
+
- spec/spec_helper.rb
|
83
|
+
- spec/support/spec_utils.rb
|
84
|
+
homepage: https://github.com/nessche/opencellid-client
|
85
|
+
licenses: []
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options: []
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
92
|
+
requirements:
|
93
|
+
- - ! '>='
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 1.8.10
|
105
|
+
signing_key:
|
106
|
+
specification_version: 3
|
107
|
+
summary: A Ruby client for OpenCellID API
|
108
|
+
test_files:
|
109
|
+
- spec/lib/bbox_spec.rb
|
110
|
+
- spec/lib/cell_spec.rb
|
111
|
+
- spec/lib/data/cell_not_found.xml
|
112
|
+
- spec/lib/data/cell_with_measures.xml
|
113
|
+
- spec/lib/data/measure_added.xml
|
114
|
+
- spec/lib/data/measure_list.xml
|
115
|
+
- spec/lib/data/one_cell.xml
|
116
|
+
- spec/lib/error_spec.rb
|
117
|
+
- spec/lib/measure_spec.rb
|
118
|
+
- spec/lib/opencellid_spec.rb
|
119
|
+
- spec/lib/response_spec.rb
|
120
|
+
- spec/lib/utils_spec.rb
|
121
|
+
- spec/spec_helper.rb
|
122
|
+
- spec/support/spec_utils.rb
|