Class: Organizer::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/organizer/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = "", query = {}) ⇒ Request

Returns a new instance of Request.


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

#method_missing(method, *args) ⇒ Object


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

#pathObject

Returns the value of attribute path.


3
4
5
# File 'lib/organizer/request.rb', line 3

def path
  @path
end

#queryObject

Returns the value of attribute query.


3
4
5
# File 'lib/organizer/request.rb', line 3

def query
  @query
end

Instance Method Details

#deleteObject


33
34
35
36
# File 'lib/organizer/request.rb', line 33

def delete
  response = api.delete(path, query)
  Response.new(response)
end

#getObject


10
11
12
13
# File 'lib/organizer/request.rb', line 10

def get
  response = api.get(path, query)
  Response.new(response)
end

#postObject


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.headers['Content-Type'] = 'application/json'
    req.body = query.to_json
  end
  Response.new(response)
end

#putObject


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.headers['Content-Type'] = 'application/json'
    req.body = query.to_json
  end
  Response.new(response)
end