pipedrive-api-client 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/Gemfile +20 -0
- data/Gemfile.lock +71 -0
- data/README.md +44 -0
- data/Rakefile +45 -0
- data/VERSION +1 -0
- data/lib/pipedrive-api-client.rb +34 -0
- data/lib/pipedrive/activity-type.rb +4 -0
- data/lib/pipedrive/activity.rb +4 -0
- data/lib/pipedrive/authorization.rb +4 -0
- data/lib/pipedrive/base.rb +134 -0
- data/lib/pipedrive/currency.rb +4 -0
- data/lib/pipedrive/deal-field.rb +4 -0
- data/lib/pipedrive/deal.rb +31 -0
- data/lib/pipedrive/file.rb +4 -0
- data/lib/pipedrive/filter.rb +4 -0
- data/lib/pipedrive/goal.rb +4 -0
- data/lib/pipedrive/note.rb +8 -0
- data/lib/pipedrive/organization-field.rb +4 -0
- data/lib/pipedrive/organization.rb +20 -0
- data/lib/pipedrive/permission-set.rb +4 -0
- data/lib/pipedrive/person-field.rb +4 -0
- data/lib/pipedrive/person.rb +16 -0
- data/lib/pipedrive/pipeline.rb +17 -0
- data/lib/pipedrive/product-field.rb +4 -0
- data/lib/pipedrive/product.rb +4 -0
- data/lib/pipedrive/push-notification.rb +4 -0
- data/lib/pipedrive/role.rb +4 -0
- data/lib/pipedrive/search-result.rb +28 -0
- data/lib/pipedrive/stage.rb +7 -0
- data/lib/pipedrive/user-connection.rb +4 -0
- data/lib/pipedrive/user-setting.rb +4 -0
- data/lib/pipedrive/user.rb +4 -0
- data/pipedrive-api-client.gemspec +111 -0
- data/test/data/create_deal_body.json +40 -0
- data/test/data/create_note_body.json +25 -0
- data/test/data/create_organization_body.json +30 -0
- data/test/data/create_person_body.json +49 -0
- data/test/data/create_stages_body.json +70 -0
- data/test/helper.rb +24 -0
- data/test/test_pipedrive_authentication.rb +21 -0
- data/test/test_pipedrive_deal.rb +48 -0
- data/test/test_pipedrive_note.rb +45 -0
- data/test/test_pipedrive_organization.rb +42 -0
- data/test/test_pipedrive_person.rb +47 -0
- data/test/test_pipedrive_stage.rb +40 -0
- metadata +233 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA1:
         | 
| 3 | 
            +
              metadata.gz: a03f3fca313457dfd86f8824ebd9d5f53a6c5631
         | 
| 4 | 
            +
              data.tar.gz: e4b3a357a77d37f6c75a1418bab512513dbfd999
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: 8a628b0c344994b9c546bb851a6e2fdb78694e491d1c0cd9cf61088f22d433e29a90af00f687d1abe5bcd5e241868929e5826d4268f7ebbe6c75e8f80b05f381
         | 
| 7 | 
            +
              data.tar.gz: 4afe74d5f8f9202adf10a3d4b3fdfbfff2ee1bc031f6ac83a0a9c780a90747d12bd5a6564c183203cdbdcbbd1dea39a255f6b009574114e737068ba7a8843739
         | 
    
        data/.document
    ADDED
    
    
    
        data/Gemfile
    ADDED
    
    | @@ -0,0 +1,20 @@ | |
| 1 | 
            +
            source "http://rubygems.org"
         | 
| 2 | 
            +
            # Add dependencies required to use your gem here.
         | 
| 3 | 
            +
            # Example:
         | 
| 4 | 
            +
            #   gem "activesupport", ">= 2.3.5"
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            gem 'httparty'
         | 
| 7 | 
            +
            gem 'json', '>= 1.7.7'
         | 
| 8 | 
            +
            gem 'multi_xml', '>= 0.5.2'
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            # Add dependencies to develop your gem here.
         | 
| 11 | 
            +
            # Include everything needed to run rake, tests, features, etc.
         | 
| 12 | 
            +
            group :development do
         | 
| 13 | 
            +
              gem "shoulda", ">= 0"
         | 
| 14 | 
            +
              gem "rdoc", "~> 3.12"
         | 
| 15 | 
            +
              gem "bundler", ">= 1.0.0"
         | 
| 16 | 
            +
              gem "jeweler", ">= 1.8.4"
         | 
| 17 | 
            +
              gem "simplecov", ">= 0"
         | 
| 18 | 
            +
              gem 'webmock'
         | 
| 19 | 
            +
              gem 'coveralls', :require => false
         | 
| 20 | 
            +
            end
         | 
    
        data/Gemfile.lock
    ADDED
    
    | @@ -0,0 +1,71 @@ | |
| 1 | 
            +
            GEM
         | 
| 2 | 
            +
              remote: http://rubygems.org/
         | 
| 3 | 
            +
              specs:
         | 
| 4 | 
            +
                activesupport (3.2.12)
         | 
| 5 | 
            +
                  i18n (~> 0.6)
         | 
| 6 | 
            +
                  multi_json (~> 1.0)
         | 
| 7 | 
            +
                addressable (2.3.4)
         | 
| 8 | 
            +
                bourne (1.1.2)
         | 
| 9 | 
            +
                  mocha (= 0.10.5)
         | 
| 10 | 
            +
                colorize (0.5.8)
         | 
| 11 | 
            +
                coveralls (0.6.7)
         | 
| 12 | 
            +
                  colorize
         | 
| 13 | 
            +
                  multi_json (~> 1.3)
         | 
| 14 | 
            +
                  rest-client
         | 
| 15 | 
            +
                  simplecov (>= 0.7)
         | 
| 16 | 
            +
                  thor
         | 
| 17 | 
            +
                crack (0.4.0)
         | 
| 18 | 
            +
                  safe_yaml (~> 0.9.0)
         | 
| 19 | 
            +
                git (1.2.5)
         | 
| 20 | 
            +
                httparty (0.10.2)
         | 
| 21 | 
            +
                  multi_json (~> 1.0)
         | 
| 22 | 
            +
                  multi_xml (>= 0.5.2)
         | 
| 23 | 
            +
                i18n (0.6.4)
         | 
| 24 | 
            +
                jeweler (1.8.4)
         | 
| 25 | 
            +
                  bundler (~> 1.0)
         | 
| 26 | 
            +
                  git (>= 1.2.5)
         | 
| 27 | 
            +
                  rake
         | 
| 28 | 
            +
                  rdoc
         | 
| 29 | 
            +
                json (1.7.7)
         | 
| 30 | 
            +
                metaclass (0.0.1)
         | 
| 31 | 
            +
                mime-types (1.24)
         | 
| 32 | 
            +
                mocha (0.10.5)
         | 
| 33 | 
            +
                  metaclass (~> 0.0.1)
         | 
| 34 | 
            +
                multi_json (1.6.1)
         | 
| 35 | 
            +
                multi_xml (0.5.3)
         | 
| 36 | 
            +
                rake (10.0.3)
         | 
| 37 | 
            +
                rdoc (3.12.2)
         | 
| 38 | 
            +
                  json (~> 1.4)
         | 
| 39 | 
            +
                rest-client (1.6.7)
         | 
| 40 | 
            +
                  mime-types (>= 1.16)
         | 
| 41 | 
            +
                safe_yaml (0.9.3)
         | 
| 42 | 
            +
                shoulda (3.3.2)
         | 
| 43 | 
            +
                  shoulda-context (~> 1.0.1)
         | 
| 44 | 
            +
                  shoulda-matchers (~> 1.4.1)
         | 
| 45 | 
            +
                shoulda-context (1.0.2)
         | 
| 46 | 
            +
                shoulda-matchers (1.4.2)
         | 
| 47 | 
            +
                  activesupport (>= 3.0.0)
         | 
| 48 | 
            +
                  bourne (~> 1.1.2)
         | 
| 49 | 
            +
                simplecov (0.7.1)
         | 
| 50 | 
            +
                  multi_json (~> 1.0)
         | 
| 51 | 
            +
                  simplecov-html (~> 0.7.1)
         | 
| 52 | 
            +
                simplecov-html (0.7.1)
         | 
| 53 | 
            +
                thor (0.18.1)
         | 
| 54 | 
            +
                webmock (1.11.0)
         | 
| 55 | 
            +
                  addressable (>= 2.2.7)
         | 
| 56 | 
            +
                  crack (>= 0.3.2)
         | 
| 57 | 
            +
             | 
| 58 | 
            +
            PLATFORMS
         | 
| 59 | 
            +
              ruby
         | 
| 60 | 
            +
             | 
| 61 | 
            +
            DEPENDENCIES
         | 
| 62 | 
            +
              bundler (>= 1.0.0)
         | 
| 63 | 
            +
              coveralls
         | 
| 64 | 
            +
              httparty
         | 
| 65 | 
            +
              jeweler (>= 1.8.4)
         | 
| 66 | 
            +
              json (>= 1.7.7)
         | 
| 67 | 
            +
              multi_xml (>= 0.5.2)
         | 
| 68 | 
            +
              rdoc (~> 3.12)
         | 
| 69 | 
            +
              shoulda
         | 
| 70 | 
            +
              simplecov
         | 
| 71 | 
            +
              webmock
         | 
    
        data/README.md
    ADDED
    
    | @@ -0,0 +1,44 @@ | |
| 1 | 
            +
            # pipedrive-api-client
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            ## Credits
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            This gem is based on pipedrive-ruby by @GeneralScripting. Since that gem doesn't seem active anymore and the PR's don't get merged I created this one and implemented some of the PR's needed to use the Pipedrive API. 
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            ## Installation
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                gem install pipedrive-api-client
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            ## Usage
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                require 'pipedrive-api-client'
         | 
| 14 | 
            +
                Pipedrive.authenticate( YOUR_API_TOKEN )
         | 
| 15 | 
            +
                Pipedrive::Deal.find( DEAL_ID )
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            ## API Calls
         | 
| 18 | 
            +
                Pipedrive::Deal.create( params )
         | 
| 19 | 
            +
                Pipedrive::Deal.find( <ID> )
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                Pipedrive::Organization.create( params )
         | 
| 22 | 
            +
                Pipedrive::Organization.find( <ID> )
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                Pipedrive::Person.create( params )
         | 
| 25 | 
            +
                Pipedrive::Person.find( <ID >)
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                Pipedrive::Note.create( params )
         | 
| 28 | 
            +
             | 
| 29 | 
            +
            You can check some of the calls at https://developers.pipedrive.com/v1
         | 
| 30 | 
            +
             | 
| 31 | 
            +
             | 
| 32 | 
            +
            ## Contributing to pipedrive-api-client
         | 
| 33 | 
            +
             | 
| 34 | 
            +
            * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
         | 
| 35 | 
            +
            * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
         | 
| 36 | 
            +
            * Fork the project.
         | 
| 37 | 
            +
            * Start a feature/bugfix branch.
         | 
| 38 | 
            +
            * Commit and push until you are happy with your contribution.
         | 
| 39 | 
            +
            * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
         | 
| 40 | 
            +
            * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
         | 
| 41 | 
            +
             | 
| 42 | 
            +
            ## License
         | 
| 43 | 
            +
             | 
| 44 | 
            +
            This gem is released under the [MIT License](http://www.opensource.org/licenses/MIT).
         | 
    
        data/Rakefile
    ADDED
    
    | @@ -0,0 +1,45 @@ | |
| 1 | 
            +
            # encoding: utf-8
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'rubygems'
         | 
| 4 | 
            +
            require 'bundler'
         | 
| 5 | 
            +
            begin
         | 
| 6 | 
            +
              Bundler.setup(:default, :development)
         | 
| 7 | 
            +
            rescue Bundler::BundlerError => e
         | 
| 8 | 
            +
              $stderr.puts e.message
         | 
| 9 | 
            +
              $stderr.puts "Run `bundle install` to install missing gems"
         | 
| 10 | 
            +
              exit e.status_code
         | 
| 11 | 
            +
            end
         | 
| 12 | 
            +
            require 'rake'
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            require 'jeweler'
         | 
| 15 | 
            +
            Jeweler::Tasks.new do |gem|
         | 
| 16 | 
            +
              # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
         | 
| 17 | 
            +
              gem.name = "pipedrive-api-client"
         | 
| 18 | 
            +
              gem.homepage = "https://github.com/boena/pipedrive-api-client.git"
         | 
| 19 | 
            +
              gem.license = "MIT"
         | 
| 20 | 
            +
              gem.summary = %Q{Ruby wrapper for the Pipedrive API}
         | 
| 21 | 
            +
              gem.description = %Q{Ruby wrapper for the Pipedrive API}
         | 
| 22 | 
            +
              gem.email = "bjorn@ratherunique.se"
         | 
| 23 | 
            +
              gem.authors = ["Björn Lennartsson", "Jan Schwenzien", "Waldemar Kusnezow", "Joel Courtney"]
         | 
| 24 | 
            +
              # dependencies defined in Gemfile
         | 
| 25 | 
            +
            end
         | 
| 26 | 
            +
            Jeweler::RubygemsDotOrgTasks.new
         | 
| 27 | 
            +
             | 
| 28 | 
            +
            require 'rake/testtask'
         | 
| 29 | 
            +
            Rake::TestTask.new(:test) do |test|
         | 
| 30 | 
            +
              test.libs << 'lib' << 'test'
         | 
| 31 | 
            +
              test.pattern = 'test/**/test_*.rb'
         | 
| 32 | 
            +
              test.verbose = true
         | 
| 33 | 
            +
            end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
            task :default => :test
         | 
| 36 | 
            +
             | 
| 37 | 
            +
            require 'rdoc/task'
         | 
| 38 | 
            +
            Rake::RDocTask.new do |rdoc|
         | 
| 39 | 
            +
              version = File.exist?('VERSION') ? File.read('VERSION') : ""
         | 
| 40 | 
            +
             | 
| 41 | 
            +
              rdoc.rdoc_dir = 'rdoc'
         | 
| 42 | 
            +
              rdoc.title = "pipedrive-api-client #{version}"
         | 
| 43 | 
            +
              rdoc.rdoc_files.include('README*')
         | 
| 44 | 
            +
              rdoc.rdoc_files.include('lib/**/*.rb')
         | 
| 45 | 
            +
            end
         | 
    
        data/VERSION
    ADDED
    
    | @@ -0,0 +1 @@ | |
| 1 | 
            +
            0.3.4
         | 
| @@ -0,0 +1,34 @@ | |
| 1 | 
            +
            require 'pipedrive/base'
         | 
| 2 | 
            +
            require 'pipedrive/activity'
         | 
| 3 | 
            +
            require 'pipedrive/activity-type'
         | 
| 4 | 
            +
            require 'pipedrive/authorization'
         | 
| 5 | 
            +
            require 'pipedrive/currency'
         | 
| 6 | 
            +
            require 'pipedrive/deal'
         | 
| 7 | 
            +
            require 'pipedrive/deal-field'
         | 
| 8 | 
            +
            require 'pipedrive/file'
         | 
| 9 | 
            +
            require 'pipedrive/filter'
         | 
| 10 | 
            +
            require 'pipedrive/note'
         | 
| 11 | 
            +
            require 'pipedrive/organization'
         | 
| 12 | 
            +
            require 'pipedrive/person'
         | 
| 13 | 
            +
            require 'pipedrive/organization-field'
         | 
| 14 | 
            +
            require 'pipedrive/person-field'
         | 
| 15 | 
            +
            require 'pipedrive/permission-set'
         | 
| 16 | 
            +
            require 'pipedrive/pipeline'
         | 
| 17 | 
            +
            require 'pipedrive/product'
         | 
| 18 | 
            +
            require 'pipedrive/product-field'
         | 
| 19 | 
            +
            require 'pipedrive/role'
         | 
| 20 | 
            +
            require 'pipedrive/search-result'
         | 
| 21 | 
            +
            require 'pipedrive/stage'
         | 
| 22 | 
            +
            require 'pipedrive/user'
         | 
| 23 | 
            +
            require 'pipedrive/user-setting'
         | 
| 24 | 
            +
            require 'pipedrive/goal'
         | 
| 25 | 
            +
            require 'pipedrive/user-connection'
         | 
| 26 | 
            +
            require 'pipedrive/push-notification'
         | 
| 27 | 
            +
             | 
| 28 | 
            +
            module Pipedrive
         | 
| 29 | 
            +
             | 
| 30 | 
            +
              def self.authenticate(token)
         | 
| 31 | 
            +
                Base.authenticate(token)
         | 
| 32 | 
            +
              end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
            end
         | 
| @@ -0,0 +1,134 @@ | |
| 1 | 
            +
            require 'httparty'
         | 
| 2 | 
            +
            require 'ostruct'
         | 
| 3 | 
            +
            require 'forwardable'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            module Pipedrive
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              # Globally set request headers
         | 
| 8 | 
            +
              HEADERS = {
         | 
| 9 | 
            +
                "User-Agent"    => "Ruby.Pipedrive.Api",
         | 
| 10 | 
            +
                "Accept"        => "application/json",
         | 
| 11 | 
            +
                "Content-Type"  => "application/x-www-form-urlencoded"
         | 
| 12 | 
            +
              }
         | 
| 13 | 
            +
             | 
| 14 | 
            +
              # Base class for setting HTTParty configurations globally
         | 
| 15 | 
            +
              class Base < OpenStruct
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                include HTTParty
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                base_uri 'https://api.pipedrive.com/v1'
         | 
| 20 | 
            +
                headers HEADERS
         | 
| 21 | 
            +
                format :json
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                extend Forwardable
         | 
| 24 | 
            +
                def_delegators 'self.class', :delete, :get, :post, :put, :resource_path, :bad_response
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                attr_reader :data
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                # Create a new Pipedrive::Base object.
         | 
| 29 | 
            +
                #
         | 
| 30 | 
            +
                # Only used internally
         | 
| 31 | 
            +
                #
         | 
| 32 | 
            +
                # @param [Hash] attributes
         | 
| 33 | 
            +
                # @return [Pipedrive::Base]
         | 
| 34 | 
            +
                def initialize(attrs = {})
         | 
| 35 | 
            +
                  if attrs['data']
         | 
| 36 | 
            +
                    struct_attrs = attrs['data']
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                    if attrs['additional_data']
         | 
| 39 | 
            +
                      struct_attrs.merge!(attrs['additional_data'])
         | 
| 40 | 
            +
                    end
         | 
| 41 | 
            +
                  else
         | 
| 42 | 
            +
                    struct_attrs = attrs
         | 
| 43 | 
            +
                  end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                  super(struct_attrs)
         | 
| 46 | 
            +
                end
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                # Updates the object.
         | 
| 49 | 
            +
                #
         | 
| 50 | 
            +
                # @param [Hash] opts
         | 
| 51 | 
            +
                # @return [Boolean]
         | 
| 52 | 
            +
                def update(opts = {})
         | 
| 53 | 
            +
                  res = put "#{resource_path}/#{id}", :body => opts
         | 
| 54 | 
            +
                  if res.success?
         | 
| 55 | 
            +
                    res['data'] = Hash[res['data'].map {|k, v| [k.to_sym, v] }]
         | 
| 56 | 
            +
                    @table.merge!(res['data'])
         | 
| 57 | 
            +
                  else
         | 
| 58 | 
            +
                    false
         | 
| 59 | 
            +
                  end
         | 
| 60 | 
            +
                end
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                class << self
         | 
| 63 | 
            +
                  # Sets the authentication credentials in a class variable.
         | 
| 64 | 
            +
                  #
         | 
| 65 | 
            +
                  # @param [String] email cl.ly email
         | 
| 66 | 
            +
                  # @param [String] password cl.ly password
         | 
| 67 | 
            +
                  # @return [Hash] authentication credentials
         | 
| 68 | 
            +
                  def authenticate(token)
         | 
| 69 | 
            +
                    default_params :api_token => token
         | 
| 70 | 
            +
                  end
         | 
| 71 | 
            +
             | 
| 72 | 
            +
                  # Examines a bad response and raises an appropriate exception
         | 
| 73 | 
            +
                  #
         | 
| 74 | 
            +
                  # @param [HTTParty::Response] response
         | 
| 75 | 
            +
                  def bad_response(response, params={})
         | 
| 76 | 
            +
                    if response.class == HTTParty::Response
         | 
| 77 | 
            +
                      raise HTTParty::ResponseError, response
         | 
| 78 | 
            +
                    end
         | 
| 79 | 
            +
                    raise StandardError, 'Unknown error'
         | 
| 80 | 
            +
                  end
         | 
| 81 | 
            +
             | 
| 82 | 
            +
                  def new_list( attrs )
         | 
| 83 | 
            +
                    attrs['data'].is_a?(Array) ? attrs['data'].map {|data| self.new( 'data' => data ) } : []
         | 
| 84 | 
            +
                  end
         | 
| 85 | 
            +
             | 
| 86 | 
            +
                  def all(response = nil, options = {}, get_absolutely_all = false)
         | 
| 87 | 
            +
                    res = response || get(resource_path, options)
         | 
| 88 | 
            +
                    if res.ok?
         | 
| 89 | 
            +
                      data = res['data'].nil? ? [] : res['data'].map{|obj| new(obj)}
         | 
| 90 | 
            +
                      if get_absolutely_all && has_pagination?(res)
         | 
| 91 | 
            +
                        options[:query] = options[:query].merge({:start => res['additional_data']['pagination']['next_start']})
         | 
| 92 | 
            +
                        data += self.all(nil,options,true)
         | 
| 93 | 
            +
                      end
         | 
| 94 | 
            +
                      data
         | 
| 95 | 
            +
                    else
         | 
| 96 | 
            +
                      bad_response(res, options)
         | 
| 97 | 
            +
                    end
         | 
| 98 | 
            +
                  end
         | 
| 99 | 
            +
             | 
| 100 | 
            +
                  def has_pagination?(res)
         | 
| 101 | 
            +
                    res['additional_data'] && res['additional_data']['pagination'] && res['additional_data']['pagination']['more_items_in_collection']
         | 
| 102 | 
            +
                  end
         | 
| 103 | 
            +
             | 
| 104 | 
            +
                  def create( opts = {} )
         | 
| 105 | 
            +
                    res = post resource_path, :body => opts
         | 
| 106 | 
            +
                    if res.success?
         | 
| 107 | 
            +
                      res['data'] = opts.merge res['data']
         | 
| 108 | 
            +
                      new(res)
         | 
| 109 | 
            +
                    else
         | 
| 110 | 
            +
                      bad_response(res,opts)
         | 
| 111 | 
            +
                    end
         | 
| 112 | 
            +
                  end
         | 
| 113 | 
            +
             | 
| 114 | 
            +
                  def find(id)
         | 
| 115 | 
            +
                    res = get "#{resource_path}/#{id}"
         | 
| 116 | 
            +
                    res.ok? ? new(res) : bad_response(res,id)
         | 
| 117 | 
            +
                  end
         | 
| 118 | 
            +
             | 
| 119 | 
            +
                  def find_by_name(name, opts={})
         | 
| 120 | 
            +
                    res = get "#{resource_path}/find", :query => { :term => name }.merge(opts)
         | 
| 121 | 
            +
                    res.ok? ? new_list(res) : bad_response(res,{:name => name}.merge(opts))
         | 
| 122 | 
            +
                  end
         | 
| 123 | 
            +
             | 
| 124 | 
            +
                  def resource_path
         | 
| 125 | 
            +
                    # The resource path should match the camelCased class name with the
         | 
| 126 | 
            +
                    # first letter downcased.  Pipedrive API is sensitive to capitalisation
         | 
| 127 | 
            +
                    klass = name.split('::').last
         | 
| 128 | 
            +
                    klass[0] = klass[0].chr.downcase
         | 
| 129 | 
            +
                    klass.end_with?('y') ? "/#{klass.chop}ies" : "/#{klass}s"
         | 
| 130 | 
            +
                  end
         | 
| 131 | 
            +
                end
         | 
| 132 | 
            +
              end
         | 
| 133 | 
            +
             | 
| 134 | 
            +
            end
         | 
| @@ -0,0 +1,31 @@ | |
| 1 | 
            +
            module Pipedrive
         | 
| 2 | 
            +
              class Deal < Base
         | 
| 3 | 
            +
             | 
| 4 | 
            +
                def add_product(opts = {})
         | 
| 5 | 
            +
                  res = post "#{resource_path}/#{id}/products", :body => opts
         | 
| 6 | 
            +
                  res.success? ? res['data']['product_attachment_id'] : bad_response(res,opts)
         | 
| 7 | 
            +
                end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                def products
         | 
| 10 | 
            +
                  Product.all(get "#{resource_path}/#{id}/products")
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
                
         | 
| 13 | 
            +
                def remove_product product_attachment_id
         | 
| 14 | 
            +
                  res = delete "#{resource_path}/#{id}/products", { :body => { :product_attachment_id => product_attachment_id } }
         | 
| 15 | 
            +
                  res.success? ? nil : bad_response(res,product_attachment_id)
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                def activities
         | 
| 19 | 
            +
                  Activity.all(get "#{resource_path}/#{id}/activities")
         | 
| 20 | 
            +
                end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                def files
         | 
| 23 | 
            +
                  File.all(get "#{resource_path}/#{id}/files")
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                def notes(opts = {:sort_by => 'add_time', :sort_mode => 'desc'})
         | 
| 27 | 
            +
                  Note.all( get("/notes", :query => opts.merge(:deal_id => id) ) )
         | 
| 28 | 
            +
                end
         | 
| 29 | 
            +
                
         | 
| 30 | 
            +
              end
         | 
| 31 | 
            +
            end
         |