capsule_crm 0.9.1 → 0.10.0
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 +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +18 -0
- data/lib/capsule_crm.rb +1 -0
- data/lib/capsule_crm/case.rb +11 -2
- data/lib/capsule_crm/opportunity.rb +12 -5
- data/lib/capsule_crm/track.rb +26 -0
- data/lib/capsule_crm/version.rb +1 -1
- data/spec/lib/capsule_crm/case_spec.rb +40 -5
- data/spec/lib/capsule_crm/opportunity_spec.rb +35 -0
- data/spec/lib/capsule_crm/track_spec.rb +26 -0
- data/spec/support/tracks.json +16 -0
- metadata +6 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f08b4e0897c37f8539c3dc0fcde24c91c374d7f
|
4
|
+
data.tar.gz: 810a9aa84d4c3a2b8fd2fd855c68b65d9315dfc5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c2ded3a643e2d174a0bc0b03c0a238434734f8320f85855994af9374abc86cb1a9d59358bb949c70b7830fec342c5f89aa9540bd97b9b2188b55e77a15c9067
|
7
|
+
data.tar.gz: ba7401ac676e2ae7130929c30522b448374d37b6f2be8c5f9133e8590cae2170468680f77c1b21a24c2df2ba6b91de4ffa9f265938a9aa5c81440c053715696e
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -157,6 +157,12 @@ history = org.histories.build note: 'some note text'
|
|
157
157
|
history = org.histories.create note: 'some note text'
|
158
158
|
```
|
159
159
|
|
160
|
+
### Tracks
|
161
|
+
```ruby
|
162
|
+
# List tracks
|
163
|
+
tracks = CapsuleCRM::Track.all
|
164
|
+
```
|
165
|
+
|
160
166
|
### Opportunities
|
161
167
|
```ruby
|
162
168
|
# Find an opportunity
|
@@ -165,6 +171,18 @@ opportunity = CapsuleCRM::Opportunity.find(ID)
|
|
165
171
|
# List all opportunities
|
166
172
|
opportunities = CapsuleCRM::Opportunity.all
|
167
173
|
|
174
|
+
# Build a new opportunity
|
175
|
+
opportunity = CapsuleCRM::Opportunity.new(
|
176
|
+
name: 'my first opportunity',
|
177
|
+
party: CapsuleCRM::Party.find(1)
|
178
|
+
milestone: CapsuleCRM::Milestone.find(10)
|
179
|
+
track: CapsuleCRM::Track.all.first
|
180
|
+
)
|
181
|
+
|
182
|
+
# Save the opportunity
|
183
|
+
opportunity.save
|
184
|
+
opportunity.save!
|
185
|
+
|
168
186
|
# List tags
|
169
187
|
opportunity.tags
|
170
188
|
|
data/lib/capsule_crm.rb
CHANGED
data/lib/capsule_crm/case.rb
CHANGED
@@ -22,6 +22,7 @@ module CapsuleCRM
|
|
22
22
|
validates :party, presence: true
|
23
23
|
|
24
24
|
belongs_to :party, class_name: 'CapsuleCRM::Party'
|
25
|
+
belongs_to :track, class_name: 'CapsuleCRM::Track'
|
25
26
|
|
26
27
|
has_many :tasks, class_name: 'CapsuleCRM::Task', source: :case
|
27
28
|
|
@@ -238,16 +239,24 @@ module CapsuleCRM
|
|
238
239
|
def to_capsule_json
|
239
240
|
{
|
240
241
|
kase: CapsuleCRM::HashHelper.camelize_keys(
|
241
|
-
attributes.dup.delete_if
|
242
|
+
attributes.dup.delete_if do |key, value|
|
243
|
+
value.blank? || key == 'track_id'
|
244
|
+
end
|
242
245
|
)
|
243
246
|
}
|
244
247
|
end
|
245
248
|
|
249
|
+
def self._for_track(track)
|
250
|
+
raise NotImplementedError.new("There is no way to find cases by trackId in the Capsule API right now")
|
251
|
+
end
|
252
|
+
|
246
253
|
private
|
247
254
|
|
248
255
|
def create_record
|
256
|
+
path = "/api/party/#{party_id}/kase"
|
257
|
+
path += "?trackId=#{track_id}" if track_id
|
249
258
|
self.attributes = CapsuleCRM::Connection.post(
|
250
|
-
|
259
|
+
path, to_capsule_json
|
251
260
|
)
|
252
261
|
self
|
253
262
|
end
|
@@ -30,8 +30,9 @@ module CapsuleCRM
|
|
30
30
|
|
31
31
|
has_many :tasks, class_name: 'CapsuleCRM::Task', source: :opportunity
|
32
32
|
|
33
|
-
belongs_to :party,
|
33
|
+
belongs_to :party, class_name: 'CapsuleCRM::Party'
|
34
34
|
belongs_to :milestone, class_name: 'CapsuleCRM::Milestone'
|
35
|
+
belongs_to :track, class_name: 'CapsuleCRM::Track'
|
35
36
|
|
36
37
|
def milestone=(milestone)
|
37
38
|
if milestone.is_a?(String)
|
@@ -42,6 +43,10 @@ module CapsuleCRM
|
|
42
43
|
self
|
43
44
|
end
|
44
45
|
|
46
|
+
def self._for_track(track)
|
47
|
+
raise NotImplementedError.new("There is no way to find opportunities by trackId in the Capsule API right now")
|
48
|
+
end
|
49
|
+
|
45
50
|
# Public: Get all opportunities from Capsule. The list can be restricted
|
46
51
|
# and/or paginated with various query parameters sent through the options
|
47
52
|
# hash.
|
@@ -289,7 +294,9 @@ module CapsuleCRM
|
|
289
294
|
def to_capsule_json
|
290
295
|
{
|
291
296
|
opportunity: CapsuleCRM::HashHelper.camelize_keys(
|
292
|
-
attributes.dup.delete_if
|
297
|
+
attributes.dup.delete_if do |key, value|
|
298
|
+
value.blank? || key == 'track_id'
|
299
|
+
end
|
293
300
|
)
|
294
301
|
}.stringify_keys
|
295
302
|
end
|
@@ -309,9 +316,9 @@ module CapsuleCRM
|
|
309
316
|
private
|
310
317
|
|
311
318
|
def create_record
|
312
|
-
|
313
|
-
|
314
|
-
)
|
319
|
+
path = "/api/party/#{party_id}/opportunity"
|
320
|
+
path += "?trackId=#{track_id}" if track_id
|
321
|
+
self.attributes = CapsuleCRM::Connection.post(path, to_capsule_json)
|
315
322
|
self
|
316
323
|
end
|
317
324
|
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module CapsuleCRM
|
2
|
+
class Track
|
3
|
+
include Virtus
|
4
|
+
|
5
|
+
extend ActiveModel::Naming
|
6
|
+
include ActiveModel::Conversion
|
7
|
+
include ActiveModel::Validations
|
8
|
+
|
9
|
+
include CapsuleCRM::Associations::HasMany
|
10
|
+
include CapsuleCRM::Attributes
|
11
|
+
include CapsuleCRM::Collection
|
12
|
+
|
13
|
+
attribute :id, Integer
|
14
|
+
attribute :description, String
|
15
|
+
attribute :capture_rule, String
|
16
|
+
|
17
|
+
has_many :opportunities, class_name: 'CapsuleCRM::Opportunity'
|
18
|
+
has_many :cases, class_name: 'CapsuleCRM::Case'
|
19
|
+
|
20
|
+
def self.all
|
21
|
+
init_collection(
|
22
|
+
CapsuleCRM::Connection.get('/api/tracks')['tracks']['track']
|
23
|
+
)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/capsule_crm/version.rb
CHANGED
@@ -12,6 +12,15 @@ describe CapsuleCRM::Case do
|
|
12
12
|
|
13
13
|
it { should validate_presence_of(:party) }
|
14
14
|
|
15
|
+
describe '._for_track' do
|
16
|
+
let(:track) { CapsuleCRM::Track.new }
|
17
|
+
|
18
|
+
it do
|
19
|
+
expect { CapsuleCRM::Case._for_track(track) }.
|
20
|
+
to raise_error(NotImplementedError)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
15
24
|
describe '#tasks' do
|
16
25
|
let(:kase) { Fabricate.build(:case, id: 3) }
|
17
26
|
|
@@ -58,17 +67,19 @@ describe CapsuleCRM::Case do
|
|
58
67
|
end
|
59
68
|
|
60
69
|
describe '.create' do
|
70
|
+
let(:request_uri) do
|
71
|
+
'https://1234:@company.capsulecrm.com/api/party/1/kase'
|
72
|
+
end
|
73
|
+
|
74
|
+
let(:party) { CapsuleCRM::Person.new(id: 1, first_name: 'Matt') }
|
75
|
+
|
61
76
|
context 'when the case is valid' do
|
62
77
|
before do
|
63
|
-
stub_request(
|
64
|
-
:post, 'https://1234:@company.capsulecrm.com/api/party/1/kase'
|
65
|
-
).to_return(
|
78
|
+
stub_request(:post, request_uri).to_return(
|
66
79
|
headers: { 'Location' => 'https://sample.capsulecrm.com/api/kase/59' }
|
67
80
|
)
|
68
81
|
end
|
69
82
|
|
70
|
-
let(:party) { CapsuleCRM::Person.new(id: 1, first_name: 'Matt') }
|
71
|
-
|
72
83
|
subject { CapsuleCRM::Case.create name: 'Test Case', party: party }
|
73
84
|
|
74
85
|
it { should be_a(CapsuleCRM::Case) }
|
@@ -81,6 +92,30 @@ describe CapsuleCRM::Case do
|
|
81
92
|
|
82
93
|
it { kase.errors.should_not be_blank }
|
83
94
|
end
|
95
|
+
|
96
|
+
context 'when the case has a track' do
|
97
|
+
before do
|
98
|
+
stub_request(:post, "#{request_uri}?trackId=#{track.id}").to_return(
|
99
|
+
headers: { 'Location' => 'https://sample.capsulecrm.com/api/kase/59' }
|
100
|
+
)
|
101
|
+
end
|
102
|
+
|
103
|
+
let(:track) { CapsuleCRM::Track.new(id: rand(10)) }
|
104
|
+
|
105
|
+
subject do
|
106
|
+
CapsuleCRM::Case.create(name: 'Test Case', party: party, track: track)
|
107
|
+
end
|
108
|
+
|
109
|
+
it { expect(subject).to be_a(CapsuleCRM::Case) }
|
110
|
+
|
111
|
+
it { expect(subject).to be_persisted }
|
112
|
+
|
113
|
+
it do
|
114
|
+
subject
|
115
|
+
expect(WebMock).
|
116
|
+
to have_requested(:post, "#{request_uri}?trackId=#{track.id}")
|
117
|
+
end
|
118
|
+
end
|
84
119
|
end
|
85
120
|
|
86
121
|
describe '.create!' do
|
@@ -35,6 +35,15 @@ describe CapsuleCRM::Opportunity do
|
|
35
35
|
it { should_not validate_presence_of(:milestone_id) }
|
36
36
|
end
|
37
37
|
|
38
|
+
describe '._for_track' do
|
39
|
+
let(:track) { CapsuleCRM::Track.new }
|
40
|
+
|
41
|
+
it 'should raise a not implemented error' do
|
42
|
+
expect { CapsuleCRM::Opportunity._for_track(track) }.
|
43
|
+
to raise_error(NotImplementedError)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
38
47
|
describe '#tasks' do
|
39
48
|
let(:opportunity) { Fabricate.build(:opportunity, id: 5) }
|
40
49
|
|
@@ -237,6 +246,32 @@ describe CapsuleCRM::Opportunity do
|
|
237
246
|
it { should be_persisted }
|
238
247
|
|
239
248
|
it { subject.id.should eql(59) }
|
249
|
+
|
250
|
+
context 'when the opportunity has a track' do
|
251
|
+
before do
|
252
|
+
stub_request(:post, "#{request_path}?trackId=#{track.id}").to_return(
|
253
|
+
headers: {
|
254
|
+
'Location' => 'https://sample.capsulecrm.com/api/opportunity/59'
|
255
|
+
}
|
256
|
+
)
|
257
|
+
end
|
258
|
+
|
259
|
+
let(:track) { CapsuleCRM::Track.new(id: rand(10)) }
|
260
|
+
|
261
|
+
subject do
|
262
|
+
CapsuleCRM::Opportunity.
|
263
|
+
create(opportunity_attributes.merge(track: track))
|
264
|
+
end
|
265
|
+
|
266
|
+
it { expect(subject).to be_a(CapsuleCRM::Opportunity) }
|
267
|
+
|
268
|
+
it do
|
269
|
+
subject
|
270
|
+
WebMock.should have_requested(
|
271
|
+
:post, "#{request_path}?trackId=#{track.id}"
|
272
|
+
)
|
273
|
+
end
|
274
|
+
end
|
240
275
|
end
|
241
276
|
|
242
277
|
context 'when the opportunity is not valid' do
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CapsuleCRM::Track do
|
4
|
+
before { configure }
|
5
|
+
|
6
|
+
describe '.all' do
|
7
|
+
before do
|
8
|
+
stub_request(:get, /\/api\/tracks$/).
|
9
|
+
to_return(body: File.read('spec/support/tracks.json'))
|
10
|
+
end
|
11
|
+
|
12
|
+
subject { CapsuleCRM::Track.all }
|
13
|
+
|
14
|
+
it { expect(subject).to be_a(Array) }
|
15
|
+
|
16
|
+
it { expect(subject.length).to eql(2) }
|
17
|
+
|
18
|
+
it { expect(subject.first).to be_a(CapsuleCRM::Track) }
|
19
|
+
|
20
|
+
it { expect(subject.first.description).to eql('Sales follow up') }
|
21
|
+
|
22
|
+
it { expect(subject.first.capture_rule).to eql('OPPORTUNITY') }
|
23
|
+
|
24
|
+
it { expect(subject.first.id).to eql(1) }
|
25
|
+
end
|
26
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capsule_crm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Beedle
|
@@ -285,6 +285,7 @@ files:
|
|
285
285
|
- lib/capsule_crm/tag.rb
|
286
286
|
- lib/capsule_crm/taggable.rb
|
287
287
|
- lib/capsule_crm/task.rb
|
288
|
+
- lib/capsule_crm/track.rb
|
288
289
|
- lib/capsule_crm/user.rb
|
289
290
|
- lib/capsule_crm/version.rb
|
290
291
|
- lib/capsule_crm/website.rb
|
@@ -312,6 +313,7 @@ files:
|
|
312
313
|
- spec/lib/capsule_crm/tag_spec.rb
|
313
314
|
- spec/lib/capsule_crm/taggable_spec.rb
|
314
315
|
- spec/lib/capsule_crm/task_spec.rb
|
316
|
+
- spec/lib/capsule_crm/track_spec.rb
|
315
317
|
- spec/lib/capsule_crm/user_spec.rb
|
316
318
|
- spec/spec_helper.rb
|
317
319
|
- spec/support/all_cases.json
|
@@ -339,6 +341,7 @@ files:
|
|
339
341
|
- spec/support/single_user.json
|
340
342
|
- spec/support/task.json
|
341
343
|
- spec/support/task_categories.json
|
344
|
+
- spec/support/tracks.json
|
342
345
|
homepage: ''
|
343
346
|
licenses: []
|
344
347
|
metadata: {}
|
@@ -388,6 +391,7 @@ test_files:
|
|
388
391
|
- spec/lib/capsule_crm/tag_spec.rb
|
389
392
|
- spec/lib/capsule_crm/taggable_spec.rb
|
390
393
|
- spec/lib/capsule_crm/task_spec.rb
|
394
|
+
- spec/lib/capsule_crm/track_spec.rb
|
391
395
|
- spec/lib/capsule_crm/user_spec.rb
|
392
396
|
- spec/spec_helper.rb
|
393
397
|
- spec/support/all_cases.json
|
@@ -415,3 +419,4 @@ test_files:
|
|
415
419
|
- spec/support/single_user.json
|
416
420
|
- spec/support/task.json
|
417
421
|
- spec/support/task_categories.json
|
422
|
+
- spec/support/tracks.json
|