Netilion

This is a Ruby Wrapper for the Netilion Information Hub API.

Installation

Add this line to your application's Gemfile:

gem 'netilion'

And then execute:

$ bundle

Or install it yourself as:

$ gem install netilion

Usage

Setup

If you are using Rails you can setup the Netilion configuration for example in an initializer: config/initializers/netilion.rb

Netilion.configure do |c|
  c.environment = :production # accepts :production, :staging, :local
  c.api_key = 'your-api-key'
  c.username = '[email protected]'
  c.password = 'your-secret-password'
end

# or

Netilion.config.environment = :production
Netilion.config.api_key = 'your-api-key'
Netilion.config.username = '[email protected]'
Netilion.config.password = 'your-secret-password'

Querying Records

Getting all records

assets = Netilion::Asset.all

assets.each do |asset|
  puts asset.serial_number # => "123123123"
  ...
end

puts assets.size # => 89

Filtering records

assets = Netilion::Asset.where(serial_number: "123123123")
puts assets.size # => 1

Getting an explicit record by id

asset = Netilion::Asset.find(3204852)
puts asset.serial_number # => "123123123"

Getting an explicit record by any attribute

asset = Netilion::Asset.find_by(serial_number: "123123123")
puts asset.serial_number # => "123123123"

Getting the first record

asset = Netilion::Asset.first
puts asset.serial_number # => "123123123"

Preload associations

asset = Netilion::Asset.includes(:status).all.first
puts asset.status.name # => "OK"

Load associations on demand

asset = Netilion::Asset.first
puts asset.status.load!.name # => "OK"

Creating Records

  Netilion::Asset.create(serial_number: "123123123", product: { id: "1" }, status: { id: "1" })

Updating Records

  asset = Netilion::Asset.last
  asset.update({ description: "This is a new description" }, { method: :patch })

Deleting Records

  asset = Netilion::Asset.last
  asset.destroy

Development

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.

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.

TODO

  • [ ] Build all classes the api offers
  • [ ] Setup pagination in all classes
  • [ ] Setup all associations between the classes
  • [ ] Support the non-typical REST endpoints
  • [ ] Add validations for all classes
  • [ ] Proper error handling
  • [ ] Setup pagination and update method globally (probably in a Netilion::Record class and let all models inherit from it)
  • [ ] Support OAuth2

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/marcoroth/netilion.

License

The gem is available as open source under the terms of the MIT License.

Learn more