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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 020bb6c2b8ab4cc16a243f3a085c0a043f61d3472afd0fe94c1a2604801c07bb
4
- data.tar.gz: dab3b71fe20f914974abebbf736cd755a236c2f5f1db424d99a0f610055243b7
3
+ metadata.gz: 2c016c0f8b6b21a305c193d350b3a1bf003bc4022da5116c56eb9eb46bd87689
4
+ data.tar.gz: fb56d8a6ad760e23c4d90d513d28d1bc46a06832cc8fe25e18e0332556021fac
5
5
  SHA512:
6
- metadata.gz: 0ecfd0e82fe24c79903cbdac6b007c5f747c37f29d73cd5713e56716dd7bf54903e328470e3edaf2a26c59985b33a1ad3a3d3d42cf8e113ea5e5dfa7f012d251
7
- data.tar.gz: 76fdbd7f4455f1a43029f508b5c3716f293ce93f1f15f5ccda6e5c284980f1ddeb20bbdeea3ac74d30ba35de728ae9933df0ad3ee15dc0030d681e1d3b9fdad9
6
+ metadata.gz: '02385bde367ee4eb289955f65e8516d9e0b548ba4e5539d6da4bd1838307c99fdcc1940f6fa53460887ddb821fb95939b4fe8de224627cd0c6ecc4b148eecd69'
7
+ data.tar.gz: ec3105555b83b46efecf619c04794e9e7873620fffaa82d7574d6a309b32949e93c84f929714687ca17b7cf798c920e54ed3f3d2c46b3cc4caf941fe509e00f8
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ax-track (0.1.8)
4
+ ax-track (0.1.14)
5
5
  faraday (~> 1.7)
6
6
  faraday_middleware (~> 1.1)
7
7
 
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
- @id = json_response['id']
6
- @url = json_response['url']
7
- @active = json_response['active']
8
- @model = json_response['model']
9
- @axtrack_asset_id = json_response['asset']
10
- @asset_details = Asset.new json_response['asset_details'] if json_response['asset_details']
11
- @name = json_response.dig('asset_details', 'name')
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 = json_response['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 = json_response.dig('asset_details', 'sensor_data', 'battery', 'value')
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 = json_response.dig('asset_details', 'sensor_data')
19
- sensor_data.delete('battery')
20
- @sensor_data = sensor_data
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)
@@ -3,14 +3,14 @@ module AxTrack
3
3
  class Resource
4
4
  attr_reader :client, :response
5
5
 
6
- GithubAPIError = Class.new(StandardError)
7
- BadRequestError = Class.new(GithubAPIError)
8
- UnauthorizedError = Class.new(GithubAPIError)
9
- ForbiddenError = Class.new(GithubAPIError)
10
- ApiRequestsQuotaReachedError = Class.new(GithubAPIError)
11
- NotFoundError = Class.new(GithubAPIError)
12
- UnprocessableEntityError = Class.new(GithubAPIError)
13
- ApiError = Class.new(GithubAPIError)
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).body
19
+ body: attributes,
20
+ headers: {}).body
20
21
 
21
22
  end
22
23
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AxTrack
4
- VERSION = "0.1.8"
4
+ VERSION = "0.1.14"
5
5
  end
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.8
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-06 00:00:00.000000000 Z
11
+ date: 2021-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday