netilion 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/ruby.yml +22 -0
- data/.gitignore +9 -0
- data/.rubocop.yml +74 -0
- data/.ruby-version +1 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +155 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/netilion.rb +53 -0
- data/lib/netilion/api_key.rb +12 -0
- data/lib/netilion/api_subscription.rb +13 -0
- data/lib/netilion/asset.rb +18 -0
- data/lib/netilion/asset_health_condition.rb +13 -0
- data/lib/netilion/asset_status.rb +17 -0
- data/lib/netilion/asset_value.rb +12 -0
- data/lib/netilion/attachment.rb +12 -0
- data/lib/netilion/authentication.rb +15 -0
- data/lib/netilion/bill_of_material.rb +10 -0
- data/lib/netilion/client_application.rb +13 -0
- data/lib/netilion/company.rb +12 -0
- data/lib/netilion/delivery.rb +14 -0
- data/lib/netilion/delivery_status.rb +12 -0
- data/lib/netilion/document.rb +14 -0
- data/lib/netilion/document_category.rb +13 -0
- data/lib/netilion/document_classification.rb +12 -0
- data/lib/netilion/document_status.rb +12 -0
- data/lib/netilion/edm.rb +6 -0
- data/lib/netilion/edm/edge_device.rb +23 -0
- data/lib/netilion/edm/edge_device_status.rb +19 -0
- data/lib/netilion/edm/edge_device_type.rb +19 -0
- data/lib/netilion/edm/field_gateway.rb +22 -0
- data/lib/netilion/edm/field_gateway_status.rb +19 -0
- data/lib/netilion/edm/field_gateway_type.rb +19 -0
- data/lib/netilion/edm/network_interface.rb +19 -0
- data/lib/netilion/edm/record.rb +8 -0
- data/lib/netilion/edm/software_image.rb +20 -0
- data/lib/netilion/edm/software_image_type.rb +19 -0
- data/lib/netilion/edm/software_version.rb +21 -0
- data/lib/netilion/edm/software_version_status.rb +19 -0
- data/lib/netilion/edm/specification.rb +12 -0
- data/lib/netilion/edm/update_schedule.rb +21 -0
- data/lib/netilion/edm/update_schedule_status.rb +19 -0
- data/lib/netilion/event.rb +14 -0
- data/lib/netilion/event_status.rb +12 -0
- data/lib/netilion/event_type.rb +12 -0
- data/lib/netilion/extended_order_code_lookup.rb +7 -0
- data/lib/netilion/health_condition.rb +13 -0
- data/lib/netilion/health_condition_cause.rb +10 -0
- data/lib/netilion/health_condition_remedy.rb +10 -0
- data/lib/netilion/instrumentation.rb +15 -0
- data/lib/netilion/instrumentation_status.rb +12 -0
- data/lib/netilion/instrumentation_type.rb +13 -0
- data/lib/netilion/netilion.rb +6 -0
- data/lib/netilion/node.rb +14 -0
- data/lib/netilion/node_type.rb +12 -0
- data/lib/netilion/notification.rb +10 -0
- data/lib/netilion/permission.rb +14 -0
- data/lib/netilion/permission_request.rb +13 -0
- data/lib/netilion/product.rb +15 -0
- data/lib/netilion/product_category.rb +13 -0
- data/lib/netilion/product_lookup.rb +7 -0
- data/lib/netilion/product_status.rb +12 -0
- data/lib/netilion/purchase_order.rb +15 -0
- data/lib/netilion/purchase_order_status.rb +12 -0
- data/lib/netilion/quotation.rb +14 -0
- data/lib/netilion/quotation_status.rb +12 -0
- data/lib/netilion/record.rb +6 -0
- data/lib/netilion/request_for_quotation.rb +14 -0
- data/lib/netilion/request_for_quotation_status.rb +12 -0
- data/lib/netilion/search.rb +7 -0
- data/lib/netilion/specification.rb +13 -0
- data/lib/netilion/subscription.rb +15 -0
- data/lib/netilion/successor_lookup.rb +9 -0
- data/lib/netilion/tenant.rb +14 -0
- data/lib/netilion/threshold.rb +10 -0
- data/lib/netilion/unit.rb +12 -0
- data/lib/netilion/user.rb +10 -0
- data/lib/netilion/user_group.rb +10 -0
- data/lib/netilion/user_role.rb +12 -0
- data/lib/netilion/version.rb +5 -0
- data/netilion.gemspec +33 -0
- metadata +218 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2090933b33b832fc6a93f869d5faff0904a2f634063fe67ebfd5706f725a46b9
|
4
|
+
data.tar.gz: f0bcf8a0906fa4145ce714f949bccd8343056b5dee03709f7efe3b534572a630
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 900dbdc7b592f872deecce38f7c88f32c73ef3d2f64e4d0962c7a9e13c4c7df614987bd07443d178f22166ed3c9377409200843543b846b8e5eec00d2994d61b
|
7
|
+
data.tar.gz: 3c52043925df5bdaaabfb41ea7cb966f10d0999a11434214a13fb2a8ffdb1e532a3723a0afbe4023bbcb7c5ff9cb353b746db3b087464ef3bca7c2c207e754ff
|
@@ -0,0 +1,22 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on: [push]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
strategy:
|
9
|
+
matrix:
|
10
|
+
ruby: [ '2.5', '2.6', '2.7' ]
|
11
|
+
name: Test Ruby ${{ matrix.ruby }}
|
12
|
+
steps:
|
13
|
+
- uses: actions/checkout@v2
|
14
|
+
- name: Set up Ruby ${{ matrix.ruby }}
|
15
|
+
uses: actions/setup-ruby@v1
|
16
|
+
with:
|
17
|
+
ruby-version: ${{ matrix.ruby }}
|
18
|
+
- name: Build and test with Rake
|
19
|
+
run: |
|
20
|
+
gem install bundler
|
21
|
+
bundle install --jobs 4 --retry 3
|
22
|
+
bundle exec rake
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- bin/*
|
4
|
+
|
5
|
+
Documentation:
|
6
|
+
Enabled: false
|
7
|
+
|
8
|
+
Layout/IndentationConsistency:
|
9
|
+
EnforcedStyle: indented_internal_methods
|
10
|
+
|
11
|
+
Metrics/AbcSize:
|
12
|
+
Max: 200
|
13
|
+
|
14
|
+
Metrics/LineLength:
|
15
|
+
Max: 180
|
16
|
+
Exclude:
|
17
|
+
- test/**/*
|
18
|
+
|
19
|
+
Metrics/BlockLength:
|
20
|
+
Max: 100
|
21
|
+
Exclude:
|
22
|
+
- test/**/*
|
23
|
+
|
24
|
+
Metrics/ClassLength:
|
25
|
+
Max: 300
|
26
|
+
Exclude:
|
27
|
+
- test/**/*
|
28
|
+
|
29
|
+
Metrics/CyclomaticComplexity:
|
30
|
+
Max: 50
|
31
|
+
|
32
|
+
Metrics/MethodLength:
|
33
|
+
Max: 100
|
34
|
+
|
35
|
+
Metrics/ModuleLength:
|
36
|
+
Max: 300
|
37
|
+
|
38
|
+
Metrics/ParameterLists:
|
39
|
+
Max: 10
|
40
|
+
|
41
|
+
Metrics/PerceivedComplexity:
|
42
|
+
Max: 50
|
43
|
+
|
44
|
+
Naming/VariableNumber:
|
45
|
+
Enabled: false
|
46
|
+
|
47
|
+
Style/RedundantReturn:
|
48
|
+
Enabled: true
|
49
|
+
AllowMultipleReturnValues: true
|
50
|
+
|
51
|
+
Style/Semicolon:
|
52
|
+
Enabled: true
|
53
|
+
AllowAsExpressionSeparator: true
|
54
|
+
|
55
|
+
Style/SymbolArray:
|
56
|
+
EnforcedStyle: brackets
|
57
|
+
|
58
|
+
Style/SymbolProc:
|
59
|
+
Enabled: false
|
60
|
+
|
61
|
+
Style/ConditionalAssignment:
|
62
|
+
Enabled: false
|
63
|
+
|
64
|
+
Style/GuardClause:
|
65
|
+
Enabled: false
|
66
|
+
|
67
|
+
Style/IfUnlessModifier:
|
68
|
+
Enabled: false
|
69
|
+
|
70
|
+
Lint/ParenthesesAsGroupedExpression:
|
71
|
+
Enabled: false
|
72
|
+
|
73
|
+
Style/FormatStringToken:
|
74
|
+
EnforcedStyle: template
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.6.5
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Marco Roth
|
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,155 @@
|
|
1
|
+
# Netilion
|
2
|
+
|
3
|
+
This is a Ruby Wrapper for the Netilion Information Hub API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'netilion'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
$ gem install netilion
|
23
|
+
```
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
### Setup
|
28
|
+
|
29
|
+
If you are using Rails you can setup the Netilion configuration for example in an initializer: `config/initializers/netilion.rb`
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
Netilion.configure do |c|
|
33
|
+
c.environment = :production # accepts :production, :staging, :local
|
34
|
+
c.api_key = 'your-api-key'
|
35
|
+
c.username = 'test@example.org'
|
36
|
+
c.password = 'your-secret-password'
|
37
|
+
end
|
38
|
+
|
39
|
+
# or
|
40
|
+
|
41
|
+
Netilion.config.environment = :production
|
42
|
+
Netilion.config.api_key = 'your-api-key'
|
43
|
+
Netilion.config.username = 'test@example.org'
|
44
|
+
Netilion.config.password = 'your-secret-password'
|
45
|
+
|
46
|
+
```
|
47
|
+
|
48
|
+
### Querying Records
|
49
|
+
|
50
|
+
Getting all records
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
assets = Netilion::Asset.all
|
54
|
+
|
55
|
+
assets.each do |asset|
|
56
|
+
puts asset.serial_number # => "123123123"
|
57
|
+
...
|
58
|
+
end
|
59
|
+
|
60
|
+
puts assets.size # => 89
|
61
|
+
```
|
62
|
+
|
63
|
+
Filtering records
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
assets = Netilion::Asset.where(serial_number: "123123123")
|
67
|
+
puts assets.size # => 1
|
68
|
+
```
|
69
|
+
|
70
|
+
Getting an explicit record by id
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
asset = Netilion::Asset.find(3204852)
|
74
|
+
puts asset.serial_number # => "123123123"
|
75
|
+
```
|
76
|
+
|
77
|
+
Getting an explicit record by any attribute
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
asset = Netilion::Asset.find_by(serial_number: "123123123")
|
81
|
+
puts asset.serial_number # => "123123123"
|
82
|
+
```
|
83
|
+
|
84
|
+
Getting the first record
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
asset = Netilion::Asset.first
|
88
|
+
puts asset.serial_number # => "123123123"
|
89
|
+
```
|
90
|
+
|
91
|
+
Preload associations
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
asset = Netilion::Asset.includes(:status).all.first
|
95
|
+
puts asset.status.name # => "OK"
|
96
|
+
```
|
97
|
+
|
98
|
+
Load associations on demand
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
asset = Netilion::Asset.first
|
102
|
+
puts asset.status.load!.name # => "OK"
|
103
|
+
```
|
104
|
+
|
105
|
+
### Creating Records
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
Netilion::Asset.create(serial_number: "123123123", product: { id: "1" }, status: { id: "1" })
|
109
|
+
```
|
110
|
+
|
111
|
+
### Updating Records
|
112
|
+
|
113
|
+
```ruby
|
114
|
+
asset = Netilion::Asset.last
|
115
|
+
asset.update({ description: "This is a new description" }, { method: :patch })
|
116
|
+
```
|
117
|
+
|
118
|
+
### Deleting Records
|
119
|
+
|
120
|
+
```ruby
|
121
|
+
asset = Netilion::Asset.last
|
122
|
+
asset.destroy
|
123
|
+
```
|
124
|
+
|
125
|
+
|
126
|
+
## Development
|
127
|
+
|
128
|
+
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.
|
129
|
+
|
130
|
+
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).
|
131
|
+
|
132
|
+
## TODO
|
133
|
+
|
134
|
+
* [ ] Build all classes the api offers
|
135
|
+
* [ ] Setup pagination in all classes
|
136
|
+
* [ ] Setup all associations between the classes
|
137
|
+
* [ ] Support the non-typical REST endpoints
|
138
|
+
* [ ] Add validations for all classes
|
139
|
+
* [ ] Proper error handling
|
140
|
+
* [ ] Setup pagination and update method globally (probably in a `Netilion::Record` class and let all models inherit from it)
|
141
|
+
* [ ] Support OAuth2
|
142
|
+
|
143
|
+
## Contributing
|
144
|
+
|
145
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/marcoroth/netilion.
|
146
|
+
|
147
|
+
## License
|
148
|
+
|
149
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
150
|
+
|
151
|
+
## Learn more
|
152
|
+
* [Swagger Documentation](https://api.netilion.endress.com/doc/v1)
|
153
|
+
* [Netilion Developer Platform](https://developer.netilion.endress.com)
|
154
|
+
* [Netilion Connect](https://developer.netilion.endress.com/netilion-connect)
|
155
|
+
* [Netilion Website](https://netilion.endress.com)
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'netilion'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require 'pry'
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/netilion.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'zeitwerk'
|
4
|
+
require 'lhc'
|
5
|
+
require 'lhs'
|
6
|
+
|
7
|
+
inflections = {
|
8
|
+
'api_key' => 'APIKey',
|
9
|
+
'edm' => 'EDM'
|
10
|
+
}
|
11
|
+
|
12
|
+
loader = Zeitwerk::Loader.for_gem
|
13
|
+
loader.enable_reloading
|
14
|
+
loader.inflector.inflect(inflections)
|
15
|
+
loader.setup
|
16
|
+
|
17
|
+
module Netilion
|
18
|
+
Config = Struct.new :environment, :api_key, :username, :password
|
19
|
+
|
20
|
+
def self.configure(&config_block)
|
21
|
+
config_block.call config
|
22
|
+
set_api_placeholders
|
23
|
+
config
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.config
|
27
|
+
@config ||= Config.new(environment: :production)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.api_base
|
31
|
+
case config.environment
|
32
|
+
when :production
|
33
|
+
'https://api.netilion.endress.com'
|
34
|
+
when :staging
|
35
|
+
'https://api.staging-env.netilion.endress.com'
|
36
|
+
when :local
|
37
|
+
'http://localhost:3000'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.set_api_placeholders
|
42
|
+
LHC.configure do |config|
|
43
|
+
config.placeholder(:api, "#{api_base}/v1")
|
44
|
+
config.placeholder(:edm, "#{api_base}/v1/edm")
|
45
|
+
|
46
|
+
config.interceptors = [
|
47
|
+
Authentication,
|
48
|
+
LHC::Auth,
|
49
|
+
LHC::Caching
|
50
|
+
]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Netilion
|
4
|
+
class APIKey < LHS::Record
|
5
|
+
configuration items_key: :api_keys
|
6
|
+
|
7
|
+
endpoint '{+api}/api_keys'
|
8
|
+
endpoint '{+api}/api_keys/{id}'
|
9
|
+
|
10
|
+
has_one :client_application, class_name: 'Netilion::ClientApplication'
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Netilion
|
4
|
+
class ApiSubscription < LHS::Record
|
5
|
+
configuration items_key: :api_subscriptions
|
6
|
+
|
7
|
+
endpoint '{+api}/api_subscriptions'
|
8
|
+
endpoint '{+api}/api_subscriptions/{id}'
|
9
|
+
|
10
|
+
has_one :user, class_name: 'Netilion::User'
|
11
|
+
has_one :client_application, class_name: 'Netilion::ClientApplication'
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Netilion
|
4
|
+
class Asset < LHS::Record
|
5
|
+
configuration items_key: 'assets',
|
6
|
+
pagination_strategy: :page,
|
7
|
+
pagination_key: { body: %w[pagination page], parameter: 'page' },
|
8
|
+
limit_key: { body: %w[pagination per_page], parameter: 'limit' },
|
9
|
+
total_key: %w[pagination total_count]
|
10
|
+
|
11
|
+
endpoint '{+api}/assets'
|
12
|
+
endpoint '{+api}/assets/{id}'
|
13
|
+
|
14
|
+
has_one :status, class_name: 'Netilion::AssetStatus'
|
15
|
+
has_one :product, class_name: 'Netilion::Product'
|
16
|
+
has_one :tenant, class_name: 'Netilion::Tenant'
|
17
|
+
end
|
18
|
+
end
|