Class: Supportbee::Client
- Inherits:
-
Object
- Object
- Supportbee::Client
- Defined in:
- lib/supportbee/client.rb,
lib/supportbee/client/agents.rb,
lib/supportbee/client/groups.rb,
lib/supportbee/client/labels.rb,
lib/supportbee/client/tickets.rb,
lib/supportbee/client/snippets.rb,
lib/supportbee/client/web_hooks.rb
Defined Under Namespace
Modules: Agents, Groups, Labels, Snippets, Tickets, WebHooks
Instance Method Summary collapse
- #index(model, extra_parameters = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #request(url, options = {}) ⇒ Object
Methods included from Groups
Methods included from Agents
Methods included from Tickets
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/supportbee/client.rb', line 13 def initialize(={}) @company = [:company] @host = "https://#{@company}.supportbee.com" @auth_token = [:auth_token] @conn = Faraday.new(:url => @host) do |faraday| faraday.params[:auth_token] = @auth_token faraday.request :url_encoded # form-encode POST params faraday.response :logger # log requests to STDOUT faraday.adapter Faraday.default_adapter # make requests with Net::HTTP end end |
Instance Method Details
#index(model, extra_parameters = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/supportbee/client.rb', line 31 def index(model, extra_parameters = {}) items = [] current_page = 1 last_page = false until last_page extra_parameters['page'] = current_page raw_response = @conn.get do |req| req.url "/#{model}.json" req.params.merge!(extra_parameters) end response = JSON.parse(raw_response.body) items.concat(response[model]) if response['current_page'].to_i >= response['total_pages'].to_i last_page = true else current_page = current_page + 1 end end items end |
#request(url, options = {}) ⇒ Object
25 26 27 28 29 |
# File 'lib/supportbee/client.rb', line 25 def request(url, = {}) method = [:method].nil? ? :get : [:method] response = @conn.run_request(method, url, [:body], [:headers]) JSON.parse(response.body) end |