Skip to content

HTTPS support and explicit update failure reporting #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions lib/pipedrive/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ module Pipedrive
class Base < OpenStruct

include HTTParty
base_uri 'api.pipedrive.com/v1'

base_uri 'https://api.pipedrive.com/v1'
headers HEADERS
format :json

Expand Down Expand Up @@ -49,16 +49,24 @@ def initialize(attrs = {})
#
# @param [Hash] opts
# @return [Boolean]
def update(opts = {})
def update(opts = {}, raise_error=false)
res = put "#{resource_path}/#{id}", :body => opts
if res.success?
res['data'] = Hash[res['data'].map {|k, v| [k.to_sym, v] }]
@table.merge!(res['data'])
else
false
if raise_error
raise StandardError.new("update to #{resource_path}/#{id} failed with #{res.code} #{res.message} #{res.body}")
else
false
end
end
end

def update!(opts = {})
update(opts, true)
end

class << self
# Sets the authentication credentials in a class variable.
#
Expand Down Expand Up @@ -107,7 +115,7 @@ def create( opts = {} )
bad_response(res,opts)
end
end

def find(id)
res = get "#{resource_path}/#{id}"
res.ok? ? new(res) : bad_response(res,id)
Expand All @@ -118,6 +126,11 @@ def find_by_name(name, opts={})
res.ok? ? new_list(res) : bad_response(res,{:name => name}.merge(opts))
end

def find_with_options(opts = { start: 0 })
res = get "#{resource_path}", query: opts
res.ok? ? new_list(res) : bad_response(res,opts)
end

def resource_path
# The resource path should match the camelCased class name with the
# first letter downcased. Pipedrive API is sensitive to capitalisation
Expand Down
3 changes: 1 addition & 2 deletions lib/pipedrive/deal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def add_product(opts = {})
def products
Product.all(get "#{resource_path}/#{id}/products")
end

def remove_product product_attachment_id
res = delete "#{resource_path}/#{id}/products", { :body => { :product_attachment_id => product_attachment_id } }
res.success? ? nil : bad_response(res,product_attachment_id)
Expand All @@ -26,6 +26,5 @@ def files
def notes(opts = {:sort_by => 'add_time', :sort_mode => 'desc'})
Note.all( get("/notes", :query => opts.merge(:deal_id => id) ) )
end

end
end