Class: LeverPostings::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/lever_postings/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api, account) ⇒ Client

Returns a new instance of Client.



5
6
7
8
9
10
11
12
13
14
# File 'lib/lever_postings/client.rb', line 5

def initialize(api, )
  @api = api
  @account = 
  @connection = Faraday.new url: "https://api.lever.co/v0/" do |conn|
    # POST/PUT params encoders:
    conn.request :multipart
    conn.request :url_encoded
    conn.adapter :net_http
  end
end

Instance Attribute Details

#accountObject

Returns the value of attribute account.



3
4
5
# File 'lib/lever_postings/client.rb', line 3

def 
  @account
end

#apiObject

Returns the value of attribute api.



3
4
5
# File 'lib/lever_postings/client.rb', line 3

def api
  @api
end

#connectionObject

Returns the value of attribute connection.



3
4
5
# File 'lib/lever_postings/client.rb', line 3

def connection
  @connection
end

Instance Method Details

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



16
17
18
# File 'lib/lever_postings/client.rb', line 16

def get(path, params = {})
  request :get, path, {}, params
end

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



20
21
22
# File 'lib/lever_postings/client.rb', line 20

def post(path, options = {}, params = {})
  request :post, path, options, params
end

#request(method, path, options = {}, params = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/lever_postings/client.rb', line 24

def request(method, path, options = {}, params = {})
  path = path && path != "" ? "/#{path}" : nil
  url = "#{api}/#{account}#{path}"
  url += "?key=#{options[:api_key]}" if options.key?(:api_key)

  if method == :post
    response = connection.post(url, params)
    response
  else
    connection.params = params
    response = connection.send(method, url)
    if response.status == 200
      if params[:mode] == "json"
        MultiJson.load(response.body, symbolize_keys: true)
      else
        response.body
      end
    else
      fail LeverPostings::Error.new("#{response.status}: #{response.body}", response.status)
    end
  end
end