Class: Insightly2::Client
- Inherits:
-
Object
- Object
- Insightly2::Client
- Defined in:
- lib/insightly2/client.rb
Constant Summary collapse
- URL =
'https://api.insight.ly/v2.1/'
- REQUESTS =
[:get, :post, :put, :delete]
- HEADERS =
{'Accept' => 'application/json', 'Content-Type' => 'application/json'}
- LOGGER =
Logger.new(STDOUT)
Instance Method Summary collapse
-
#initialize(api_key = Insightly2.api_key) ⇒ Client
constructor
A new instance of Client.
-
#request(method, path, query = {}, headers = HEADERS) ⇒ Faraday::Response
Server response.
Methods included from DSL::Users
Methods included from DSL::Teams
#create_team, #delete_team, #get_team, #get_teams, #update_team
Methods included from DSL::TeamMembers
#create_team_member, #delete_team_member, #get_team_member, #get_team_members, #update_team_member
Methods included from DSL::Tasks
#create_task, #create_task_comment, #delete_task, #get_task, #get_task_comments, #get_tasks, #update_task
Methods included from DSL::TaskCategories
#create_task_category, #delete_task_category, #get_task_categories, #get_task_category, #update_task_category
Methods included from DSL::Tags
Methods included from DSL::Relationships
Methods included from DSL::Projects
#create_project, #create_project_image, #delete_project, #delete_project_image, #get_project, #get_project_emails, #get_project_image, #get_project_notes, #get_project_tasks, #get_projects, #update_project, #update_project_image
Methods included from DSL::ProjectCategories
#create_project_category, #delete_project_category, #get_project_categories, #get_project_category, #update_project_category
Methods included from DSL::Pipelines
Methods included from DSL::PipelineStages
#get_pipeline_stage, #get_pipeline_stages
Methods included from DSL::Organisations
#create_organisation, #create_organisation_image, #delete_organisation, #delete_organisation_image, #get_organisation, #get_organisation_emails, #get_organisation_image, #get_organisation_notes, #get_organisation_tasks, #get_organisations, #update_organisation, #update_organisation_image
Methods included from DSL::OpportunityStateReasons
#get_opportunity_state_reasons
Methods included from DSL::OpportunityCategories
#create_opportunity_category, #delete_opportunity_category, #get_opportunity_categories, #get_opportunity_category, #update_opportunity_category
Methods included from DSL::Opportunities
#create_opportunity, #create_opportunity_image, #delete_opportunity, #delete_opportunity_image, #get_opportunities, #get_opportunity, #get_opportunity_emails, #get_opportunity_image, #get_opportunity_notes, #get_opportunity_state_history, #get_opportunity_tasks, #update_opportunity, #update_opportunity_image
Methods included from DSL::Notes
#create_note, #create_note_comment, #create_note_file, #delete_note, #get_note, #get_note_comments, #get_notes, #update_note
Methods included from DSL::FileCategories
#create_file_category, #delete_file_category, #get_file_categories, #get_file_category, #update_file_category
Methods included from DSL::FileAttachments
Methods included from DSL::Events
#create_event, #delete_event, #get_event, #get_events, #update_event
Methods included from DSL::Emails
#create_email_comment, #delete_email, #get_email, #get_email_comments, #get_emails
Methods included from DSL::CustomFields
#get_custom_field, #get_custom_fields
Methods included from DSL::Currencies
Methods included from DSL::Countries
Methods included from DSL::Contacts
#create_contact, #create_contact_image, #delete_contact, #delete_contact_image, #get_contact, #get_contact_emails, #get_contact_image, #get_contact_notes, #get_contact_tasks, #get_contacts, #update_contact, #update_contact_image
Methods included from DSL::Comments
#create_comment_attachment, #delete_comment, #get_comment, #update_comment
Constructor Details
#initialize(api_key = Insightly2.api_key) ⇒ Client
Returns a new instance of Client.
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/insightly2/client.rb', line 20 def initialize(api_key = Insightly2.api_key) @api_key = api_key # Setup HTTP request connection to insightly. @connection ||= Faraday.new do |builder| builder.basic_auth @api_key, '' builder.request :url_encoded builder.response :logger if Insightly2.logger builder.adapter Faraday.default_adapter end end |
Instance Method Details
#request(method, path, query = {}, headers = HEADERS) ⇒ Faraday::Response
Returns server response.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/insightly2/client.rb', line 40 def request(method, path, query = {}, headers = HEADERS) raise ArgumentError, "Unsupported method #{method.inspect}. Only :get, :post, :put, :delete are allowed" unless REQUESTS.include?(method) = query.empty? ? "with no payload" : "with payload: #{query.inspect}" = "INSIGHTLY starting [#{method.to_s}] request to [#{path.to_s}] #{payload_logger_message}" LOGGER.info() payload = !query.empty? ? JSON.generate(query) : '' response = @connection.run_request(method, "#{URL}#{path}", payload, headers) case response.status.to_i when 200..299 return response when 404 raise ResourceNotFoundError.new(response: response) else raise ClientError.new(response: response) end end |