Class: DoceboRuby::API

Inherits:
Object
  • Object
show all
Defined in:
lib/docebo_ruby/api.rb

Instance Method Summary collapse

Constructor Details

#initializeAPI

Returns a new instance of API.


8
9
10
11
12
# File 'lib/docebo_ruby/api.rb', line 8

def initialize
  @url = DoceboRuby::Configuration::URL
  @key = DoceboRuby::Configuration::KEY
  @secret = DoceboRuby::Configuration::SECRET
end

Instance Method Details

#send_request(api, method, params, &block) ⇒ Object

Raises:


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/docebo_ruby/api.rb', line 14

def send_request(api, method, params, &block)
  raise ArgumentError.new('Please specify parameters') if params.nil?
  parameters = Parameters.new params
  options = request_options parameters
  url = rest_url api, method

  RestClient.post(url, params, options) do |raw_response|
    case raw_response.code
    when 200
      response = parse_response raw_response
      if block_given?
        yield response 
      else
        return response
      end
    when 404
      raise NotFound.new(response)
    else
      raise RequestError.new(response)
    end        
  end
end