Class: SimpleMapper::HttpAdapter
- Inherits:
-
Object
- Object
- SimpleMapper::HttpAdapter
show all
- Includes:
- CallbacksExtension, Oauth
- 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
#add_callback, #callbacks, #run_callback
Methods included from Oauth
#oauth, #requires_oauth, #set_oauth, with_oauth
Instance Attribute Details
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
|
#raise_http_errors ⇒ Object
Returns the value of attribute raise_http_errors.
15
16
17
|
# File 'lib/simple_mapper/adapters/http_adapter.rb', line 15
def raise_http_errors
@raise_http_errors
end
|
Instance Method Details
18
19
20
|
# File 'lib/simple_mapper/adapters/http_adapter.rb', line 18
def base_uri
URI.parse(base_url)
end
|
#delete(identifier) ⇒ Object
In the http adapter, the identifier is a url.
69
70
71
72
73
74
75
76
|
# File 'lib/simple_mapper/adapters/http_adapter.rb', line 69
def delete(identifier)
begin
http.request(request('delete', URI.parse(identifier).path)).body
rescue => e
raise e if !!raise_http_errors
nil
end
end
|
#finder_options ⇒ Object
31
32
33
|
# File 'lib/simple_mapper/adapters/http_adapter.rb', line 31
def finder_options
@finder_options ||= {}
end
|
#finder_options=(options) ⇒ Object
34
35
36
37
|
# File 'lib/simple_mapper/adapters/http_adapter.rb', line 34
def finder_options=(options)
raise TypeError, "options must be a hash!" unless options.is_a?(Hash)
@finder_options = options
end
|
#get(find_options = {}) ⇒ Object
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/simple_mapper/adapters/http_adapter.rb', line 39
def get(find_options={})
options = finder_options.merge(find_options)
query = options.empty? ? '' : ('?' + options.to_query)
begin
http.request(request('get', base_uri.path + query)).body
rescue => e
raise e if !!raise_http_errors
nil
end
end
|
22
23
24
|
# File 'lib/simple_mapper/adapters/http_adapter.rb', line 22
def
||= {}
end
|
25
26
27
28
|
# File 'lib/simple_mapper/adapters/http_adapter.rb', line 25
def (v)
raise TypeError, "headers set must be a hash" unless v.is_a?(Hash)
.merge!(v)
end
|
#post(data) ⇒ Object
59
60
61
62
63
64
65
66
|
# File 'lib/simple_mapper/adapters/http_adapter.rb', line 59
def post(data)
begin
http.request(request('post', base_uri.path, data)).body
rescue => e
raise e if !!raise_http_errors
nil
end
end
|
#put(identifier, data) ⇒ Object
50
51
52
53
54
55
56
57
|
# File 'lib/simple_mapper/adapters/http_adapter.rb', line 50
def put(identifier,data)
begin
http.request(request('put', URI.parse(identifier).path, data)).body
rescue => e
raise e if !!raise_http_errors
nil
end
end
|