capsule_crm 1.6.0 → 1.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.hound.yml +3 -0
- data/CHANGELOG.md +10 -0
- data/README.md +46 -5
- data/lib/capsule_crm/associations/has_many_association.rb +3 -2
- data/lib/capsule_crm/connection.rb +37 -21
- data/lib/capsule_crm/errors/response_error.rb +11 -1
- data/lib/capsule_crm/querying/find_all.rb +4 -0
- data/lib/capsule_crm/version.rb +1 -1
- data/spec/lib/capsule_crm/errors/response_error_spec.rb +19 -7
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4b9fd67a190082bdfaee77004d8b1a955292f6e
|
4
|
+
data.tar.gz: 0194fb59ce8ae5227ecbdf97db8b69384ae810b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db99f83850c54977fea4732871099fc1f1fc5e31f01c8cefda62eb83f29d2f17e09147322e3ddd6f5489ad0435e2659aee1c3ffca06688b973f4aca64bb10b97
|
7
|
+
data.tar.gz: 316ac65226479c988cc5f0565ea9abbe5301a88b66c0f5e4d0c6dc22dccffd6daa97a85f8dcd63248623dda62c89b6d7239c6bd7400d44348f9a2897381afa4c
|
data/.hound.yml
ADDED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 1.6.0
|
4
|
+
|
5
|
+
- ResponseError#to_s now return the response message from the server so errors
|
6
|
+
are a little easier to debug.
|
7
|
+
|
8
|
+
## 1.5.3
|
9
|
+
|
10
|
+
- A has many association will now accept a single object as an argument and
|
11
|
+
coerce that object into an array.
|
12
|
+
|
3
13
|
## 1.5.2
|
4
14
|
|
5
15
|
- Fix issue with ruby 1.9.3 where incompatible OpenStruct syntax was being used.
|
data/README.md
CHANGED
@@ -10,6 +10,8 @@ Status](https://coveralls.io/repos/mattbeedle/capsule_crm/badge.png?branch=maste
|
|
10
10
|
Status](https://gemnasium.com/mattbeedle/capsule_crm.png)](https://gemnasium.com/mattbeedle/capsule_crm)
|
11
11
|
[![Stories in
|
12
12
|
Ready](http://badge.waffle.io/mattbeedle/capsule_crm.png)](http://waffle.io/mattbeedle/capsule_crm)
|
13
|
+
[![Gitter
|
14
|
+
chat](https://badges.gitter.im/mattbeedle/capsule_crm.png)](https://gitter.im/mattbeedle/capsule_crm)
|
13
15
|
|
14
16
|
# CapsuleCRM
|
15
17
|
|
@@ -157,6 +159,39 @@ history = org.histories.build note: 'some note text'
|
|
157
159
|
history = org.histories.create note: 'some note text'
|
158
160
|
```
|
159
161
|
|
162
|
+
### Contacts
|
163
|
+
|
164
|
+
People and organizations may both have contacts. Contacts consist of emails,
|
165
|
+
phones, websites and addresses.
|
166
|
+
|
167
|
+
```ruby
|
168
|
+
person.contacts
|
169
|
+
# => CapsuleCRM::Contacts
|
170
|
+
|
171
|
+
# Assign an array of CapsuleCRM::Email objects
|
172
|
+
person.contacts.emails =
|
173
|
+
[CapsuleCRM::Email.new(email_address: 'test@test.com', type: 'Work')]
|
174
|
+
|
175
|
+
# Assign an array of email attributes
|
176
|
+
person.contacts.emails = [{ email_address: 'test@test.com', type: 'Work' }]
|
177
|
+
|
178
|
+
# Add a new email
|
179
|
+
person.contacts.emails << CapsuleCRM::Email.new(email_address: 'test@test.com')
|
180
|
+
|
181
|
+
# person.emails delegates to person.contacts.emails so the above code may be
|
182
|
+
# shortened to:
|
183
|
+
|
184
|
+
person.emails =
|
185
|
+
[CapsuleCRM::Email.new(email_address: 'test@test.com', type: 'Work')]
|
186
|
+
|
187
|
+
# Assign an array of email attributes
|
188
|
+
person.emails = [{ email_address: 'test@test.com', type: 'Work' }]
|
189
|
+
|
190
|
+
person.emails << CapsuleCRM::Email.new(email_address: 'test@test.com')
|
191
|
+
|
192
|
+
# The above syntax is exactly the same for addresses, websites and phones.
|
193
|
+
```
|
194
|
+
|
160
195
|
### Tracks
|
161
196
|
```ruby
|
162
197
|
# List tracks
|
@@ -330,8 +365,14 @@ with fix.
|
|
330
365
|
|
331
366
|
Many thanks to the following contributers:
|
332
367
|
|
333
|
-
- @srbaker
|
334
|
-
- @clod81
|
335
|
-
- @danthompson
|
336
|
-
- @ryanbooker
|
337
|
-
- @ghiculescu
|
368
|
+
- [@srbaker](https://github.com/srbaker)
|
369
|
+
- [@clod81](https://github.com/clod81)
|
370
|
+
- [@danthompson](https://github.com/danthompson)
|
371
|
+
- [@ryanbooker](https://github.com/ryanbooker)
|
372
|
+
- [@ghiculescu](https://github.com/ghiculescu)
|
373
|
+
|
374
|
+
## Alternatives
|
375
|
+
|
376
|
+
- [placebo](https://github.com/adrianpike/placebo)
|
377
|
+
- [capsulecrm](https://github.com/ahmedrb/capsulecrm) - most active fork seems
|
378
|
+
to be [here](https://github.com/theodi/capsulecrm)
|
@@ -32,8 +32,9 @@ module CapsuleCRM
|
|
32
32
|
#
|
33
33
|
# parent - The instance of the class that the has many assocation is
|
34
34
|
# defined on
|
35
|
-
# collection - An optional Array or
|
36
|
-
# proxy
|
35
|
+
# collection - An optional Array, Hash or Object to use as the target for
|
36
|
+
# the proxy. An Object will be coerced into an Array, a Hash will be
|
37
|
+
# turned in to an Object and then coerced into an Array.
|
37
38
|
#
|
38
39
|
# Returns a CapsuleCRM::Associations::HasManyProxy
|
39
40
|
def proxy(parent, collection = nil)
|
@@ -1,54 +1,66 @@
|
|
1
1
|
module CapsuleCRM
|
2
2
|
class Connection
|
3
|
-
|
4
|
-
# Public: Send a GET request to CapsuleCRM API
|
5
|
-
#
|
6
|
-
# path - The String path where the request should go
|
7
|
-
# params - The Hash of URL parameters
|
8
|
-
#
|
9
|
-
# Returns a Hash from the JSON response
|
10
3
|
def self.get(path, params = {})
|
4
|
+
new.get(path, params)
|
5
|
+
end
|
6
|
+
|
7
|
+
def get(path, params)
|
11
8
|
preprocess_params(params)
|
12
9
|
JSON.parse request(:get, path, params).body
|
13
10
|
end
|
14
11
|
|
15
12
|
def self.post(path, params = {})
|
13
|
+
new.post(path, params)
|
14
|
+
end
|
15
|
+
|
16
|
+
def post(path, params)
|
16
17
|
process_post_response request(:post, path, params.to_json)
|
17
18
|
end
|
18
19
|
|
19
|
-
def self.put(path, params)
|
20
|
+
def self.put(path, params = {})
|
21
|
+
new.put(path, params)
|
22
|
+
end
|
23
|
+
|
24
|
+
def put(path, params)
|
20
25
|
request(:put, path, params.to_json).success?
|
21
26
|
end
|
22
27
|
|
23
28
|
def self.delete(path)
|
24
|
-
|
29
|
+
new.delete(path)
|
30
|
+
end
|
31
|
+
|
32
|
+
def delete(path)
|
33
|
+
request(:delete, path).success?
|
25
34
|
end
|
26
35
|
|
27
36
|
private
|
28
37
|
|
29
|
-
def
|
30
|
-
|
38
|
+
def request(method, path, params = {})
|
39
|
+
log "CapsuleCRM: #{method.upcase} #{path} with #{params}"
|
31
40
|
faraday.send(method, path, params) do |req|
|
32
41
|
req.headers.update default_request_headers
|
33
42
|
end.tap do |response|
|
34
|
-
|
43
|
+
log "CapsuleCRM Response: #{response.body}"
|
35
44
|
end
|
36
45
|
end
|
37
46
|
|
38
|
-
def
|
47
|
+
def log(string)
|
48
|
+
CapsuleCRM.log string
|
49
|
+
end
|
50
|
+
|
51
|
+
def preprocess_params(params)
|
39
52
|
params.symbolize_keys!
|
40
53
|
if params_contains_lastmodified(params)
|
41
54
|
params[:lastmodified] = params[:lastmodified].strftime("%Y%m%dT%H%M%S")
|
42
55
|
end
|
43
56
|
end
|
44
57
|
|
45
|
-
def
|
58
|
+
def params_contains_lastmodified(params)
|
46
59
|
params.keys.include?(:lastmodified) &&
|
47
60
|
params[:lastmodified].respond_to?(:strftime)
|
48
61
|
end
|
49
62
|
|
50
|
-
|
51
|
-
def self.process_post_response(response)
|
63
|
+
def process_post_response(response)
|
52
64
|
if response.headers['Location'] &&
|
53
65
|
match = response.headers['Location'].match(/\/(?<id>\d+)$/)
|
54
66
|
{ id: match[:id].to_i }
|
@@ -57,20 +69,24 @@ module CapsuleCRM
|
|
57
69
|
end
|
58
70
|
end
|
59
71
|
|
60
|
-
def
|
72
|
+
def default_request_headers
|
61
73
|
{ accept: 'application/json', content_type: 'application/json' }
|
62
74
|
end
|
63
75
|
|
64
|
-
def
|
65
|
-
::Faraday.new("https://#{
|
76
|
+
def faraday
|
77
|
+
@faraday ||= ::Faraday.new("https://#{host}").tap do |connection|
|
66
78
|
connection.basic_auth(CapsuleCRM.configuration.api_token, '')
|
67
79
|
connection.request :json
|
68
80
|
connection.use CapsuleCRM::Faraday::Middleware::RaiseError
|
69
81
|
end
|
70
82
|
end
|
71
83
|
|
72
|
-
def
|
73
|
-
|
84
|
+
def host
|
85
|
+
@host ||= "#{subdomain}.capsulecrm.com"
|
86
|
+
end
|
87
|
+
|
88
|
+
def subdomain
|
89
|
+
@subdomain ||= CapsuleCRM.configuration.subdomain
|
74
90
|
end
|
75
91
|
end
|
76
92
|
end
|
@@ -8,7 +8,17 @@ module CapsuleCRM
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def to_s
|
11
|
-
|
11
|
+
response_message || empty_message
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def response_message
|
17
|
+
JSON.parse(response.body)['message'] if response
|
18
|
+
end
|
19
|
+
|
20
|
+
def empty_message
|
21
|
+
'capsulecrm.com returned an empty response'
|
12
22
|
end
|
13
23
|
end
|
14
24
|
end
|
data/lib/capsule_crm/version.rb
CHANGED
@@ -1,17 +1,29 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe CapsuleCRM::Errors::ResponseError do
|
4
|
+
let(:error) { CapsuleCRM::Errors::ResponseError.new(response) }
|
5
|
+
|
6
|
+
subject { error.to_s }
|
7
|
+
|
4
8
|
describe '#to_s' do
|
5
|
-
|
6
|
-
|
7
|
-
|
9
|
+
context 'when the response is not nil' do
|
10
|
+
let(:response) { double('Response', body: response_body.to_json) }
|
11
|
+
let(:response_body) do
|
12
|
+
{ message: 'this is an error message from the server' }
|
13
|
+
end
|
14
|
+
let(:error) { CapsuleCRM::Errors::ResponseError.new(response) }
|
15
|
+
|
16
|
+
it 'should include the server error message' do
|
17
|
+
expect(subject).to eql(response_body[:message])
|
18
|
+
end
|
8
19
|
end
|
9
|
-
let(:error) { CapsuleCRM::Errors::ResponseError.new(response) }
|
10
20
|
|
11
|
-
|
21
|
+
context 'when the response is nil' do
|
22
|
+
let(:response) { nil }
|
12
23
|
|
13
|
-
|
14
|
-
|
24
|
+
it 'should return an empty response message' do
|
25
|
+
expect(subject).to eql('capsulecrm.com returned an empty response')
|
26
|
+
end
|
15
27
|
end
|
16
28
|
end
|
17
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capsule_crm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.6.
|
4
|
+
version: 1.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Beedle
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -242,6 +242,7 @@ extensions: []
|
|
242
242
|
extra_rdoc_files: []
|
243
243
|
files:
|
244
244
|
- ".gitignore"
|
245
|
+
- ".hound.yml"
|
245
246
|
- ".rspec"
|
246
247
|
- ".travis.yml"
|
247
248
|
- CHANGELOG.md
|