Class: Perry::Adapters::RestfulHTTPAdapter

Inherits:
AbstractAdapter show all
Defined in:
lib/perry/adapters/restful_http_adapter.rb

Defined Under Namespace

Classes: KeyError

Instance Attribute Summary collapse

Attributes inherited from AbstractAdapter

#config, #type

Instance Method Summary collapse

Methods inherited from AbstractAdapter

#call, create, #execute, #extend_adapter, #initialize, #middlewares, #processors, register_as

Methods included from Logger

included

Constructor Details

This class inherits a constructor from Perry::Adapters::AbstractAdapter

Instance Attribute Details

#last_responseObject (readonly)

Returns the value of attribute last_response.



16
17
18
# File 'lib/perry/adapters/restful_http_adapter.rb', line 16

def last_response
  @last_response
end

Instance Method Details

#delete(options) ⇒ Object



32
33
34
# File 'lib/perry/adapters/restful_http_adapter.rb', line 32

def delete(options)
  delete_http(options[:object])
end

#read(options) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/perry/adapters/restful_http_adapter.rb', line 18

def read(options)
  response = get_http(options[:relation])
  unless response.parsed.is_a?(Array)
    raise Perry::MalformedResponse, "Expected instance of Array got '#{response.raw.inspect}'"
  end
  response.array_attributes
end

#write(options) ⇒ Object



26
27
28
29
30
# File 'lib/perry/adapters/restful_http_adapter.rb', line 26

def write(options)
  object = options[:object]
  params = build_params_from_attributes(object)
  object.new_record? ? post_http(object, params) : put_http(object, params)
end