ruby-fiix-cmms-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 +7 -0
- data/.github/workflows/ci.yml +27 -0
- data/CHANGELOG.md +5 -0
- data/CLAUDE.md +61 -0
- data/CODE_OF_CONDUCT.md +10 -0
- data/LICENSE.txt +21 -0
- data/README.md +142 -0
- data/Rakefile +8 -0
- data/lib/ruby/fiix/cmms/client/api_client.rb +126 -0
- data/lib/ruby/fiix/cmms/client/auth.rb +26 -0
- data/lib/ruby/fiix/cmms/client/configuration.rb +29 -0
- data/lib/ruby/fiix/cmms/client/errors.rb +24 -0
- data/lib/ruby/fiix/cmms/client/response.rb +42 -0
- data/lib/ruby/fiix/cmms/client/version.rb +11 -0
- data/lib/ruby/fiix/cmms/client.rb +29 -0
- data/sig/ruby/fiix/cmms/client.rbs +10 -0
- metadata +60 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: e9869f6020778153f7836b0d77af9238ffa5f334192098a76bb421117cbd70d8
|
|
4
|
+
data.tar.gz: c065c5d1e9a47cf28e70ecda4c9698d6b5212f78105302bccdb129e40c7e65cf
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 6273384a2acc4ba6297dac1cf182b97f621446e95f825b1172e70fb99bcf46e4839b1aecc429c19d7d83cfb865fc2c9acb2167e9c7787a3daf206a35d835142a
|
|
7
|
+
data.tar.gz: da1cc68df6842f83a835442ecd6d5f2fb59fc992106bc7c9dc6707bbbc0b6062099d5e4659158afbf5b79eae2a16198626fa10134920600506545effc0e0f6b2
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
|
|
13
|
+
strategy:
|
|
14
|
+
matrix:
|
|
15
|
+
ruby-version: ["3.2", "3.3", "3.4", "4.0"]
|
|
16
|
+
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@v4
|
|
19
|
+
|
|
20
|
+
- name: Set up Ruby ${{ matrix.ruby-version }}
|
|
21
|
+
uses: ruby/setup-ruby@v1
|
|
22
|
+
with:
|
|
23
|
+
ruby-version: ${{ matrix.ruby-version }}
|
|
24
|
+
bundler-cache: true
|
|
25
|
+
|
|
26
|
+
- name: Run tests
|
|
27
|
+
run: bundle exec rake test
|
data/CHANGELOG.md
ADDED
data/CLAUDE.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Project Overview
|
|
6
|
+
|
|
7
|
+
Ruby client gem for the Fiix CMMS (Computerized Maintenance Management System) REST API. Requires Ruby >= 3.2.0. Zero runtime dependencies (uses stdlib: net/http, openssl, json).
|
|
8
|
+
|
|
9
|
+
**Goal:** Idiomatic Ruby gem covering the full Fiix CMMS API surface, usable standalone or in Rails apps.
|
|
10
|
+
|
|
11
|
+
### Reference Clients
|
|
12
|
+
|
|
13
|
+
- **Python** (`Saint-Solutions/python-fiix-cmms-client`): HMAC-SHA256 auth, 5 operations.
|
|
14
|
+
- **JS** (`fiixlabs/fiix-cmms-client-js` v2.41.0): 8 operations including FindByIdRequest, RpcRequest, and file upload.
|
|
15
|
+
|
|
16
|
+
This gem covers all 8 operations.
|
|
17
|
+
|
|
18
|
+
## Commands
|
|
19
|
+
|
|
20
|
+
- **Install dependencies:** `bin/setup` or `bundle install`
|
|
21
|
+
- **Run all tests:** `bundle exec rake test` (or just `rake`, test is the default task)
|
|
22
|
+
- **Run a single test file:** `bundle exec ruby -Ilib:test test/ruby/fiix/cmms/test_api_client.rb`
|
|
23
|
+
- **Run a single test method:** `bundle exec ruby -Ilib:test test/ruby/fiix/cmms/test_api_client.rb --name test_find_sends_find_request`
|
|
24
|
+
- **Interactive console:** `bin/console`
|
|
25
|
+
- **Install gem locally:** `bundle exec rake install`
|
|
26
|
+
|
|
27
|
+
## Architecture
|
|
28
|
+
|
|
29
|
+
- **Module namespace:** `Ruby::Fiix::Cmms::Client`
|
|
30
|
+
- **Entry point:** `lib/ruby/fiix/cmms/client.rb` — requires all modules, provides `configure` / `reset_configuration!`
|
|
31
|
+
- **Core files:**
|
|
32
|
+
- `client/version.rb` — `VERSION` constant
|
|
33
|
+
- `client/errors.rb` — `Error`, `ConfigurationError`, `ApiError`, `ConnectionError`
|
|
34
|
+
- `client/configuration.rb` — credential holder with `validate!`
|
|
35
|
+
- `client/auth.rb` — `Auth.base_url` and `Auth.sign` (HMAC-SHA256)
|
|
36
|
+
- `client/response.rb` — wraps `Net::HTTPResponse` with `body`, `success?`, `status`, `[]`, `to_h`
|
|
37
|
+
- `client/api_client.rb` — `ApiClient` class with 8 operations: `create`, `find`, `find_by_id`, `update`, `delete`, `rpc`, `batch`, `upload_file`
|
|
38
|
+
- **Test framework:** Minitest + WebMock (tests in `test/`)
|
|
39
|
+
- **Type signatures:** `sig/` directory (RBS)
|
|
40
|
+
|
|
41
|
+
## Development Principles
|
|
42
|
+
|
|
43
|
+
### TDD (Test-Driven Development)
|
|
44
|
+
|
|
45
|
+
Follow the Red-Green-Refactor cycle strictly:
|
|
46
|
+
1. **Red:** Write a failing test first — no production code without a failing test.
|
|
47
|
+
2. **Green:** Write the minimum code to make the test pass.
|
|
48
|
+
3. **Refactor:** Clean up while keeping tests green.
|
|
49
|
+
|
|
50
|
+
Tests go in `test/` using Minitest. Write tests before implementation, not after.
|
|
51
|
+
|
|
52
|
+
### Clean Code (Uncle Bob)
|
|
53
|
+
|
|
54
|
+
- **Small functions:** Each method does one thing. If a method needs a comment to explain *what* it does, it should be extracted or renamed.
|
|
55
|
+
- **Meaningful names:** Classes, methods, and variables should reveal intent. No abbreviations or cryptic names.
|
|
56
|
+
- **Single Responsibility Principle:** Each class has one reason to change.
|
|
57
|
+
- **One level of abstraction per function:** Don't mix high-level orchestration with low-level details in the same method.
|
|
58
|
+
- **No dead code:** Don't leave commented-out code, unused methods, or unreachable branches.
|
|
59
|
+
- **DRY but not premature:** Extract duplication only when the pattern is clear (Rule of Three).
|
|
60
|
+
- **Command-Query Separation:** Methods either do something (command) or return something (query), not both.
|
|
61
|
+
- **Prefer exceptions over error codes:** Use custom error classes inheriting from `Ruby::Fiix::Cmms::Client::Error`.
|
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Code of Conduct
|
|
2
|
+
|
|
3
|
+
"ruby-fiix-cmms-client" follows [The Ruby Community Conduct Guideline](https://www.ruby-lang.org/en/conduct) in all "collaborative space", which is defined as community communications channels (such as mailing lists, submitted patches, commit comments, etc.):
|
|
4
|
+
|
|
5
|
+
* Participants will be tolerant of opposing views.
|
|
6
|
+
* Participants must ensure that their language and actions are free of personal attacks and disparaging personal remarks.
|
|
7
|
+
* When interpreting the words and actions of others, participants should always assume good intentions.
|
|
8
|
+
* Behaviour which can be reasonably considered harassment will not be tolerated.
|
|
9
|
+
|
|
10
|
+
If you have any concerns about behaviour within this project, please contact us at ["hi@ronaldlangeveld.com"](mailto:"hi@ronaldlangeveld.com").
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ronald Langeveld
|
|
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,142 @@
|
|
|
1
|
+
# Ruby Fiix CMMS Client
|
|
2
|
+
|
|
3
|
+
A Ruby gem for the [Fiix CMMS](https://www.fiixsoftware.com/) REST API with HMAC-SHA256 authentication. Zero runtime dependencies.
|
|
4
|
+
|
|
5
|
+
Supports all core API operations: find, find by ID, create, update, delete, RPC, batch, and file uploads.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add to your Gemfile:
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem "ruby-fiix-cmms-client"
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Then run `bundle install`.
|
|
16
|
+
|
|
17
|
+
Or install directly:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
gem install ruby-fiix-cmms-client
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
### Direct instantiation
|
|
26
|
+
|
|
27
|
+
```ruby
|
|
28
|
+
require "ruby/fiix/cmms/client"
|
|
29
|
+
|
|
30
|
+
client = Ruby::Fiix::Cmms::Client::ApiClient.new(
|
|
31
|
+
subdomain: "mycompany",
|
|
32
|
+
api_key: "your-app-key",
|
|
33
|
+
access_key: "your-access-key",
|
|
34
|
+
api_secret: "your-api-secret"
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
# Find records
|
|
38
|
+
response = client.find(className: "Account", fields: "id,strCode,strDescription")
|
|
39
|
+
response.body # => parsed Hash
|
|
40
|
+
response.success? # => true
|
|
41
|
+
response.status # => 200
|
|
42
|
+
|
|
43
|
+
# Find by ID
|
|
44
|
+
response = client.find_by_id(className: "Asset", id: 12345, fields: "id,strName")
|
|
45
|
+
|
|
46
|
+
# Create
|
|
47
|
+
response = client.create(
|
|
48
|
+
className: "WorkOrder",
|
|
49
|
+
fields: "id",
|
|
50
|
+
object: { "strDescription" => "Fix pump" }
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
# Update
|
|
54
|
+
response = client.update(
|
|
55
|
+
className: "WorkOrder",
|
|
56
|
+
object: { "id" => 1, "strDescription" => "Fix pump - urgent" }
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
# Delete
|
|
60
|
+
response = client.delete(className: "WorkOrder", objects: [{ "id" => 1 }])
|
|
61
|
+
|
|
62
|
+
# RPC (remote procedure call)
|
|
63
|
+
response = client.rpc(className: "User", action: "getPermissions")
|
|
64
|
+
|
|
65
|
+
# Batch (multiple operations in one request)
|
|
66
|
+
response = client.batch(
|
|
67
|
+
requests: [
|
|
68
|
+
{ "_maCn" => "FindRequest", "className" => "Account", "fields" => "id,strCode" },
|
|
69
|
+
{ "_maCn" => "FindRequest", "className" => "PurchaseOrder", "fields" => "id,intCode" }
|
|
70
|
+
]
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
# File upload
|
|
74
|
+
file = File.open("document.pdf")
|
|
75
|
+
response = client.upload_file(
|
|
76
|
+
className: "CMAFileContainer",
|
|
77
|
+
file: file,
|
|
78
|
+
description: "Maintenance report"
|
|
79
|
+
)
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Rails initializer pattern
|
|
83
|
+
|
|
84
|
+
```ruby
|
|
85
|
+
# config/initializers/fiix.rb
|
|
86
|
+
Ruby::Fiix::Cmms::Client.configure do |c|
|
|
87
|
+
c.subdomain = ENV["FIIX_SUBDOMAIN"]
|
|
88
|
+
c.api_key = ENV["FIIX_API_KEY"]
|
|
89
|
+
c.access_key = ENV["FIIX_ACCESS_KEY"]
|
|
90
|
+
c.api_secret = ENV["FIIX_API_SECRET"]
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# Anywhere in your app
|
|
94
|
+
client = Ruby::Fiix::Cmms::Client::ApiClient.new # uses global config
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Response object
|
|
98
|
+
|
|
99
|
+
All operations return a `Ruby::Fiix::Cmms::Client::Response`:
|
|
100
|
+
|
|
101
|
+
```ruby
|
|
102
|
+
response = client.find(className: "Account", fields: "id")
|
|
103
|
+
|
|
104
|
+
response.body # => parsed JSON as Hash
|
|
105
|
+
response.success? # => true/false (based on HTTP status)
|
|
106
|
+
response.status # => 200 (integer)
|
|
107
|
+
response["key"] # => shorthand for response.body["key"]
|
|
108
|
+
response.to_h # => Hash (empty hash if body isn't JSON)
|
|
109
|
+
response.http_response # => raw Net::HTTPResponse
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Error handling
|
|
113
|
+
|
|
114
|
+
```ruby
|
|
115
|
+
begin
|
|
116
|
+
client.find(className: "Account")
|
|
117
|
+
rescue Ruby::Fiix::Cmms::Client::ConfigurationError => e
|
|
118
|
+
# Missing or invalid credentials
|
|
119
|
+
rescue Ruby::Fiix::Cmms::Client::ConnectionError => e
|
|
120
|
+
# Network connectivity issues
|
|
121
|
+
rescue Ruby::Fiix::Cmms::Client::ApiError => e
|
|
122
|
+
# API-level errors (e.response holds the Response object)
|
|
123
|
+
rescue Ruby::Fiix::Cmms::Client::Error => e
|
|
124
|
+
# Catch-all for any gem error
|
|
125
|
+
end
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Development
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
bin/setup # Install dependencies
|
|
132
|
+
rake test # Run tests
|
|
133
|
+
bin/console # Interactive console
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Contributing
|
|
137
|
+
|
|
138
|
+
Bug reports and pull requests are welcome on [GitHub](https://github.com/ronaldlangeveld/ruby-fiix-cmms-client).
|
|
139
|
+
|
|
140
|
+
## License
|
|
141
|
+
|
|
142
|
+
MIT License. See [LICENSE.txt](LICENSE.txt).
|
data/Rakefile
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "net/http"
|
|
4
|
+
require "uri"
|
|
5
|
+
require "json"
|
|
6
|
+
|
|
7
|
+
module Ruby
|
|
8
|
+
module Fiix
|
|
9
|
+
module Cmms
|
|
10
|
+
module Client
|
|
11
|
+
class ApiClient
|
|
12
|
+
OPERATIONS = {
|
|
13
|
+
create: "AddRequest",
|
|
14
|
+
find: "FindRequest",
|
|
15
|
+
find_by_id: "FindByIdRequest",
|
|
16
|
+
update: "ChangeRequest",
|
|
17
|
+
delete: "RemoveRequest",
|
|
18
|
+
rpc: "RpcRequest",
|
|
19
|
+
batch: "BatchRequest"
|
|
20
|
+
}.freeze
|
|
21
|
+
|
|
22
|
+
DEFAULT_CLIENT_VERSION = { "clientVersion" => { "major" => 2, "minor" => 8, "patch" => 1 } }.freeze
|
|
23
|
+
|
|
24
|
+
def initialize(subdomain: nil, api_key: nil, access_key: nil, api_secret: nil)
|
|
25
|
+
config = Client.configuration
|
|
26
|
+
@subdomain = subdomain || config&.subdomain
|
|
27
|
+
@api_key = api_key || config&.api_key
|
|
28
|
+
@access_key = access_key || config&.access_key
|
|
29
|
+
@api_secret = api_secret || config&.api_secret
|
|
30
|
+
|
|
31
|
+
validate_credentials!
|
|
32
|
+
|
|
33
|
+
@base_url = Auth.base_url(@subdomain, @api_key, @access_key)
|
|
34
|
+
@signature = Auth.sign(@api_secret, @base_url)
|
|
35
|
+
@uri = URI.parse(@base_url)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
OPERATIONS.each do |method_name, request_type|
|
|
39
|
+
define_method(method_name) do |context|
|
|
40
|
+
payload = { "_maCn" => request_type }
|
|
41
|
+
.merge(DEFAULT_CLIENT_VERSION)
|
|
42
|
+
.merge(normalize_context(context))
|
|
43
|
+
request(payload)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def upload_file(context)
|
|
48
|
+
normalized = normalize_context(context)
|
|
49
|
+
file = normalized.delete("file")
|
|
50
|
+
multipart_request(normalized, file)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
private
|
|
54
|
+
|
|
55
|
+
def validate_credentials!
|
|
56
|
+
Configuration.new(
|
|
57
|
+
subdomain: @subdomain,
|
|
58
|
+
api_key: @api_key,
|
|
59
|
+
access_key: @access_key,
|
|
60
|
+
api_secret: @api_secret
|
|
61
|
+
).validate!
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def normalize_context(context)
|
|
65
|
+
context.transform_keys(&:to_s)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def request(payload)
|
|
69
|
+
http = build_http
|
|
70
|
+
req = Net::HTTP::Post.new(@uri.request_uri)
|
|
71
|
+
req["Authorization"] = @signature
|
|
72
|
+
req["Content-Type"] = "text/plain;charset=utf-8"
|
|
73
|
+
req.body = JSON.generate(payload)
|
|
74
|
+
|
|
75
|
+
Response.new(http.request(req))
|
|
76
|
+
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH, SocketError => e
|
|
77
|
+
raise ConnectionError, "Failed to connect to Fiix API: #{e.message}"
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def multipart_request(params, file)
|
|
81
|
+
boundary = "----RubyFiixCmms#{SecureRandom.hex(16)}"
|
|
82
|
+
body = build_multipart_body(params, file, boundary)
|
|
83
|
+
|
|
84
|
+
http = build_http
|
|
85
|
+
req = Net::HTTP::Post.new(@uri.request_uri)
|
|
86
|
+
req["Authorization"] = @signature
|
|
87
|
+
req["Content-Type"] = "multipart/form-data; boundary=#{boundary}"
|
|
88
|
+
req.body = body
|
|
89
|
+
|
|
90
|
+
Response.new(http.request(req))
|
|
91
|
+
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH, SocketError => e
|
|
92
|
+
raise ConnectionError, "Failed to connect to Fiix API: #{e.message}"
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def build_http
|
|
96
|
+
http = Net::HTTP.new(@uri.host, @uri.port)
|
|
97
|
+
http.use_ssl = true
|
|
98
|
+
http
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def build_multipart_body(params, file, boundary)
|
|
102
|
+
parts = []
|
|
103
|
+
|
|
104
|
+
params.each do |key, value|
|
|
105
|
+
parts << "--#{boundary}\r\n" \
|
|
106
|
+
"Content-Disposition: form-data; name=\"#{key}\"\r\n\r\n" \
|
|
107
|
+
"#{value}\r\n"
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
if file
|
|
111
|
+
filename = file.respond_to?(:path) ? File.basename(file.path) : "upload"
|
|
112
|
+
file_content = file.respond_to?(:read) ? file.read : file
|
|
113
|
+
parts << "--#{boundary}\r\n" \
|
|
114
|
+
"Content-Disposition: form-data; name=\"file\"; filename=\"#{filename}\"\r\n" \
|
|
115
|
+
"Content-Type: application/octet-stream\r\n\r\n" \
|
|
116
|
+
"#{file_content}\r\n"
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
parts << "--#{boundary}--\r\n"
|
|
120
|
+
parts.join
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "openssl"
|
|
4
|
+
|
|
5
|
+
module Ruby
|
|
6
|
+
module Fiix
|
|
7
|
+
module Cmms
|
|
8
|
+
module Client
|
|
9
|
+
module Auth
|
|
10
|
+
module_function
|
|
11
|
+
|
|
12
|
+
def base_url(subdomain, api_key, access_key)
|
|
13
|
+
"https://#{subdomain}.macmms.com/api/" \
|
|
14
|
+
"?service=cmms&appKey=#{api_key}&accessKey=#{access_key}" \
|
|
15
|
+
"&signatureMethod=HmacSHA256&signatureVersion=1"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def sign(api_secret, url)
|
|
19
|
+
message = url.sub("https://", "")
|
|
20
|
+
OpenSSL::HMAC.hexdigest("SHA256", api_secret, message)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Ruby
|
|
4
|
+
module Fiix
|
|
5
|
+
module Cmms
|
|
6
|
+
module Client
|
|
7
|
+
class Configuration
|
|
8
|
+
REQUIRED_ATTRIBUTES = %i[subdomain api_key access_key api_secret].freeze
|
|
9
|
+
|
|
10
|
+
attr_accessor :subdomain, :api_key, :access_key, :api_secret
|
|
11
|
+
|
|
12
|
+
def initialize(subdomain: nil, api_key: nil, access_key: nil, api_secret: nil)
|
|
13
|
+
@subdomain = subdomain
|
|
14
|
+
@api_key = api_key
|
|
15
|
+
@access_key = access_key
|
|
16
|
+
@api_secret = api_secret
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def validate!
|
|
20
|
+
REQUIRED_ATTRIBUTES.each do |attr|
|
|
21
|
+
value = send(attr)
|
|
22
|
+
raise ConfigurationError, "#{attr} is required" if value.nil? || value.to_s.empty?
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Ruby
|
|
4
|
+
module Fiix
|
|
5
|
+
module Cmms
|
|
6
|
+
module Client
|
|
7
|
+
class Error < StandardError; end
|
|
8
|
+
|
|
9
|
+
class ConfigurationError < Error; end
|
|
10
|
+
|
|
11
|
+
class ConnectionError < Error; end
|
|
12
|
+
|
|
13
|
+
class ApiError < Error
|
|
14
|
+
attr_reader :response
|
|
15
|
+
|
|
16
|
+
def initialize(message, response: nil)
|
|
17
|
+
@response = response
|
|
18
|
+
super(message)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
require "net/http"
|
|
5
|
+
|
|
6
|
+
module Ruby
|
|
7
|
+
module Fiix
|
|
8
|
+
module Cmms
|
|
9
|
+
module Client
|
|
10
|
+
class Response
|
|
11
|
+
attr_reader :http_response
|
|
12
|
+
|
|
13
|
+
def initialize(http_response)
|
|
14
|
+
@http_response = http_response
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def body
|
|
18
|
+
@body ||= JSON.parse(http_response.body)
|
|
19
|
+
rescue JSON::ParserError
|
|
20
|
+
@body = http_response.body
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def success?
|
|
24
|
+
http_response.is_a?(Net::HTTPSuccess)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def status
|
|
28
|
+
http_response.code.to_i
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def [](key)
|
|
32
|
+
body[key]
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def to_h
|
|
36
|
+
body.is_a?(Hash) ? body : {}
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "client/version"
|
|
4
|
+
require_relative "client/errors"
|
|
5
|
+
require_relative "client/configuration"
|
|
6
|
+
require_relative "client/auth"
|
|
7
|
+
require_relative "client/response"
|
|
8
|
+
require_relative "client/api_client"
|
|
9
|
+
|
|
10
|
+
module Ruby
|
|
11
|
+
module Fiix
|
|
12
|
+
module Cmms
|
|
13
|
+
module Client
|
|
14
|
+
class << self
|
|
15
|
+
attr_accessor :configuration
|
|
16
|
+
|
|
17
|
+
def configure
|
|
18
|
+
self.configuration ||= Configuration.new
|
|
19
|
+
yield(configuration)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def reset_configuration!
|
|
23
|
+
self.configuration = nil
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: ruby-fiix-cmms-client
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Ronald Langeveld
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies: []
|
|
12
|
+
description: 'A Ruby gem wrapping the Fiix CMMS (Computerized Maintenance Management
|
|
13
|
+
System) REST API with HMAC-SHA256 authentication. Supports all core operations:
|
|
14
|
+
find, create, update, delete, batch, RPC, and file uploads. Zero runtime dependencies.'
|
|
15
|
+
email:
|
|
16
|
+
- hi@ronaldlangeveld.com
|
|
17
|
+
executables: []
|
|
18
|
+
extensions: []
|
|
19
|
+
extra_rdoc_files: []
|
|
20
|
+
files:
|
|
21
|
+
- ".github/workflows/ci.yml"
|
|
22
|
+
- CHANGELOG.md
|
|
23
|
+
- CLAUDE.md
|
|
24
|
+
- CODE_OF_CONDUCT.md
|
|
25
|
+
- LICENSE.txt
|
|
26
|
+
- README.md
|
|
27
|
+
- Rakefile
|
|
28
|
+
- lib/ruby/fiix/cmms/client.rb
|
|
29
|
+
- lib/ruby/fiix/cmms/client/api_client.rb
|
|
30
|
+
- lib/ruby/fiix/cmms/client/auth.rb
|
|
31
|
+
- lib/ruby/fiix/cmms/client/configuration.rb
|
|
32
|
+
- lib/ruby/fiix/cmms/client/errors.rb
|
|
33
|
+
- lib/ruby/fiix/cmms/client/response.rb
|
|
34
|
+
- lib/ruby/fiix/cmms/client/version.rb
|
|
35
|
+
- sig/ruby/fiix/cmms/client.rbs
|
|
36
|
+
homepage: https://github.com/ronaldlangeveld/ruby-fiix-cmms-client
|
|
37
|
+
licenses:
|
|
38
|
+
- MIT
|
|
39
|
+
metadata:
|
|
40
|
+
homepage_uri: https://github.com/ronaldlangeveld/ruby-fiix-cmms-client
|
|
41
|
+
source_code_uri: https://github.com/ronaldlangeveld/ruby-fiix-cmms-client
|
|
42
|
+
changelog_uri: https://github.com/ronaldlangeveld/ruby-fiix-cmms-client/blob/main/CHANGELOG.md
|
|
43
|
+
rdoc_options: []
|
|
44
|
+
require_paths:
|
|
45
|
+
- lib
|
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
47
|
+
requirements:
|
|
48
|
+
- - ">="
|
|
49
|
+
- !ruby/object:Gem::Version
|
|
50
|
+
version: 3.2.0
|
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
52
|
+
requirements:
|
|
53
|
+
- - ">="
|
|
54
|
+
- !ruby/object:Gem::Version
|
|
55
|
+
version: '0'
|
|
56
|
+
requirements: []
|
|
57
|
+
rubygems_version: 3.6.9
|
|
58
|
+
specification_version: 4
|
|
59
|
+
summary: Ruby client for the Fiix CMMS REST API
|
|
60
|
+
test_files: []
|