class PipedriveAPI::Base
Public Class Methods
all(**params)
click to toggle source
# File lib/pipedrive_api/base.rb, line 19 def all(**params) # TODO pagination response = get "#{resource_path}", query: params handle response end
auth(api_token:, account_name: "api")
click to toggle source
# File lib/pipedrive_api/base.rb, line 14 def auth(api_token:, account_name: "api") default_params api_token: api_token base_uri "https://#{account_name}.pipedrive.com/#{API_VERSION}/" end
create(**params)
click to toggle source
# File lib/pipedrive_api/base.rb, line 35 def create(**params) response = post resource_path, body: params.to_json handle response end
find(id)
click to toggle source
# File lib/pipedrive_api/base.rb, line 25 def find(id) response = get "#{resource_path}/#{id}" handle response end
find_by_name(name, **params)
click to toggle source
# File lib/pipedrive_api/base.rb, line 30 def find_by_name(name, **params) response = get "#{resource_path}/find", query: { term: name }.merge(params) handle response end
handle(response)
click to toggle source
# File lib/pipedrive_api/base.rb, line 58 def handle response case response.code when 200..299 response['data'] when 403..404 raise HTTParty::Error, response.parsed_response['error'] when 500..600 raise HTTParty::Error, response.parsed_response['error'] else raise StandardError, 'Unknown error' end end
remove(id)
click to toggle source
# File lib/pipedrive_api/base.rb, line 45 def remove(id) response = delete "#{resource_path}/#{id}" handle response end
resource_path()
click to toggle source
# File lib/pipedrive_api/base.rb, line 50 def resource_path # The resource path should match the camelCased class name with the # first letter downcased. Pipedrive API is sensitive to capitalisation klass = name.split('::').last klass[0] = klass[0].chr.downcase klass.end_with?('y') ? "/#{klass.chop}ies" : "/#{klass}s" end
update(id, **params)
click to toggle source
# File lib/pipedrive_api/base.rb, line 40 def update(id, **params) response = put "#{resource_path}/#{id}", body: params.to_json handle response end