Class: Webcoder::Resource
- Inherits:
-
Object
- Object
- Webcoder::Resource
show all
- Includes:
- Serializer
- Defined in:
- lib/webcoder/resource.rb
Class Method Summary
collapse
Methods included from Serializer
#decode, #encode, included
Class Method Details
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/webcoder/resource.rb', line 51
def self.(options)
effective_api_key = options.delete(:api_key) || api_key
if effective_api_key
if options[:headers]
options[:headers] = options[:headers].dup
else
options[:headers] = {}
end
options[:headers]["Webcoder-Api-Key"] = effective_api_key
end
options
end
|
.api_key ⇒ Object
6
7
8
|
# File 'lib/webcoder/resource.rb', line 6
def self.api_key
Webcoder.api_key
end
|
.base_url ⇒ Object
10
11
12
|
# File 'lib/webcoder/resource.rb', line 10
def self.base_url
Webcoder.base_url
end
|
.delete(path, options = {}) ⇒ Object
37
38
39
40
41
42
|
# File 'lib/webcoder/resource.rb', line 37
def self.delete(path, options={})
options = options.dup
url = url_for(path, options)
options = (options)
HTTP.delete(url, options)
end
|
.get(path, options = {}) ⇒ Object
30
31
32
33
34
35
|
# File 'lib/webcoder/resource.rb', line 30
def self.get(path, options={})
options = options.dup
url = url_for(path, options)
options = (options)
HTTP.get(url, options)
end
|
.merge_params(options, params) ⇒ Object
66
67
68
69
70
71
72
73
|
# File 'lib/webcoder/resource.rb', line 66
def self.merge_params(options, params)
if options[:params]
options[:params] = options[:params].merge(params)
options
else
options.merge(:params => params)
end
end
|
.post(path, params = {}, options = {}) ⇒ Object
14
15
16
17
18
19
20
|
# File 'lib/webcoder/resource.rb', line 14
def self.post(path, params={}, options={})
options = options.dup
url = url_for(path, options)
body = encode(params)
options = (options)
HTTP.post(url, body, options)
end
|
.put(path, params = {}, options = {}) ⇒ Object
22
23
24
25
26
27
28
|
# File 'lib/webcoder/resource.rb', line 22
def self.put(path, params={}, options={})
options = options.dup
url = url_for(path, options)
body = encode(params)
options = (options)
HTTP.put(url, body, options)
end
|
.url_for(path, options = {}) ⇒ Object
47
48
49
|
# File 'lib/webcoder/resource.rb', line 47
def self.url_for(path, options={})
File.join((options[:base_url] || base_url).to_s, path.to_s)
end
|