Class: Makeleaps::Request::RequestHandler

Inherits:
Object
  • Object
show all
Includes:
ErrorHandler
Defined in:
lib/makeleaps/request/request_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ErrorHandler

#handle_api_response

Constructor Details

#initialize(connection) ⇒ RequestHandler

Returns a new instance of RequestHandler.



7
8
9
# File 'lib/makeleaps/request/request_handler.rb', line 7

def initialize(connection)
  @connection = connection
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



6
7
8
# File 'lib/makeleaps/request/request_handler.rb', line 6

def connection
  @connection
end

Instance Method Details

#delete(*args, &block) ⇒ Object



39
40
41
42
43
44
# File 'lib/makeleaps/request/request_handler.rb', line 39

def delete(*args, &block)
  response = handle_api_response(success: 204) do
    connection.delete(*args, &block)
  end
  Makeleaps::Response::Wrapper.new response
end

#get(*args, &block) ⇒ Object



11
12
13
14
15
16
# File 'lib/makeleaps/request/request_handler.rb', line 11

def get(*args, &block)
  response = handle_api_response(success: 200) do
    connection.get(*args, &block)
  end
  Makeleaps::Response::Wrapper.new response
end

#options(url, &block) ⇒ Object



46
47
48
49
50
51
# File 'lib/makeleaps/request/request_handler.rb', line 46

def options(url, &block)
  response = handle_api_response(success: 200) do
    connection.run_request(:options, url, nil, nil, &block)
  end
  Makeleaps::Response::Wrapper.new response
end

#patch(*args, &block) ⇒ Object



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

def patch(*args, &block)
  response = handle_api_response(success: 200) do
    connection.patch(*args, &block)
  end
  Makeleaps::Response::Wrapper.new response
end

#post(*args, &block) ⇒ Object



18
19
20
21
22
23
# File 'lib/makeleaps/request/request_handler.rb', line 18

def post(*args, &block)
  response = handle_api_response(success: 201) do
    connection.post(*args, &block)
  end
  Makeleaps::Response::Wrapper.new response
end

#put(*args, &block) ⇒ Object



32
33
34
35
36
37
# File 'lib/makeleaps/request/request_handler.rb', line 32

def put(*args, &block)
  response = handle_api_response(success: 200) do
    connection.put(*args, &block)
  end
  Makeleaps::Response::Wrapper.new response
end