ax-track 0.2.5 → 0.3
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/Gemfile.lock +4 -3
- data/README.md +54 -5
- data/lib/ax-track.rb +26 -0
- data/lib/ax_track/client.rb +3 -7
- data/lib/ax_track/objects/tracker.rb +4 -4
- data/lib/ax_track/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 64ef65462f1efd6dc741c8abfc2b1ef96b3cf4ab852f62ce44af60250690d86e
|
4
|
+
data.tar.gz: d610a397e1f547867a1a5b6429858d73e3f1b3b6cc87b6eaf9ba9537e047733b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 892cbf5549bcc97265b8f0922ebc45750adb22b618f9838b5c7728688ebe75882213c55028a40e68e301840e7612ce94ba4547b5ac976122dcec6ce47a0d7162
|
7
|
+
data.tar.gz: df2aa12059668f758bd40d484c299f1a66af998dd3c5191bf7efed0ee5cc69686ca4332e146423f9639cdc09490428e517bc9e71ad41b2d1f918804d2d9f5f28
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ax-track (0.
|
4
|
+
ax-track (0.3)
|
5
5
|
faraday (~> 1.7)
|
6
6
|
faraday_middleware (~> 1.1)
|
7
7
|
|
@@ -28,7 +28,7 @@ GEM
|
|
28
28
|
faraday-net_http_persistent (1.2.0)
|
29
29
|
faraday-patron (1.0.0)
|
30
30
|
faraday-rack (1.0.0)
|
31
|
-
faraday_middleware (1.
|
31
|
+
faraday_middleware (1.2.0)
|
32
32
|
faraday (~> 1.0)
|
33
33
|
minitest (5.14.4)
|
34
34
|
multipart-post (2.1.1)
|
@@ -56,6 +56,7 @@ GEM
|
|
56
56
|
|
57
57
|
PLATFORMS
|
58
58
|
x86_64-darwin-19
|
59
|
+
x86_64-darwin-20
|
59
60
|
|
60
61
|
DEPENDENCIES
|
61
62
|
ax-track!
|
@@ -64,4 +65,4 @@ DEPENDENCIES
|
|
64
65
|
rubocop (~> 1.7)
|
65
66
|
|
66
67
|
BUNDLED WITH
|
67
|
-
2.2.
|
68
|
+
2.2.29
|
data/README.md
CHANGED
@@ -24,9 +24,31 @@ Or install it yourself as:
|
|
24
24
|
$ gem install axTrack
|
25
25
|
|
26
26
|
## Usage
|
27
|
+
### Configure the client
|
28
|
+
The Gem is configured by default to work with the public platform of Adnexo at
|
29
|
+
* API: `https://prod.api.ax-track.ch/api/v1`
|
30
|
+
* User Interface: `https://app.ax-track.ch/#/map/assets/`
|
27
31
|
|
32
|
+
If you want the gem to use a different URL, create a file in the initializer folder
|
33
|
+
```ruby
|
34
|
+
# folder: `config/initializers/ax-track.rb`
|
35
|
+
AxTrack.set_base_url_api = 'NEW API URL'
|
36
|
+
AxTrack.set_base_url_user = 'NEW USER URL'
|
37
|
+
```
|
38
|
+
|
39
|
+
If you want to test which URL is configures, you can
|
40
|
+
```ruby
|
41
|
+
AxTrack.base_url_api
|
42
|
+
=> "https://prod.api.ax-track.ch/api/v1"
|
43
|
+
AxTrack.base_url_user
|
44
|
+
=> "https://app.ax-track.ch/#/map/assets/"
|
45
|
+
```
|
46
|
+
|
47
|
+
### Instantiate a client
|
28
48
|
```ruby
|
29
49
|
client = AxTrack::Client.new(api_key: your_api_key)
|
50
|
+
# Or if you have a ENV['AXTRACK_API_KEY'] set, you don't need to pass in the api key.
|
51
|
+
client = AxTrack::Client.new
|
30
52
|
```
|
31
53
|
|
32
54
|
### Trackers
|
@@ -35,9 +57,30 @@ client = AxTrack::Client.new(api_key: your_api_key)
|
|
35
57
|
client.tracker.list
|
36
58
|
|
37
59
|
# Get the specific information of a specific tracker. If :asset_id is invalid, a AxTrack::Resource::NotFoundError is returned
|
38
|
-
client.tracker.retrieve(:tracker_id)
|
60
|
+
record = client.tracker.retrieve(:tracker_id)
|
61
|
+
```
|
62
|
+
|
63
|
+
You will receive an object AxTrack::Tracker (or a collection for the list call), where you can comfortably access each value
|
64
|
+
```ruby
|
65
|
+
record.asset_id
|
66
|
+
=> 1361
|
67
|
+
# The name on asset_id
|
68
|
+
record.name
|
69
|
+
=> #Name of asset on AxTrack#
|
70
|
+
record.identifier
|
71
|
+
=> "70B3D57050006F3B"
|
72
|
+
record.model
|
73
|
+
=> "dm-oyster"
|
74
|
+
|
75
|
+
# To access any asset details directly on the tracker just do
|
76
|
+
record.asset_details
|
77
|
+
|
78
|
+
# To get an array with all sensors
|
79
|
+
record.available_sensor_data
|
80
|
+
=> ["gps", "temperature", "battery", "humidity"]
|
39
81
|
```
|
40
82
|
|
83
|
+
|
41
84
|
### Assets
|
42
85
|
```ruby
|
43
86
|
# Get a list of all assets
|
@@ -52,15 +95,19 @@ client.asset.update(:tracker_id, params)
|
|
52
95
|
client.tracker.update(:tracker_id, name: 'New name')
|
53
96
|
```
|
54
97
|
|
55
|
-
### Errors
|
56
|
-
|
57
|
-
|
58
98
|
## Development
|
59
99
|
|
60
100
|
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.
|
61
101
|
|
62
102
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
63
103
|
|
104
|
+
To test the application in the console
|
105
|
+
```ruby
|
106
|
+
client = AxTrack::Client.new(api_key: _YOUR_API_KEY_)
|
107
|
+
# to get a list of all trackers (just as an example)
|
108
|
+
client.trackers
|
109
|
+
```
|
110
|
+
|
64
111
|
## Contributing
|
65
112
|
|
66
113
|
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/axTrack.
|
@@ -70,4 +117,6 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERN
|
|
70
117
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
71
118
|
|
72
119
|
## Open development
|
73
|
-
* Pagination for development
|
120
|
+
* Pagination for development
|
121
|
+
|
122
|
+
|
data/lib/ax-track.rb
CHANGED
@@ -16,4 +16,30 @@ module AxTrack
|
|
16
16
|
autoload :TrackerResource, 'ax_track/resources/tracker_resource'
|
17
17
|
autoload :AssetResource, 'ax_track/resources/asset_resource'
|
18
18
|
|
19
|
+
@@base_url_api = 'https://prod.api.ax-track.ch/api/v1'.freeze
|
20
|
+
@@base_url_user = 'https://app.ax-track.ch/#/map/assets/'.freeze
|
21
|
+
InvalidURL = Class.new(StandardError)
|
22
|
+
|
23
|
+
def self.base_url_api
|
24
|
+
@@base_url_api
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.set_base_url_api=(new_base_url_api)
|
28
|
+
raise InvalidURL.new 'This is not a valid URL' unless new_base_url_api =~ URI::regexp
|
29
|
+
@@base_url_api = new_base_url_api
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.base_url_user
|
34
|
+
@@base_url_user
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.set_base_url_user=(new_base_url_user = nil)
|
38
|
+
raise InvalidURL.new 'This is not a valid URL' unless new_base_url_user =~ URI::regexp
|
39
|
+
new_base_url_user = new_base_url_user + "/" unless new_base_url_user[-1] == '/'
|
40
|
+
@@base_url_user = new_base_url_user
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
|
19
45
|
end
|
data/lib/ax_track/client.rb
CHANGED
@@ -4,18 +4,13 @@ require 'faraday_middleware'
|
|
4
4
|
module AxTrack
|
5
5
|
|
6
6
|
class Client
|
7
|
-
# include HttpStatusCodes
|
8
|
-
# include ApiExceptions
|
9
|
-
|
10
|
-
BASE_URL = 'https://prod.api.ax-track.ch/api/v1'.freeze
|
11
|
-
|
12
7
|
APIKeyMissing = Class.new(StandardError)
|
13
8
|
|
14
9
|
attr_reader :api_key, :adapter
|
15
10
|
attr_writer :connection
|
16
11
|
|
17
12
|
def initialize(api_key: nil, adapter: nil, stubs: nil)
|
18
|
-
@api_key = api_key || ENV['AXTRACK_API_KEY']
|
13
|
+
@api_key = api_key&.strip || ENV['AXTRACK_API_KEY']&.strip
|
19
14
|
@adapter = adapter || Faraday.default_adapter
|
20
15
|
@stubs = stubs
|
21
16
|
|
@@ -32,12 +27,13 @@ module AxTrack
|
|
32
27
|
end
|
33
28
|
|
34
29
|
def connection
|
35
|
-
@connection ||= Faraday.new(
|
30
|
+
@connection ||= Faraday.new(AxTrack.base_url_api) do |conn|
|
36
31
|
#conn.request :url_encoded
|
37
32
|
conn.request :json
|
38
33
|
conn.response :json, content_type: 'application/json'
|
39
34
|
conn.adapter adapter, @stubs
|
40
35
|
conn.headers['Authorization'] = "Token #{api_key}" unless api_key.empty?
|
36
|
+
conn.options.timeout = 20
|
41
37
|
end
|
42
38
|
end
|
43
39
|
end
|
@@ -11,7 +11,7 @@ module AxTrack
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def name
|
14
|
-
@name
|
14
|
+
@name ||= asset_details.name
|
15
15
|
end
|
16
16
|
|
17
17
|
def last_message_timestamp
|
@@ -20,7 +20,7 @@ module AxTrack
|
|
20
20
|
|
21
21
|
def last_gps_position
|
22
22
|
#GPSPosition.new(@last_gps_measurement || { lat: asset_details.lat, lng: asset_details.lng } )
|
23
|
-
GPSPosition.new(@last_gps_measurement)
|
23
|
+
GPSPosition.new(@last_gps_measurement) unless @last_gps_measurement.nil?
|
24
24
|
end
|
25
25
|
|
26
26
|
def battery
|
@@ -32,7 +32,7 @@ module AxTrack
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def website_url
|
35
|
-
"
|
35
|
+
"#{AxTrack.base_url_user}#{@id}"
|
36
36
|
end
|
37
37
|
|
38
38
|
def available_sensor_data
|
@@ -40,7 +40,7 @@ module AxTrack
|
|
40
40
|
sensor_data_temp = self.sensor_data.keys
|
41
41
|
# if no timestamp is available in the GPSPosition, then there wasn't a last_gps_measurement returned in the json
|
42
42
|
# hence the sensor doesn't contain a GPS module.
|
43
|
-
sensor_data_temp = sensor_data_temp.unshift('gps') if self.last_gps_position
|
43
|
+
sensor_data_temp = sensor_data_temp.unshift('gps') if self.last_gps_position&.respond_to? :timestamp
|
44
44
|
sensor_data_temp
|
45
45
|
end
|
46
46
|
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.
|
4
|
+
version: '0.3'
|
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-
|
11
|
+
date: 2021-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -92,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: '0'
|
94
94
|
requirements: []
|
95
|
-
rubygems_version: 3.
|
95
|
+
rubygems_version: 3.2.22
|
96
96
|
signing_key:
|
97
97
|
specification_version: 4
|
98
98
|
summary: API Wrapper for AX Track (from Adnexo).
|