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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d1edcdd8d69a89209c63296cadd8ce24ca016d61
4
- data.tar.gz: c8ea9420994ff54c71967c48feac9ad63087065d
3
+ metadata.gz: f4b9fd67a190082bdfaee77004d8b1a955292f6e
4
+ data.tar.gz: 0194fb59ce8ae5227ecbdf97db8b69384ae810b1
5
5
  SHA512:
6
- metadata.gz: 7e8ef70a7bbc1a6fc40ae099617b4924eddc1dd5075ed30ede8fdb4a14ca5cb1e29e50114619dd02db62238ca59d4b40ba50da613a90c2dabdfcedfc68a987da
7
- data.tar.gz: 8c0a324a128c47f696d8f46ce1c124994bd3c5bdae9ed3722b43d74f6b76dcff500b4b3dc8479439670c6c362e0cff152a1f460c41c791a46c7fe02779ee2d6a
6
+ metadata.gz: db99f83850c54977fea4732871099fc1f1fc5e31f01c8cefda62eb83f29d2f17e09147322e3ddd6f5489ad0435e2659aee1c3ffca06688b973f4aca64bb10b97
7
+ data.tar.gz: 316ac65226479c988cc5f0565ea9abbe5301a88b66c0f5e4d0c6dc22dccffd6daa97a85f8dcd63248623dda62c89b6d7239c6bd7400d44348f9a2897381afa4c
data/.hound.yml ADDED
@@ -0,0 +1,3 @@
1
+ StringLiterals:
2
+ EnforcedStyle: double_quotes
3
+ Enabled: true
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 Hash to use as the target for the
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
- request(:delete, path, {}).success?
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 self.request(method, path, params)
30
- CapsuleCRM.log "CapsuleCRM: #{method.upcase} #{path} with #{params}"
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
- CapsuleCRM.log "CapsuleCRM Response: #{response.body}"
43
+ log "CapsuleCRM Response: #{response.body}"
35
44
  end
36
45
  end
37
46
 
38
- def self.preprocess_params(params)
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 self.params_contains_lastmodified(params)
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
- # TODO clean this shit up
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 self.default_request_headers
72
+ def default_request_headers
61
73
  { accept: 'application/json', content_type: 'application/json' }
62
74
  end
63
75
 
64
- def self.faraday
65
- ::Faraday.new("https://#{subdomain}.capsulecrm.com").tap do |connection|
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 self.subdomain
73
- CapsuleCRM.configuration.subdomain
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
- JSON.parse(response.body)['message']
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
@@ -10,6 +10,10 @@ module CapsuleCRM
10
10
  get("/api/#{queryable_options.plural}", options)
11
11
  )
12
12
  end
13
+
14
+ def first
15
+ all(limit: 1).first
16
+ end
13
17
  end
14
18
  end
15
19
  end
@@ -1,3 +1,3 @@
1
1
  module CapsuleCrm
2
- VERSION = '1.6.0'
2
+ VERSION = '1.6.1'
3
3
  end
@@ -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
- let(:response) { double('Response', body: response_body.to_json) }
6
- let(:response_body) do
7
- { message: 'this is an error message from the server' }
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
- subject { error.to_s }
21
+ context 'when the response is nil' do
22
+ let(:response) { nil }
12
23
 
13
- it 'should include the server error message' do
14
- expect(subject).to eql(response_body[:message])
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.0
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-04-02 00:00:00.000000000 Z
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