Skip to content
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

Enhanced and added feature sets (incomplete though) #14

Merged
merged 31 commits into from
Apr 23, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
bfcb09b
Enhanced and added feature sets (incomplete though)
jufemaiz Jan 30, 2014
6d311ed
Deal extended for files and activities
jufemaiz Jan 30, 2014
b699ac8
Notes for a deal
jufemaiz Jan 30, 2014
08f4e8f
Notes reference
jufemaiz Jan 30, 2014
6e4b10e
Notes reference
jufemaiz Jan 30, 2014
8fecfd8
Notes reference
jufemaiz Jan 30, 2014
93c2cd9
Notes reference
jufemaiz Jan 30, 2014
d697fbc
Notes reference
jufemaiz Jan 30, 2014
b422286
Notes reference
jufemaiz Jan 30, 2014
7898ca4
Notes reference
jufemaiz Jan 31, 2014
e0e3b44
Notes reference
jufemaiz Jan 31, 2014
09dc0b2
Notes reference
jufemaiz Jan 31, 2014
2c6ffbc
Notes reference
jufemaiz Jan 31, 2014
e423581
Notes reference
jufemaiz Jan 31, 2014
8d8974d
Updates to the error handling to include parameters
jufemaiz Feb 6, 2014
0517087
bumped up bugfix
jufemaiz Feb 6, 2014
9eaf0ea
Log error issues
jufemaiz Feb 6, 2014
8227adb
Updates again
jufemaiz Feb 6, 2014
130d36f
Gemspec update
jufemaiz Feb 6, 2014
27e8247
Gemspec update
jufemaiz Feb 6, 2014
e16ba49
Logging added
jufemaiz Feb 11, 2014
bca47e6
Bumped gemspec
jufemaiz Feb 11, 2014
3f2d409
Update
jufemaiz Feb 11, 2014
09ddf7e
More logging
jufemaiz Feb 11, 2014
f750a20
Updated 'all' function to continuously request further data with flag
jufemaiz Feb 11, 2014
17eff0b
Updated 'all' function to continuously request further data with flag
jufemaiz Feb 11, 2014
e0b9610
Updated 'all' function to continuously request further data with flag
jufemaiz Feb 11, 2014
0a45fc7
Removed logging
jufemaiz Feb 11, 2014
a4f4cf6
Defective code fixed
jufemaiz Feb 21, 2014
58b7f59
Deals from Person
Meekohi Mar 17, 2014
2f2fc38
Merge pull request #1 from Meekohi/personDeals
jufemaiz Mar 17, 2014
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
19 changes: 17 additions & 2 deletions lib/pipedrive-ruby.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
require 'pipedrive/base'
require 'pipedrive/activity'
require 'pipedrive/activity-type'
require 'pipedrive/authorization'
require 'pipedrive/currency'
require 'pipedrive/deal'
require 'pipedrive/deal-field'
require 'pipedrive/file'
require 'pipedrive/filter'
require 'pipedrive/note'
require 'pipedrive/organization'
require 'pipedrive/person'
require 'pipedrive/organization-field'
require 'pipedrive/person-field'
require 'pipedrive/product'
require 'pipedrive/permission-set'
require 'pipedrive/pipeline'
require 'pipedrive/product'
require 'pipedrive/product-field'
require 'pipedrive/role'
require 'pipedrive/search-result'
require 'pipedrive/stage'
require 'pipedrive/note'
require 'pipedrive/user'
require 'pipedrive/user-setting'
require 'pipedrive/goal'
require 'pipedrive/user-connection'
require 'pipedrive/push-notification'

module Pipedrive

Expand Down
4 changes: 4 additions & 0 deletions lib/pipedrive/activity-type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Pipedrive
class ActivityType < Base
end
end
4 changes: 4 additions & 0 deletions lib/pipedrive/authorization.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Pipedrive
class Authorization < Base
end
end
34 changes: 23 additions & 11 deletions lib/pipedrive/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module Pipedrive
class Base < OpenStruct

include HTTParty

base_uri 'api.pipedrive.com/v1'
headers HEADERS
format :json
Expand All @@ -24,12 +25,12 @@ class Base < OpenStruct

attr_reader :data

# Create a new CloudApp::Base object.
# Create a new Pipedrive::Base object.
#
# Only used internally
#
# @param [Hash] attributes
# @return [CloudApp::Base]
# @return [Pipedrive::Base]
def initialize(attrs = {})
if attrs['data']
struct_attrs = attrs['data']
Expand All @@ -50,7 +51,12 @@ def initialize(attrs = {})
# @return [Boolean]
def update(opts = {})
res = put "#{resource_path}/#{id}", :body => opts
!!(res.success? && @table.merge!(res['data'].symbolize_keys))
if res.success?
res['data'] = Hash[res['data'].map {|k, v| [k.to_sym, v] }]
@table.merge!(res['data'])
else
false
end
end

class << self
Expand All @@ -66,7 +72,8 @@ def authenticate(token)
# Examines a bad response and raises an appropriate exception
#
# @param [HTTParty::Response] response
def bad_response(response)
def bad_response(response, params={})
puts params.inspect
if response.class == HTTParty::Response
raise HTTParty::ResponseError, response
end
Expand All @@ -77,12 +84,17 @@ def new_list( attrs )
attrs['data'].is_a?(Array) ? attrs['data'].map {|data| self.new( 'data' => data ) } : []
end

def all(response = nil, options={})
def all(response = nil, options={},get_absolutely_all=false)
res = response || get(resource_path, options)
if res.ok?
res['data'].nil? ? [] : res['data'].map{|obj| new(obj)}
data = res['data'].nil? ? [] : res['data'].map{|obj| new(obj)}
if get_absolutely_all && res['additional_data']['pagination'] && res['additional_data']['pagination'] && res['additional_data']['pagination']['more_items_in_collection']
options[:query] = options[:query].merge({:start => res['additional_data']['pagination']['next_start']})
data += self.all(nil,options,true)
end
data
else
bad_response(res)
bad_response(res,attrs)
end
end

Expand All @@ -92,18 +104,18 @@ def create( opts = {} )
res['data'] = opts.merge res['data']
new(res)
else
bad_response(res)
bad_response(res,opts)
end
end

def find(id)
res = get "#{resource_path}/#{id}"
res.ok? ? new(res) : bad_response(res)
res.ok? ? new(res) : bad_response(res,id)
end

def find_by_name(name, opts={})
res = get "#{resource_path}/find", :query => { :term => name }.merge(opts)
res.ok? ? new_list(res) : bad_response(res)
res.ok? ? new_list(res) : bad_response(res,{:name => name}.merge(opts))
end

def resource_path
Expand Down
4 changes: 4 additions & 0 deletions lib/pipedrive/currency.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Pipedrive
class Currency < Base
end
end
4 changes: 4 additions & 0 deletions lib/pipedrive/deal-field.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Pipedrive
class DealField < Base
end
end
19 changes: 16 additions & 3 deletions lib/pipedrive/deal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,29 @@ class Deal < Base

def add_product(opts = {})
res = post "#{resource_path}/#{id}/products", :body => opts
res.success? ? res['data']['product_attachment_id'] : bad_response(res)
res.success? ? res['data']['product_attachment_id'] : bad_response(res,opts)
end

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)
res.success? ? nil : bad_response(res,product_attachment_id)
end

def activities
Activity.all(get "#{resource_path}/#{id}/activities")
end

def files
File.all(get "#{resource_path}/#{id}/files")
end

def notes(opts = {:sort_by => 'add_time', :sort_mode => 'desc'})
Note.all( get("/notes", :query => opts.merge(:deal_id => id) ) )
end

end
end
4 changes: 4 additions & 0 deletions lib/pipedrive/file.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Pipedrive
class File < Base
end
end
4 changes: 4 additions & 0 deletions lib/pipedrive/filter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Pipedrive
class Filter < Base
end
end
4 changes: 4 additions & 0 deletions lib/pipedrive/goal.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Pipedrive
class Goal < Base
end
end
2 changes: 1 addition & 1 deletion lib/pipedrive/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def deals
class << self

def find_or_create_by_name(name, opts={})
find_by_name(name).first || create(opts.merge(:title => name))
find_by_name(name).first || create(opts.merge(:name => name))
end

end
Expand Down
4 changes: 4 additions & 0 deletions lib/pipedrive/permission-set.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Pipedrive
class PermissionSet < Base
end
end
4 changes: 4 additions & 0 deletions lib/pipedrive/person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@ def find_or_create_by_name(name, opts={})
end

end

def deals()
Deal.all(get "#{resource_path}/#{id}/deals", :everyone => 1)
end
end
end
2 changes: 1 addition & 1 deletion lib/pipedrive/pipeline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def stages
def statistics(id, start_date, end_date)
res = get("#{resource_path}/#{id}/movement_statistics",
:query => {:start_date => start_date, :end_date => end_date})
res.ok? ? new(res) : bad_response(res)
res.ok? ? new(res) : bad_response(res,{:id=>id,:start_date=>start_date,:end_date=>end_date})
end

def deals(id, stage_id)
Expand Down
4 changes: 4 additions & 0 deletions lib/pipedrive/product-field.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Pipedrive
class ProductField < Base
end
end
4 changes: 4 additions & 0 deletions lib/pipedrive/push-notification.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Pipedrive
class PushNotification < Base
end
end
4 changes: 4 additions & 0 deletions lib/pipedrive/role.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Pipedrive
class Role < Base
end
end
28 changes: 28 additions & 0 deletions lib/pipedrive/search-result.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module Pipedrive
class SearchResult < Base

# Class Methods
class << self

def search(term, start=0, limit=nil)
res = get(resource_path, :query => { :term => term, :start => start, :limit => limit})
if res.ok?
res['data'].nil? ? [] : res['data'].map{|obj| new(obj)}
else
bad_response(res,{:term=>term,:start=>start,:limit=>limit})
end
end

def field(term, field_type, field_key, opts={})
res = get("#{resource_path}/field", :query => opts.merge(:term => term, :field_type => field_type, :field_key => field_key) )
if res.ok?
res['data'].nil? ? [] : res['data'].map{|obj| new(obj)}
else
bad_response(res,{:term=>term,:field_type=>field_type,:field_key=>field_key}.merge(opts))
end
end

end

end
end
4 changes: 4 additions & 0 deletions lib/pipedrive/user-connection.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Pipedrive
class UserConnection < Base
end
end
4 changes: 4 additions & 0 deletions lib/pipedrive/user-setting.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Pipedrive
class UserSetting < Base
end
end
4 changes: 4 additions & 0 deletions lib/pipedrive/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Pipedrive
class User < Base
end
end
25 changes: 22 additions & 3 deletions pipedrive-ruby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

Gem::Specification.new do |s|
s.name = "pipedrive-ruby"
s.version = "0.2.6"
s.version = "0.3.3"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Jan Schwenzien", "Waldemar Kusnezow"]
s.date = "2013-06-17"
s.authors = ["Jan Schwenzien", "Waldemar Kusnezow", "Joel Courtney"]
s.date = "2014-01-30"
s.description = "Ruby wrapper for the Pipedrive API"
s.email = "[email protected]"
s.extra_rdoc_files = [
Expand All @@ -24,12 +24,31 @@ Gem::Specification.new do |s|
"VERSION",
"lib/pipedrive-ruby.rb",
"lib/pipedrive/base.rb",
"lib/pipedrive/activity.rb",
"lib/pipedrive/activity-type.rb",
"lib/pipedrive/authorization.rb",
"lib/pipedrive/currency.rb",
"lib/pipedrive/deal.rb",
"lib/pipedrive/deal-field.rb",
"lib/pipedrive/file.rb",
"lib/pipedrive/filter.rb",
"lib/pipedrive/note.rb",
"lib/pipedrive/organization.rb",
"lib/pipedrive/person.rb",
"lib/pipedrive/organization-field.rb",
"lib/pipedrive/person-field.rb",
"lib/pipedrive/permission-set.rb",
"lib/pipedrive/pipeline.rb",
"lib/pipedrive/product.rb",
"lib/pipedrive/product-field.rb",
"lib/pipedrive/role.rb",
"lib/pipedrive/search-result.rb",
"lib/pipedrive/stage.rb",
"lib/pipedrive/user.rb",
"lib/pipedrive/user-setting.rb",
"lib/pipedrive/goal.rb",
"lib/pipedrive/user-connection.rb",
"lib/pipedrive/push-notification.rb",
"pipedrive-ruby.gemspec",
"test/data/create_deal_body.json",
"test/data/create_organization_body.json",
Expand Down