ax-track 0.1.8 → 0.1.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +5 -2
- data/lib/ax_track/objects/tracker.rb +25 -13
- data/lib/ax_track/resource.rb +9 -11
- data/lib/ax_track/resources/asset_resource.rb +3 -2
- data/lib/ax_track/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c016c0f8b6b21a305c193d350b3a1bf003bc4022da5116c56eb9eb46bd87689
|
4
|
+
data.tar.gz: fb56d8a6ad760e23c4d90d513d28d1bc46a06832cc8fe25e18e0332556021fac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '02385bde367ee4eb289955f65e8516d9e0b548ba4e5539d6da4bd1838307c99fdcc1940f6fa53460887ddb821fb95939b4fe8de224627cd0c6ecc4b148eecd69'
|
7
|
+
data.tar.gz: ec3105555b83b46efecf619c04794e9e7873620fffaa82d7574d6a309b32949e93c84f929714687ca17b7cf798c920e54ed3f3d2c46b3cc4caf941fe509e00f8
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -34,7 +34,7 @@ client = AxTrack::Client.new(api_key: your_api_key)
|
|
34
34
|
# Get a list of all trackers
|
35
35
|
client.tracker.list
|
36
36
|
|
37
|
-
# Get the specific information of a specific tracker
|
37
|
+
# Get the specific information of a specific tracker. If :asset_id is invalid, a AxTrack::Resource::NotFoundError is returned
|
38
38
|
client.tracker.retrieve(:tracker_id)
|
39
39
|
```
|
40
40
|
|
@@ -43,7 +43,7 @@ client.tracker.retrieve(:tracker_id)
|
|
43
43
|
# Get a list of all assets
|
44
44
|
client.asset.list
|
45
45
|
|
46
|
-
# Get a specific asset
|
46
|
+
# Get a specific asset. If :asset_id is invalid, a AxTrack::Resource::NotFoundError is returned
|
47
47
|
client.asset.retrieve(:asset_id)
|
48
48
|
|
49
49
|
# Update a specif asset
|
@@ -52,6 +52,9 @@ client.asset.update(:tracker_id, params)
|
|
52
52
|
client.tracker.update(:tracker_id, name: 'New name')
|
53
53
|
```
|
54
54
|
|
55
|
+
### Errors
|
56
|
+
|
57
|
+
|
55
58
|
## Development
|
56
59
|
|
57
60
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -2,31 +2,43 @@ module AxTrack
|
|
2
2
|
class Tracker < Object
|
3
3
|
|
4
4
|
def initialize(json_response)
|
5
|
-
@
|
6
|
-
@
|
7
|
-
@
|
8
|
-
@
|
9
|
-
@
|
10
|
-
@
|
11
|
-
@
|
5
|
+
@tracker_id = json_response['id']
|
6
|
+
@asset_id = json_response['asset']
|
7
|
+
@identifier = json_response['identifier']
|
8
|
+
@url = json_response['url']
|
9
|
+
@active = json_response['active']
|
10
|
+
@model = json_response['model']
|
11
|
+
@asset_details = Asset.new json_response['asset_details'] if json_response['asset_details']
|
12
|
+
@name = json_response.dig('asset_details', 'name')
|
12
13
|
@last_message_timestamp = DateTime.parse(json_response['last_message_timestamp'], false) if json_response['last_message_timestamp']
|
13
|
-
@url
|
14
|
+
@url = json_response['url']
|
15
|
+
@user_url = website_url
|
14
16
|
@last_gps_position = GPSPosition.new(json_response['last_gps_measurement'] || json_response['asset_details'])
|
15
17
|
|
16
|
-
@battery
|
18
|
+
@battery = json_response.dig('asset_details', 'sensor_data', 'battery', 'value')
|
19
|
+
sensor_data = json_response.dig('asset_details', 'sensor_data')
|
17
20
|
|
18
|
-
sensor_data
|
19
|
-
|
20
|
-
@
|
21
|
+
@sensor_data = sensor_data
|
22
|
+
|
23
|
+
@network = json_response['network']
|
21
24
|
|
22
25
|
create_getters
|
23
26
|
end
|
24
27
|
|
25
28
|
def available_sensor_data
|
26
29
|
# returns a hash with available senson data
|
27
|
-
self.sensor_data.keys
|
30
|
+
sensor_data_temp = self.sensor_data.keys
|
31
|
+
# if no timestamp is available in the GPSPosition, then there wasn't a last_gps_measurement returned in the json
|
32
|
+
# hence the sensor doesn't contain a GPS module.
|
33
|
+
sensor_data_temp = sensor_data_temp.unshift('gps') if self.last_gps_position.respond_to? :timestamp
|
34
|
+
sensor_data_temp
|
35
|
+
end
|
36
|
+
|
37
|
+
def website_url
|
38
|
+
"https://app.ax-track.ch/#/map/assets/#{@tracker_id}"
|
28
39
|
end
|
29
40
|
|
41
|
+
|
30
42
|
class GPSPosition < Object
|
31
43
|
|
32
44
|
def initialize(json_response)
|
data/lib/ax_track/resource.rb
CHANGED
@@ -3,14 +3,14 @@ module AxTrack
|
|
3
3
|
class Resource
|
4
4
|
attr_reader :client, :response
|
5
5
|
|
6
|
-
|
7
|
-
BadRequestError = Class.new(
|
8
|
-
UnauthorizedError = Class.new(
|
9
|
-
ForbiddenError = Class.new(
|
10
|
-
ApiRequestsQuotaReachedError = Class.new(
|
11
|
-
NotFoundError = Class.new(
|
12
|
-
UnprocessableEntityError = Class.new(
|
13
|
-
ApiError = Class.new(
|
6
|
+
ApiError = Class.new(StandardError)
|
7
|
+
BadRequestError = Class.new(ApiError)
|
8
|
+
UnauthorizedError = Class.new(ApiError)
|
9
|
+
ForbiddenError = Class.new(ApiError)
|
10
|
+
ApiRequestsQuotaReachedError = Class.new(ApiError)
|
11
|
+
NotFoundError = Class.new(ApiError)
|
12
|
+
UnprocessableEntityError = Class.new(ApiError)
|
13
|
+
ApiError = Class.new(ApiError)
|
14
14
|
|
15
15
|
HTTP_OK_CODE = 200
|
16
16
|
|
@@ -43,9 +43,7 @@ module AxTrack
|
|
43
43
|
BadRequestError
|
44
44
|
when HTTP_UNAUTHORIZED_CODE
|
45
45
|
UnauthorizedError
|
46
|
-
when HTTP_FORBIDDEN_CODE
|
47
|
-
ForbiddenError
|
48
|
-
when HTTP_NOT_FOUND_CODE
|
46
|
+
when HTTP_NOT_FOUND_CODE, HTTP_FORBIDDEN_CODE
|
49
47
|
NotFoundError
|
50
48
|
when HTTP_UNPROCESSABLE_ENTITY_CODE
|
51
49
|
UnprocessableEntityError
|
@@ -13,10 +13,11 @@ module AxTrack
|
|
13
13
|
endpoint: "assets/#{asset_id}").body
|
14
14
|
end
|
15
15
|
|
16
|
-
def update(asset_id, **attributes)
|
16
|
+
def update(asset_id, headers: {}, **attributes)
|
17
17
|
Asset.new request(http_method: :patch,
|
18
18
|
endpoint: "assets/#{asset_id}",
|
19
|
-
body: attributes
|
19
|
+
body: attributes,
|
20
|
+
headers: {}).body
|
20
21
|
|
21
22
|
end
|
22
23
|
end
|
data/lib/ax_track/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ax-track
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Philipp Baumann
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-10-
|
11
|
+
date: 2021-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|