diff --git a/lib/pipedrive/activity-type.rb b/lib/pipedrive/activity-type.rb index 1940c8e..42cf13e 100644 --- a/lib/pipedrive/activity-type.rb +++ b/lib/pipedrive/activity-type.rb @@ -1,4 +1,4 @@ module Pipedrive class ActivityType < Base end -end \ No newline at end of file +end diff --git a/lib/pipedrive/activity.rb b/lib/pipedrive/activity.rb index d986d33..b5ccf7a 100644 --- a/lib/pipedrive/activity.rb +++ b/lib/pipedrive/activity.rb @@ -1,4 +1,4 @@ module Pipedrive class Activity < Base end -end \ No newline at end of file +end diff --git a/lib/pipedrive/authorization.rb b/lib/pipedrive/authorization.rb index d4fe4a9..5fa45b3 100644 --- a/lib/pipedrive/authorization.rb +++ b/lib/pipedrive/authorization.rb @@ -1,4 +1,4 @@ module Pipedrive class Authorization < Base end -end \ No newline at end of file +end diff --git a/lib/pipedrive/base.rb b/lib/pipedrive/base.rb index 9a0adb0..528f592 100644 --- a/lib/pipedrive/base.rb +++ b/lib/pipedrive/base.rb @@ -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 @@ -72,7 +72,7 @@ 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 @@ -80,42 +80,42 @@ def bad_response(response, params={}) 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 diff --git a/lib/pipedrive/currency.rb b/lib/pipedrive/currency.rb index 418c685..69f8164 100644 --- a/lib/pipedrive/currency.rb +++ b/lib/pipedrive/currency.rb @@ -1,4 +1,4 @@ module Pipedrive class Currency < Base end -end \ No newline at end of file +end diff --git a/lib/pipedrive/deal.rb b/lib/pipedrive/deal.rb index cd3577c..7cbf9ec 100644 --- a/lib/pipedrive/deal.rb +++ b/lib/pipedrive/deal.rb @@ -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 @@ -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 diff --git a/lib/pipedrive/file.rb b/lib/pipedrive/file.rb index cf9f7ba..46af987 100644 --- a/lib/pipedrive/file.rb +++ b/lib/pipedrive/file.rb @@ -1,4 +1,4 @@ module Pipedrive class File < Base end -end \ No newline at end of file +end diff --git a/lib/pipedrive/filter.rb b/lib/pipedrive/filter.rb index e26bd86..3baea7b 100644 --- a/lib/pipedrive/filter.rb +++ b/lib/pipedrive/filter.rb @@ -1,4 +1,4 @@ module Pipedrive class Filter < Base end -end \ No newline at end of file +end diff --git a/lib/pipedrive/goal.rb b/lib/pipedrive/goal.rb index 9609dc3..0720a86 100644 --- a/lib/pipedrive/goal.rb +++ b/lib/pipedrive/goal.rb @@ -1,4 +1,4 @@ module Pipedrive class Goal < Base end -end \ No newline at end of file +end diff --git a/lib/pipedrive/note.rb b/lib/pipedrive/note.rb index 368d4e4..b1cdaa1 100644 --- a/lib/pipedrive/note.rb +++ b/lib/pipedrive/note.rb @@ -2,7 +2,7 @@ module Pipedrive class Note < Base class << self - end + end -end \ No newline at end of file +end diff --git a/lib/pipedrive/organization.rb b/lib/pipedrive/organization.rb index b1874a7..1c10084 100644 --- a/lib/pipedrive/organization.rb +++ b/lib/pipedrive/organization.rb @@ -16,5 +16,6 @@ def find_or_create_by_name(name, opts={}) end end + end end diff --git a/lib/pipedrive/permission-set.rb b/lib/pipedrive/permission-set.rb index dfa1453..5116df4 100644 --- a/lib/pipedrive/permission-set.rb +++ b/lib/pipedrive/permission-set.rb @@ -1,4 +1,4 @@ module Pipedrive class PermissionSet < Base end -end \ No newline at end of file +end diff --git a/lib/pipedrive/person.rb b/lib/pipedrive/person.rb index 87a3186..8d32b51 100644 --- a/lib/pipedrive/person.rb +++ b/lib/pipedrive/person.rb @@ -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 \ No newline at end of file +end diff --git a/lib/pipedrive/pipeline.rb b/lib/pipedrive/pipeline.rb index ba7e6f7..394a6df 100644 --- a/lib/pipedrive/pipeline.rb +++ b/lib/pipedrive/pipeline.rb @@ -1,5 +1,6 @@ module Pipedrive class Pipeline < Base + def stages Stage.all(get "/stages", { :pipeline_id => self.id }) end @@ -7,11 +8,12 @@ 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,{: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 \ No newline at end of file +end diff --git a/lib/pipedrive/product-field.rb b/lib/pipedrive/product-field.rb index 57a3f80..f7cfdcc 100644 --- a/lib/pipedrive/product-field.rb +++ b/lib/pipedrive/product-field.rb @@ -1,4 +1,4 @@ module Pipedrive class ProductField < Base end -end \ No newline at end of file +end diff --git a/lib/pipedrive/push-notification.rb b/lib/pipedrive/push-notification.rb index c6d5293..7e17332 100644 --- a/lib/pipedrive/push-notification.rb +++ b/lib/pipedrive/push-notification.rb @@ -1,4 +1,4 @@ module Pipedrive class PushNotification < Base end -end \ No newline at end of file +end diff --git a/lib/pipedrive/role.rb b/lib/pipedrive/role.rb index 06e27c8..141c52f 100644 --- a/lib/pipedrive/role.rb +++ b/lib/pipedrive/role.rb @@ -1,4 +1,4 @@ module Pipedrive class Role < Base end -end \ No newline at end of file +end diff --git a/lib/pipedrive/search-result.rb b/lib/pipedrive/search-result.rb index cbb0f88..fc291ae 100644 --- a/lib/pipedrive/search-result.rb +++ b/lib/pipedrive/search-result.rb @@ -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 \ No newline at end of file +end diff --git a/lib/pipedrive/user-connection.rb b/lib/pipedrive/user-connection.rb index df96577..529addf 100644 --- a/lib/pipedrive/user-connection.rb +++ b/lib/pipedrive/user-connection.rb @@ -1,4 +1,4 @@ module Pipedrive class UserConnection < Base end -end \ No newline at end of file +end diff --git a/lib/pipedrive/user-setting.rb b/lib/pipedrive/user-setting.rb index 896f258..f3329d9 100644 --- a/lib/pipedrive/user-setting.rb +++ b/lib/pipedrive/user-setting.rb @@ -1,4 +1,4 @@ module Pipedrive class UserSetting < Base end -end \ No newline at end of file +end diff --git a/lib/pipedrive/user.rb b/lib/pipedrive/user.rb index e4aee4a..a74afae 100644 --- a/lib/pipedrive/user.rb +++ b/lib/pipedrive/user.rb @@ -1,4 +1,4 @@ module Pipedrive class User < Base end -end \ No newline at end of file +end diff --git a/test/test_pipedrive_authentication.rb b/test/test_pipedrive_authentication.rb index f04c36a..838c3f0 100644 --- a/test/test_pipedrive_authentication.rb +++ b/test/test_pipedrive_authentication.rb @@ -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("/") diff --git a/test/test_pipedrive_deal.rb b/test/test_pipedrive_deal.rb index 4f7ee9b..00a0e12 100644 --- a/test/test_pipedrive_deal.rb +++ b/test/test_pipedrive_deal.rb @@ -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, @@ -45,4 +45,4 @@ def setup #TODO # flunk "to be tested" end -end \ No newline at end of file +end diff --git a/test/test_pipedrive_note.rb b/test/test_pipedrive_note.rb index 848997c..114a2e1 100644 --- a/test/test_pipedrive_note.rb +++ b/test/test_pipedrive_note.rb @@ -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, diff --git a/test/test_pipedrive_organization.rb b/test/test_pipedrive_organization.rb index 1e9dc86..26b6254 100644 --- a/test/test_pipedrive_organization.rb +++ b/test/test_pipedrive_organization.rb @@ -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, diff --git a/test/test_pipedrive_person.rb b/test/test_pipedrive_person.rb index 80df000..bca9304 100644 --- a/test/test_pipedrive_person.rb +++ b/test/test_pipedrive_person.rb @@ -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,