capsulecrm 0.0.2 → 0.0.3

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.
@@ -6,11 +6,11 @@ Gem::Specification.new do |s|
6
6
  s.name = "capsulecrm"
7
7
  s.version = CapsuleCRM::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
- s.authors = ["Ahmed Adam"]
10
- s.email = ["ahmed.msgs@gmail.com"]
11
- s.homepage = ""
9
+ s.authors = ["Ahmed Adam", "Tadas Tamosauskas"]
10
+ s.email = ["ahmed.msgs@gmail.com", "tadastoo@yahoo.com"]
11
+ s.homepage = "https://github.com/ahmedrb/capsulecrm"
12
12
  s.summary = %q{CapsuleCRM API Gem}
13
- s.description = %q{CapsuleCRM API Gem}
13
+ s.description = %q{Wraps up a CapsuleCRM API}
14
14
 
15
15
  s.add_dependency 'httparty', '>= 0.7.4'
16
16
  s.add_dependency 'activemodel', '>= 3.0.5'
@@ -4,6 +4,11 @@
4
4
  # find by id
5
5
  person = CapsuleCRM::Person.find 123
6
6
 
7
+ # or if you don't know what you are searching for Party
8
+ something = CapsuleCRM::Party.find 123
9
+ something.is?(:person)
10
+ something.is?(:organisation)
11
+
7
12
  # find by email
8
13
  person = CapsuleCRM::Person.find_by_email 'foo@example.com'
9
14
 
@@ -46,6 +51,11 @@ person.phone_numbers # CapsuleCRM::Collection
46
51
  person.phone_numbers.first.number # 01234 56789
47
52
  person.phone_numbers.first.type # work
48
53
 
54
+ # Contacts: CapsuleCRM::Website (read-only)
55
+ party.websites # CapsuleCRM::Collection
56
+ party.websites.first.url # http://google.com
57
+ party.websites.first.web_address # http://google.com
58
+
49
59
  # Contacts: CapsuleCRM::Email (read-only)
50
60
  person.emails # CapsuleCRM::Collection
51
61
  person.emails.first.address # 'foo@example.com'
@@ -63,3 +73,7 @@ person.addresses.first.country # United Kingdom
63
73
  person.custom_fields # CapsuleCRM::Collection
64
74
  person.custom_fields.first.label # 'Favourite colour'
65
75
  person.custom_fields.first.value # 'Blue'
76
+
77
+ # CapsuleCRM::Tag (read-only)
78
+ person.tags # CapsuleCRM::Collection
79
+ person.tag_names # ["array", "of all", "tags", "as strings"]
@@ -38,3 +38,5 @@ require 'capsulecrm/contact'
38
38
  require 'capsulecrm/email'
39
39
  require 'capsulecrm/phone'
40
40
  require 'capsulecrm/address'
41
+ require 'capsulecrm/tag'
42
+ require 'capsulecrm/website'
@@ -7,7 +7,7 @@ class CapsuleCRM::Organisation < CapsuleCRM::Party
7
7
  # nodoc
8
8
  def people
9
9
  return @people if @people
10
- path = self.class.base_path
10
+ path = self.class.get_path
11
11
  path = [path, '/', id, '/people'].join
12
12
  last_response = self.class.get(path)
13
13
  @people = CapsuleCRM::Person.init_many(last_response)
@@ -4,7 +4,7 @@ class CapsuleCRM::Party < CapsuleCRM::Base
4
4
  # nodoc
5
5
  def addresses
6
6
  return @addresses if @addresses
7
- data = raw_data['contacts']['address']
7
+ data = raw_data['contacts'].try(:[], 'address')
8
8
  @addresses = CapsuleCRM::Address.init_many(self, data)
9
9
  end
10
10
 
@@ -12,18 +12,30 @@ class CapsuleCRM::Party < CapsuleCRM::Base
12
12
  # nodoc
13
13
  def custom_fields
14
14
  return @custom_fields if @custom_fields
15
- path = self.class.base_path
15
+ path = self.class.get_path
16
16
  path = [path, '/', id, '/customfield'].join
17
17
  last_response = self.class.get(path)
18
- data = last_response['customFields']['customField']
18
+ data = last_response['customFields'].try(:[], 'customField')
19
19
  @custom_fields = CapsuleCRM::CustomField.init_many(self, data)
20
20
  end
21
21
 
22
+ def tags
23
+ return @tags if @tags
24
+ path = self.class.get_path
25
+ path = [path, '/', id, '/tag'].join
26
+ last_response = self.class.get(path)
27
+ data = last_response['tags'].try(:[], 'tag')
28
+ @tags = CapsuleCRM::Tag.init_many(self, data)
29
+ end
30
+
31
+ def tag_names
32
+ tags.map(&:name)
33
+ end
22
34
 
23
35
  # nodoc
24
36
  def emails
25
37
  return @emails if @emails
26
- data = raw_data['contacts']['email']
38
+ data = raw_data['contacts'].try(:[], 'email')
27
39
  @emails = CapsuleCRM::Email.init_many(self, data)
28
40
  end
29
41
 
@@ -31,10 +43,21 @@ class CapsuleCRM::Party < CapsuleCRM::Base
31
43
  # nodoc
32
44
  def phone_numbers
33
45
  return @phone_numbers if @phone_numbers
34
- data = raw_data['contacts']['phone']
46
+ data = raw_data['contacts'].try(:[], 'phone')
35
47
  @phone_numbers = CapsuleCRM::Phone.init_many(self, data)
36
48
  end
37
49
 
50
+ # nodoc
51
+ def websites
52
+ return @websites if @websites
53
+ data = raw_data['contacts'].try(:[], 'website')
54
+ @websites = CapsuleCRM::Website.init_many(self, data)
55
+ end
56
+
57
+ def is?(kind)
58
+ required_class = kind.to_s.camelize
59
+ self.class.to_s.include? required_class
60
+ end
38
61
 
39
62
  # nodoc
40
63
  def self.get_path
@@ -60,5 +83,9 @@ class CapsuleCRM::Party < CapsuleCRM::Base
60
83
  find_all(options)
61
84
  end
62
85
 
63
-
86
+ def self.init_one(response)
87
+ return CapsuleCRM::Person.init_one(response) if response['person']
88
+ return CapsuleCRM::Organisation.init_one(response) if response['organisation']
89
+ raise CapsuleCRM::RecordNotRecognised, "Could not recognise returned entity type: #{response}"
90
+ end
64
91
  end
@@ -0,0 +1 @@
1
+ class CapsuleCRM::RecordNotRecognised < StandardError; end
@@ -0,0 +1,12 @@
1
+ class CapsuleCRM::Tag < CapsuleCRM::Child
2
+
3
+ attr_accessor :name
4
+
5
+ # nodoc
6
+ def self.xml_map
7
+ map = {
8
+ 'name' => 'name'
9
+ }
10
+ super.merge map
11
+ end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module CapsuleCRM
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,19 @@
1
+ class CapsuleCRM::Website < CapsuleCRM::Child
2
+
3
+ attr_accessor :web_address
4
+ attr_accessor :url
5
+ attr_accessor :web_service
6
+
7
+
8
+ # nodoc
9
+ def self.xml_map
10
+ map = {
11
+ 'webAddress' => 'web_address',
12
+ 'url' => 'url',
13
+ 'webService' => 'web_service'
14
+ }
15
+ super.merge map
16
+ end
17
+
18
+
19
+ end
@@ -0,0 +1,26 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: https://[API-TOKEN]:x@[ACCOUNT-NAME].capsulecrm.com:443/api/party/10185257/tag
6
+ body:
7
+ headers:
8
+ user-agent:
9
+ - CapsuleCRM ruby gem
10
+ response: !ruby/struct:VCR::Response
11
+ status: !ruby/struct:VCR::ResponseStatus
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ content-type:
16
+ - "*/*"
17
+ server:
18
+ - Apache
19
+ date:
20
+ - Tue, 12 Apr 2011 12:31:20 GMT
21
+ content-length:
22
+ - "426"
23
+ set-cookie:
24
+ - "[SESSION-COOKIE]"
25
+ body: <?xml version="1.0" encoding="UTF-8" standalone="yes"?><tags size="11"><tag><name>TMT</name></tag><tag><name>Industrials</name></tag><tag><name>Energy</name></tag><tag><name>Consumer</name></tag><tag><name>Healthcare</name></tag><tag><name>Professional Services</name></tag><tag><name>Mid-cap</name></tag><tag><name>Large-cap</name></tag><tag><name>EU</name></tag><tag><name>Asia</name></tag><tag><name>USA</name></tag></tags>
26
+ http_version: "1.1"
@@ -1,76 +1,102 @@
1
- ---
2
- - !ruby/struct:VCR::HTTPInteraction
3
- request: !ruby/struct:VCR::Request
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
4
  method: :get
5
5
  uri: https://[API-TOKEN]:x@[ACCOUNT-NAME].capsulecrm.com:443/api/party/10185256
6
- body:
7
- headers:
8
- user-agent:
6
+ body:
7
+ headers:
8
+ user-agent:
9
9
  - CapsuleCRM ruby gem
10
- response: !ruby/struct:VCR::Response
11
- status: !ruby/struct:VCR::ResponseStatus
10
+ response: !ruby/struct:VCR::Response
11
+ status: !ruby/struct:VCR::ResponseStatus
12
12
  code: 200
13
13
  message: OK
14
- headers:
15
- content-type:
14
+ headers:
15
+ content-type:
16
16
  - "*/*"
17
- server:
17
+ server:
18
18
  - Apache
19
- date:
19
+ date:
20
20
  - Tue, 12 Apr 2011 12:34:21 GMT
21
- content-length:
21
+ content-length:
22
22
  - "333"
23
- set-cookie:
23
+ set-cookie:
24
24
  - "[SESSION-COOKIE]"
25
25
  body: <?xml version="1.0" encoding="UTF-8" standalone="yes"?><organisation><id>10185256</id><contacts><email><id>18583945</id><emailAddress>gov@example.com</emailAddress></email></contacts><pictureURL>https://d365sd3k9yw37.cloudfront.net/a/543325/theme/default/images/org_avatar_70.png</pictureURL><name>UK Government</name></organisation>
26
26
  http_version: "1.1"
27
- - !ruby/struct:VCR::HTTPInteraction
28
- request: !ruby/struct:VCR::Request
27
+ - !ruby/struct:VCR::HTTPInteraction
28
+ request: !ruby/struct:VCR::Request
29
29
  method: :get
30
30
  uri: https://[API-TOKEN]:x@[ACCOUNT-NAME].capsulecrm.com:443/api/party/10185257
31
- body:
32
- headers:
33
- user-agent:
31
+ body:
32
+ headers:
33
+ user-agent:
34
34
  - CapsuleCRM ruby gem
35
- response: !ruby/struct:VCR::Response
36
- status: !ruby/struct:VCR::ResponseStatus
35
+ response: !ruby/struct:VCR::Response
36
+ status: !ruby/struct:VCR::ResponseStatus
37
37
  code: 200
38
38
  message: OK
39
- headers:
40
- content-type:
39
+ headers:
40
+ content-type:
41
41
  - "*/*"
42
- server:
42
+ server:
43
43
  - Apache
44
- date:
44
+ date:
45
45
  - Tue, 12 Apr 2011 12:34:22 GMT
46
- content-length:
46
+ content-length:
47
47
  - "897"
48
- set-cookie:
48
+ set-cookie:
49
49
  - "[SESSION-COOKIE]"
50
50
  body: <?xml version="1.0" encoding="UTF-8" standalone="yes"?><person><id>10185257</id><contacts><address><id>18565068</id><type>Office</type><street>10 Downing Street</street><city>London</city><zip>SW1A 2AA</zip><country>United Kingdom</country></address><email><id>18565066</id><type>Work</type><emailAddress>pm@example.com</emailAddress></email><phone><id>18566503</id><phoneNumber>12345 67890</phoneNumber></phone><website><id>18565067</id><webAddress>http://www.number10.gov.uk/</webAddress><webService>URL</webService><url>http://www.number10.gov.uk/</url></website></contacts><pictureURL>https://d365sd3k9yw37.cloudfront.net/a/543325/theme/default/images/person_avatar_70.png</pictureURL><title>Mr</title><firstName>David</firstName><lastName>Cameron</lastName><jobTitle>Prime Minister</jobTitle><organisationId>10185256</organisationId><organisationName>UK Government</organisationName></person>
51
51
  http_version: "1.1"
52
- - !ruby/struct:VCR::HTTPInteraction
53
- request: !ruby/struct:VCR::Request
52
+ - !ruby/struct:VCR::HTTPInteraction
53
+ request: !ruby/struct:VCR::Request
54
54
  method: :get
55
55
  uri: https://[API-TOKEN]:x@[ACCOUNT-NAME].capsulecrm.com:443/api/party/10185256
56
- body:
57
- headers:
58
- user-agent:
56
+ body:
57
+ headers:
58
+ user-agent:
59
59
  - CapsuleCRM ruby gem
60
- response: !ruby/struct:VCR::Response
61
- status: !ruby/struct:VCR::ResponseStatus
60
+ response: !ruby/struct:VCR::Response
61
+ status: !ruby/struct:VCR::ResponseStatus
62
62
  code: 200
63
63
  message: OK
64
- headers:
65
- content-type:
64
+ headers:
65
+ content-type:
66
66
  - "*/*"
67
- server:
67
+ server:
68
68
  - Apache
69
- date:
69
+ date:
70
70
  - Tue, 12 Apr 2011 12:34:24 GMT
71
- content-length:
71
+ content-length:
72
72
  - "333"
73
- set-cookie:
73
+ set-cookie:
74
74
  - "[SESSION-COOKIE]"
75
75
  body: <?xml version="1.0" encoding="UTF-8" standalone="yes"?><organisation><id>10185256</id><contacts><email><id>18583945</id><emailAddress>gov@example.com</emailAddress></email></contacts><pictureURL>https://d365sd3k9yw37.cloudfront.net/a/543325/theme/default/images/org_avatar_70.png</pictureURL><name>UK Government</name></organisation>
76
76
  http_version: "1.1"
77
+
78
+ - !ruby/struct:VCR::HTTPInteraction
79
+ request: !ruby/struct:VCR::Request
80
+ method: :get
81
+ uri: https://[API-TOKEN]:x@[ACCOUNT-NAME].capsulecrm.com:443/api/party/11111111
82
+ body:
83
+ headers:
84
+ user-agent:
85
+ - CapsuleCRM ruby gem
86
+ response: !ruby/struct:VCR::Response
87
+ status: !ruby/struct:VCR::ResponseStatus
88
+ code: 200
89
+ message: OK
90
+ headers:
91
+ content-type:
92
+ - "*/*"
93
+ server:
94
+ - Apache
95
+ date:
96
+ - Tue, 12 Apr 2011 12:34:24 GMT
97
+ content-length:
98
+ - "333"
99
+ set-cookie:
100
+ - "[SESSION-COOKIE]"
101
+ body: <?xml version="1.0" encoding="UTF-8" standalone="yes"?><organisation><id>10185256</id><pictureURL>https://d365sd3k9yw37.cloudfront.net/a/543325/theme/default/images/org_avatar_70.png</pictureURL><name>UK Government</name></organisation>
102
+ http_version: "1.1"
@@ -0,0 +1,40 @@
1
+ require 'test_helper'
2
+ class PartyDotFindTest < Test::Unit::TestCase
3
+
4
+ def setup
5
+ end
6
+
7
+ # nodoc
8
+ def test_find_organisation
9
+ VCR.use_cassette('person.find_by_id') do
10
+ @organisation = CapsuleCRM::Party.find organisations(:gov)
11
+ end
12
+ assert @organisation.is?(:organisation)
13
+ end
14
+
15
+ # nodoc
16
+ def test_find_person
17
+ VCR.use_cassette('person.find_by_id') do
18
+ @person = CapsuleCRM::Party.find people(:pm)
19
+ end
20
+ assert @person.is?(:person)
21
+ assert_equal @person.first_name, "David"
22
+ end
23
+
24
+ def test_party_without_contacts
25
+ VCR.use_cassette('person.find_by_id') do
26
+ @org = CapsuleCRM::Party.find organisations(:emptyish)
27
+ end
28
+
29
+ fields = %w(emails phone_numbers websites addresses)
30
+ fields.each do |field|
31
+ assert @org.send(field).blank?
32
+ end
33
+ end
34
+
35
+ # nodoc
36
+ def teardown
37
+ WebMock.reset!
38
+ end
39
+
40
+ end
@@ -0,0 +1,30 @@
1
+ require 'test_helper'
2
+ class PartyDotTagsTest < Test::Unit::TestCase
3
+
4
+ def setup
5
+ VCR.use_cassette('person.find_by_id') do
6
+ @person = CapsuleCRM::Person.find people(:pm)
7
+ end
8
+ end
9
+
10
+ def test_tag_names
11
+ VCR.use_cassette('party.tags') do
12
+ @taglist = @person.tag_names
13
+ end
14
+ assert_equal @taglist.size, 11
15
+ end
16
+
17
+
18
+ def test_tags_and_tagnames
19
+ VCR.use_cassette('party.tags') do
20
+ @tagnames = @person.tag_names
21
+ @taglist = @person.tags
22
+ end
23
+ assert_equal @tagnames.size, @taglist.size
24
+ end
25
+
26
+ def teardown
27
+ WebMock.reset!
28
+ end
29
+
30
+ end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require 'test_helper'
2
2
 
3
3
  class PersonDotFindAllTest < Test::Unit::TestCase
4
4
 
@@ -48,6 +48,10 @@ class PersonDotFindByIdTest < Test::Unit::TestCase
48
48
  @person.phone_numbers.each { |pn| assert pn.is_a?(CapsuleCRM::Phone) }
49
49
  end
50
50
 
51
+ def test_websites
52
+ assert_equal CapsuleCRM::ChildCollection, @person.phone_numbers.class
53
+ assert_equal 1, @person.websites.size
54
+ end
51
55
 
52
56
  def teardown
53
57
  WebMock.reset!
@@ -1,5 +1,5 @@
1
1
  require 'rubygems'
2
- require 'ruby-debug'
2
+ # require 'ruby-debug'
3
3
  require 'test/unit'
4
4
  require 'webmock/test_unit'
5
5
  require 'vcr'
@@ -33,7 +33,8 @@ class Test::Unit::TestCase
33
33
  # nodoc
34
34
  def organisations(key)
35
35
  ids = {
36
- :gov => 10185256
36
+ :gov => 10185256,
37
+ :emptyish => 11111111
37
38
  }
38
39
  ids[key]
39
40
  end
metadata CHANGED
@@ -1,21 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capsulecrm
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 0
9
- - 2
10
- version: 0.0.2
4
+ prerelease:
5
+ version: 0.0.3
11
6
  platform: ruby
12
7
  authors:
13
8
  - Ahmed Adam
9
+ - Tadas Tamosauskas
14
10
  autorequire:
15
11
  bindir: bin
16
12
  cert_chain: []
17
13
 
18
- date: 2011-04-12 00:00:00 +01:00
14
+ date: 2011-04-18 00:00:00 +01:00
19
15
  default_executable:
20
16
  dependencies:
21
17
  - !ruby/object:Gem::Dependency
@@ -26,11 +22,6 @@ dependencies:
26
22
  requirements:
27
23
  - - ">="
28
24
  - !ruby/object:Gem::Version
29
- hash: 11
30
- segments:
31
- - 0
32
- - 7
33
- - 4
34
25
  version: 0.7.4
35
26
  type: :runtime
36
27
  version_requirements: *id001
@@ -42,11 +33,6 @@ dependencies:
42
33
  requirements:
43
34
  - - ">="
44
35
  - !ruby/object:Gem::Version
45
- hash: 13
46
- segments:
47
- - 3
48
- - 0
49
- - 5
50
36
  version: 3.0.5
51
37
  type: :runtime
52
38
  version_requirements: *id002
@@ -58,17 +44,13 @@ dependencies:
58
44
  requirements:
59
45
  - - ">="
60
46
  - !ruby/object:Gem::Version
61
- hash: 13
62
- segments:
63
- - 3
64
- - 0
65
- - 5
66
47
  version: 3.0.5
67
48
  type: :runtime
68
49
  version_requirements: *id003
69
- description: CapsuleCRM API Gem
50
+ description: Wraps up a CapsuleCRM API
70
51
  email:
71
52
  - ahmed.msgs@gmail.com
53
+ - tadastoo@yahoo.com
72
54
  executables: []
73
55
 
74
56
  extensions: []
@@ -96,21 +78,27 @@ files:
96
78
  - lib/capsulecrm/person.rb
97
79
  - lib/capsulecrm/phone.rb
98
80
  - lib/capsulecrm/record_not_found.rb
81
+ - lib/capsulecrm/recorn_not_recognised.rb
82
+ - lib/capsulecrm/tag.rb
99
83
  - lib/capsulecrm/version.rb
84
+ - lib/capsulecrm/website.rb
100
85
  - test/create_person_test.rb
101
86
  - test/fixtures/responses/create_person.yml
87
+ - test/fixtures/responses/party_tags.yml
102
88
  - test/fixtures/responses/person_find_all.yml
103
89
  - test/fixtures/responses/person_find_all_with_limit.yml
104
90
  - test/fixtures/responses/person_find_all_with_offset.yml
105
91
  - test/fixtures/responses/person_find_by_id.yml
106
92
  - test/fixtures/responses/update_person.yml
107
93
  - test/fixtures/responses/update_person_without_changes.yml
94
+ - test/party_dot_find_test.rb
95
+ - test/party_dot_tags_test.rb
108
96
  - test/person_dot_find_all_test.rb
109
97
  - test/person_dot_find_by_id_test.rb
110
98
  - test/test_helper.rb
111
99
  - test/update_person_test.rb
112
100
  has_rdoc: true
113
- homepage: ""
101
+ homepage: https://github.com/ahmedrb/capsulecrm
114
102
  licenses: []
115
103
 
116
104
  post_install_message:
@@ -123,25 +111,33 @@ required_ruby_version: !ruby/object:Gem::Requirement
123
111
  requirements:
124
112
  - - ">="
125
113
  - !ruby/object:Gem::Version
126
- hash: 3
127
- segments:
128
- - 0
129
114
  version: "0"
130
115
  required_rubygems_version: !ruby/object:Gem::Requirement
131
116
  none: false
132
117
  requirements:
133
118
  - - ">="
134
119
  - !ruby/object:Gem::Version
135
- hash: 3
136
- segments:
137
- - 0
138
120
  version: "0"
139
121
  requirements: []
140
122
 
141
123
  rubyforge_project: capsulecrm
142
- rubygems_version: 1.3.7
124
+ rubygems_version: 1.6.2
143
125
  signing_key:
144
126
  specification_version: 3
145
127
  summary: CapsuleCRM API Gem
146
- test_files: []
147
-
128
+ test_files:
129
+ - test/create_person_test.rb
130
+ - test/fixtures/responses/create_person.yml
131
+ - test/fixtures/responses/party_tags.yml
132
+ - test/fixtures/responses/person_find_all.yml
133
+ - test/fixtures/responses/person_find_all_with_limit.yml
134
+ - test/fixtures/responses/person_find_all_with_offset.yml
135
+ - test/fixtures/responses/person_find_by_id.yml
136
+ - test/fixtures/responses/update_person.yml
137
+ - test/fixtures/responses/update_person_without_changes.yml
138
+ - test/party_dot_find_test.rb
139
+ - test/party_dot_tags_test.rb
140
+ - test/person_dot_find_all_test.rb
141
+ - test/person_dot_find_by_id_test.rb
142
+ - test/test_helper.rb
143
+ - test/update_person_test.rb