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
@@ -1,9 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
RSpec.describe ::Pipedrive::Filter 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('filters') }
|
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::Goal 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('goals') }
|
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::Note 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('notes') }
|
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::Organization 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('organizations') }
|
8
12
|
end
|
9
|
-
end
|
13
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
RSpec.describe ::Pipedrive::Operations::Create do
|
@@ -7,9 +9,9 @@ RSpec.describe ::Pipedrive::Operations::Create do
|
|
7
9
|
end.new('token')
|
8
10
|
end
|
9
11
|
|
10
|
-
|
11
|
-
it '
|
12
|
-
expect(subject).to receive(:make_api_call).with(:post, {foo: 'bar'})
|
12
|
+
describe '#create' do
|
13
|
+
it 'calls #make_api_call' do
|
14
|
+
expect(subject).to receive(:make_api_call).with(:post, { foo: 'bar' })
|
13
15
|
subject.create(foo: 'bar')
|
14
16
|
end
|
15
17
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
RSpec.describe ::Pipedrive::Operations::Delete do
|
@@ -7,16 +9,17 @@ RSpec.describe ::Pipedrive::Operations::Delete do
|
|
7
9
|
end.new('token')
|
8
10
|
end
|
9
11
|
|
10
|
-
|
11
|
-
it '
|
12
|
+
describe '#delete' do
|
13
|
+
it 'calls #make_api_call' do
|
12
14
|
expect(subject).to receive(:make_api_call).with(:delete, 12)
|
13
15
|
subject.delete(12)
|
14
16
|
end
|
15
17
|
end
|
16
|
-
|
17
|
-
|
18
|
+
|
19
|
+
describe '#delete_all' do
|
20
|
+
it 'calls #make_api_call' do
|
18
21
|
expect(subject).to receive(:make_api_call).with(:delete)
|
19
22
|
subject.delete_all
|
20
23
|
end
|
21
24
|
end
|
22
|
-
end
|
25
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
RSpec.describe ::Pipedrive::Operations::Read do
|
@@ -7,45 +9,51 @@ RSpec.describe ::Pipedrive::Operations::Read do
|
|
7
9
|
end.new('token')
|
8
10
|
end
|
9
11
|
|
10
|
-
|
11
|
-
it '
|
12
|
+
describe '#find_by_id' do
|
13
|
+
it 'calls #make_api_call' do
|
12
14
|
expect(subject).to receive(:make_api_call).with(:get, 12)
|
13
15
|
subject.find_by_id(12)
|
14
16
|
end
|
15
17
|
end
|
16
18
|
|
17
|
-
|
19
|
+
describe '#each' do
|
18
20
|
let(:additional_data) do
|
19
|
-
{pagination: { more_items_in_collection?: true, next_start: 10}}
|
21
|
+
{ pagination: { more_items_in_collection?: true, next_start: 10 } }
|
20
22
|
end
|
21
|
-
|
23
|
+
|
24
|
+
it 'returns Enumerator if no block given' do
|
22
25
|
expect(subject.each).to be_a(::Enumerator)
|
23
26
|
end
|
24
|
-
|
25
|
-
|
27
|
+
|
28
|
+
it 'calls to_enum with params' do
|
29
|
+
expect(subject).to receive(:to_enum).with(:each, { foo: 'bar' })
|
26
30
|
subject.each(foo: 'bar')
|
27
31
|
end
|
28
|
-
|
29
|
-
|
30
|
-
expect
|
32
|
+
|
33
|
+
it 'yields data' do
|
34
|
+
expect(subject).to receive(:chunk).and_return(::Hashie::Mash.new(data: [1, 2], success: true))
|
35
|
+
expect { |b| subject.each(&b) }.to yield_successive_args(1, 2)
|
31
36
|
end
|
32
|
-
|
33
|
-
|
34
|
-
expect(subject).to receive(:chunk).with(start:
|
35
|
-
expect
|
37
|
+
|
38
|
+
it 'follows pagination' do
|
39
|
+
expect(subject).to receive(:chunk).with(start: 0).and_return(::Hashie::Mash.new(data: [1, 2], success: true, additional_data: additional_data))
|
40
|
+
expect(subject).to receive(:chunk).with(start: 10).and_return(::Hashie::Mash.new(data: [3, 4], success: true))
|
41
|
+
expect { |b| subject.each(&b) }.to yield_successive_args(1, 2, 3, 4)
|
36
42
|
end
|
37
|
-
|
43
|
+
|
44
|
+
it 'does not yield anything if result is empty' do
|
38
45
|
expect(subject).to receive(:chunk).with(start: 0).and_return(::Hashie::Mash.new(success: true))
|
39
|
-
expect { |b| subject.each(&b)}.to yield_successive_args
|
46
|
+
expect { |b| subject.each(&b) }.to yield_successive_args
|
40
47
|
end
|
41
|
-
|
48
|
+
|
49
|
+
it 'does not yield anything if result is not success' do
|
42
50
|
expect(subject).to receive(:chunk).with(start: 0).and_return(::Hashie::Mash.new(success: false))
|
43
|
-
expect { |b| subject.each(&b)}.to yield_successive_args
|
51
|
+
expect { |b| subject.each(&b) }.to yield_successive_args
|
44
52
|
end
|
45
53
|
end
|
46
54
|
|
47
|
-
|
48
|
-
it '
|
55
|
+
describe '#all' do
|
56
|
+
it 'calls #each' do
|
49
57
|
arr = double('enumerator')
|
50
58
|
allow(arr).to receive(:to_a)
|
51
59
|
expect(subject).to receive(:each).and_return(arr)
|
@@ -53,17 +61,17 @@ RSpec.describe ::Pipedrive::Operations::Read do
|
|
53
61
|
end
|
54
62
|
end
|
55
63
|
|
56
|
-
|
57
|
-
it '
|
64
|
+
describe '#chunk' do
|
65
|
+
it 'returns []' do
|
58
66
|
res = double('res', success?: false)
|
59
67
|
expect(subject).to receive(:make_api_call).with(:get, {}).and_return(res)
|
60
68
|
expect(subject.chunk).to eq([])
|
61
69
|
end
|
62
70
|
|
63
|
-
it '
|
71
|
+
it 'returns result' do
|
64
72
|
res = double('res', success?: true)
|
65
73
|
expect(subject).to receive(:make_api_call).with(:get, {}).and_return(res)
|
66
74
|
expect(subject.chunk).to eq(res)
|
67
75
|
end
|
68
76
|
end
|
69
|
-
end
|
77
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
RSpec.describe ::Pipedrive::Operations::Update do
|
@@ -7,14 +9,15 @@ RSpec.describe ::Pipedrive::Operations::Update do
|
|
7
9
|
end.new('token')
|
8
10
|
end
|
9
11
|
|
10
|
-
|
11
|
-
it '
|
12
|
-
expect(subject).to receive(:make_api_call).with(:put, 12, {foo: 'bar'})
|
12
|
+
describe '#create' do
|
13
|
+
it 'calls #make_api_call' do
|
14
|
+
expect(subject).to receive(:make_api_call).with(:put, 12, { foo: 'bar' })
|
13
15
|
subject.update(12, foo: 'bar')
|
14
16
|
end
|
15
|
-
|
16
|
-
|
17
|
+
|
18
|
+
it 'calls #make_api_call with id in params' do
|
19
|
+
expect(subject).to receive(:make_api_call).with(:put, 14, { foo: 'bar' })
|
17
20
|
subject.update(foo: 'bar', id: 14)
|
18
21
|
end
|
19
22
|
end
|
20
|
-
end
|
23
|
+
end
|
@@ -1,9 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
RSpec.describe ::Pipedrive::OrganizationField 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('organizationFields') }
|
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::PersonField 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('personFields') }
|
8
12
|
end
|
9
|
-
end
|
13
|
+
end
|
@@ -1,24 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
RSpec.describe ::Pipedrive::Person 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('persons') }
|
8
12
|
end
|
9
13
|
|
10
|
-
|
11
|
-
it '
|
12
|
-
expect(subject).to receive(:make_api_call).with(:get, 'find', {term: 'term', search_by_email: 0, start: 0})
|
13
|
-
expect { |b| subject.find_by_name('term', &b)}.to yield_successive_args
|
14
|
+
describe '#find_by_name' do
|
15
|
+
it 'calls #make_api_call with term' do
|
16
|
+
expect(subject).to receive(:make_api_call).with(:get, 'find', { term: 'term', search_by_email: 0, start: 0 })
|
17
|
+
expect { |b| subject.find_by_name('term', &b) }.to yield_successive_args
|
14
18
|
end
|
15
|
-
|
16
|
-
|
17
|
-
expect {
|
19
|
+
|
20
|
+
it 'calls #make_api_call with term and search_by_email' do
|
21
|
+
expect(subject).to receive(:make_api_call).with(:get, 'find', { term: 'term', search_by_email: 1, start: 0 })
|
22
|
+
expect { |b| subject.find_by_name('term', true, &b) }.to yield_successive_args
|
18
23
|
end
|
19
|
-
|
20
|
-
|
21
|
-
expect {
|
24
|
+
|
25
|
+
it 'yields results' do
|
26
|
+
expect(subject).to receive(:make_api_call).with(:get, 'find', { term: 'term', search_by_email: 0, start: 0 }).and_return(::Hashie::Mash.new(data: [1, 2], success: true))
|
27
|
+
expect { |b| subject.find_by_name('term', &b) }.to yield_successive_args(1, 2)
|
22
28
|
end
|
23
29
|
end
|
24
|
-
end
|
30
|
+
end
|
@@ -1,9 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
RSpec.describe ::Pipedrive::ProductField 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('productFields') }
|
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::Product 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('products') }
|
8
12
|
end
|
9
|
-
end
|
13
|
+
end
|
data/spec/lib/pipedrive_spec.rb
CHANGED
@@ -1,65 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
RSpec.describe ::Pipedrive do
|
4
|
-
|
5
6
|
subject { described_class }
|
6
7
|
|
7
|
-
before
|
8
|
+
before do
|
8
9
|
described_class.reset!
|
9
10
|
end
|
10
11
|
|
11
|
-
|
12
|
+
describe '#reset!' do
|
12
13
|
describe '#user_agent' do
|
13
14
|
subject { super().user_agent }
|
15
|
+
|
14
16
|
it { is_expected.to eq("Pipedrive Ruby Client v#{::Pipedrive::VERSION}") }
|
15
17
|
end
|
16
18
|
|
17
19
|
describe '#api_token' do
|
18
20
|
subject { super().api_token }
|
21
|
+
|
19
22
|
it { is_expected.to be_nil }
|
20
23
|
end
|
21
24
|
|
22
25
|
describe '#logger' do
|
23
26
|
subject { super().logger }
|
27
|
+
|
24
28
|
it { is_expected.to be_kind_of(::Logger) }
|
25
29
|
end
|
26
30
|
end
|
27
31
|
|
28
|
-
|
32
|
+
describe '#setup' do
|
29
33
|
context 'single call' do
|
30
|
-
|
31
|
-
|
34
|
+
let(:client) { described_class }
|
35
|
+
|
36
|
+
it 'sets user_agent' do
|
37
|
+
client.setup do |c|
|
32
38
|
c.user_agent = 'Test1245'
|
33
39
|
end
|
34
|
-
expect(
|
40
|
+
expect(client.user_agent).to eq('Test1245')
|
35
41
|
end
|
36
42
|
|
37
|
-
it '
|
38
|
-
newlogger = ::Logger.new(
|
39
|
-
|
43
|
+
it 'sets logger' do
|
44
|
+
newlogger = ::Logger.new($stderr)
|
45
|
+
client.setup do |c|
|
40
46
|
c.logger = newlogger
|
41
47
|
end
|
42
|
-
expect(
|
48
|
+
expect(client.logger).to eq(newlogger)
|
43
49
|
end
|
44
50
|
|
45
|
-
it '
|
46
|
-
|
51
|
+
it 'sets api_token' do
|
52
|
+
client.setup do |c|
|
47
53
|
c.api_token = 'test-api-key'
|
48
54
|
end
|
49
|
-
expect(
|
55
|
+
expect(client.api_token).to eq('test-api-key')
|
50
56
|
end
|
51
57
|
end
|
52
58
|
|
53
|
-
context 'double call' do
|
54
|
-
|
55
|
-
|
59
|
+
context 'with double call' do
|
60
|
+
let(:client) { described_class }
|
61
|
+
|
62
|
+
it 'does not accept running setup more then once' do
|
63
|
+
client.setup do |c|
|
56
64
|
c.api_token = 'test-api-key'
|
57
65
|
end
|
58
|
-
|
66
|
+
client.setup do |c|
|
59
67
|
c.api_token = 'test-api-key2'
|
60
68
|
end
|
61
|
-
expect(
|
69
|
+
expect(client.api_token).to eq('test-api-key')
|
62
70
|
end
|
63
71
|
end
|
64
72
|
end
|
65
|
-
end
|
73
|
+
end
|
data/spec/spec_helper.rb
CHANGED