Skip to content
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
2 changes: 1 addition & 1 deletion lib/pipedrive/activity-type.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Pipedrive
class ActivityType < Base
end
end
end
2 changes: 1 addition & 1 deletion lib/pipedrive/activity.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Pipedrive
class Activity < Base
end
end
end
2 changes: 1 addition & 1 deletion lib/pipedrive/authorization.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Pipedrive
class Authorization < Base
end
end
end
26 changes: 13 additions & 13 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 @@ -72,50 +72,50 @@ def authenticate(token)
# Examines a bad response and raises an appropriate exception
#
# @param [HTTParty::Response] response
def bad_response(response, params={})
def bad_response(response, params = {})
puts params.inspect
if response.class == HTTParty::Response
raise HTTParty::ResponseError, response
end
raise StandardError, 'Unknown error'
end

def new_list( attrs )
def new_list(attrs)
attrs['data'].is_a?(Array) ? attrs['data'].map {|data| self.new( 'data' => data ) } : []
end

def all(response = nil, options={},get_absolutely_all=false)
def all(response = nil, options = {}, get_absolutely_all = false)
res = response || get(resource_path, options)
if res.ok?
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)
data += self.all(nil, options, true)
end
data
else
bad_response(res,attrs)
bad_response(res, options)
end
end

def create( opts = {} )
def create(opts = {})
res = post resource_path, :body => opts
if res.success?
res['data'] = opts.merge res['data']
new(res)
else
bad_response(res,opts)
bad_response(res, opts)
end
end

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

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

def resource_path
Expand Down
2 changes: 1 addition & 1 deletion lib/pipedrive/currency.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Pipedrive
class Currency < Base
end
end
end
10 changes: 5 additions & 5 deletions lib/pipedrive/deal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ 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,opts)
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,product_attachment_id)
res.success? ? nil : bad_response(res, product_attachment_id)
end

def activities
Expand All @@ -24,8 +24,8 @@ def files
end

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

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

class << self

end

end
end
end
1 change: 1 addition & 0 deletions lib/pipedrive/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ def find_or_create_by_name(name, opts={})
end

end

end
end
2 changes: 1 addition & 1 deletion lib/pipedrive/permission-set.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Pipedrive
class PermissionSet < Base
end
end
end
3 changes: 2 additions & 1 deletion lib/pipedrive/person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ def find_or_create_by_name(name, opts={})
def deals()
Deal.all(get "#{resource_path}/#{id}/deals", :everyone => 1)
end

end
end
end
6 changes: 4 additions & 2 deletions lib/pipedrive/pipeline.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
module Pipedrive
class Pipeline < Base

def stages
Stage.all(get "/stages", { :pipeline_id => self.id })
end

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,{:id=>id,:start_date=>start_date,:end_date=>end_date})
res.ok? ? new(res) : bad_response(res, {:id => id, :start_date => start_date, :end_date => end_date})
end

def deals(id, stage_id)
Pipedrive::Deal.all(get "#{resource_path}/#{id}/deals", :stage_id => stage_id )
end

end
end
end
2 changes: 1 addition & 1 deletion lib/pipedrive/product-field.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Pipedrive
class ProductField < Base
end
end
end
2 changes: 1 addition & 1 deletion lib/pipedrive/push-notification.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Pipedrive
class PushNotification < Base
end
end
end
2 changes: 1 addition & 1 deletion lib/pipedrive/role.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Pipedrive
class Role < Base
end
end
end
14 changes: 7 additions & 7 deletions lib/pipedrive/search-result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ 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})
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))
bad_response(res, {:term => term, :field_type => field_type, :field_key => field_key}.merge(opts))
end
end

end

end
end
end
2 changes: 1 addition & 1 deletion lib/pipedrive/user-connection.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Pipedrive
class UserConnection < Base
end
end
end
2 changes: 1 addition & 1 deletion lib/pipedrive/user-setting.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Pipedrive
class UserSetting < Base
end
end
end
2 changes: 1 addition & 1 deletion lib/pipedrive/user.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Pipedrive
class User < Base
end
end
end
8 changes: 4 additions & 4 deletions test/test_pipedrive_authentication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ class TestPipedriveAuthentication < Test::Unit::TestCase
should "send authentication token with each request" do
Pipedrive.authenticate("some-token")

stub_request(:get, "http://api.pipedrive.com/v1/?api_token=some-token").
stub_request(:get, "https://api.pipedrive.com/v1/?api_token=some-token").
with(:headers => {
'Accept'=>'application/json',
'Content-Type'=>'application/x-www-form-urlencoded',
'User-Agent'=>'Ruby.Pipedrive.Api'
'Accept' => 'application/json',
'Content-Type' => 'application/x-www-form-urlencoded',
'User-Agent' => 'Ruby.Pipedrive.Api'
}).
to_return(:status => 200, :body => "", :headers => {})
Pipedrive::Base.get("/")
Expand Down
10 changes: 5 additions & 5 deletions test/test_pipedrive_deal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ def setup
"value" => "37k"
}

stub_request(:post, "http://api.pipedrive.com/v1/deals?api_token=some-token").
stub_request(:post, "https://api.pipedrive.com/v1/deals?api_token=some-token").
with(:body => body,
:headers => {
'Accept'=>'application/json',
'Content-Type'=>'application/x-www-form-urlencoded',
'User-Agent'=>'Ruby.Pipedrive.Api'
'Accept' => 'application/json',
'Content-Type' => 'application/x-www-form-urlencoded',
'User-Agent' => 'Ruby.Pipedrive.Api'
}).
to_return(
:status => 200,
Expand All @@ -45,4 +45,4 @@ def setup
#TODO
# flunk "to be tested"
end
end
end
12 changes: 6 additions & 6 deletions test/test_pipedrive_note.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ def setup

should "execute a valid person request" do
body = {
"content"=>"whatever html body",
"person_id"=>"1"
"content" => "whatever html body",
"person_id" => "1"
# org_id
# deal_id
}

stub_request(:post, "http://api.pipedrive.com/v1/notes?api_token=some-token").
stub_request(:post, "https://api.pipedrive.com/v1/notes?api_token=some-token").
with(:body => body, :headers => {
'Accept'=>'application/json',
'Content-Type'=>'application/x-www-form-urlencoded',
'User-Agent'=>'Ruby.Pipedrive.Api'
'Accept' => 'application/json',
'Content-Type' => 'application/x-www-form-urlencoded',
'User-Agent' => 'Ruby.Pipedrive.Api'
}).
to_return(
:status => 200,
Expand Down
8 changes: 4 additions & 4 deletions test/test_pipedrive_organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ def setup
end

should "execute a valid person request" do
stub_request(:post, "http://api.pipedrive.com/v1/organizations?api_token=some-token").
stub_request(:post, "https://api.pipedrive.com/v1/organizations?api_token=some-token").
with(:body => {
"name" => "Dope.org"
},
:headers => {
'Accept'=>'application/json',
'Content-Type'=>'application/x-www-form-urlencoded',
'User-Agent'=>'Ruby.Pipedrive.Api'
'Accept' => 'application/json',
'Content-Type' => 'application/x-www-form-urlencoded',
'User-Agent' => 'Ruby.Pipedrive.Api'
}).
to_return(
:status => 200,
Expand Down
16 changes: 8 additions & 8 deletions test/test_pipedrive_person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ def setup

should "execute a valid person request" do
body = {
"email"=>["john@dope.org"],
"name"=>"John Dope",
"org_id"=>"404",
"phone"=>["0123456789"]
"email" => ["john@dope.org"],
"name" => "John Dope",
"org_id" => "404",
"phone" => ["0123456789"]
}

stub_request(:post, "http://api.pipedrive.com/v1/persons?api_token=some-token").
stub_request(:post, "https://api.pipedrive.com/v1/persons?api_token=some-token").
with(:body => body, :headers => {
'Accept'=>'application/json',
'Content-Type'=>'application/x-www-form-urlencoded',
'User-Agent'=>'Ruby.Pipedrive.Api'
'Accept' => 'application/json',
'Content-Type' => 'application/x-www-form-urlencoded',
'User-Agent' => 'Ruby.Pipedrive.Api'
}).
to_return(
:status => 200,
Expand Down