pipedrive.rb 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +98 -10
  3. data/.travis.yml +4 -7
  4. data/Gemfile +4 -6
  5. data/HISTORY.md +43 -0
  6. data/Rakefile +5 -2
  7. data/lib/pipedrive.rb +9 -1
  8. data/lib/pipedrive/activity.rb +2 -0
  9. data/lib/pipedrive/activity_type.rb +2 -0
  10. data/lib/pipedrive/base.rb +14 -11
  11. data/lib/pipedrive/deal.rb +2 -0
  12. data/lib/pipedrive/deal_field.rb +2 -0
  13. data/lib/pipedrive/file.rb +2 -0
  14. data/lib/pipedrive/filter.rb +2 -0
  15. data/lib/pipedrive/goal.rb +2 -0
  16. data/lib/pipedrive/note.rb +2 -0
  17. data/lib/pipedrive/operations/create.rb +2 -0
  18. data/lib/pipedrive/operations/delete.rb +2 -0
  19. data/lib/pipedrive/operations/read.rb +6 -3
  20. data/lib/pipedrive/operations/update.rb +4 -1
  21. data/lib/pipedrive/organization.rb +6 -3
  22. data/lib/pipedrive/organization_field.rb +2 -0
  23. data/lib/pipedrive/person.rb +7 -3
  24. data/lib/pipedrive/person_field.rb +2 -0
  25. data/lib/pipedrive/pipeline.rb +10 -0
  26. data/lib/pipedrive/product.rb +2 -0
  27. data/lib/pipedrive/product_field.rb +2 -0
  28. data/lib/pipedrive/railties.rb +2 -0
  29. data/lib/pipedrive/role.rb +2 -0
  30. data/lib/pipedrive/stage.rb +2 -0
  31. data/lib/pipedrive/user.rb +10 -0
  32. data/lib/pipedrive/utils.rb +6 -4
  33. data/lib/pipedrive/version.rb +3 -1
  34. data/pipedrive.gemspec +12 -8
  35. data/spec/lib/pipedrive/activity_spec.rb +6 -2
  36. data/spec/lib/pipedrive/activity_type_spec.rb +6 -2
  37. data/spec/lib/pipedrive/base_spec.rb +82 -49
  38. data/spec/lib/pipedrive/deal_field_spec.rb +6 -2
  39. data/spec/lib/pipedrive/deal_spec.rb +6 -2
  40. data/spec/lib/pipedrive/file_spec.rb +6 -2
  41. data/spec/lib/pipedrive/filter_spec.rb +6 -2
  42. data/spec/lib/pipedrive/goal_spec.rb +6 -2
  43. data/spec/lib/pipedrive/note_spec.rb +6 -2
  44. data/spec/lib/pipedrive/ogranization_spec.rb +6 -2
  45. data/spec/lib/pipedrive/operations/create_spec.rb +5 -3
  46. data/spec/lib/pipedrive/operations/delete_spec.rb +8 -5
  47. data/spec/lib/pipedrive/operations/read_spec.rb +32 -24
  48. data/spec/lib/pipedrive/operations/update_spec.rb +9 -6
  49. data/spec/lib/pipedrive/organization_field_spec.rb +6 -2
  50. data/spec/lib/pipedrive/person_field_spec.rb +6 -2
  51. data/spec/lib/pipedrive/person_spec.rb +18 -12
  52. data/spec/lib/pipedrive/product_field_spec.rb +6 -2
  53. data/spec/lib/pipedrive/product_spec.rb +6 -2
  54. data/spec/lib/pipedrive_spec.rb +28 -20
  55. data/spec/spec_helper.rb +2 -2
  56. metadata +40 -10
  57. data/Guardfile +0 -24
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Pipedrive
2
4
  class OrganizationField < Base
3
5
  include ::Pipedrive::Operations::Read
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Pipedrive
2
4
  class Person < Base
3
5
  include ::Pipedrive::Operations::Read
@@ -6,13 +8,15 @@ module Pipedrive
6
8
  include ::Pipedrive::Operations::Delete
7
9
  include ::Pipedrive::Utils
8
10
 
9
- def find_by_name(*args)
11
+ def find_by_name(*args, &block)
10
12
  params = args.extract_options!
11
13
  params[:term] ||= args[0]
12
- fail 'term is missing' unless params[:term]
14
+ raise 'term is missing' unless params[:term]
15
+
13
16
  params[:search_by_email] ||= args[1] ? 1 : 0
14
17
  return to_enum(:find_by_name, params) unless block_given?
15
- follow_pagination(:make_api_call, [:get, 'find'], params) { |item| yield item }
18
+
19
+ follow_pagination(:make_api_call, [:get, 'find'], params, &block)
16
20
  end
17
21
  end
18
22
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Pipedrive
2
4
  class PersonField < Base
3
5
  include ::Pipedrive::Operations::Read
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pipedrive
4
+ class Pipeline < Base
5
+ include ::Pipedrive::Operations::Create
6
+ include ::Pipedrive::Operations::Read
7
+ include ::Pipedrive::Operations::Update
8
+ include ::Pipedrive::Operations::Delete
9
+ end
10
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Pipedrive
2
4
  class Product < Base
3
5
  include ::Pipedrive::Operations::Read
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Pipedrive
2
4
  class ProductField < Base
3
5
  include ::Pipedrive::Operations::Read
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Pipedrive
2
4
  class Railties < ::Rails::Railtie
3
5
  initializer 'Pipedrive logger' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Pipedrive
2
4
  class Role < Base
3
5
  include ::Pipedrive::Operations::Create
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Pipedrive
2
4
  class Stage < Base
3
5
  include ::Pipedrive::Operations::Create
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pipedrive
4
+ class User < Base
5
+ include ::Pipedrive::Operations::Create
6
+ include ::Pipedrive::Operations::Read
7
+ include ::Pipedrive::Operations::Update
8
+ include ::Pipedrive::Operations::Delete
9
+ end
10
+ end
@@ -1,16 +1,18 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Pipedrive
2
4
  module Utils
3
5
  extend ActiveSupport::Concern
4
6
 
5
- def follow_pagination(method, args, params)
7
+ def follow_pagination(method, args, params, &block)
6
8
  start = params[:start] || 0
7
9
  loop do
8
10
  res = __send__(method, *args, params.merge(start: start))
9
11
  break if !res.try(:data) || !res.success?
10
- res.data.each do |item|
11
- yield item
12
- end
12
+
13
+ res.data.each(&block)
13
14
  break unless res.try(:additional_data).try(:pagination).try(:more_items_in_collection?)
15
+
14
16
  start = res.try(:additional_data).try(:pagination).try(:next_start)
15
17
  end
16
18
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Pipedrive
2
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
3
5
  end
@@ -1,15 +1,16 @@
1
- # encoding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'pipedrive/version'
5
6
 
6
7
  Gem::Specification.new do |gem|
7
- gem.name = "pipedrive.rb"
8
+ gem.name = 'pipedrive.rb'
8
9
  gem.version = Pipedrive::VERSION
9
- gem.authors = ["Alexander Simonov"]
10
- gem.email = ["alex@amoniac.eu"]
11
- gem.summary = %q{Pipedrive.com API Wrapper}
12
- gem.description = %q{Pipedrive.com API Wrapper}
10
+ gem.authors = ['Alexander Simonov']
11
+ gem.email = ['alex@amoniac.eu']
12
+ gem.summary = 'Pipedrive.com API Wrapper'
13
+ gem.description = 'Pipedrive.com API Wrapper'
13
14
  gem.homepage = 'https://github.com/amoniacou/pipedrive.rb'
14
15
  gem.license = 'MIT'
15
16
 
@@ -17,14 +18,17 @@ Gem::Specification.new do |gem|
17
18
  gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
19
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
20
  gem.require_paths = ['lib']
21
+ gem.required_ruby_version = '>=2.5'
20
22
 
21
23
  gem.add_dependency('activesupport', '>= 4.0.0')
22
24
  gem.add_dependency('faraday')
23
25
  gem.add_dependency('faraday_middleware')
24
26
  gem.add_dependency('hashie', '>= 3.0')
25
27
  gem.add_development_dependency('bundler')
26
- gem.add_development_dependency('rake', '< 12')
28
+ gem.add_development_dependency('rake', '> 12')
27
29
  gem.add_development_dependency('rspec', '>= 3.0')
28
30
  gem.add_development_dependency('rubocop')
31
+ gem.add_development_dependency('rubocop-performance')
32
+ gem.add_development_dependency('rubocop-rspec')
29
33
  gem.add_development_dependency('webmock')
30
34
  end
@@ -1,9 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe ::Pipedrive::Activity do
4
6
  subject { described_class.new('token') }
5
- context '#entity_name' do
7
+
8
+ describe '#entity_name' do
6
9
  subject { super().entity_name }
10
+
7
11
  it { is_expected.to eq('activities') }
8
12
  end
9
- end
13
+ end
@@ -1,9 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe ::Pipedrive::ActivityType do
4
6
  subject { described_class.new('token') }
5
- context '#entity_name' do
7
+
8
+ describe '#entity_name' do
6
9
  subject { super().entity_name }
10
+
7
11
  it { is_expected.to eq('activityTypes') }
8
12
  end
9
- end
13
+ end
@@ -1,120 +1,153 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe ::Pipedrive::Base do
4
6
  subject { described_class.new('token') }
5
- context '#entity_name' do
7
+
8
+ describe '#entity_name' do
6
9
  subject { super().entity_name }
10
+
7
11
  it { is_expected.to eq described_class.name.split('::')[-1].downcase.pluralize }
8
12
  end
9
13
 
10
14
  context '::faraday_options' do
11
15
  subject { described_class.faraday_options }
12
- it { is_expected.to eq({
13
- url: 'https://api.pipedrive.com',
14
- headers: { accept: 'application/json', user_agent: 'Pipedrive Ruby Client v0.1.0' }
15
- }) }
16
+
17
+ it {
18
+ expect(subject).to eq({
19
+ url: 'https://api.pipedrive.com',
20
+ headers: { accept: 'application/json', user_agent: 'Pipedrive Ruby Client v0.2.0' }
21
+ })
22
+ }
16
23
  end
17
24
 
18
25
  context '::connection' do
19
26
  subject { super().connection }
27
+
20
28
  it { is_expected.to be_kind_of(::Faraday::Connection) }
21
29
  end
22
30
 
23
- context '#failed_response' do
24
- let(:res) { double('res', body: ::Hashie::Mash.new({}), status: status) }
31
+ describe '#failed_response' do
25
32
  subject { super().failed_response(res) }
33
+
34
+ let(:res) { double('res', body: ::Hashie::Mash.new({}), status: status) }
35
+
26
36
  context 'status is 401' do
27
37
  let(:status) { 401 }
28
- it { is_expected.to eq(::Hashie::Mash.new({
29
- failed: false,
38
+
39
+ it {
40
+ expect(subject).to eq(::Hashie::Mash.new({
41
+ failed: false,
30
42
  not_authorized: true,
31
43
  success: false
32
- })) }
44
+ }))
45
+ }
33
46
  end
47
+
34
48
  context 'status is 420' do
35
49
  let(:status) { 420 }
36
- it { is_expected.to eq(::Hashie::Mash.new({
37
- failed: true,
50
+
51
+ it {
52
+ expect(subject).to eq(::Hashie::Mash.new({
53
+ failed: true,
38
54
  not_authorized: false,
39
55
  success: false
40
- })) }
56
+ }))
57
+ }
41
58
  end
59
+
42
60
  context 'status is 400' do
43
61
  let(:status) { 400 }
44
- it { is_expected.to eq(::Hashie::Mash.new({
45
- failed: false,
62
+
63
+ it {
64
+ expect(subject).to eq(::Hashie::Mash.new({
65
+ failed: false,
46
66
  not_authorized: false,
47
67
  success: false
48
- })) }
68
+ }))
69
+ }
49
70
  end
50
71
  end
51
- context '#make_api_call' do
52
- it 'should failed no method' do
72
+
73
+ describe '#make_api_call' do
74
+ it 'faileds no method' do
53
75
  expect { subject.make_api_call(test: 'foo') }.to raise_error('method param missing')
54
76
  end
77
+
55
78
  context 'without id' do
56
- it 'should call :get' do
57
- stub_request(:get, 'https://api.pipedrive.com/v1/bases?api_token=token').to_return(:status => 200, :body => {}.to_json, :headers => {})
79
+ it 'calls :get' do
80
+ stub_request(:get, 'https://api.pipedrive.com/v1/bases?api_token=token').to_return(status: 200, body: {}.to_json, headers: {})
58
81
  expect_any_instance_of(::Faraday::Connection).to receive(:get).with('/v1/bases?api_token=token', {}).and_call_original
59
82
  expect(subject.make_api_call(:get))
60
83
  end
61
- it 'should call :post' do
62
- stub_request(:post, 'https://api.pipedrive.com/v1/bases?api_token=token').to_return(:status => 200, :body => {}.to_json, :headers => {})
84
+
85
+ it 'calls :post' do
86
+ stub_request(:post, 'https://api.pipedrive.com/v1/bases?api_token=token').to_return(status: 200, body: {}.to_json, headers: {})
63
87
  expect_any_instance_of(::Faraday::Connection).to receive(:post).with('/v1/bases?api_token=token', { test: 'bar' }).and_call_original
64
88
  expect(subject.make_api_call(:post, test: 'bar'))
65
89
  end
66
- it 'should call :put' do
67
- stub_request(:put, 'https://api.pipedrive.com/v1/bases?api_token=token').to_return(:status => 200, :body => {}.to_json, :headers => {})
90
+
91
+ it 'calls :put' do
92
+ stub_request(:put, 'https://api.pipedrive.com/v1/bases?api_token=token').to_return(status: 200, body: {}.to_json, headers: {})
68
93
  expect_any_instance_of(::Faraday::Connection).to receive(:put).with('/v1/bases?api_token=token', { test: 'bar' }).and_call_original
69
94
  expect(subject.make_api_call(:put, test: 'bar'))
70
95
  end
71
- it 'should use field_selector properly' do
72
- stub_request(:get, 'https://api.pipedrive.com/v1/bases:(a,b,c)?api_token=token').to_return(:status => 200, :body => {}.to_json, :headers => {})
73
- expect_any_instance_of(::Faraday::Connection).to receive(:get).
74
- with('/v1/bases:(a,b,c)?api_token=token', {}).and_call_original
75
- expect(subject.make_api_call(:get, fields_to_select: %w(a b c)))
96
+
97
+ it 'uses field_selector properly' do
98
+ stub_request(:get, 'https://api.pipedrive.com/v1/bases:(a,b,c)?api_token=token').to_return(status: 200, body: {}.to_json, headers: {})
99
+ expect_any_instance_of(::Faraday::Connection).to receive(:get)
100
+ .with('/v1/bases:(a,b,c)?api_token=token', {}).and_call_original
101
+ expect(subject.make_api_call(:get, fields_to_select: %w[a b c]))
76
102
  end
77
- it 'should not use field_selector if it empty' do
78
- stub_request(:get, 'https://api.pipedrive.com/v1/bases?api_token=token').to_return(:status => 200, :body => {}.to_json, :headers => {})
79
- expect_any_instance_of(::Faraday::Connection).to receive(:get).
80
- with('/v1/bases?api_token=token', {}).and_call_original
103
+
104
+ it 'does not use field_selector if it empty' do
105
+ stub_request(:get, 'https://api.pipedrive.com/v1/bases?api_token=token').to_return(status: 200, body: {}.to_json, headers: {})
106
+ expect_any_instance_of(::Faraday::Connection).to receive(:get)
107
+ .with('/v1/bases?api_token=token', {}).and_call_original
81
108
  expect(subject.make_api_call(:get, fields_to_select: []))
82
109
  end
83
- it 'should retry if Errno::ETIMEDOUT' do
84
- stub_request(:get, 'https://api.pipedrive.com/v1/bases?api_token=token').to_return(:status => 200, :body => {}.to_json, :headers => {})
110
+
111
+ it 'retries if Errno::ETIMEDOUT' do
112
+ stub_request(:get, 'https://api.pipedrive.com/v1/bases?api_token=token').to_return(status: 200, body: {}.to_json, headers: {})
85
113
  connection = subject.connection
86
114
  allow(subject).to receive(:connection).and_return(connection)
87
- allow(connection).to receive(:get).
88
- with('/v1/bases?api_token=token', {}).and_raise(Errno::ETIMEDOUT)
89
- expect(connection).to receive(:get).
90
- with('/v1/bases?api_token=token', {}).and_call_original
115
+ allow(connection).to receive(:get)
116
+ .with('/v1/bases?api_token=token', {}).and_raise(Errno::ETIMEDOUT)
117
+ expect(connection).to receive(:get)
118
+ .with('/v1/bases?api_token=token', {}).and_call_original
91
119
  expect(subject.make_api_call(:get, fields_to_select: []))
92
120
  end
93
121
  end
122
+
94
123
  context 'with id' do
95
- it 'should call :get' do
96
- stub_request(:get, 'https://api.pipedrive.com/v1/bases/12?api_token=token').to_return(:status => 200, :body => {}.to_json, :headers => {})
124
+ it 'calls :get' do
125
+ stub_request(:get, 'https://api.pipedrive.com/v1/bases/12?api_token=token').to_return(status: 200, body: {}.to_json, headers: {})
97
126
  expect_any_instance_of(::Faraday::Connection).to receive(:get).with('/v1/bases/12?api_token=token', {}).and_call_original
98
127
  expect(subject.make_api_call(:get, 12))
99
128
  end
100
- it 'should call :post' do
101
- stub_request(:post, 'https://api.pipedrive.com/v1/bases/13?api_token=token').to_return(:status => 200, :body => {}.to_json, :headers => {})
129
+
130
+ it 'calls :post' do
131
+ stub_request(:post, 'https://api.pipedrive.com/v1/bases/13?api_token=token').to_return(status: 200, body: {}.to_json, headers: {})
102
132
  expect_any_instance_of(::Faraday::Connection).to receive(:post).with('/v1/bases/13?api_token=token', { test: 'bar' }).and_call_original
103
133
  expect(subject.make_api_call(:post, 13, test: 'bar'))
104
134
  end
105
- it 'should call :put' do
106
- stub_request(:put, 'https://api.pipedrive.com/v1/bases/14?api_token=token').to_return(:status => 200, :body => {}.to_json, :headers => {})
135
+
136
+ it 'calls :put' do
137
+ stub_request(:put, 'https://api.pipedrive.com/v1/bases/14?api_token=token').to_return(status: 200, body: {}.to_json, headers: {})
107
138
  expect_any_instance_of(::Faraday::Connection).to receive(:put).with('/v1/bases/14?api_token=token', { test: 'bar' }).and_call_original
108
139
  expect(subject.make_api_call(:put, 14, test: 'bar'))
109
140
  end
110
141
  end
111
- it 'should call Hashie::Mash if return empty string' do
112
- stub_request(:get, 'https://api.pipedrive.com/v1/bases?api_token=token').to_return(:status => 200, :body => '', :headers => {})
142
+
143
+ it 'calls Hashie::Mash if return empty string' do
144
+ stub_request(:get, 'https://api.pipedrive.com/v1/bases?api_token=token').to_return(status: 200, body: '', headers: {})
113
145
  expect(::Hashie::Mash).to receive(:new).with(success: true).and_call_original
114
146
  expect(subject.make_api_call(:get))
115
147
  end
116
- it 'should call #failed_response if failed status' do
117
- stub_request(:get, 'https://api.pipedrive.com/v1/bases?api_token=token').to_return(:status => 400, :body => '', :headers => {})
148
+
149
+ it 'calls #failed_response if failed status' do
150
+ stub_request(:get, 'https://api.pipedrive.com/v1/bases?api_token=token').to_return(status: 400, body: '', headers: {})
118
151
  expect(subject).to receive(:failed_response)
119
152
  expect(subject.make_api_call(:get))
120
153
  end
@@ -1,9 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe ::Pipedrive::DealField do
4
6
  subject { described_class.new('token') }
5
- context '#entity_name' do
7
+
8
+ describe '#entity_name' do
6
9
  subject { super().entity_name }
10
+
7
11
  it { is_expected.to eq('dealFields') }
8
12
  end
9
- end
13
+ end
@@ -1,9 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe ::Pipedrive::Deal do
4
6
  subject { described_class.new('token') }
5
- context '#entity_name' do
7
+
8
+ describe '#entity_name' do
6
9
  subject { super().entity_name }
10
+
7
11
  it { is_expected.to eq('deals') }
8
12
  end
9
- end
13
+ end
@@ -1,9 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe ::Pipedrive::File do
4
6
  subject { described_class.new('token') }
5
- context '#entity_name' do
7
+
8
+ describe '#entity_name' do
6
9
  subject { super().entity_name }
10
+
7
11
  it { is_expected.to eq('files') }
8
12
  end
9
- end
13
+ end