Module: Hashblue::API::Request

Included in:
Hashblue::API
Defined in:
lib/hashblue/api/request.rb

Overview

:nodoc:all

Defined Under Namespace

Classes: Response

Instance Method Summary collapse

Instance Method Details

#_requestObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/hashblue/api/request.rb', line 14

def _request
  _with_timeout do
    response = Response.new(yield)
    if response.success? && response.json?
      return response
    else
      raise Hashblue::API::Error.from_response(response)
    end
  end
end

#_with_timeout(seconds = default_options[:timeout], &block) ⇒ Object



25
26
27
28
29
# File 'lib/hashblue/api/request.rb', line 25

def _with_timeout(seconds = default_options[:timeout], &block)
  Timeout::timeout(seconds, &block)
rescue Timeout::Error
  raise Hashblue::API::NotRespondingError
end

#delete(path) ⇒ Object



6
7
8
# File 'lib/hashblue/api/request.rb', line 6

def delete(path)
  _request { super }
end

#get(path, options = {}) ⇒ Object



2
3
4
# File 'lib/hashblue/api/request.rb', line 2

def get(path, options={})
  _request { super }
end

#post(path, options = {}) ⇒ Object



10
11
12
# File 'lib/hashblue/api/request.rb', line 10

def post(path, options={})
  _request { super }
end