capsule_crm 0.0.6 → 0.1.6

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: 27fbb70234eb3c2f46340bb621531d44ef172089
4
- data.tar.gz: 545a7d2b1f2dba314ed4e399fff534e56a549a54
3
+ metadata.gz: 808ce675363a8bae072d7242b8973f41cf5e0c08
4
+ data.tar.gz: edb34f7e67119375ed840b6da034b2fa653ea116
5
5
  SHA512:
6
- metadata.gz: 5a8948dc7c1ca6c64a084b31e371f1b51ddff6e15ef991878a2b3985a84ae3a004021883a0d32603c5050cf9753d03ad96a5560f0e287cdb2c4c73bc50c21453
7
- data.tar.gz: 925f7f147a537fef527ecce482a9b8975fb5ca2a230ea70c0dab2bc87997963b15faee4408b8b193584aa4e3601848600a0b2cea3e439a458cc5474bd3f5cbac
6
+ metadata.gz: 5d0464a4804f4551450541ff4e237d9b04eb94581d074a7460b51eb4ab4dc6008109a98774778e597ad8c9534240e3899a291edb6cc7ad63253c92c9656f5628
7
+ data.tar.gz: 56388862805ba1ad015807817c545d9688930d87da6e4b96971e17d68e8d40a9a0adcfd9e92021d30419d69fe1e07db7b43a552ae92dd1c2cd728121d7a5327b
data/README.md CHANGED
@@ -31,7 +31,17 @@ Or install it yourself as:
31
31
  ## Usage
32
32
 
33
33
  ```ruby
34
- person = CapsuleCRM::Person.new(first_name: 'Matt', last_name: 'Beedle', organisation_name: "Matt's Company")
34
+ contacts = CapsuleCRM::Contacts.new(
35
+ addresses: [CapsuleCRM::Address.new(street: 'Oranieburgerstr', city: 'Berlin')],
36
+ emails: [CapsuleCRM::Email.new(email_address: 'mattbeedle@gmail.com')],
37
+ phones: [CapsuleCRM::Phone.new(phone_number: '123456789')],
38
+ webstes: [CapsuleCRM::Website.new(web_service: 'URL', web_address: 'http://github.com']
39
+ )
40
+
41
+ person = CapsuleCRM::Person.new(
42
+ first_name: 'Matt', last_name: 'Beedle', organisation_name: "Matt's Company",
43
+ contacts: contacts
44
+ )
35
45
  person.save
36
46
 
37
47
  person.first_name = 'John'
@@ -39,6 +49,17 @@ person.save #=> true
39
49
 
40
50
  person.valid? #=> true
41
51
 
52
+ person.organization #=> CapsuleCRM::Organization
53
+
54
+ person.organization.tap do |org|
55
+ org.update_attributes! contacts: CapsuleCRM::Contacts.new(
56
+ addresses: CapsuleCRM::Address.new(street: 'Thurneysserstr')
57
+ )
58
+
59
+ org.contacts.phones << CapsuleCRM::Phone.new(phone_number: '234243')
60
+ org.save
61
+ end
62
+
42
63
  person.first_name = nil
43
64
  person.last_name = nil
44
65
  person.valid? #=> false
@@ -49,6 +70,9 @@ person.save! #=> CapsuleCRM::Errors::InvalidRecord
49
70
  person.destroy #=> true
50
71
 
51
72
  person = CapsuleCRM::Person.create(first_name: 'Matt', last_name: 'Beedle')
73
+
74
+ kase = CapsuleCRM::Case.create! name: 'My First Case', party: person
75
+ kase.update_attributes name: 'A New Case Name'
52
76
  ```
53
77
 
54
78
  ## Contributing
@@ -7,6 +7,7 @@ module CapsuleCRM
7
7
  include ActiveModel::Validations
8
8
 
9
9
  include CapsuleCRM::Associations::BelongsTo
10
+ include CapsuleCRM::Taggable
10
11
 
11
12
  attribute :id, Integer
12
13
  attribute :name, String
@@ -14,13 +14,16 @@ module CapsuleCRM
14
14
  JSON.parse response.body
15
15
  end
16
16
 
17
- def self.post(path, params)
17
+ def self.post(path, params = {})
18
18
  response = faraday.post(path, params.to_json) do |request|
19
19
  request.headers.update default_request_headers
20
20
  end
21
21
  if response.success?
22
- id = response.headers['Location'].match(/\/(?<id>\d+)$/)[:id]
23
- { id: id }
22
+ if match = response.headers['Location'].match(/\/(?<id>\d+)$/)
23
+ { id: match[:id] }
24
+ else
25
+ true
26
+ end
24
27
  else
25
28
  false
26
29
  end
@@ -15,10 +15,10 @@ module CapsuleCRM
15
15
  #
16
16
  # Returns a CapsuleCRM::Contact
17
17
  def initialize(attributes = {})
18
- self.addresses = attributes[:addresses]
19
- self.emails = attributes[:emails]
20
- self.phones = attributes[:phones]
21
- self.websites = attributes[:websites]
18
+ self.addresses = Array(attributes[:addresses])
19
+ self.emails = Array(attributes[:emails])
20
+ self.phones = Array(attributes[:phones])
21
+ self.websites = Array(attributes[:websites])
22
22
  end
23
23
 
24
24
  # Public: Sets the addresses for this contacts container
@@ -11,6 +11,7 @@ module CapsuleCRM
11
11
  include ActiveModel::Validations::Callbacks
12
12
 
13
13
  include CapsuleCRM::Associations::HasMany
14
+ include CapsuleCRM::Taggable
14
15
 
15
16
  attribute :id, Integer
16
17
  attribute :name, String
@@ -1,4 +1,5 @@
1
1
  class CapsuleCRM::Party
2
+ include CapsuleCRM::Taggable
2
3
 
3
4
  def self.all(options = {})
4
5
  attributes = CapsuleCRM::Connection.get('/api/party', options)
@@ -0,0 +1,13 @@
1
+ module CapsuleCRM
2
+ class Tag
3
+ include Virtus
4
+
5
+ extend ActiveModel::Naming
6
+ include ActiveModel::Conversion
7
+ include ActiveModel::Validations
8
+
9
+ attribute :name
10
+
11
+ validates :name, presence: true
12
+ end
13
+ end
@@ -0,0 +1,23 @@
1
+ module CapsuleCRM
2
+ module Taggable
3
+ extend ActiveSupport::Concern
4
+
5
+ def tags
6
+ CapsuleCRM::Connection.get(
7
+ "/api/#{api_singular_name}/#{id}/tag"
8
+ )['tags']['tag'].map { |item| CapsuleCRM::Tag.new(item) }
9
+ end
10
+
11
+ def add_tag(tag_name)
12
+ if id
13
+ CapsuleCRM::Connection.post(
14
+ "/api/#{api_singular_name}/#{id}/#{URI.encode(tag_name)}"
15
+ )
16
+ end
17
+ end
18
+
19
+ def api_singular_name
20
+ self.class.to_s.demodulize.downcase.singularize
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,34 @@
1
+ module CapsuleCRM
2
+ class User
3
+ include Virtus
4
+
5
+ extend ActiveModel::Naming
6
+ include ActiveModel::Conversion
7
+ include ActiveModel::Validations
8
+
9
+ include CapsuleCRM::Associations::BelongsTo
10
+
11
+ attribute :username, String
12
+ attribute :name, String
13
+ attribute :currency, String
14
+ attribute :timezone, String
15
+ attribute :logged_in, Boolean
16
+
17
+ belongs_to :party, class_name: 'CapsuleCRM::Party'
18
+
19
+ # Public: Retrieve all users from CapsuleCRM
20
+ #
21
+ # Examples:
22
+ #
23
+ # CapsuleCRM::User.all
24
+ #
25
+ # Returns a CapsuleCRM::ResultsProxy of CapsuleCRM::User objects
26
+ def self.all
27
+ CapsuleCRM::ResultsProxy.new(
28
+ CapsuleCRM::Connection.get('/api/users')['users']['user'].map do |item|
29
+ new item
30
+ end
31
+ )
32
+ end
33
+ end
34
+ end
@@ -1,3 +1,3 @@
1
1
  module CapsuleCrm
2
- VERSION = '0.0.6'
2
+ VERSION = '0.1.6'
3
3
  end
data/lib/capsule_crm.rb CHANGED
@@ -3,6 +3,7 @@ require 'faraday'
3
3
  require 'faraday_middleware'
4
4
  require 'virtus'
5
5
  require 'capsule_crm/capsule_jsonable'
6
+ require 'capsule_crm/taggable'
6
7
  require 'capsule_crm/associations'
7
8
  require 'capsule_crm/address'
8
9
  require 'capsule_crm/case'
@@ -10,6 +11,8 @@ require 'capsule_crm/connection'
10
11
  require 'capsule_crm/email'
11
12
  require 'capsule_crm/party'
12
13
  require 'capsule_crm/phone'
14
+ require 'capsule_crm/tag'
15
+ require 'capsule_crm/user'
13
16
  require 'capsule_crm/website'
14
17
  require 'capsule_crm/hash_helper'
15
18
  require 'capsule_crm/results_proxy'
@@ -0,0 +1,6 @@
1
+ require 'spec_helper'
2
+
3
+ describe CapsuleCRM::Tag do
4
+
5
+ it { should validate_presence_of(:name) }
6
+ end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ class TaggableItem
4
+ include CapsuleCRM::Taggable
5
+ include Virtus
6
+
7
+ attribute :id
8
+ end
9
+
10
+ describe CapsuleCRM::Taggable do
11
+ before { configure }
12
+
13
+ describe '#tags' do
14
+ before do
15
+ stub_request(:get, /\/api\/taggableitem\/1\/tag$/).
16
+ to_return(body: File.read('spec/support/all_tags.json'))
17
+ end
18
+
19
+ let(:taggable_item) { TaggableItem.new(id: 1) }
20
+
21
+ subject { taggable_item.tags }
22
+
23
+ it { should be_a(Array) }
24
+
25
+ it { subject.length.should eql(2) }
26
+
27
+ it do
28
+ subject.all? { |item| item.is_a?(CapsuleCRM::Tag) }.should be_true
29
+ end
30
+
31
+ it { subject.first.name.should eql('Customer') }
32
+
33
+ it { subject.last.name.should eql('VIP') }
34
+ end
35
+
36
+ describe '#add_tag' do
37
+ context 'when the taggable item has an id' do
38
+ let(:taggable_item) { TaggableItem.new(id: 1) }
39
+
40
+ before do
41
+ loc = 'https://sample.capsulecrm.com/api/party/1000/tag/A%20Test%20Tag'
42
+ stub_request(:post, /\/api\/taggableitem\/1\/A%20Test%20Tag$/).
43
+ to_return(headers: { 'Location' => loc })
44
+ end
45
+
46
+ subject { taggable_item.add_tag 'A Test Tag' }
47
+
48
+ it { subject.should be_true }
49
+ end
50
+
51
+ context 'when the taggable item has no id' do
52
+ let(:taggable_item) { TaggableItem.new }
53
+
54
+ subject { taggable_item.add_tag 'A Test Tag' }
55
+
56
+ it { subject.should be_nil }
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe CapsuleCRM::User do
4
+ before { configure }
5
+
6
+ describe '.all' do
7
+ before do
8
+ stub_request(:get, /\/api\/users$/).
9
+ to_return(body: File.read('spec/support/all_users.json'))
10
+ end
11
+
12
+ subject { CapsuleCRM::User.all }
13
+
14
+ it { should be_a(Array) }
15
+
16
+ it { subject.length.should eql(2) }
17
+
18
+ it { subject.all? { |item| item.is_a?(CapsuleCRM::User) }.should be_true }
19
+ end
20
+ end
@@ -0,0 +1,12 @@
1
+ {
2
+ "tags": {
3
+ "tag": [
4
+ {
5
+ "name": "Customer"
6
+ },
7
+ {
8
+ "name": "VIP"
9
+ }
10
+ ]
11
+ }
12
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "users": {
3
+ "user": [
4
+ {
5
+ "username": "a.user",
6
+ "currency": "GBP",
7
+ "name": "Alfred User",
8
+ "loggedIn": "true",
9
+ "timezone": "Europe/London",
10
+ "partyId": "100"
11
+ },
12
+ {
13
+ "username": "j.joe",
14
+ "currency": "GBP",
15
+ "name": "Jane Doe",
16
+ "timezone": "Europe/London",
17
+ "partyId": "101"
18
+ }
19
+ ]
20
+ }
21
+ }
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: 0.0.6
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Beedle
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-11 00:00:00.000000000 Z
11
+ date: 2013-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -244,6 +244,9 @@ files:
244
244
  - lib/capsule_crm/person.rb
245
245
  - lib/capsule_crm/phone.rb
246
246
  - lib/capsule_crm/results_proxy.rb
247
+ - lib/capsule_crm/tag.rb
248
+ - lib/capsule_crm/taggable.rb
249
+ - lib/capsule_crm/user.rb
247
250
  - lib/capsule_crm/version.rb
248
251
  - lib/capsule_crm/website.rb
249
252
  - spec/fabricators/opportunity_fabricator.rb
@@ -257,11 +260,16 @@ files:
257
260
  - spec/lib/capsule_crm/opportunity_spec.rb
258
261
  - spec/lib/capsule_crm/organization_spec.rb
259
262
  - spec/lib/capsule_crm/person_spec.rb
263
+ - spec/lib/capsule_crm/tag_spec.rb
264
+ - spec/lib/capsule_crm/taggable_spec.rb
265
+ - spec/lib/capsule_crm/user_spec.rb
260
266
  - spec/spec_helper.rb
261
267
  - spec/support/all_cases.json
262
268
  - spec/support/all_opportunities.json
263
269
  - spec/support/all_parties.json
264
270
  - spec/support/all_people.json
271
+ - spec/support/all_tags.json
272
+ - spec/support/all_users.json
265
273
  - spec/support/case.json
266
274
  - spec/support/deleted_opportunities.json
267
275
  - spec/support/helpers.rb
@@ -304,11 +312,16 @@ test_files:
304
312
  - spec/lib/capsule_crm/opportunity_spec.rb
305
313
  - spec/lib/capsule_crm/organization_spec.rb
306
314
  - spec/lib/capsule_crm/person_spec.rb
315
+ - spec/lib/capsule_crm/tag_spec.rb
316
+ - spec/lib/capsule_crm/taggable_spec.rb
317
+ - spec/lib/capsule_crm/user_spec.rb
307
318
  - spec/spec_helper.rb
308
319
  - spec/support/all_cases.json
309
320
  - spec/support/all_opportunities.json
310
321
  - spec/support/all_parties.json
311
322
  - spec/support/all_people.json
323
+ - spec/support/all_tags.json
324
+ - spec/support/all_users.json
312
325
  - spec/support/case.json
313
326
  - spec/support/deleted_opportunities.json
314
327
  - spec/support/helpers.rb