Class: AcmeManager::Request
- Inherits:
-
Object
- Object
- AcmeManager::Request
- Defined in:
- lib/acme_manager/request.rb
Overview
Simplify the process of making an API request to acme-manager
Constant Summary collapse
- PATH_PREFIX =
'~acmemanager/'.freeze
Class Method Summary collapse
-
.make(path) ⇒ Object
Convenicence method to make a new instance and return the result of the request.
Instance Method Summary collapse
-
#initialize(path) ⇒ Request
constructor
A new instance of Request.
-
#make ⇒ Array, Hash
Make a request to the acme-manager API.
Constructor Details
#initialize(path) ⇒ Request
Returns a new instance of Request.
12 13 14 |
# File 'lib/acme_manager/request.rb', line 12 def initialize(path) @path = path end |
Class Method Details
.make(path) ⇒ Object
Convenicence method to make a new instance and return the result of the request
19 20 21 |
# File 'lib/acme_manager/request.rb', line 19 def self.make(path) new(path).make end |
Instance Method Details
#make ⇒ Array, Hash
Make a request to the acme-manager API. Requests will be sent to the host defined in AcmeManager.config, and sent with the API key from the same configuration.
Successfull responses are assumed to be in JSON format and are automatically parsed
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/acme_manager/request.rb', line 31 def make AcmeManager.logger.debug "Requesting #{request_uri}" http = new_http_connection request = Net::HTTP::Get.new(request_uri.path) request['X-API-KEY'] = AcmeManager.config.api_key result = http.request(request) AcmeManager.logger.debug "Response Status: #{result.code}" AcmeManager.logger.debug "Response Body:\n#{result.body}" if result.is_a?(Net::HTTPSuccess) JSON.parse(result.body) else AcmeManager.logger.warn "Request to #{request_uri} failed" result.value end end |