AmadeusDiscover
Faraday based Ruby client for the Amadeus Discover API for content partners use.
Installation
AmadeusDiscover is distributed as a gem and available on rubygems.org so you can add it to your Gemfile or install it manually with:
$ gem install amadeus-discover
Usage
Initializing a new client instance
The client can be initialized directly:
connection = Faraday::Connection.new('https://api-test.amadeus-discover.com') do |builder|
end
credentials = {
username: '{username}',
password: '{password}',
client_id: 'content-partner-api',
grant_type: 'password'
}
client = AmadeusDiscover::Client.new(connection, credentials)
Alternatively, you can configure AmadeusDiscover to use default connection and credentials for every client instances:
AmadeusDiscover.configure do |config|
config.connection = Faraday::Connection.new(ENV['AMADEUS_DISCOVER_HOST']) do |builder|
builder.response :logger, Rails.logger
builder.adapter :typhoeus
end
config.credentials = {
username: ENV['AMADEUS_DISCOVER_USERNAME'],
password: ENV['AMADEUS_DISCOVER_PASSWORD'],
client_id: 'content-partner-api',
grant_type: 'password'
}
end
client = AmadeusDiscover::Client.new
Using a client
Once created, a client gives you access to Amadeus Discover API methods:
client = AmadeusDiscover::Client.new
s = client.suppliers.create(name: 'My supplier')
client.suppliers(s['id']).tap do |supplier|
supplier.get
supplier.update(more_data)
supplier.delete
products = supplier.products.list
p = supplier.products.create(title: { en: "Let's have some fun!" })
supplier.products(p['id']).tap do |product|
product.update(more_data)
product.delete
end
end
If an error occured, a Faraday::Error will be raised. The exact type of that exception will depend on the encountered error type (authentication error, client error, server error…). See https://lostisland.github.io/faraday/middleware/raise-error for details.
Contributing
Bug reports and pull requests are welcome on Gitlab at https://gitlab.com/vaolo-public/ruby/amadeus-discover.
Development
After checking out the repo, run bundle install to install development dependencies.
Running tests require a bunch of environment variables to be declared, to identify where is hosted the instance of the Amadeus Discover API you'll target and credentials you'll use for authentication. Development tools integrate dotenv so you can do it in a .env file and a .env.example is available to list and document all required variables.
Once your .env file is ready, run bundle exec rake spec to run the tests.