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



36
37
38
39
40
41
# File 'lib/organizer/request.rb', line 36

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



31
32
33
34
# File 'lib/organizer/request.rb', line 31

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

#getObject



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

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

#postObject



15
16
17
18
19
20
21
# File 'lib/organizer/request.rb', line 15

def post
  api.post do |req|
    req.url path
    req.headers['Content-Type'] = 'application/json'
    req.body = query.to_json
  end
end

#putObject



23
24
25
26
27
28
29
# File 'lib/organizer/request.rb', line 23

def put
  api.put do |req|
    req.url path
    req.headers['Content-Type'] = 'application/json'
    req.body = query.to_json
  end
end