Class: SimpleMapper::HttpAdapter

Inherits:
Object
  • Object
show all
Includes:
CallbacksExtension, HttpOAuthExtension
Defined in:
lib/simple_mapper/adapters/http_adapter.rb,
lib/simple_mapper/default_plugins/oauth.rb,
lib/simple_mapper/default_plugins/callbacks.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CallbacksExtension

#add_callback, #callbacks, #run_callback

Methods included from HttpOAuthExtension

#oauth, #requires_oauth, #set_oauth, with_oauth

Instance Attribute Details

#base_urlObject

Returns the value of attribute base_url.



14
15
16
# File 'lib/simple_mapper/adapters/http_adapter.rb', line 14

def base_url
  @base_url
end

Instance Method Details

#base_uriObject



16
17
18
# File 'lib/simple_mapper/adapters/http_adapter.rb', line 16

def base_uri
  URI.parse(base_url)
end

#delete(identifier) ⇒ Object

In the http adapter, the identifier is a url.



43
44
45
# File 'lib/simple_mapper/adapters/http_adapter.rb', line 43

def delete(identifier)
  http.request(request('delete', URI.parse(identifier).path)).body
end

#get(find_options = {}) ⇒ Object



29
30
31
32
# File 'lib/simple_mapper/adapters/http_adapter.rb', line 29

def get(find_options={})
  query = find_options.empty? ? '' : ('?' + find_options.to_query)
  http.request(request('get', base_uri.path + query)).body
end

#headersObject



20
21
22
# File 'lib/simple_mapper/adapters/http_adapter.rb', line 20

def headers
  @headers ||= {}
end

#headers=(v) ⇒ Object Also known as: set_headers

Raises:

  • (TypeError)


23
24
25
26
# File 'lib/simple_mapper/adapters/http_adapter.rb', line 23

def headers=(v)
  raise TypeError, "headers set must be a hash" unless v.is_a?(Hash)
  headers.merge!(v)
end

#post(data) ⇒ Object



38
39
40
# File 'lib/simple_mapper/adapters/http_adapter.rb', line 38

def post(data)
  http.request(request('post', base_uri.path, data)).body
end

#put(identifier, data) ⇒ Object



34
35
36
# File 'lib/simple_mapper/adapters/http_adapter.rb', line 34

def put(identifier,data)
  http.request(request('put', URI.parse(identifier).path, data)).body
end