opencellid-client 0.1.1 → 0.1.2

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.
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.9.3"
4
+
5
+ script: bundle exec rake spec yard
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- # Specify your gem's dependencies in aebus.gemspec
3
+ # Specify your gem's dependencies in opencellid-client.gemspec
4
4
  gemspec
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  OpenCellID Client Library
2
2
  =========================
3
3
 
4
+
5
+ [![Build Status](https://travis-ci.org/nessche/opencellid-client.png)](https://travis-ci.org/nessche/opencellid-client)
6
+
7
+
4
8
  `opencellid-client` is a ruby gem that aims at simplifying the usage of the APIs provided by opencellid.org to transform cell IDs into coordinates.
5
9
 
6
10
  Installing
data/Rakefile CHANGED
@@ -1,4 +1,10 @@
1
1
  require 'bundler/gem_tasks'
2
2
  require 'rspec/core/rake_task'
3
+ require 'yard'
4
+ require 'yard/rake/yardoc_task'
3
5
 
4
- RSpec::Core::RakeTask.new('spec')
6
+ RSpec::Core::RakeTask.new('spec')
7
+
8
+ YARD::Rake::YardocTask.new('yard')
9
+
10
+ task :default => :spec
@@ -11,10 +11,10 @@ module Opencellid
11
11
  # @param latmax [Float] latmax the latitude of the NE corner of the box
12
12
  # @param lonmax [Float] lonmax the longitude of the NE corner of the box
13
13
  def initialize(latmin, lonmin, latmax, lonmax)
14
- raise ArgumentError, "latmin must not be nil" unless latmin
15
- raise ArgumentError, "lonmin must not be nil" unless lonmin
16
- raise ArgumentError, "latmax must not be nil" unless latmax
17
- raise ArgumentError, "lonmax must not be nil" unless lonmax
14
+ raise ArgumentError, 'latmin must not be nil' unless latmin
15
+ raise ArgumentError, 'lonmin must not be nil' unless lonmin
16
+ raise ArgumentError, 'latmax must not be nil' unless latmax
17
+ raise ArgumentError, 'lonmax must not be nil' unless lonmax
18
18
  @latmin = latmin
19
19
  @lonmin = lonmin
20
20
  @latmax = latmax
@@ -27,8 +27,8 @@ module Opencellid
27
27
  # @return [Cell] the Cell object obtained by parsing the XML
28
28
  def self.from_element(element)
29
29
  return nil unless element
30
- raise ArgumentError, "element must be of type XEXML::Element" unless element.is_a? REXML::Element
31
- raise ArgumentError, "element must be a <cell>" unless element.name == "cell"
30
+ raise ArgumentError, 'element must be of type XEXML::Element' unless element.is_a? REXML::Element
31
+ raise ArgumentError, 'element must be a <cell>' unless element.name == 'cell'
32
32
  attrs = element.attributes
33
33
 
34
34
  result = Cell.new(::Opencellid.to_i_or_nil(attrs['cellId']), ::Opencellid.to_i_or_nil(attrs['mnc']),
@@ -59,7 +59,7 @@ module Opencellid
59
59
  # with the library cell querying functions
60
60
  # @return [Hash] a hash object containing the non nil parameters which can be used in while querying for cells
61
61
  def to_query_hash
62
- {cellid: id, mnc: mnc, mcc: mcc, lac: lac}.delete_if {|k,v| v.nil?}
62
+ {cellid: id, mnc: mnc, mcc: mcc, lac: lac}.delete_if {|_,v| v.nil?}
63
63
  end
64
64
 
65
65
  # Returns an array containing the longitude and latitude of the cell, this method makes the Cell
@@ -20,8 +20,8 @@ module Opencellid
20
20
  # @return [Error] the error object created by parsing the XML element
21
21
  def self.from_element(element)
22
22
  return nil unless element
23
- raise ArgumentError, "element must be of type XEXML::Element" unless element.is_a? REXML::Element
24
- raise ArgumentError, "element must be an <err>" unless element.name == "err"
23
+ raise ArgumentError, 'element must be of type XEXML::Element' unless element.is_a? REXML::Element
24
+ raise ArgumentError, 'element must be an <err>' unless element.name == 'err'
25
25
  attrs = element.attributes
26
26
  return Error.new(::Opencellid.to_i_or_nil(attrs['code']),attrs['info'])
27
27
  end
@@ -7,7 +7,7 @@ module Opencellid
7
7
 
8
8
  # The format used by the OpenCellId API to pass date/time information
9
9
  # @private
10
- DATE_FORMAT = "%a %b %d %H:%M:%S %z %Y"
10
+ DATE_FORMAT = '%a %b %d %H:%M:%S %z %Y'
11
11
 
12
12
  attr_accessor :lat, :lon, :taken_by, :taken_on, :id, :signal
13
13
 
@@ -26,8 +26,8 @@ module Opencellid
26
26
  # @return [Measure] the Measure object obtained by parsing the XML
27
27
  def self.from_element(element)
28
28
  return nil unless element
29
- raise ArgumentError, "element must be of type XEXML::Element" unless element.is_a? REXML::Element
30
- raise ArgumentError, "element must be a <measure>" unless element.name == "measure"
29
+ raise ArgumentError, 'element must be of type XEXML::Element' unless element.is_a? REXML::Element
30
+ raise ArgumentError, 'element must be a <measure>' unless element.name == 'measure'
31
31
  attrs = element.attributes
32
32
  date = attrs['takenOn']
33
33
  date ||= attrs['measured_at']
@@ -15,7 +15,7 @@ module Opencellid
15
15
 
16
16
  private
17
17
  #the default URI used in all requests
18
- DEFAULT_URI = "http://www.opencellid.org"
18
+ DEFAULT_URI = 'http://www.opencellid.org'
19
19
 
20
20
  # the list of parameters allowed in the options for get_cells_in_area
21
21
  GET_IN_AREA_ALLOWED_PARAMS = [:limit, :mcc, :mnc]
@@ -32,7 +32,7 @@ module Opencellid
32
32
  # @param[Cell] cell the object containing the parameters to be used in searching the database
33
33
  # the result received from the server
34
34
  def get_cell(cell)
35
- query_cell_info "/cell/get", cell
35
+ query_cell_info '/cell/get', cell
36
36
  end
37
37
 
38
38
  # Retrieves the cell information and the measures used to calculate its position based on the parameters
@@ -40,7 +40,7 @@ module Opencellid
40
40
  # @param[Cell] cell the object containing the parameters used to search the cell database
41
41
  # @return[Response] the result received from the server
42
42
  def get_cell_measures(cell)
43
- query_cell_info "/cell/getMeasures", cell
43
+ query_cell_info '/cell/getMeasures', cell
44
44
  end
45
45
 
46
46
  # Retrieves all the cells located inside the bounding box and whose parameters match the ones specified in the options
@@ -49,11 +49,11 @@ module Opencellid
49
49
  # of results), `:mnc` specifying the mnc value of the desired cells and `:mcc` specifying the mcc value of the desired cells
50
50
  # @return [Response] the result received from the server
51
51
  def get_cells_in_area(bbox, options = {})
52
- raise ArgumentError, "options must be a Hash" unless options.is_a? Hash
53
- raise ArgumentError, "bbox must be of type BBox" unless bbox.is_a? BBox
52
+ raise ArgumentError, 'options must be a Hash' unless options.is_a? Hash
53
+ raise ArgumentError, 'bbox must be of type BBox' unless bbox.is_a? BBox
54
54
  params = {bbox: bbox.to_s, fmt: 'xml'}
55
55
  params.merge!(options.reject { |key| !GET_IN_AREA_ALLOWED_PARAMS.include? key})
56
- execute_request_and_parse_response "/cell/getInArea", params
56
+ exec_req_and_parse_response '/cell/getInArea', params
57
57
  end
58
58
 
59
59
  # Adds a measure (specified by the measure object) to a given cell (specified by the cell object). In case of
@@ -71,13 +71,13 @@ module Opencellid
71
71
  params[:lon] = measure.lon
72
72
  params[:signal] = measure.signal if measure.signal
73
73
  params[:measured_at] = measure.taken_on if measure.taken_on
74
- execute_request_and_parse_response "/measure/add", params
74
+ exec_req_and_parse_response "/measure/add", params
75
75
  end
76
76
 
77
77
  # List the measures added with a given API key.
78
78
  # @return [Response] the result received from the server
79
79
  def list_measures
80
- execute_request_and_parse_response "/measure/list"
80
+ exec_req_and_parse_response "/measure/list"
81
81
  end
82
82
 
83
83
  # Deletes a measure previously added with the same API key.
@@ -85,7 +85,7 @@ module Opencellid
85
85
  # @return [Response] the result received from the server
86
86
  def delete_measure(measure_id)
87
87
  raise ArgumentError,"measure_id cannot be nil" unless measure_id
88
- execute_request_and_parse_response "/measure/delete", {id: measure_id}
88
+ exec_req_and_parse_response "/measure/delete", {id: measure_id}
89
89
  end
90
90
 
91
91
  protected
@@ -93,10 +93,10 @@ module Opencellid
93
93
  def query_cell_info(path, cell)
94
94
  raise ArgumentError, "cell must be a Cell" unless cell.is_a? Cell
95
95
  params = cell.to_query_hash
96
- execute_request_and_parse_response path, params
96
+ exec_req_and_parse_response path, params
97
97
  end
98
98
 
99
- def execute_request_and_parse_response(path, params = {})
99
+ def exec_req_and_parse_response(path, params = {})
100
100
  params[:key] = @key if @key
101
101
  uri = URI(DEFAULT_URI + path)
102
102
  uri.query = URI.encode_www_form params if params.count > 0
@@ -1,5 +1,5 @@
1
1
  module Opencellid
2
2
 
3
3
  # This library current version
4
- VERSION = "0.1.1"
4
+ VERSION = '0.1.2'
5
5
  end
@@ -23,5 +23,8 @@ Gem::Specification.new do |s|
23
23
  s.add_development_dependency "rspec"
24
24
  s.add_development_dependency "webmock"
25
25
  s.add_development_dependency "simplecov"
26
+ s.add_development_dependency "rake"
27
+ s.add_development_dependency "yard"
28
+ s.add_development_dependency "redcarpet"
26
29
  # s.add_runtime_dependency "rest-client"
27
30
  end
@@ -13,46 +13,46 @@ module Opencellid
13
13
  Response.stub(:from_xml).and_return(@response)
14
14
  end
15
15
 
16
- describe "execute_request_and_parse_response" do
16
+ describe 'exec_req_and_parse_response' do
17
17
 
18
18
  before do
19
- @method = @oci.method(:execute_request_and_parse_response)
19
+ @method = @oci.method(:exec_req_and_parse_response)
20
20
 
21
21
  end
22
22
 
23
- context "when the api key is specified" do
23
+ context 'when the api key is specified' do
24
24
 
25
25
  before do
26
- @oci = Opencellid.new "myapikey"
27
- @method = @oci.method(:execute_request_and_parse_response)
26
+ @oci = Opencellid.new 'myapikey'
27
+ @method = @oci.method(:exec_req_and_parse_response)
28
28
  end
29
29
 
30
- it "should add it to the parameters" do
30
+ it 'should add it to the parameters' do
31
31
  @method.call("/")
32
- WebMock.should have_requested(:get, "www.opencellid.org/")
33
- .with(query: { "key" => "myapikey"})
32
+ WebMock.should have_requested(:get, 'www.opencellid.org/')
33
+ .with(query: { 'key' => 'myapikey'})
34
34
  end
35
35
 
36
36
  end
37
37
 
38
- context "when the api key is not specified" do
38
+ context 'when the api key is not specified' do
39
39
 
40
- it "should not add it to the parameters" do
41
- @method.call("/")
42
- WebMock.should have_requested(:get, "www.opencellid.org/")
40
+ it 'should not add it to the parameters' do
41
+ @method.call('/')
42
+ WebMock.should have_requested(:get, 'www.opencellid.org/')
43
43
  end
44
44
 
45
45
  end
46
46
 
47
- it "should add the params as query params" do
47
+ it 'should add the params as query params' do
48
48
 
49
- @method.call("/",{"a" => "10", "b" => "20", "c" => "30"})
50
- WebMock.should have_requested(:get, "www.opencellid.org/")
49
+ @method.call('/',{"a" => "10", "b" => "20", "c" => "30"})
50
+ WebMock.should have_requested(:get, 'www.opencellid.org/')
51
51
  .with(query: {"a" => "10", "b" => "20", "c" => "30"})
52
52
  end
53
53
 
54
- it "should set the path correctly" do
55
- @method.call("/mypath")
54
+ it 'should set the path correctly' do
55
+ @method.call('/mypath')
56
56
  WebMock.should have_requested(:get, "www.opencellid.org/mypath")
57
57
  end
58
58
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opencellid-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-10 00:00:00.000000000 Z
12
+ date: 2013-02-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70362406860500 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70362406860500
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: webmock
27
- requirement: &70362406859960 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,47 @@ dependencies:
32
37
  version: '0'
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *70362406859960
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: simplecov
38
- requirement: &70362406859380 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: yard
80
+ requirement: !ruby/object:Gem::Requirement
39
81
  none: false
40
82
  requirements:
41
83
  - - ! '>='
@@ -43,7 +85,28 @@ dependencies:
43
85
  version: '0'
44
86
  type: :development
45
87
  prerelease: false
46
- version_requirements: *70362406859380
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: redcarpet
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
47
110
  description: A Ruby client for OpenCellID API
48
111
  email:
49
112
  - nessche@gmail.com
@@ -53,6 +116,7 @@ extra_rdoc_files: []
53
116
  files:
54
117
  - .gitignore
55
118
  - .simplecov
119
+ - .travis.yml
56
120
  - .yardopts
57
121
  - Gemfile
58
122
  - License.txt
@@ -94,15 +158,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
94
158
  - - ! '>='
95
159
  - !ruby/object:Gem::Version
96
160
  version: '0'
161
+ segments:
162
+ - 0
163
+ hash: 868652574644727038
97
164
  required_rubygems_version: !ruby/object:Gem::Requirement
98
165
  none: false
99
166
  requirements:
100
167
  - - ! '>='
101
168
  - !ruby/object:Gem::Version
102
169
  version: '0'
170
+ segments:
171
+ - 0
172
+ hash: 868652574644727038
103
173
  requirements: []
104
174
  rubyforge_project:
105
- rubygems_version: 1.8.10
175
+ rubygems_version: 1.8.24
106
176
  signing_key:
107
177
  specification_version: 3
108
178
  summary: A Ruby client for OpenCellID API