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.
- checksums.yaml +4 -4
- data/.rubocop.yml +98 -10
- data/.travis.yml +4 -7
- data/Gemfile +4 -6
- data/HISTORY.md +43 -0
- data/Rakefile +5 -2
- data/lib/pipedrive.rb +9 -1
- data/lib/pipedrive/activity.rb +2 -0
- data/lib/pipedrive/activity_type.rb +2 -0
- data/lib/pipedrive/base.rb +14 -11
- data/lib/pipedrive/deal.rb +2 -0
- data/lib/pipedrive/deal_field.rb +2 -0
- data/lib/pipedrive/file.rb +2 -0
- data/lib/pipedrive/filter.rb +2 -0
- data/lib/pipedrive/goal.rb +2 -0
- data/lib/pipedrive/note.rb +2 -0
- data/lib/pipedrive/operations/create.rb +2 -0
- data/lib/pipedrive/operations/delete.rb +2 -0
- data/lib/pipedrive/operations/read.rb +6 -3
- data/lib/pipedrive/operations/update.rb +4 -1
- data/lib/pipedrive/organization.rb +6 -3
- data/lib/pipedrive/organization_field.rb +2 -0
- data/lib/pipedrive/person.rb +7 -3
- data/lib/pipedrive/person_field.rb +2 -0
- data/lib/pipedrive/pipeline.rb +10 -0
- data/lib/pipedrive/product.rb +2 -0
- data/lib/pipedrive/product_field.rb +2 -0
- data/lib/pipedrive/railties.rb +2 -0
- data/lib/pipedrive/role.rb +2 -0
- data/lib/pipedrive/stage.rb +2 -0
- data/lib/pipedrive/user.rb +10 -0
- data/lib/pipedrive/utils.rb +6 -4
- data/lib/pipedrive/version.rb +3 -1
- data/pipedrive.gemspec +12 -8
- data/spec/lib/pipedrive/activity_spec.rb +6 -2
- data/spec/lib/pipedrive/activity_type_spec.rb +6 -2
- data/spec/lib/pipedrive/base_spec.rb +82 -49
- data/spec/lib/pipedrive/deal_field_spec.rb +6 -2
- data/spec/lib/pipedrive/deal_spec.rb +6 -2
- data/spec/lib/pipedrive/file_spec.rb +6 -2
- data/spec/lib/pipedrive/filter_spec.rb +6 -2
- data/spec/lib/pipedrive/goal_spec.rb +6 -2
- data/spec/lib/pipedrive/note_spec.rb +6 -2
- data/spec/lib/pipedrive/ogranization_spec.rb +6 -2
- data/spec/lib/pipedrive/operations/create_spec.rb +5 -3
- data/spec/lib/pipedrive/operations/delete_spec.rb +8 -5
- data/spec/lib/pipedrive/operations/read_spec.rb +32 -24
- data/spec/lib/pipedrive/operations/update_spec.rb +9 -6
- data/spec/lib/pipedrive/organization_field_spec.rb +6 -2
- data/spec/lib/pipedrive/person_field_spec.rb +6 -2
- data/spec/lib/pipedrive/person_spec.rb +18 -12
- data/spec/lib/pipedrive/product_field_spec.rb +6 -2
- data/spec/lib/pipedrive/product_spec.rb +6 -2
- data/spec/lib/pipedrive_spec.rb +28 -20
- data/spec/spec_helper.rb +2 -2
- metadata +40 -10
- data/Guardfile +0 -24
data/lib/pipedrive/person.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
18
|
+
|
19
|
+
follow_pagination(:make_api_call, [:get, 'find'], params, &block)
|
16
20
|
end
|
17
21
|
end
|
18
22
|
end
|
data/lib/pipedrive/product.rb
CHANGED
data/lib/pipedrive/railties.rb
CHANGED
data/lib/pipedrive/role.rb
CHANGED
data/lib/pipedrive/stage.rb
CHANGED
data/lib/pipedrive/utils.rb
CHANGED
@@ -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
|
-
|
11
|
-
|
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
|
data/lib/pipedrive/version.rb
CHANGED
data/pipedrive.gemspec
CHANGED
@@ -1,15 +1,16 @@
|
|
1
|
-
#
|
2
|
-
|
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 =
|
8
|
+
gem.name = 'pipedrive.rb'
|
8
9
|
gem.version = Pipedrive::VERSION
|
9
|
-
gem.authors = [
|
10
|
-
gem.email = [
|
11
|
-
gem.summary =
|
12
|
-
gem.description =
|
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', '
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
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
|
-
|
29
|
-
|
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
|
-
|
37
|
-
|
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
|
-
|
45
|
-
|
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
|
-
|
52
|
-
|
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 '
|
57
|
-
stub_request(:get, 'https://api.pipedrive.com/v1/bases?api_token=token').to_return(:
|
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
|
-
|
62
|
-
|
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
|
-
|
67
|
-
|
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
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
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
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
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
|
-
|
84
|
-
|
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 '
|
96
|
-
stub_request(:get, 'https://api.pipedrive.com/v1/bases/12?api_token=token').to_return(:
|
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
|
-
|
101
|
-
|
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
|
-
|
106
|
-
|
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
|
-
|
112
|
-
|
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
|
-
|
117
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|