Class: Organizer::Request
- Inherits:
-
Object
- Object
- Organizer::Request
show all
- Defined in:
- lib/organizer/request.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
permalink
#initialize(path = "", query = {}) ⇒ Request
Returns a new instance of Request.
[View source]
5
6
7
8
|
# File 'lib/organizer/request.rb', line 5
def initialize(path = "", query = {})
@path = path
@query = query
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
permalink
#method_missing(method, *args) ⇒ Object
[View source]
38
39
40
41
42
43
|
# File 'lib/organizer/request.rb', line 38
def method_missing(method, *args)
params = args[0].is_a?(Hash) ? args[0] : {}
id = params.delete(:id)
route = path + "#{method}/#{id}"
Request.new(route, params)
end
|
Instance Attribute Details
Returns the value of attribute path.
3
4
5
|
# File 'lib/organizer/request.rb', line 3
def path
@path
end
|
Returns the value of attribute query.
3
4
5
|
# File 'lib/organizer/request.rb', line 3
def query
@query
end
|
Instance Method Details
[View source]
33
34
35
36
|
# File 'lib/organizer/request.rb', line 33
def delete
response = api.delete(path, query)
Response.new(response)
end
|
[View source]
10
11
12
13
|
# File 'lib/organizer/request.rb', line 10
def get
response = api.get(path, query)
Response.new(response)
end
|
[View source]
15
16
17
18
19
20
21
22
|
# File 'lib/organizer/request.rb', line 15
def post
response = api.post do |req|
req.url path
req.['Content-Type'] = 'application/json'
req.body = query.to_json
end
Response.new(response)
end
|
[View source]
24
25
26
27
28
29
30
31
|
# File 'lib/organizer/request.rb', line 24
def put
response = api.put do |req|
req.url path
req.['Content-Type'] = 'application/json'
req.body = query.to_json
end
Response.new(response)
end
|