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



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

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

#path ⇒ Object

Returns the value of attribute path.



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

def path
  @path
end

#query ⇒ Object

Returns the value of attribute query.



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

def query
  @query
end

Instance Method Details

#delete ⇒ Object



20
21
22
23
# File 'lib/organizer/request.rb', line 20

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

#get ⇒ Object



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

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

#post ⇒ Object



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

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