spot-gps 0.1.0 → 0.2.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 +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +47 -4
- data/lib/spot-gps/list_response.rb +4 -0
- data/lib/spot-gps/resources/message.rb +27 -12
- data/lib/spot-gps/version.rb +1 -1
- data/spec/api_response_spec.rb +1 -0
- data/spec/fixtures/message.json +1 -1
- data/spec/resources/message_spec.rb +30 -4
- data/spec/services/messages_spec.rb +4 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd30beee45ef852e2ef63c83c1671600b1aef085
|
4
|
+
data.tar.gz: fe3e6c3dc00cd6f8ccf2fe00955c121be5919009
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9807c61a995b52a9b6ec8cf36ffd10d43b87b222a6b87096216ed0e7e3e90b0abf6e2564ac03c0cc28372b13bf34cbff12d8a894a270527a3220be426677f83
|
7
|
+
data.tar.gz: 3794197c9ca65049abefb6483409f5b627fd83d697cb525d7c0a8728145778994794971347ffd6cce1ed8ba67f388e8f18cd6cc1c7b21c22b061bbf47f997fbe
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## v0.2.0, 11 July 2016
|
2
|
+
|
3
|
+
- `#to_h` now returns a resources cleaned attributes, not its initial input
|
4
|
+
- Add `#to_raw_h` method to SPOT::Resources::Message, which replaces `#to_h`
|
5
|
+
- Make `#response` available on ListResponse, and document it
|
6
|
+
|
1
7
|
## v0.1.0, 10 July 2016
|
2
8
|
|
3
9
|
- Move old `all` functionality to `list`
|
data/README.md
CHANGED
@@ -15,7 +15,8 @@ gem 'spot-gps'
|
|
15
15
|
|
16
16
|
## Configuration
|
17
17
|
|
18
|
-
|
18
|
+
Timeout options can be configured globally, or you can rely on the default
|
19
|
+
values below:
|
19
20
|
|
20
21
|
```ruby
|
21
22
|
SPOT.configure do |config|
|
@@ -26,7 +27,7 @@ end
|
|
26
27
|
|
27
28
|
## Usage
|
28
29
|
|
29
|
-
API calls are made using an instance of the `
|
30
|
+
API calls are made using an instance of the `SPOT::Client` class:
|
30
31
|
|
31
32
|
```ruby
|
32
33
|
api = SPOT::Client.new(feed_id: 'FEED_GIID', feed_password: 'OPTIONAL_PASSWORD')
|
@@ -34,7 +35,7 @@ api = SPOT::Client.new(feed_id: 'FEED_GIID', feed_password: 'OPTIONAL_PASSWORD')
|
|
34
35
|
|
35
36
|
### Resources
|
36
37
|
|
37
|
-
Currently, the SPOT API only supports
|
38
|
+
Currently, the SPOT API only supports the `messages` resource.
|
38
39
|
|
39
40
|
#### Messages
|
40
41
|
|
@@ -46,6 +47,28 @@ api.messages.list # => Returns a list of messages for a given page of a feed
|
|
46
47
|
api.messages.latest # => Returns the most recent message for a feed
|
47
48
|
```
|
48
49
|
|
50
|
+
Each message has the following details available:
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
message = api.messages.latest
|
54
|
+
|
55
|
+
message.id # => Integer. ID of the SPOT message
|
56
|
+
message.created_at # => Time
|
57
|
+
message.type # => String. Message type (e.g., "OK", or "HELP")
|
58
|
+
message.latitude # => Float
|
59
|
+
message.longitude # => Float
|
60
|
+
message.battery_state # => String. Battery state at time of sending (e.g., "GOOD")
|
61
|
+
message.hidden # => Boolean. I'm not sure what this is for...
|
62
|
+
message.show_custom_message # => Boolean. I'm not sure what this is for...
|
63
|
+
message.content # => String
|
64
|
+
message.messenger_id # => String. As used when registering your SPOT
|
65
|
+
message.messenger_name # => String. As specified when registering your SPOT
|
66
|
+
message.messenger_model # => String. E.g., "SPOT3"
|
67
|
+
```
|
68
|
+
|
69
|
+
You can also call `#to_h` on a message to get its (cleaned) attributes as a
|
70
|
+
hash, or `#to_raw_h` to get the attributes as returned by SPOT.
|
71
|
+
|
49
72
|
### Pagination
|
50
73
|
|
51
74
|
If you want to get all of the records for a given resource type, you can use the
|
@@ -66,17 +89,37 @@ api.messages.list(page: 2)
|
|
66
89
|
|
67
90
|
### Filtering
|
68
91
|
|
69
|
-
The SPOT API supports filtering by date.
|
92
|
+
The SPOT API only supports filtering by date. You can do so using either the
|
93
|
+
`#list` or `#all` methods.
|
70
94
|
|
71
95
|
```ruby
|
96
|
+
api.messages.all(start_at: '2014-06-01T00:00:00', end_at: '2015-06-01T00:00:00')
|
72
97
|
api.messages.list(start_at: '2014-06-01T00:00:00', end_at: '2015-06-01T00:00:00')
|
73
98
|
```
|
74
99
|
|
100
|
+
You can pass the `start_at` and `end_at` parameters as a `String`, `Time`,
|
101
|
+
`DateTime` or `Date`, and the gem will handle formatting it correctly for SPOT.
|
102
|
+
|
103
|
+
### Raw responses
|
104
|
+
|
105
|
+
If you'd like to query the un-wrapped response data from SPOT, you can use the
|
106
|
+
`#response` method to do so.
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
message = api.messages.latest
|
110
|
+
response = message.response
|
111
|
+
|
112
|
+
response.body # => Hash. JSON body
|
113
|
+
response.headers # => Hash. Headers returned by SPOT
|
114
|
+
response.status # => Integer. Status code returned by SPOT
|
115
|
+
```
|
116
|
+
|
75
117
|
### Error Handling
|
76
118
|
|
77
119
|
TODO: Currently the gem will just raise Faraday errors if anything goes wrong
|
78
120
|
with a request.
|
79
121
|
|
122
|
+
|
80
123
|
## Contributing
|
81
124
|
|
82
125
|
1. Fork it ( https://github.com/greysteil/spot-gps/fork )
|
@@ -14,33 +14,48 @@ module SPOT
|
|
14
14
|
attr_reader :messenger_name
|
15
15
|
attr_reader :messenger_model
|
16
16
|
|
17
|
-
|
18
|
-
@object = object
|
17
|
+
attr_reader :response
|
19
18
|
|
19
|
+
def initialize(object, response = nil)
|
20
20
|
@id = object.fetch('id')
|
21
21
|
@created_at = Time.at(object.fetch('unixTime'))
|
22
22
|
@type = object.fetch('messageType')
|
23
23
|
@latitude = object.fetch('latitude')
|
24
24
|
@longitude = object.fetch('longitude')
|
25
25
|
@battery_state = object.fetch('batteryState')
|
26
|
+
@hidden = object.fetch('hidden') == 1
|
27
|
+
@show_custom_message = object.fetch('showCustomMsg') == "Y"
|
28
|
+
@content = object.fetch('messageContent')
|
29
|
+
@messenger_id = object.fetch('messengerId')
|
30
|
+
@messenger_name = object.fetch('messengerName')
|
31
|
+
@messenger_model = object.fetch('modelId')
|
26
32
|
|
27
|
-
@
|
28
|
-
@show_custom_message = object['showCustomMsg'] == "Y"
|
29
|
-
@content = object['messageContent']
|
30
|
-
@messenger_id = object['messengerId']
|
31
|
-
@messenger_name = object['messengerName']
|
32
|
-
@messenger_model = object['modelId']
|
33
|
-
|
33
|
+
@object = object
|
34
34
|
@response = response
|
35
35
|
end
|
36
36
|
|
37
|
-
def
|
38
|
-
@
|
37
|
+
def to_h
|
38
|
+
@hash ||=
|
39
|
+
begin
|
40
|
+
attribute_ivars =
|
41
|
+
(instance_variables - [:@response, :@object, :@hash])
|
42
|
+
|
43
|
+
attribute_ivars.each_with_object({}) do |ivar, hash|
|
44
|
+
hash[ivar.to_s.delete('@').to_sym] = instance_variable_get(ivar)
|
45
|
+
end
|
46
|
+
end
|
39
47
|
end
|
40
48
|
|
41
|
-
def
|
49
|
+
def to_raw_h
|
42
50
|
@object
|
43
51
|
end
|
52
|
+
|
53
|
+
def inspect
|
54
|
+
attr_list =
|
55
|
+
to_h.map { |key, value| "#{key}: #{value.inspect}" }.join(', ')
|
56
|
+
|
57
|
+
"#<#{self.class} #{attr_list}>"
|
58
|
+
end
|
44
59
|
end
|
45
60
|
end
|
46
61
|
end
|
data/lib/spot-gps/version.rb
CHANGED
data/spec/api_response_spec.rb
CHANGED
data/spec/fixtures/message.json
CHANGED
@@ -22,7 +22,7 @@ describe SPOT::Resources::Message do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'can be initialized from an unenveloped response' do
|
25
|
-
resource = described_class.new(data)
|
25
|
+
resource = described_class.new(data, nil)
|
26
26
|
|
27
27
|
expect(resource.id).to eq(585079373)
|
28
28
|
expect(resource.created_at).to eq(Time.at(1468164566))
|
@@ -40,13 +40,39 @@ describe SPOT::Resources::Message do
|
|
40
40
|
|
41
41
|
it 'can handle new attributes without erroring' do
|
42
42
|
data['foo'] = 'bar'
|
43
|
-
expect { described_class.new(data) }.to_not raise_error
|
43
|
+
expect { described_class.new(data, nil) }.to_not raise_error
|
44
44
|
end
|
45
45
|
|
46
46
|
describe '#to_h' do
|
47
|
-
|
48
|
-
|
47
|
+
subject { described_class.new(data, nil).to_h }
|
48
|
+
let(:expected_hash) do
|
49
|
+
{
|
50
|
+
id: 585079373,
|
51
|
+
created_at: Time.at(1468164566),
|
52
|
+
type: 'OK',
|
53
|
+
latitude: 61.54875,
|
54
|
+
longitude: -3.0697,
|
55
|
+
battery_state: 'GOOD',
|
56
|
+
hidden: false,
|
57
|
+
show_custom_message: true,
|
58
|
+
content: 'Example SPOT message.',
|
59
|
+
messenger_id: '0-1234567',
|
60
|
+
messenger_name: 'My SPOT',
|
61
|
+
messenger_model: 'SPOT3'
|
62
|
+
}
|
49
63
|
end
|
64
|
+
|
65
|
+
it { is_expected.to eq(expected_hash) }
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '#to_aw_h' do
|
69
|
+
subject { described_class.new(data, nil).to_raw_h }
|
70
|
+
it { is_expected.to eq(data) }
|
71
|
+
end
|
72
|
+
|
73
|
+
describe '#response' do
|
74
|
+
subject { described_class.new(data, "response").response }
|
75
|
+
it { is_expected.to eq("response") }
|
50
76
|
end
|
51
77
|
end
|
52
78
|
end
|
@@ -76,6 +76,7 @@ describe SPOT::Services::Messages do
|
|
76
76
|
end
|
77
77
|
|
78
78
|
it { is_expected.to be_a(SPOT::ListResponse) }
|
79
|
+
its(:response) { is_expected.to be_a(SPOT::ApiResponse) }
|
79
80
|
its("records.first") { is_expected.to be_a(SPOT::Resources::Message) }
|
80
81
|
|
81
82
|
context "when there are no displayable messages" do
|
@@ -196,6 +197,7 @@ describe SPOT::Services::Messages do
|
|
196
197
|
end
|
197
198
|
|
198
199
|
describe "#latest" do
|
200
|
+
subject { messages.latest }
|
199
201
|
before do
|
200
202
|
stub_url = SPOT.endpoint + 'EXAMPLE_ID/latest.json'
|
201
203
|
stub_request(:get, stub_url).to_return(
|
@@ -213,8 +215,7 @@ describe SPOT::Services::Messages do
|
|
213
215
|
messages.latest
|
214
216
|
end
|
215
217
|
|
216
|
-
it
|
217
|
-
|
218
|
-
end
|
218
|
+
it { is_expected.to be_a(SPOT::Resources::Message) }
|
219
|
+
its(:response) { is_expected.to be_a(SPOT::ApiResponse) }
|
219
220
|
end
|
220
221
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spot-gps
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Grey Baker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: webmock
|