Class: Kookaburra::JsonApiDriver

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/kookaburra/json_api_driver.rb

Overview

Delegates all methods (by default) to and instance of APIDriver.

Expects the application's API to accept and respond with JSON formatted data. All methods will decode the response body using ActiveSupport::JSON.decode. Methods that take input data (#post and #put) will encode the post data using ActiveSupport::JSON.encode.

Instance Method Summary collapse

Constructor Details

#initialize(configuration, api_driver = nil) ⇒ JsonApiDriver

Sets both the "Content-Type" and "Accept" headers to "application/json".

Parameters:

  • configuration (Kookaburra::Configuration)
  • api_driver (Kookaburra::APIDriver) (defaults to: nil)

    (Kookaburra::APIDriver.new) The APIDriver instance to be delegated to. Changing this is probably only useful for testing Kookaburra itself.



21
22
23
24
25
26
27
28
# File 'lib/kookaburra/json_api_driver.rb', line 21

def initialize(configuration, api_driver = nil)
  api_driver = api_driver || APIDriver.new(configuration)
  api_driver.headers.merge!(
    'Content-Type' => 'application/json',
    'Accept' => 'application/json'
  )
  super(api_driver)
end

Instance Method Details

#delete(path, *args) ⇒ Object



42
43
44
# File 'lib/kookaburra/json_api_driver.rb', line 42

def delete(path, *args)
  request(:delete, path, nil, *args)
end

#get(path, *args) ⇒ Object



38
39
40
# File 'lib/kookaburra/json_api_driver.rb', line 38

def get(path, *args)
  request(:get, path, nil, *args)
end

#post(path, data, *args) ⇒ Object



30
31
32
# File 'lib/kookaburra/json_api_driver.rb', line 30

def post(path, data, *args)
  request(:post, path, data, *args)
end

#put(path, data, *args) ⇒ Object



34
35
36
# File 'lib/kookaburra/json_api_driver.rb', line 34

def put(path, data, *args)
  request(:put, path, data, *args)
end