Skip to content

Commit

Permalink
Allow objects to be updated.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaygen committed Feb 7, 2013
1 parent b2f38f7 commit b45ec58
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions lib/pipedrive/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
require 'forwardable'

module Pipedrive

# Globally set request headers
HEADERS = {
"User-Agent" => "Ruby.Pipedrive.Api",
"Accept" => "application/json",
"Content-Type" => "application/x-www-form-urlencoded"
}

# Base class for setting HTTParty configurations globally
class Base < OpenStruct

Expand All @@ -20,7 +20,7 @@ class Base < OpenStruct
format :json

extend Forwardable
def_delegators 'self.class', :get, :post, :resource_path, :bad_response
def_delegators 'self.class', :get, :post, :put, :resource_path, :bad_response

attr_reader :data

Expand All @@ -38,6 +38,15 @@ def initialize(attrs = {})
end
end

# Updates the object.
#
# @param [Hash] opts
# @return [Boolean]
def update(opts = {})
res = put "#{resource_path}/#{id}", :body => opts
!!(res.success? && @table.merge!(res['data'].symbolize_keys))
end

class << self
# Sets the authentication credentials in a class variable.
#
Expand Down Expand Up @@ -102,6 +111,6 @@ def deals
Deal.all(get "#{resource_path}/#{id}/deals")
end
end
end
end

end

0 comments on commit b45ec58

Please sign in to comment.