Skip to content

truly-systems/glpi-sdk-ruby

Repository files navigation

GLPI SDK for Ruby

Gem Gem

Ruby wrapper for GLPI REST API.

Installation

Add this line to your application's Gemfile:

gem 'glpi-sdk-ruby'

And then execute:

$ bundle

Or install it yourself as:

$ gem install glpi-sdk-ruby

Usage

A session object is mandatory to uses the others GLPI methods.

require 'glpi/sdk'
	
# Request a session token to uses other GLPI functions

url = 'http://path/to/glpi/apirest.php'
app_token = 'YOUR_APP_TOKEN'
username = 'YOUR_GLPI_USERNAME'
password = 'YOUR_GLPI_PASSWORD'
    
session = GLPI::SDK::Session.new(url, app_token, username, password)
session.token
# => "74e735e494e9613ee50d13135df6d27d"
session.kill
session.active_profile
session.active_entities
session.full_session
session.glpi_config
ticket = GLPI::SDK::Resource.find(session, 1, 'Ticket')
ticket.id
# => 1

ticket.name
# => "Hello World"
tickets = GLPI::SDK::Resource.all(session, item_type: 'Ticket')
ticket = GLPI::SDK::Resource.create(
  session,
  name: 'New ticket from SDK',
  content: 'Ticket created by GLPI SDK',
  item_type: 'Ticket'
)

ticket.id
# => 29

ticket.content
# => "Ticket created by GLPI SDK"
ticket = GLPI::SDK::Resource.update(
  session,
  29,
  content: 'Content updated by GLPI SDK',
  item_type: 'Ticket'
)

ticket.content
# => "Ticket updated by GLPI SDK"
GLPI::SDK::Resource.destroy(session, 29, 'Ticket')
# => true

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/truly-systems/glpi-sdk-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

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

Code of Conduct

Everyone interacting in the GLPI::SDK::Ruby project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.