Class: PipeDrive::SendRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/pipe_drive/send_request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSendRequest

Returns a new instance of SendRequest.

Raises:



5
6
7
8
9
# File 'lib/pipe_drive/send_request.rb', line 5

def initialize
  raise MissingApiToken.new if PipeDrive.api_token.nil?
  @host = PipeDrive.host
  @api_token = PipeDrive.api_token
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



3
4
5
# File 'lib/pipe_drive/send_request.rb', line 3

def host
  @host
end

Instance Method Details

#http_del(path, params = {}, header = {}, &block) ⇒ Object



39
40
41
# File 'lib/pipe_drive/send_request.rb', line 39

def http_del(path, params={}, header={}, &block)
  body_request(:delete, path, params, header, &block)
end

#http_get(path, params = {}, header = {}) {|PipeDrive.hash_except(result, [:status])| ... } ⇒ Object

Yields:

Raises:



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/pipe_drive/send_request.rb', line 11

def http_get(path, params={}, header={}, &block)
  begin
    full_url = "#{host}/#{API_VERSION}#{path}"
    uri = URI(full_url)
    params.merge!(api_token: @api_token)
    uri.query = URI.encode_www_form(params)
    http = Net::HTTP.new(uri.host, uri.port)
    http.use_ssl = uri.scheme == 'https'

    request = Net::HTTP::Get.new(uri.request_uri, header)
    response = http.request(request)
    result = handle_response(response)
  rescue Exception => e
    result = server_error_response(e.message)
  end
  return result unless block_given?
  raise RequestError.new(result) unless success_result?(result)
  yield PipeDrive.hash_except(result, [:status])
end

#http_post(path, params = {}, header = {}, &block) ⇒ Object



31
32
33
# File 'lib/pipe_drive/send_request.rb', line 31

def http_post(path, params={}, header={}, &block)
  body_request(:post, path, params, header, &block)
end

#http_put(path, params = {}, header = {}, &block) ⇒ Object



35
36
37
# File 'lib/pipe_drive/send_request.rb', line 35

def http_put(path, params={}, header={}, &block)
  body_request(:put, path, params, header, &block)
end