Class: VagrantPlugins::DigitalOcean::Helpers::Client
- Inherits:
-
Object
- Object
- VagrantPlugins::DigitalOcean::Helpers::Client
- Defined in:
- lib/vagrant-digitalocean/helpers/client.rb
Instance Method Summary collapse
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #request(path, params = {}) ⇒ Object
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
9 10 11 |
# File 'lib/vagrant-digitalocean/helpers/client.rb', line 9 def initialize @client = Faraday.new(:url => "https://api.digitalocean.com/") end |
Instance Method Details
#request(path, params = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/vagrant-digitalocean/helpers/client.rb', line 13 def request(path, params = {}) # create the key result = @client.get(path, params = params.merge({ :client_id => ENV["DO_CLIENT_ID"], :api_key => ENV["DO_API_KEY"] })) # remove the api key in case an error gets dumped to the console params[:api_key] = "REMOVED" begin body = JSON.parse(result.body) rescue JSON::ParserError => e raise(Errors::JSONError, { :message => e., :path => path, :params => params, :response => result.body }) end if body["status"] != "OK" raise(Errors::APIStatusError, { :path => path, :params => params, :status => body["status"], :response => body.inspect }) end Result.new(body) end |