Class: LeverPostings::Client
- Inherits:
-
Object
- Object
- LeverPostings::Client
- Defined in:
- lib/lever_postings/client.rb
Instance Attribute Summary collapse
-
#account ⇒ Object
Returns the value of attribute account.
-
#api ⇒ Object
Returns the value of attribute api.
-
#connection ⇒ Object
Returns the value of attribute connection.
Instance Method Summary collapse
- #get(path, params = {}) ⇒ Object
-
#initialize(api, account) ⇒ Client
constructor
A new instance of Client.
- #post(path, options = {}, params = {}) ⇒ Object
- #request(method, path, options = {}, params = {}) ⇒ Object
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, account) @api = api @account = 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
#account ⇒ Object
Returns the value of attribute account.
3 4 5 |
# File 'lib/lever_postings/client.rb', line 3 def account @account end |
#api ⇒ Object
Returns the value of attribute api.
3 4 5 |
# File 'lib/lever_postings/client.rb', line 3 def api @api end |
#connection ⇒ Object
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, = {}, params = {}) request :post, path, , 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, = {}, params = {}) path = path && path != "" ? "/#{path}" : nil url = "#{api}/#{account}#{path}" url += "?key=#{options[:api_key]}" if .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 |