Class: VagrantPlugins::Vmck::Client
- Inherits:
-
Object
- Object
- VagrantPlugins::Vmck::Client
- Defined in:
- lib/vagrant-vmck/client.rb
Instance Method Summary collapse
- #create(options) ⇒ Object
- #get(id) ⇒ Object
-
#initialize(url) ⇒ Client
constructor
A new instance of Client.
- #request(method, path, data = nil) ⇒ Object
- #stop(id) ⇒ Object
Constructor Details
#initialize(url) ⇒ Client
Returns a new instance of Client.
9 10 11 12 |
# File 'lib/vagrant-vmck/client.rb', line 9 def initialize(url) @logger = Log4r::Logger.new("vagrant_vmck::client") @client = Faraday.new({ :url => url }) end |
Instance Method Details
#create(options) ⇒ Object
44 45 46 |
# File 'lib/vagrant-vmck/client.rb', line 44 def create() request(:post, "/v0/jobs", ) end |
#get(id) ⇒ Object
48 49 50 |
# File 'lib/vagrant-vmck/client.rb', line 48 def get(id) request(:get, "/v0/jobs/#{id}") end |
#request(method, path, data = nil) ⇒ Object
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 |
# File 'lib/vagrant-vmck/client.rb', line 14 def request(method, path, data=nil) @logger.info "Request: #{path}" result = @client.send(method) do |req| req.url(path) if data req.headers['Content-Type'] = 'application/json' @logger.info "Request body: #{data}" req.body = JSON.generate(data) end end if method == :delete body = nil else body = JSON.parse(result.body) @logger.info "Response: #{body}" return body end if result.status < 200 or result.status >= 300 raise({ :path => path, :status => result.status, :response => body.inspect, }) end end |
#stop(id) ⇒ Object
52 53 54 |
# File 'lib/vagrant-vmck/client.rb', line 52 def stop(id) request(:delete, "/v0/jobs/#{id}") end |