mapon_client 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c3a0641f5b7c2ec708af18504b677b247d6cc41463f43535da3f2584c88845aa
4
+ data.tar.gz: '0758faa99ebcdc7ca98410ba8b0153560f864ab093991d586771ecba0b924a46'
5
+ SHA512:
6
+ metadata.gz: 2b075513dd784dcc08b94ff3c7fe92989011aaed1d63829fa789ec2a6b6c8f5b70ae6737134afab8e8095a3e5adf4ede4dab3d30ba24360f053cff9cc4574694
7
+ data.tar.gz: 62ebddfdc128affcb48d16445edaf3b7e78d218b6387161cbe9ce4ecf862db706102de55142a8ce1c8cf25f5bf2a3053acbe6a9cbd35f6cc51c24d0ffd25e86c
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ .env
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.0.0
5
+ - 2.1.10
6
+ - 2.2.8
7
+ - 2.3.5
8
+ - 2.4.2
9
+ - 2.5.0
10
+ before_install: gem install bundler -v 1.16.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at ingus.skaistkalns@makit.lv. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ gemspec
6
+
7
+ gem 'dotenv'
data/Gemfile.lock ADDED
@@ -0,0 +1,53 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mapon_client (0.1.0)
5
+ rest-client (> 1)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.3)
11
+ domain_name (0.5.20170404)
12
+ unf (>= 0.0.5, < 1.0.0)
13
+ dotenv (2.2.1)
14
+ http-cookie (1.0.3)
15
+ domain_name (~> 0.5)
16
+ mime-types (3.1)
17
+ mime-types-data (~> 3.2015)
18
+ mime-types-data (3.2016.0521)
19
+ netrc (0.11.0)
20
+ rake (10.5.0)
21
+ rest-client (2.0.2)
22
+ http-cookie (>= 1.0.2, < 2.0)
23
+ mime-types (>= 1.16, < 4.0)
24
+ netrc (~> 0.8)
25
+ rspec (3.7.0)
26
+ rspec-core (~> 3.7.0)
27
+ rspec-expectations (~> 3.7.0)
28
+ rspec-mocks (~> 3.7.0)
29
+ rspec-core (3.7.1)
30
+ rspec-support (~> 3.7.0)
31
+ rspec-expectations (3.7.0)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.7.0)
34
+ rspec-mocks (3.7.0)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.7.0)
37
+ rspec-support (3.7.1)
38
+ unf (0.1.4)
39
+ unf_ext
40
+ unf_ext (0.0.7.5)
41
+
42
+ PLATFORMS
43
+ ruby
44
+
45
+ DEPENDENCIES
46
+ bundler (~> 1.16)
47
+ dotenv
48
+ mapon_client!
49
+ rake (~> 10.0)
50
+ rspec (~> 3.0)
51
+
52
+ BUNDLED WITH
53
+ 1.16.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Ingus Skaistkalns
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,211 @@
1
+ # MaponClient
2
+
3
+ Ruby client library for https://www.mapon.com API
4
+
5
+ ### GET API
6
+ Check `lib/mapon_client/resources/*` for supported resource actions.
7
+
8
+ ### POST API
9
+ `POST` actions still can be executed by using `MaponClient::Client#resource_base`,
10
+ that is `RestClient::Resource` instance already with parameter `key` set.
11
+ Thought currently RestClient does not handle parameter merging.
12
+ It completely overrides parameters set on Resource init, so `MaponClient::Client#with_key` is available
13
+ for appending key to payload.
14
+
15
+ ## Installation
16
+
17
+ Add this line to your application's Gemfile:
18
+
19
+ ```ruby
20
+ gem 'mapon_client'
21
+ ```
22
+
23
+ And then execute:
24
+
25
+ $ bundle
26
+
27
+ Or install it yourself as:
28
+
29
+ $ gem install mapon_client
30
+
31
+ ## Usage
32
+
33
+ ### Instantiate client:
34
+ * api_key - create it under Settings/API keys, if blank, will try to read environment variable MAPON_CLIENT_API_KEY on the [site](https://mapon.com/new/settings#9)
35
+ * base_url - defaults to https://mapon.com/api/v1/
36
+ * format - json/xml, defaults to json
37
+
38
+ ```ruby
39
+ mapon_client = MaponClient::Client.new
40
+ # OR
41
+ mapon_client = MaponClient::Client.new(
42
+ api_key: ENV['BY_DIFFERENT_NAME_API_KEY'],
43
+ base_url: 'https://mapon.com/api/v300/not-the-default-endpoint',
44
+ format: 'xml'
45
+ )
46
+ ```
47
+
48
+ ### Request resources
49
+
50
+ Mapon API documentation can be found [here](https://mapon.com/api).
51
+ Look there to find out required params in case error messages are not clear enough.
52
+
53
+ #### Company
54
+ ```ruby
55
+ @mapon_client.resources[:company].get
56
+ ```
57
+
58
+ #### Unit list
59
+ ```ruby
60
+ @mapon_client.resources[:unit].list
61
+ @mapon_client.resources[:unit].list(
62
+ unit_id: [80669', 85113], car_number: ['VY92278', 'DK56625'], empty_box_id: true,
63
+ include: [
64
+ 'in_objects', 'io_din', 'fuel', 'can', 'reefer', 'drivers', 'temperature', 'ambienttemp', 'device', 'supply_voltage'
65
+ ]
66
+ )
67
+ ```
68
+
69
+ #### Unit group
70
+ ```ruby
71
+ @mapon_client.resources[:unit_group].list(unit_id: [80669, 85113])
72
+
73
+ @mapon_client.resources[:unit_group].list_units(id: 11677)
74
+
75
+ ```
76
+
77
+ #### Unit data
78
+ ```ruby
79
+ @mapon_client.resources[:unit_data].ignitions(
80
+ from: '2018-02-01T00:00:00Z', till: '2018-02-10T00:00:00Z', unit_id: [80669, 85113]
81
+ )
82
+
83
+ @mapon_client.resources[:unit_data].temperature(
84
+ from: '2018-02-01T00:00:00Z', till: '2018-02-20T00:00:00Z', unit_id: 80669
85
+ )
86
+
87
+ @mapon_client.resources[:unit_data].digital_inputs(
88
+ from: '2018-02-01T00:00:00Z', till: '2018-02-20T00:00:00Z', unit_id: 80669
89
+ )
90
+
91
+ @mapon_client.resources[:unit_data].can_period(
92
+ datetime: '2018-02-01T00:00:00Z', unit_id: 80669,
93
+ include: [
94
+ 'rpm_average', 'rpm_max', 'fuel_level', 'service_distance', 'total_distance', 'total_fuel', 'total_engine_hours', 'ambient_temperature'
95
+ ]
96
+ )
97
+
98
+ @mapon_client.resources[:unit_data].can_point(
99
+ from: '2018-02-01T00:00:00Z', till: '2018-02-20T00:00:00Z', unit_id: 80669,
100
+ include: [
101
+ 'rpm_average', 'rpm_max', 'fuel_level', 'service_distance', 'total_distance', 'total_fuel', 'total_engine_hours', 'ambient_temperature'
102
+ ]
103
+ )
104
+
105
+ @mapon_client.resources[:unit_data].fields(unit_id: 85188)
106
+ ```
107
+
108
+ #### Reefer
109
+ ```ruby
110
+ @mapon_client.resources[:reefer].alert_list(id: 12345, unit_id: [80669, 85113])
111
+
112
+ @mapon_client.resources[:reefer].runmodes(unit_id: [80669, 85113])
113
+
114
+ @mapon_client.resources[:reefer].list_temperature_data(
115
+ unit_id: 85113, from: '2018-01-20T00:00:00Z', till: '2018-03-03T00:00:00Z'
116
+ )
117
+ ```
118
+
119
+ #### Route
120
+ ```ruby
121
+ @mapon_client.resources[:route].list(
122
+ from: '2018-02-20T00:00:00Z', till: '2018-03-06T00:00:00Z', unit_id: [80669, 85113], empty_box_id: true,
123
+ include: ['polyline', 'speed', 'decoded_route', 'driver_id']
124
+ )
125
+
126
+ @mapon_client.resources[:route].custom_fields(route_id: 639655550)
127
+ ```
128
+
129
+ For decoding polyline use https://github.com/joshuaclayton/polylines
130
+
131
+ #### Fuel
132
+ ```ruby
133
+ @mapon_client.resources[:fuel].summary(
134
+ from: '2018-02-20T00:00:00Z', till: '2018-03-06T00:00:00Z', unit_id: [86303, 80669]
135
+ )
136
+
137
+ @mapon_client.resources[:fuel].changes(
138
+ from: '2018-02-20T00:00:00Z', till: '2018-03-06T00:00:00Z', unit_id: [86303, 80669]
139
+ )
140
+ ```
141
+
142
+ #### Object
143
+ ```ruby
144
+ @mapon_client.resources[:object].list(
145
+ id: 345901, name: 'Depot', group_id: 0, deleted: 1, updated_from: '2017-12-22T09:50:23Z', updated_till: '2017-12-22T09:55:25Z'
146
+ )
147
+
148
+ @mapon_client.resources[:object].list_groups(id: 1234, name: 'Group name')
149
+ ```
150
+
151
+ #### User
152
+ ```ruby
153
+ @mapon_client.resources[:user].list(id: '116361', type: 'user_all')
154
+ ```
155
+
156
+ #### Driver
157
+ ```ruby
158
+ @mapon_client.resources[:driver].list(id: 116551)
159
+ ```
160
+
161
+ #### Tachograph
162
+ ```ruby
163
+ @mapon_client.resources[:tachograph].list_ddd_driver(from: '2018-02-20T00:00:00Z', till: '2018-03-03T00:00:00Z')
164
+
165
+ @mapon_client.resources[:tachograph].download_ddd_driver(id: 55)
166
+
167
+ @mapon_client.resources[:tachograph].list_ddd_vehicle(from: '2018-02-20T00:00:00Z', till: '2018-03-03T00:00:00Z')
168
+
169
+ @mapon_client.resources[:tachograph].download_ddd_vehicle(id: 55)
170
+ ```
171
+
172
+ #### Tracking
173
+ ```ruby
174
+ @mapon_client.resources[:tracking].list(from: '2018-02-20T00:00:00Z', till: '2018-03-03T00:00:00Z')
175
+ ```
176
+
177
+ #### Data forward
178
+ ```ruby
179
+ @mapon_client.resources[:data_forward].list
180
+
181
+ @mapon_client.resources[:data_forward].list_packs
182
+ ```
183
+
184
+ #### Application menu
185
+ ```ruby
186
+ @mapon_client.resources[:application_menu].list
187
+ ```
188
+
189
+ ### Rest client
190
+
191
+ MaponClient uses [rest-client](https://github.com/rest-client/rest-client) as HTTP client.
192
+ So on any lower level calls rest-client library class instances gets returned,
193
+ like RestClient::Response, RestClient::Resource, etc.
194
+
195
+ ## Development
196
+
197
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
198
+
199
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
200
+
201
+ ## Contributing
202
+
203
+ Bug reports and pull requests are welcome on GitHub at https://github.com/IngusSkaistkalns/mapon_client. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
204
+
205
+ ## License
206
+
207
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
208
+
209
+ ## Code of Conduct
210
+
211
+ Everyone interacting in the MaponClient project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/mapon_client/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "dotenv/load"
5
+ require "mapon_client"
6
+
7
+ @mapon_client = MaponClient::Client.new
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,46 @@
1
+ require 'rest-client'
2
+ require 'mapon_client/resources'
3
+
4
+ module MaponClient
5
+ class Client
6
+ attr_reader :api_key, :base_url, :resource_base, :format
7
+
8
+ def initialize(api_key: nil, base_url: nil, format: nil)
9
+ @api_key = (
10
+ api_key || ENV['MAPON_CLIENT_API_KEY']
11
+ )
12
+
13
+ @base_url = (
14
+ base_url || MaponClient::DEFAULT_BASE_URL
15
+ )
16
+
17
+ @format = (
18
+ format || MaponClient::DEFAULT_FORMAT
19
+ )
20
+
21
+ @resource_base ||= RestClient::Resource.new(
22
+ @base_url, headers: { params: { key: @api_key } }
23
+ )
24
+ end
25
+
26
+ def [](*args)
27
+ @resource_base.public_send(
28
+ :[],
29
+ *append_format_to_url(*args)
30
+ )
31
+ end
32
+
33
+ def resources
34
+ @resources ||= Resources.new(self)
35
+ end
36
+
37
+ def with_key(params)
38
+ params.merge(key: @api_key)
39
+ end
40
+
41
+ def append_format_to_url(*args)
42
+ suburl = "#{args.shift}.#{@format}"
43
+ args.unshift(suburl)
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,11 @@
1
+ module MaponClient
2
+ class Resources
3
+ class ApplicationMenuResource < Resources
4
+ def list(params = {})
5
+ @client['application_menu/list'].get(
6
+ params: with_key(params)
7
+ )
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ module MaponClient
2
+ class Resources
3
+ class CompanyResource < Resources
4
+ def get
5
+ @client['company/get'].get
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ module MaponClient
2
+ class Resources
3
+ class DataForwardResource < Resources
4
+ def list(params = {})
5
+ @client['data_forward/list'].get(
6
+ params: with_key(params)
7
+ )
8
+ end
9
+
10
+ def list_packs(params = {})
11
+ @client['data_forward/list_packs'].get(
12
+ params: with_key(params)
13
+ )
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ module MaponClient
2
+ class Resources
3
+ class DriverResource < Resources
4
+ def list(params = {})
5
+ @client['driver/list'].get(
6
+ params: with_key(params)
7
+ )
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,17 @@
1
+ module MaponClient
2
+ class Resources
3
+ class FuelResource < Resources
4
+ def summary(params = {})
5
+ @client['fuel/summary'].get(
6
+ params: with_key(params)
7
+ )
8
+ end
9
+
10
+ def changes(params = {})
11
+ @client['fuel/changes'].get(
12
+ params: with_key(params)
13
+ )
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module MaponClient
2
+ class Resources
3
+ class ObjectResource < Resources
4
+ def list(params = {})
5
+ @client['object/list'].get(
6
+ params: with_key(params)
7
+ )
8
+ end
9
+
10
+ def list_groups(params = {})
11
+ @client['object/list_groups'].get(
12
+ params: with_key(params)
13
+ )
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,23 @@
1
+ module MaponClient
2
+ class Resources
3
+ class ReeferResource < Resources
4
+ def alert_list(params = {})
5
+ @client['reefer/alert_list'].get(
6
+ params: with_key(params)
7
+ )
8
+ end
9
+
10
+ def runmodes(params = {})
11
+ @client['reefer/runmodes'].get(
12
+ params: with_key(params)
13
+ )
14
+ end
15
+
16
+ def list_temperature_data(params = {})
17
+ @client['reefer/list_temperature_data'].get(
18
+ params: with_key(params)
19
+ )
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,17 @@
1
+ module MaponClient
2
+ class Resources
3
+ class RouteResource < Resources
4
+ def list(params = {})
5
+ @client['route/list'].get(
6
+ params: with_key(params)
7
+ )
8
+ end
9
+
10
+ def custom_fields(params = {})
11
+ @client['route/custom_fields'].get(
12
+ params: with_key(params)
13
+ )
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,29 @@
1
+ module MaponClient
2
+ class Resources
3
+ class TachographResource < Resources
4
+ def list_ddd_driver(params = {})
5
+ @client['tachograph/list_ddd_driver'].get(
6
+ params: with_key(params)
7
+ )
8
+ end
9
+
10
+ def download_ddd_driver(params = {})
11
+ @client['tachograph/download_ddd_driver'].get(
12
+ params: with_key(params)
13
+ )
14
+ end
15
+
16
+ def list_ddd_vehicle(params = {})
17
+ @client['tachograph/list_ddd_vehicle'].get(
18
+ params: with_key(params)
19
+ )
20
+ end
21
+
22
+ def download_ddd_vehicle(params = {})
23
+ @client['tachograph/download_ddd_vehicle'].get(
24
+ params: with_key(params)
25
+ )
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,11 @@
1
+ module MaponClient
2
+ class Resources
3
+ class TrackingResource < Resources
4
+ def list(params = {})
5
+ @client['tracking/list'].get(
6
+ params: with_key(params)
7
+ )
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,47 @@
1
+ module MaponClient
2
+ class Resources
3
+ class UnitDataResource < Resources
4
+ def ignitions(params = {})
5
+ @client['unit_data/ignitions'].get(
6
+ params: with_key(params)
7
+ )
8
+ end
9
+
10
+ def temperature(params = {})
11
+ @client['unit_data/temperature'].get(
12
+ params: with_key(params)
13
+ )
14
+ end
15
+
16
+ def digital_inputs(params = {})
17
+ @client['unit_data/digital_inputs'].get(
18
+ params: with_key(params)
19
+ )
20
+ end
21
+
22
+ def can_period(params = {})
23
+ @client['unit_data/can_period'].get(
24
+ params: with_key(params)
25
+ )
26
+ end
27
+
28
+ def can_point(params = {})
29
+ @client['unit_data/can_point'].get(
30
+ params: with_key(params)
31
+ )
32
+ end
33
+
34
+ def fields(params = {})
35
+ @client['unit_data/fields'].get(
36
+ params: with_key(params)
37
+ )
38
+ end
39
+
40
+ def debug_info(params = {})
41
+ @client['unit_data/debug_info'].get(
42
+ params: with_key(params)
43
+ )
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,17 @@
1
+ module MaponClient
2
+ class Resources
3
+ class UnitGroupResource < Resources
4
+ def list(params = {})
5
+ @client['unit_groups/list'].get(
6
+ params: with_key(params)
7
+ )
8
+ end
9
+
10
+ def list_units(params = {})
11
+ @client['unit_groups/list_units'].get(
12
+ params: with_key(params)
13
+ )
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ module MaponClient
2
+ class Resources
3
+ class UnitResource < Resources
4
+ def list(params = {})
5
+ @client['unit/list'].get(
6
+ params: with_key(params)
7
+ )
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module MaponClient
2
+ class Resources
3
+ class UserResource < Resources
4
+ def list(params = {})
5
+ @client['user/list'].get(
6
+ params: with_key(params)
7
+ )
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,53 @@
1
+ require 'mapon_client/resources/company_resource'
2
+ require 'mapon_client/resources/unit_resource'
3
+ require 'mapon_client/resources/unit_group_resource'
4
+ require 'mapon_client/resources/unit_data_resource'
5
+ require 'mapon_client/resources/route_resource'
6
+ require 'mapon_client/resources/fuel_resource'
7
+ require 'mapon_client/resources/object_resource'
8
+ require 'mapon_client/resources/user_resource'
9
+ require 'mapon_client/resources/driver_resource'
10
+ require 'mapon_client/resources/reefer_resource'
11
+ require 'mapon_client/resources/tachograph_resource'
12
+ require 'mapon_client/resources/tracking_resource'
13
+ require 'mapon_client/resources/data_forward_resource'
14
+ require 'mapon_client/resources/application_menu_resource'
15
+
16
+ module MaponClient
17
+ class Resources
18
+ AVAILABLE_RESOURCES = {
19
+ company: CompanyResource,
20
+ unit_group: UnitGroupResource,
21
+ unit: UnitResource,
22
+ unit_data: UnitDataResource,
23
+ route: RouteResource,
24
+ fuel: FuelResource,
25
+ object: ObjectResource,
26
+ user: UserResource,
27
+ driver: DriverResource,
28
+ reefer: ReeferResource,
29
+ tachograph: TachographResource,
30
+ tracking: TrackingResource,
31
+ data_forward: DataForwardResource,
32
+ application_menu: ApplicationMenuResource,
33
+ }.freeze
34
+
35
+ def initialize(client)
36
+ @client = client
37
+ @resources_repository = {}
38
+ end
39
+
40
+ def [](resource)
41
+ return @resources_repository[resource] if @resources_repository[resource]
42
+ raise ResourceNotFound.new(resource) unless AVAILABLE_RESOURCES[resource]
43
+ @resources_repository[resource] = AVAILABLE_RESOURCES[resource].new(@client)
44
+ end
45
+
46
+ def with_key(params)
47
+ @client.with_key(params)
48
+ end
49
+ end
50
+
51
+ class ResourceNotFound < ::StandardError
52
+ end
53
+ end
@@ -0,0 +1,3 @@
1
+ module MaponClient
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,8 @@
1
+ require "mapon_client/version"
2
+
3
+ module MaponClient
4
+ DEFAULT_BASE_URL = 'https://mapon.com/api/v1/'.freeze
5
+ DEFAULT_FORMAT = 'json'.freeze
6
+
7
+ autoload :Client, 'mapon_client/client'
8
+ end
@@ -0,0 +1,28 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "mapon_client/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mapon_client"
8
+ spec.version = MaponClient::VERSION
9
+ spec.authors = ["Ingus Skaistkalns"]
10
+ spec.email = ["ingus.skaistkalns@gmail.com"]
11
+
12
+ spec.summary = %q{Ruby client library for https://www.mapon.com API}
13
+ spec.homepage = "https://github.com/IngusSkaistkalns/mapon_client"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "rest-client", ">1"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.16"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mapon_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ingus Skaistkalns
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-03-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">"
18
+ - !ruby/object:Gem::Version
19
+ version: '1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">"
25
+ - !ruby/object:Gem::Version
26
+ version: '1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description:
70
+ email:
71
+ - ingus.skaistkalns@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - Gemfile.lock
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/setup
87
+ - lib/mapon_client.rb
88
+ - lib/mapon_client/client.rb
89
+ - lib/mapon_client/resources.rb
90
+ - lib/mapon_client/resources/application_menu_resource.rb
91
+ - lib/mapon_client/resources/company_resource.rb
92
+ - lib/mapon_client/resources/data_forward_resource.rb
93
+ - lib/mapon_client/resources/driver_resource.rb
94
+ - lib/mapon_client/resources/fuel_resource.rb
95
+ - lib/mapon_client/resources/object_resource.rb
96
+ - lib/mapon_client/resources/reefer_resource.rb
97
+ - lib/mapon_client/resources/route_resource.rb
98
+ - lib/mapon_client/resources/tachograph_resource.rb
99
+ - lib/mapon_client/resources/tracking_resource.rb
100
+ - lib/mapon_client/resources/unit_data_resource.rb
101
+ - lib/mapon_client/resources/unit_group_resource.rb
102
+ - lib/mapon_client/resources/unit_resource.rb
103
+ - lib/mapon_client/resources/user_resource.rb
104
+ - lib/mapon_client/version.rb
105
+ - mapon_client.gemspec
106
+ homepage: https://github.com/IngusSkaistkalns/mapon_client
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.7.3
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Ruby client library for https://www.mapon.com API
130
+ test_files: []