pipedrive-adhit 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/Gemfile +20 -0
  4. data/Gemfile.lock +71 -0
  5. data/README.md +45 -0
  6. data/Rakefile +45 -0
  7. data/VERSION +1 -0
  8. data/lib/pipedrive/activity-type.rb +4 -0
  9. data/lib/pipedrive/activity.rb +4 -0
  10. data/lib/pipedrive/authorization.rb +4 -0
  11. data/lib/pipedrive/base.rb +134 -0
  12. data/lib/pipedrive/currency.rb +4 -0
  13. data/lib/pipedrive/deal-field.rb +4 -0
  14. data/lib/pipedrive/deal.rb +31 -0
  15. data/lib/pipedrive/file.rb +4 -0
  16. data/lib/pipedrive/filter.rb +4 -0
  17. data/lib/pipedrive/goal.rb +4 -0
  18. data/lib/pipedrive/note.rb +8 -0
  19. data/lib/pipedrive/organization-field.rb +4 -0
  20. data/lib/pipedrive/organization.rb +20 -0
  21. data/lib/pipedrive/permission-set.rb +4 -0
  22. data/lib/pipedrive/person-field.rb +4 -0
  23. data/lib/pipedrive/person.rb +16 -0
  24. data/lib/pipedrive/pipeline.rb +17 -0
  25. data/lib/pipedrive/product-field.rb +4 -0
  26. data/lib/pipedrive/product.rb +4 -0
  27. data/lib/pipedrive/push-notification.rb +4 -0
  28. data/lib/pipedrive/role.rb +4 -0
  29. data/lib/pipedrive/search-result.rb +28 -0
  30. data/lib/pipedrive/stage.rb +7 -0
  31. data/lib/pipedrive/user-connection.rb +4 -0
  32. data/lib/pipedrive/user-setting.rb +4 -0
  33. data/lib/pipedrive/user.rb +4 -0
  34. data/lib/pipedrive-ruby.rb +34 -0
  35. data/pipedrive-ruby.gemspec +109 -0
  36. data/test/data/create_deal_body.json +40 -0
  37. data/test/data/create_note_body.json +25 -0
  38. data/test/data/create_organization_body.json +30 -0
  39. data/test/data/create_person_body.json +49 -0
  40. data/test/helper.rb +24 -0
  41. data/test/test_pipedrive_authentication.rb +21 -0
  42. data/test/test_pipedrive_deal.rb +48 -0
  43. data/test/test_pipedrive_note.rb +45 -0
  44. data/test/test_pipedrive_organization.rb +42 -0
  45. data/test/test_pipedrive_person.rb +47 -0
  46. metadata +230 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 41071b676acf940661435d1590afc73c63485996
4
+ data.tar.gz: 974e2ca18dcb8e954b8b886d10e151af275c280f
5
+ SHA512:
6
+ metadata.gz: bbb5e3817cd082e2616d10b71b03ab5fc095f4e9e243692036c1a710860f14e8701917199c43347e710bba68b9b219b5779407a7c44b7048c10ca83d84ee07d9
7
+ data.tar.gz: 55c5450b2bd28f77a58ac38a2e75f7a41db30598ef8656e1c6b8afea204c3c1f24a3649c14bd65ca06f91f56add187282135bde8930d6003017abc16cdbfd84f
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
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
+ gem 'webmock'
10
+ gem 'coveralls', :require => false
11
+
12
+ # Add dependencies to develop your gem here.
13
+ # Include everything needed to run rake, tests, features, etc.
14
+ group :development do
15
+ gem "shoulda", ">= 0"
16
+ gem "rdoc", "~> 3.12"
17
+ gem "bundler", ">= 1.0.0"
18
+ gem "jeweler", ">= 1.8.4"
19
+ gem "simplecov", ">= 0"
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,45 @@
1
+ # pipedrive-ruby
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/pipedrive-ruby.png)](http://badge.fury.io/rb/pipedrive-ruby)
4
+ [![Code Climate](https://codeclimate.com/github/GeneralScripting/pipedrive-ruby.png)](https://codeclimate.com/github/GeneralScripting/pipedrive-ruby)
5
+ [![Build Status](https://travis-ci.org/GeneralScripting/pipedrive-ruby.png?branch=master)](https://travis-ci.org/GeneralScripting/pipedrive-ruby)
6
+ [![Coverage Status](https://coveralls.io/repos/GeneralScripting/pipedrive-ruby/badge.png?branch=master)](https://coveralls.io/r/GeneralScripting/pipedrive-ruby?branch=master)
7
+
8
+ ## Installation
9
+
10
+ gem install pipedrive-ruby
11
+
12
+ ## Usage
13
+
14
+ require 'pipedrive-ruby'
15
+ Pipedrive.authenticate( YOUR_API_TOKEN )
16
+ Pipedrive::Deal.find( DEAL_ID )
17
+
18
+ ## API Calls
19
+ Pipedrive::Deal.create( params )
20
+ Pipedrive::Deal.find( <ID> )
21
+
22
+ Pipedrive::Organization.create( params )
23
+ Pipedrive::Organization.find( <ID> )
24
+
25
+ Pipedrive::Person.create( params )
26
+ Pipedrive::Person.find( <ID >)
27
+
28
+ Pipedrive::Note.create( params )
29
+
30
+ You can check some of the calls at https://developers.pipedrive.com/v1
31
+
32
+
33
+ ## Contributing to pipedrive-ruby
34
+
35
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
36
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
37
+ * Fork the project.
38
+ * Start a feature/bugfix branch.
39
+ * Commit and push until you are happy with your contribution.
40
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
41
+ * 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.
42
+
43
+ ## License
44
+
45
+ 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-ruby"
18
+ gem.homepage = "https://github.com/GeneralScripting/pipedrive-ruby.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 = "jan@general-scripting.com"
23
+ gem.authors = ["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-rails #{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,4 @@
1
+ module Pipedrive
2
+ class ActivityType < Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Pipedrive
2
+ class Activity < Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Pipedrive
2
+ class Authorization < Base
3
+ end
4
+ 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
+ puts params.inspect
77
+ if response.class == HTTParty::Response
78
+ raise HTTParty::ResponseError, response
79
+ end
80
+ raise StandardError, 'Unknown error'
81
+ end
82
+
83
+ def new_list( attrs )
84
+ attrs['data'].is_a?(Array) ? attrs['data'].map {|data| self.new( 'data' => data ) } : []
85
+ end
86
+
87
+ def all(response = nil, options={},get_absolutely_all=false)
88
+ res = response || get(resource_path, options)
89
+ if res.ok?
90
+ data = res['data'].nil? ? [] : res['data'].map{|obj| new(obj)}
91
+ if get_absolutely_all && res['additional_data']['pagination'] && res['additional_data']['pagination'] && res['additional_data']['pagination']['more_items_in_collection']
92
+ options[:query] = options[:query].merge({:start => res['additional_data']['pagination']['next_start']})
93
+ data += self.all(nil,options,true)
94
+ end
95
+ data
96
+ else
97
+ bad_response(res,options)
98
+ end
99
+ end
100
+
101
+ def create( opts = {} )
102
+ res = post resource_path, :body => opts
103
+ puts res
104
+ if res.success?
105
+ res['data'] = opts.merge res['data']
106
+ new(res)
107
+ else
108
+ puts 'failed to create contact'
109
+ puts res
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,4 @@
1
+ module Pipedrive
2
+ class Currency < Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Pipedrive
2
+ class DealField < Base
3
+ end
4
+ 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
@@ -0,0 +1,4 @@
1
+ module Pipedrive
2
+ class File < Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Pipedrive
2
+ class Filter < Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Pipedrive
2
+ class Goal < Base
3
+ end
4
+ end
@@ -0,0 +1,8 @@
1
+ module Pipedrive
2
+ class Note < Base
3
+
4
+ class << self
5
+
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,4 @@
1
+ module Pipedrive
2
+ class OrganizationField < Base
3
+ end
4
+ end
@@ -0,0 +1,20 @@
1
+ module Pipedrive
2
+ class Organization < Base
3
+
4
+ def persons
5
+ Person.all(get "#{resource_path}/#{id}/persons")
6
+ end
7
+
8
+ def deals
9
+ Deal.all(get "#{resource_path}/#{id}/deals")
10
+ end
11
+
12
+ class << self
13
+
14
+ def find_or_create_by_name(name, opts={})
15
+ find_by_name(name).first || create(opts.merge(:name => name))
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,4 @@
1
+ module Pipedrive
2
+ class PermissionSet < Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Pipedrive
2
+ class PersonField < Base
3
+ end
4
+ end
@@ -0,0 +1,16 @@
1
+ module Pipedrive
2
+ class Person < Base
3
+
4
+ class << self
5
+
6
+ def find_or_create_by_name(name, opts={})
7
+ find_by_name(name, :org_id => opts[:org_id]).first || create(opts.merge(:name => name))
8
+ end
9
+
10
+ end
11
+
12
+ def deals()
13
+ Deal.all(get "#{resource_path}/#{id}/deals", :everyone => 1)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,17 @@
1
+ module Pipedrive
2
+ class Pipeline < Base
3
+ def stages
4
+ Stage.all(get "/stages", { :pipeline_id => self.id })
5
+ end
6
+
7
+ def statistics(id, start_date, end_date)
8
+ res = get("#{resource_path}/#{id}/movement_statistics",
9
+ :query => {:start_date => start_date, :end_date => end_date})
10
+ res.ok? ? new(res) : bad_response(res,{:id=>id,:start_date=>start_date,:end_date=>end_date})
11
+ end
12
+
13
+ def deals(id, stage_id)
14
+ Pipedrive::Deal.all(get "#{resource_path}/#{id}/deals", :stage_id => stage_id )
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,4 @@
1
+ module Pipedrive
2
+ class ProductField < Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Pipedrive
2
+ class Product < Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Pipedrive
2
+ class PushNotification < Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Pipedrive
2
+ class Role < Base
3
+ end
4
+ end
@@ -0,0 +1,28 @@
1
+ module Pipedrive
2
+ class SearchResult < Base
3
+
4
+ # Class Methods
5
+ class << self
6
+
7
+ def search(term, start=0, limit=nil)
8
+ res = get(resource_path, :query => { :term => term, :start => start, :limit => limit})
9
+ if res.ok?
10
+ res['data'].nil? ? [] : res['data'].map{|obj| new(obj)}
11
+ else
12
+ bad_response(res,{:term=>term,:start=>start,:limit=>limit})
13
+ end
14
+ end
15
+
16
+ def field(term, field_type, field_key, opts={})
17
+ res = get("#{resource_path}/field", :query => opts.merge(:term => term, :field_type => field_type, :field_key => field_key) )
18
+ if res.ok?
19
+ res['data'].nil? ? [] : res['data'].map{|obj| new(obj)}
20
+ else
21
+ bad_response(res,{:term=>term,:field_type=>field_type,:field_key=>field_key}.merge(opts))
22
+ end
23
+ end
24
+
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,7 @@
1
+ module Pipedrive
2
+ class Stage < Base
3
+ def self.deals(id)
4
+ Deal.all(get "#{resource_path}/#{id}/deals", :query => {:everyone => 1})
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,4 @@
1
+ module Pipedrive
2
+ class UserConnection < Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Pipedrive
2
+ class UserSetting < Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Pipedrive
2
+ class User < Base
3
+ end
4
+ end
@@ -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