opencellid-client 0.1.0 → 0.1.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.
- data/.gitignore +5 -0
- data/.yardopts +1 -0
- data/README.md +4 -4
- data/lib/opencellid/bbox.rb +0 -1
- data/lib/opencellid/cell.rb +14 -2
- data/lib/opencellid/error.rb +1 -0
- data/lib/opencellid/measure.rb +2 -0
- data/lib/opencellid/opencellid.rb +7 -0
- data/lib/opencellid/response.rb +3 -0
- data/lib/opencellid/version.rb +1 -1
- data/spec/lib/cell_spec.rb +12 -0
- metadata +11 -9
- data/.gitgnore +0 -3
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--no-private - License.txt
|
data/README.md
CHANGED
@@ -17,7 +17,7 @@ Usage
|
|
17
17
|
|
18
18
|
First of all `require 'opencellid'` in your application.
|
19
19
|
|
20
|
-
Read functionality (i.e. methods that only query the database generally do not require an API key
|
20
|
+
Read functionality (i.e. methods that only query the database) generally do not require an API key, write methods instead
|
21
21
|
do require an API key, so if you do not have one, head to the [OpenCellID website](http://www.opencellid.org/) and get one
|
22
22
|
for yourself.
|
23
23
|
|
@@ -35,7 +35,7 @@ got from the response, otherwise an error object can be extracted from the respo
|
|
35
35
|
methods to obtain the error code and human readable description.
|
36
36
|
|
37
37
|
Querying Cells
|
38
|
-
|
38
|
+
--------------
|
39
39
|
|
40
40
|
Cells can be queried using a combination of parameters: the cell id, the mnc (operator) and mcc (country) code or the local area
|
41
41
|
code lac. For a more detailed description of these parameters please refere to the OpenCellID site.
|
@@ -65,7 +65,7 @@ response = opencellid.get_cells_in_area(bbox, :limit => 10, :mnc => 5)
|
|
65
65
|
cells = response.cells`
|
66
66
|
|
67
67
|
Adding and Deleting Measures
|
68
|
-
|
68
|
+
----------------------------
|
69
69
|
|
70
70
|
Adding, deleting and listing "own" measures (i.e. measures inserted by the same user) require that an API key is
|
71
71
|
made available to the library at initialization time.
|
@@ -91,6 +91,6 @@ measures = response.measures`
|
|
91
91
|
|
92
92
|
|
93
93
|
Bulk addition of measures
|
94
|
-
|
94
|
+
-------------------------
|
95
95
|
|
96
96
|
Bulk addition of measure by uploading a CSV formatted file to the OpenCellID server is not yet supported by this library.
|
data/lib/opencellid/bbox.rb
CHANGED
data/lib/opencellid/cell.rb
CHANGED
@@ -22,7 +22,7 @@ module Opencellid
|
|
22
22
|
@measures = []
|
23
23
|
end
|
24
24
|
|
25
|
-
|
25
|
+
# Parses the given element setting the information into a Cell object
|
26
26
|
# @param element [REXML::Element] the XML element containing the representation of the Cell element
|
27
27
|
# @return [Cell] the Cell object obtained by parsing the XML
|
28
28
|
def self.from_element(element)
|
@@ -41,22 +41,34 @@ module Opencellid
|
|
41
41
|
result
|
42
42
|
end
|
43
43
|
|
44
|
+
|
45
|
+
# Indicates whether this cell contains measure objects
|
44
46
|
# @return [bool] whether this cell contains measure objects
|
45
47
|
def has_measures?
|
46
48
|
@measures.count > 0
|
47
49
|
end
|
48
50
|
|
51
|
+
# Adds a new measure to this cell
|
49
52
|
# @param measure [Measure] a measure object to be added to this cell. Note that adding the object to the cell
|
50
53
|
# does NOT result in an add_measure call being invoked on the Opencellid object
|
51
54
|
def add_measure(measure)
|
52
55
|
@measures << measure
|
53
56
|
end
|
54
57
|
|
55
|
-
#
|
58
|
+
# Helper function that transforms the parameters of this cell in a hash of query parameters to be used
|
59
|
+
# with the library cell querying functions
|
60
|
+
# @return [Hash] a hash object containing the non nil parameters which can be used in while querying for cells
|
56
61
|
def to_query_hash
|
57
62
|
{cellid: id, mnc: mnc, mcc: mcc, lac: lac}.delete_if {|k,v| v.nil?}
|
58
63
|
end
|
59
64
|
|
65
|
+
# Returns an array containing the longitude and latitude of the cell, this method makes the Cell
|
66
|
+
# object to be compatible with mongoid_spacial gem
|
67
|
+
# @return [Array] an array containing longitude and latitude of the cell.
|
68
|
+
def to_lng_lat
|
69
|
+
[lon, lat]
|
70
|
+
end
|
71
|
+
|
60
72
|
end
|
61
73
|
|
62
74
|
end
|
data/lib/opencellid/error.rb
CHANGED
@@ -15,6 +15,7 @@ module Opencellid
|
|
15
15
|
@code = code
|
16
16
|
end
|
17
17
|
|
18
|
+
# Parses the given XML element extracting the information into the corresponding Error object
|
18
19
|
# @param element [REXML::Element] an XML element containing the error
|
19
20
|
# @return [Error] the error object created by parsing the XML element
|
20
21
|
def self.from_element(element)
|
data/lib/opencellid/measure.rb
CHANGED
@@ -6,6 +6,7 @@ module Opencellid
|
|
6
6
|
class Measure
|
7
7
|
|
8
8
|
# The format used by the OpenCellId API to pass date/time information
|
9
|
+
# @private
|
9
10
|
DATE_FORMAT = "%a %b %d %H:%M:%S %z %Y"
|
10
11
|
|
11
12
|
attr_accessor :lat, :lon, :taken_by, :taken_on, :id, :signal
|
@@ -20,6 +21,7 @@ module Opencellid
|
|
20
21
|
end
|
21
22
|
|
22
23
|
|
24
|
+
# Parses the given XML element extracting the information into the corresponding Measure object
|
23
25
|
# @param element [REXML::Element] the XML element containing the representation of the measurement
|
24
26
|
# @return [Measure] the Measure object obtained by parsing the XML
|
25
27
|
def self.from_element(element)
|
@@ -6,14 +6,21 @@ require_relative 'measure'
|
|
6
6
|
require_relative 'bbox'
|
7
7
|
require_relative 'error'
|
8
8
|
|
9
|
+
# The module for the opencellid-client gem
|
9
10
|
module Opencellid
|
10
11
|
|
11
12
|
# The main entry for this library. Each method maps to the corresponding method of the
|
12
13
|
# OpenCellId API defined at {http:://www.opencellid.org/api}.
|
13
14
|
class Opencellid
|
14
15
|
|
16
|
+
private
|
17
|
+
#the default URI used in all requests
|
15
18
|
DEFAULT_URI = "http://www.opencellid.org"
|
19
|
+
|
20
|
+
# the list of parameters allowed in the options for get_cells_in_area
|
16
21
|
GET_IN_AREA_ALLOWED_PARAMS = [:limit, :mcc, :mnc]
|
22
|
+
|
23
|
+
public
|
17
24
|
attr_reader :key
|
18
25
|
|
19
26
|
# @param key [String] the API key used for "write" operations. Defaults to nil
|
data/lib/opencellid/response.rb
CHANGED
@@ -17,16 +17,19 @@ module Opencellid
|
|
17
17
|
@ok = ok
|
18
18
|
end
|
19
19
|
|
20
|
+
# Tells whether the response is a successful response or not
|
20
21
|
# @return [bool] `true` if the response is a successful response
|
21
22
|
def ok?
|
22
23
|
@ok
|
23
24
|
end
|
24
25
|
|
26
|
+
# Tells whether the response is a failure response or not
|
25
27
|
# @return [bool] `true` if the response is a failure response
|
26
28
|
def failed?
|
27
29
|
not @ok
|
28
30
|
end
|
29
31
|
|
32
|
+
# Parses the string containing the response as XML and returns the corresponding Response object
|
30
33
|
# @param string [String] a string containing the XML response received from the server
|
31
34
|
# @return [Response] the Response object obtained by parsing the XML file
|
32
35
|
def self.from_xml(string)
|
data/lib/opencellid/version.rb
CHANGED
data/spec/lib/cell_spec.rb
CHANGED
@@ -131,7 +131,19 @@ XML
|
|
131
131
|
|
132
132
|
end
|
133
133
|
|
134
|
+
describe "to_lng_lat" do
|
134
135
|
|
136
|
+
before do
|
137
|
+
@cell = Cell.new(1,2,3,4)
|
138
|
+
@cell.lat = 60.3276113
|
139
|
+
@cell.lon = 24.8689952
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should return the correct array" do
|
143
|
+
@cell.to_lng_lat.should == [24.8689952,60.3276113]
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
135
147
|
|
136
148
|
end
|
137
149
|
|
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.
|
4
|
+
version: 0.1.1
|
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-
|
12
|
+
date: 2012-02-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70362406860500 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70362406860500
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: webmock
|
27
|
-
requirement: &
|
27
|
+
requirement: &70362406859960 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70362406859960
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: simplecov
|
38
|
-
requirement: &
|
38
|
+
requirement: &70362406859380 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70362406859380
|
47
47
|
description: A Ruby client for OpenCellID API
|
48
48
|
email:
|
49
49
|
- nessche@gmail.com
|
@@ -51,8 +51,9 @@ executables: []
|
|
51
51
|
extensions: []
|
52
52
|
extra_rdoc_files: []
|
53
53
|
files:
|
54
|
-
- .
|
54
|
+
- .gitignore
|
55
55
|
- .simplecov
|
56
|
+
- .yardopts
|
56
57
|
- Gemfile
|
57
58
|
- License.txt
|
58
59
|
- README.md
|
@@ -120,3 +121,4 @@ test_files:
|
|
120
121
|
- spec/lib/utils_spec.rb
|
121
122
|
- spec/spec_helper.rb
|
122
123
|
- spec/support/spec_utils.rb
|
124
|
+
has_rdoc:
|
data/.gitgnore
DELETED