class AnsibleGalaxy::API

Wrapper for Galaxy HTTP API

Public Class Methods

new(options = {}) click to toggle source
# File lib/ansible_galaxy/api.rb, line 12
def initialize(options = {})
  username = options.fetch 'username', ENV['ANSIBLE_GALAXY_USERNAME']
  password = options.fetch 'password', ENV['ANSIBLE_GALAXY_PASSWORD']
  @auth = "#{username}:#{password}"
end

Public Instance Methods

request() click to toggle source

Contract None => Hash NoContractBecause: Contracts break __callee__ by changing method names.

# File lib/ansible_galaxy/api.rb, line 20
def request
  endpoint = "https://galaxy.ansible.com/api/v1/#{__callee__}/"
  request = Typhoeus::Request.new(endpoint, userpwd: @auth)
  request.run
  JSON.parse(request.response.body).tap do |response|
    fail AuthenticationError, response['detail'] if response['detail']
  end
end