Class: AnsibleGalaxy::API
- Inherits:
-
Object
- Object
- AnsibleGalaxy::API
- Includes:
- Contracts
- Defined in:
- lib/ansible_galaxy/api.rb
Overview
Wrapper for Galaxy HTTP API
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ API
constructor
A new instance of API.
-
#request ⇒ Object
Contract None => Hash NoContractBecause: Contracts break __callee__ by changing method names.
Constructor Details
#initialize(options = {}) ⇒ API
Returns a new instance of API.
12 13 14 15 16 |
# File 'lib/ansible_galaxy/api.rb', line 12 def initialize( = {}) username = .fetch 'username', ENV['ANSIBLE_GALAXY_USERNAME'] password = .fetch 'password', ENV['ANSIBLE_GALAXY_PASSWORD'] @auth = "#{username}:#{password}" end |
Instance Method Details
#request ⇒ Object
Contract None => Hash NoContractBecause: Contracts break __callee__ by changing method names.
20 21 22 23 24 25 26 27 |
# 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 |