my_tank_info 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/main.yml +17 -0
  3. data/.gitignore +9 -0
  4. data/CHANGELOG.md +5 -0
  5. data/CODE_OF_CONDUCT.md +84 -0
  6. data/Gemfile +10 -0
  7. data/Gemfile.lock +74 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +253 -0
  10. data/Rakefile +12 -0
  11. data/bin/console +14 -0
  12. data/bin/setup +8 -0
  13. data/lib/my_tank_info/client.rb +106 -0
  14. data/lib/my_tank_info/collection.rb +33 -0
  15. data/lib/my_tank_info/error.rb +6 -0
  16. data/lib/my_tank_info/errors/missing_required_attribute_error.rb +6 -0
  17. data/lib/my_tank_info/object.rb +18 -0
  18. data/lib/my_tank_info/objects/alarm.rb +6 -0
  19. data/lib/my_tank_info/objects/alarm_note.rb +6 -0
  20. data/lib/my_tank_info/objects/csld_result.rb +6 -0
  21. data/lib/my_tank_info/objects/environmental_sitegroup.rb +9 -0
  22. data/lib/my_tank_info/objects/inventory_sitegroup.rb +9 -0
  23. data/lib/my_tank_info/objects/line_leak_result.rb +6 -0
  24. data/lib/my_tank_info/objects/notification_code.rb +6 -0
  25. data/lib/my_tank_info/objects/notification_contact.rb +6 -0
  26. data/lib/my_tank_info/objects/notification_rule.rb +9 -0
  27. data/lib/my_tank_info/objects/notification_rule_contact.rb +6 -0
  28. data/lib/my_tank_info/objects/notification_site.rb +6 -0
  29. data/lib/my_tank_info/objects/sensor_status_result.rb +6 -0
  30. data/lib/my_tank_info/objects/site.rb +6 -0
  31. data/lib/my_tank_info/objects/sitegroup_inventory_dashboard.rb +9 -0
  32. data/lib/my_tank_info/objects/tank.rb +6 -0
  33. data/lib/my_tank_info/objects/tank_daily_usage_record.rb +6 -0
  34. data/lib/my_tank_info/objects/tank_delivery_record.rb +6 -0
  35. data/lib/my_tank_info/objects/tank_inventory_record.rb +6 -0
  36. data/lib/my_tank_info/objects/tank_leak_result.rb +6 -0
  37. data/lib/my_tank_info/objects/tank_reconciliation_record.rb +30 -0
  38. data/lib/my_tank_info/objects/tank_rule.rb +6 -0
  39. data/lib/my_tank_info/objects/tank_runout_record.rb +6 -0
  40. data/lib/my_tank_info/resource.rb +75 -0
  41. data/lib/my_tank_info/resources/active_alarms.rb +29 -0
  42. data/lib/my_tank_info/resources/alarm_history.rb +25 -0
  43. data/lib/my_tank_info/resources/alarm_notes.rb +13 -0
  44. data/lib/my_tank_info/resources/csld_results.rb +10 -0
  45. data/lib/my_tank_info/resources/environmental_sitegroups.rb +9 -0
  46. data/lib/my_tank_info/resources/inventory_sitegroups.rb +9 -0
  47. data/lib/my_tank_info/resources/line_leak_results.rb +10 -0
  48. data/lib/my_tank_info/resources/notification_contacts.rb +32 -0
  49. data/lib/my_tank_info/resources/notification_rules.rb +28 -0
  50. data/lib/my_tank_info/resources/sensor_status_results.rb +10 -0
  51. data/lib/my_tank_info/resources/sitegroup_inventory_dashboards.rb +12 -0
  52. data/lib/my_tank_info/resources/tank_daily_usage.rb +10 -0
  53. data/lib/my_tank_info/resources/tank_deliveries.rb +27 -0
  54. data/lib/my_tank_info/resources/tank_inventory.rb +10 -0
  55. data/lib/my_tank_info/resources/tank_leak_results.rb +10 -0
  56. data/lib/my_tank_info/resources/tank_reconciliation_records.rb +34 -0
  57. data/lib/my_tank_info/resources/tank_rules.rb +15 -0
  58. data/lib/my_tank_info/resources/tank_runout.rb +10 -0
  59. data/lib/my_tank_info/resources/tanks.rb +24 -0
  60. data/lib/my_tank_info/resources/tokens.rb +10 -0
  61. data/lib/my_tank_info/tank_reconciliation_record_collection.rb +51 -0
  62. data/lib/my_tank_info/tank_reconciliation_record_summary.rb +113 -0
  63. data/lib/my_tank_info/version.rb +5 -0
  64. data/lib/my_tank_info.rb +68 -0
  65. data/my_tank_info.gemspec +34 -0
  66. metadata +138 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cac3de797757a7f6e4848ab35ba9fad75b144db0e7f514591eed1ee7393cd2be
4
+ data.tar.gz: c77d732d609e34790b253d2ecaf8f0e77efe430dbf56fb19c5cee784f385c444
5
+ SHA512:
6
+ metadata.gz: 203baf9c369abfb79d74217291cd23c9d6c7abb0a4353a761209c4799c9756abc996e15b44aaccac7d447e8ec826ccf136063989662684b0aecdcc8e18100f11
7
+ data.tar.gz: e0472c0a4903efa0e3bb2b19e87c8d53561e71aa4b7309c3375eb5660ac1ae553914983baf82721c75c75f78f077c420dbba55c09c24b1f0d11f070b7aaa234c
@@ -0,0 +1,17 @@
1
+ name: Ruby
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@master
10
+ - name: Set up Ruby
11
+ uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: 3.0.2
14
+ bundler-cache: true
15
+
16
+ - name: Run tests
17
+ run: bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .env
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-09-14
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at me@kylekeesling.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in my_tank_info.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+ gem "minitest", "~> 5.0"
10
+ gem "standard"
data/Gemfile.lock ADDED
@@ -0,0 +1,74 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ my_tank_info (0.1.0)
5
+ faraday (~> 1.7)
6
+ faraday_middleware (~> 1.1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ ast (2.4.2)
12
+ faraday (1.7.2)
13
+ faraday-em_http (~> 1.0)
14
+ faraday-em_synchrony (~> 1.0)
15
+ faraday-excon (~> 1.1)
16
+ faraday-httpclient (~> 1.0.1)
17
+ faraday-net_http (~> 1.0)
18
+ faraday-net_http_persistent (~> 1.1)
19
+ faraday-patron (~> 1.0)
20
+ faraday-rack (~> 1.0)
21
+ multipart-post (>= 1.2, < 3)
22
+ ruby2_keywords (>= 0.0.4)
23
+ faraday-em_http (1.0.0)
24
+ faraday-em_synchrony (1.0.0)
25
+ faraday-excon (1.1.0)
26
+ faraday-httpclient (1.0.1)
27
+ faraday-net_http (1.0.1)
28
+ faraday-net_http_persistent (1.2.0)
29
+ faraday-patron (1.0.0)
30
+ faraday-rack (1.0.0)
31
+ faraday_middleware (1.1.0)
32
+ faraday (~> 1.0)
33
+ minitest (5.14.4)
34
+ multipart-post (2.1.1)
35
+ parallel (1.21.0)
36
+ parser (3.0.2.0)
37
+ ast (~> 2.4.1)
38
+ rainbow (3.0.0)
39
+ rake (13.0.6)
40
+ regexp_parser (2.1.1)
41
+ rexml (3.2.5)
42
+ rubocop (1.20.0)
43
+ parallel (~> 1.10)
44
+ parser (>= 3.0.0.0)
45
+ rainbow (>= 2.2.2, < 4.0)
46
+ regexp_parser (>= 1.8, < 3.0)
47
+ rexml
48
+ rubocop-ast (>= 1.9.1, < 2.0)
49
+ ruby-progressbar (~> 1.7)
50
+ unicode-display_width (>= 1.4.0, < 3.0)
51
+ rubocop-ast (1.11.0)
52
+ parser (>= 3.0.1.1)
53
+ rubocop-performance (1.11.5)
54
+ rubocop (>= 1.7.0, < 2.0)
55
+ rubocop-ast (>= 0.4.0)
56
+ ruby-progressbar (1.11.0)
57
+ ruby2_keywords (0.0.5)
58
+ standard (1.3.0)
59
+ rubocop (= 1.20.0)
60
+ rubocop-performance (= 1.11.5)
61
+ unicode-display_width (2.0.0)
62
+
63
+ PLATFORMS
64
+ arm64-darwin-20
65
+ x86_64-linux
66
+
67
+ DEPENDENCIES
68
+ minitest (~> 5.0)
69
+ my_tank_info!
70
+ rake (~> 13.0)
71
+ standard
72
+
73
+ BUNDLED WITH
74
+ 2.2.25
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Kyle Keesling
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,253 @@
1
+ # MyTankInfo
2
+
3
+ [![Ruby](https://github.com/kylekeesling/my_tank_info/actions/workflows/main.yml/badge.svg)](https://github.com/kylekeesling/my_tank_info/actions/workflows/main.yml)
4
+
5
+ A simple Ruby gem for interacting with the [MyTankInfo](http://mytankinfo.com) API.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'my_tank_info'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install my_tank_info
22
+
23
+ ## Usage
24
+
25
+ ### Creating a Client
26
+
27
+ ```ruby
28
+ client = MyTankInfo::Client.new(api_key: ENV["MYTANKINFO_API_KEY"])
29
+ ```
30
+
31
+ ### API Tokens
32
+ You must obtain an API token in order to use this gem. Tokens appear to last for 1 year before the expire.
33
+
34
+ Once the token is generated it should be stored for use on all subsequent API requests.
35
+
36
+ Practically speaking you'll need to store the username/password for then account you'd like to access
37
+ so that you can periodically generate a new API token prior to expiration.
38
+
39
+ Alternatively you can have your code catch _403 Forbidden_ errors and use that as a sign that a new API token is needed.
40
+
41
+ This is also the only call you can perform without providing an :api_key to the client
42
+
43
+ ```ruby
44
+ client.generate_api_token(username:, password:)
45
+ ```
46
+ ### Environmental API
47
+ ```ruby
48
+ # Return a list of all sitegroups for the account
49
+ client.environmental_sitegroups
50
+
51
+ # Active Alarms records be retrived either as a full list, or filtered by :site_id
52
+ # Will return empty if there are no active alarms
53
+ client.active_alarms.list
54
+ client.active_alarms.list(site_id: 123)
55
+ ```
56
+
57
+ In addition to the defined parameters below you may also pass ``:report_start_date`` and ``:report_end_date`` as optional parameters to retrive records for a given timeframe
58
+
59
+ ```ruby
60
+ # Alarm History records be retrived either as a full list, or filtered by :site_id
61
+ client.alarm_history.list
62
+ client.alarm_history.list(site_id: 123)
63
+
64
+ # View Tank Leak Test Results for a site
65
+ # Will return empty if the site does not have line tank leak detection configured
66
+ client.tank_leak_results.list(site_id: 123)
67
+
68
+ # View Line Leak Test Results for a site
69
+ # Will return empty if the site does not have line leak detection configured
70
+ client.line_leak_results.list(site_id: 123)
71
+
72
+ # View Sensor Status Results for a site
73
+ # Will return empty if the site does not have Continuous iI-tank Leak Detection (CITLD), which is
74
+ # often referred to as CSLD or (Continuous Statistical Leak Detection)
75
+ client.csld_results.list(site_id: 123)
76
+
77
+ # View Sensor Status Results for a site
78
+ # Will return empty if the site does not have any sensors
79
+ client.sensor_status_results.list(site_id: 123)
80
+ ```
81
+
82
+ ### Reconciliation API
83
+ You may also pass ``:report_start_date`` and ``:report_end_date`` as optional parameters to retrive records for a given timeframe
84
+
85
+ ```ruby
86
+ # reconciliation_period must be one of the following - :weekly, :ten_day, :monthly
87
+ client.tank_reconciliation_records.list(site_id: 123, reconciliation_period: :monthly)
88
+ ```
89
+
90
+ This call returns a special collection object called `TankReconciliationRecordCollection` that gives you a number
91
+ of convienience methods for accessing the data in a easily usable way:
92
+
93
+ ```ruby
94
+ collection = client.tank_reconciliation_records.list(site_id: 123, reconciliation_period: :monthly)
95
+
96
+ collection.started_at
97
+ collection.ended_at
98
+
99
+ # returns a collection of TankReconciliationRecords
100
+ collection.data
101
+
102
+ # this returns a collection of Tank objects
103
+ tanks = collection.tanks
104
+ tank = tanks.fist
105
+
106
+ tank.name # 1 - Unleaded
107
+ tank.product_name # Unleaded
108
+ tank.tank_number # 1
109
+ tank.capacity # 5000
110
+
111
+ # collection of TankReconciliationRecords belonging only to this tank
112
+ tank.reconciliation_records
113
+
114
+ # returns TankReconciliationRecordSummary object which provides
115
+ # a number of calculations based upon the provided reconciliation_period
116
+ tank.reconciliation_summary
117
+
118
+ # evaluates associated reconciliation_records based upon the
119
+ # provided reconciliation_period to decide if tank has passed
120
+ tank.passed?
121
+
122
+ # evaluates associated reconciliation_records based upon the
123
+ # provided reconciliation_period to decide if tank has failed
124
+ tank.failed?
125
+ ```
126
+
127
+
128
+ ### Inventory API
129
+ ```ruby
130
+ # Will return a list of all sitegroups for the account, along with a host of additional data relating
131
+ # to corresponding sites and their current inventory and alarm status
132
+ client.inventory_sitegroups.list
133
+
134
+ # Tanks can be retrived either as a full list, or filtered by :site_id
135
+ client.tanks.list
136
+ client.tanks.list(site_id: 123)
137
+
138
+ # Will return a list all sites belonging to a sitegroup, along with a host of additional data relating
139
+ # each site's current inventory and alarm status
140
+ client.sitegroup_inventory_dashboards.list(sitegroup_id: 1)
141
+
142
+ # Returns daily inventory usage over the previous 4 weeks for a given tank
143
+ client.tank_daily_usage.list(tank_id: 1)
144
+
145
+ # Returns deliveries made to the given tank over a time period.
146
+ # Supports :report_start_date and :report_end_date parameters
147
+ client.tank_deliveries.list(tank_id: 1)
148
+
149
+
150
+ ## To update a tank delivery, the folowing params are required in the update request
151
+ params = {
152
+ start_date_and_time: "2021-08-10T11:48:00.0000000-04:00",
153
+ start_gross: 500,
154
+ stop_date_and_time: "2021-08-10T12:48:00.0000000-04:00",
155
+ stop_gross: 600,
156
+ delivery_net: 100,
157
+ delivery_gross: 105,
158
+ bol_number: "123"
159
+ }
160
+
161
+ client.tank_deliveries.update(tank_id: 1, delivery_id: 1, **params)
162
+
163
+ # Returns inventory readings for the given tank over a time period.
164
+ # Supports :report_start_date and :report_end_date parameters
165
+ client.tank_inventory.list(tank_id: 1)
166
+
167
+ # Returns recent inventory records for a tank (similiar to client.tank_deliveries.list)
168
+ # with an extra record indicating the estimated runout.
169
+
170
+ # The period of time over which the records are queried varies depending on how far out in the
171
+ # future the estimated runout is. But the results will contain inventory records from at least
172
+ # the last two days and at most the last 28 days.
173
+
174
+ client.tank_runout.list(tank_id: 1)
175
+ ```
176
+
177
+ ### Admin API
178
+
179
+ #### Notification Contacts
180
+ ```ruby
181
+ client.notification_contacts.list
182
+
183
+ # A list of all sites that the contact is setup to recieve notifications about
184
+ # Note: will be empty if contact is setup to recieve updates for all sites (default_contact_settings: 1)
185
+ client.notification_contacts.list_sites(contact_id: 1)
186
+
187
+ client.notification_contacts.retrieve(contact_id: 1)
188
+
189
+
190
+ # Updating and creating a NotificationContact record requires the following params
191
+ params = {
192
+ first_name: "Kyle",
193
+ last_name: "Keesling",
194
+ email: "kyle@example.com",
195
+ sms_phone: "555-555-5555",
196
+ contact_method: 3, # 1 (SMS), 2 (Email), 3 (SMS & Email)
197
+ is_active: true,
198
+ default_contact_settings: 1 # 0 (None/No Sites), 1 (All Sites), 2 (Only Selected Sites)
199
+ }
200
+
201
+ client.notification_contacts.update(contact_id: 1, **params)
202
+
203
+ client.notification_contacts.create(**params)
204
+
205
+ client.notification_contacts.delete(contact_id: 1)
206
+ ```
207
+
208
+ #### Notification Rules
209
+ ```ruby
210
+ # Provides a list of all alarm/warning codes that rules can be defined for
211
+ client.notification_rules.list_codes
212
+
213
+ # List all contacts associated with a rule
214
+ client.notification_rules.list_contacts(rule_id: 1)
215
+
216
+ # List all rules that have been defined for a given code
217
+ client.notification_rules.list(code_id: 1)
218
+
219
+ # Updating a rule requires that you pass along an array of the
220
+ # contacts who the rule should apply to as well as the prefereed
221
+ # contact method. isSuppressed will silence the rule without
222
+ # actually deleting it
223
+ params = {
224
+ contacts: [
225
+ {
226
+ contactId: 3110,
227
+ contactMethod: 3 # 1 (SMS), 2 (Email), 3 (SMS & Email)
228
+ }
229
+ ],
230
+ isSuppressed: false
231
+ }
232
+
233
+ client.notification_rules.update(rule_id: 1, **params)
234
+
235
+ client.notification_rules.delete(rule_id: 1)
236
+ ```
237
+
238
+ ## Development
239
+
240
+ 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.
241
+
242
+
243
+ ## Contributing
244
+
245
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kylekeesling/my_tank_info. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/kylekeesling/my_tank_info/blob/master/CODE_OF_CONDUCT.md).
246
+
247
+ ## License
248
+
249
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
250
+
251
+ ## Code of Conduct
252
+
253
+ Everyone interacting in the MyTankInfo project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/kylekeesling/my_tank_info/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ task default: %i[test]
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "my_tank_info"
6
+
7
+ client = MyTankInfo::Client.new(api_key: ENV["MYTANKINFO_API_KEY"])
8
+
9
+ puts
10
+ puts "We've created a 'client' variable as a MyTankInfo::Client using ENV['MYTANKINFO_API_KEY'] as the API key."
11
+ puts
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,106 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+ require "faraday_middleware"
5
+
6
+ module MyTankInfo
7
+ class Client
8
+ BASE_URL = "https://app.mytankinfo.com"
9
+ attr_reader :api_key
10
+
11
+ def initialize(api_key:, adapter: Faraday.default_adapter, stubs: nil)
12
+ @api_key = api_key
13
+ @adapter = adapter
14
+ @stubs = stubs
15
+ end
16
+
17
+ def environmental_sitegroups
18
+ EnvironmentalSitegroupsResource.new(self)
19
+ end
20
+
21
+ def active_alarms
22
+ ActiveAlarmsResource.new(self)
23
+ end
24
+
25
+ def alarm_history
26
+ AlarmHistoryResource.new(self)
27
+ end
28
+
29
+ def alarm_notes
30
+ AlarmNotesResource.new(self)
31
+ end
32
+
33
+ def tank_leak_results
34
+ TankLeakResultsResource.new(self)
35
+ end
36
+
37
+ def line_leak_results
38
+ LineLeakResultsResource.new(self)
39
+ end
40
+
41
+ def csld_results
42
+ CsldResultsResource.new(self)
43
+ end
44
+
45
+ def sensor_status_results
46
+ SensorStatusResultsResource.new(self)
47
+ end
48
+
49
+ def inventory_sitegroups
50
+ InventorySitegroupsResource.new(self)
51
+ end
52
+
53
+ def tanks
54
+ TanksResource.new(self)
55
+ end
56
+
57
+ def sitegroup_inventory_dashboards
58
+ SitegroupInventoryDashboardsResource.new(self)
59
+ end
60
+
61
+ def tank_daily_usage
62
+ TankDailyUsageResource.new(self)
63
+ end
64
+
65
+ def tank_deliveries
66
+ TankDeliveriesResource.new(self)
67
+ end
68
+
69
+ def tank_inventory
70
+ TankInventoryResource.new(self)
71
+ end
72
+
73
+ def tank_runout
74
+ TankRunoutResource.new(self)
75
+ end
76
+
77
+ def tank_rules
78
+ TankRulesResource.new(self)
79
+ end
80
+
81
+ def tank_reconciliation_records
82
+ TankReconciliationRecordsResource.new(self)
83
+ end
84
+
85
+ def notification_contacts
86
+ NotificationContactsResource.new(self)
87
+ end
88
+
89
+ def notification_rules
90
+ NotificationRulesResource.new(self)
91
+ end
92
+
93
+ def generate_api_token(username:, password:)
94
+ TokensResource.new(self).generate(username: username, password: password)
95
+ end
96
+
97
+ def connection
98
+ @connection ||= Faraday.new do |conn|
99
+ conn.url_prefix = BASE_URL
100
+ conn.request :json
101
+ conn.response :json, content_type: "application/json"
102
+ conn.adapter @adapter, @stubs
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MyTankInfo
4
+ class Collection
5
+ attr_reader :data, :size
6
+
7
+ def self.from_response(response, type:, filter_attribute: nil, filter_value: nil)
8
+ body =
9
+ if response.body.instance_of?(Hash)
10
+ [response.body]
11
+ else
12
+ response.body
13
+ end
14
+
15
+ @collection = new(
16
+ data: body.map { |attrs| type.new(attrs) },
17
+ filter_attribute: filter_attribute,
18
+ filter_value: filter_value
19
+ )
20
+ end
21
+
22
+ def initialize(data:, filter_attribute: nil, filter_value: nil)
23
+ @data =
24
+ if filter_attribute && filter_value
25
+ data.select { |item| item.send(filter_attribute) == filter_value }
26
+ else
27
+ data
28
+ end
29
+
30
+ @size = @data.size
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MyTankInfo
4
+ class Error < StandardError
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MyTankInfo
4
+ class MissingRequiredAttributeError < Error
5
+ end
6
+ end