capsulecrmii 0.0.5

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.
Files changed (44) hide show
  1. data/.gitignore +4 -0
  2. data/Gemfile +10 -0
  3. data/README.rdoc +33 -0
  4. data/Rakefile +9 -0
  5. data/capsulecrm.gemspec +23 -0
  6. data/examples.rb +82 -0
  7. data/lib/capsulecrm.rb +45 -0
  8. data/lib/capsulecrm/address.rb +23 -0
  9. data/lib/capsulecrm/base.rb +176 -0
  10. data/lib/capsulecrm/child.rb +24 -0
  11. data/lib/capsulecrm/child_collection.rb +14 -0
  12. data/lib/capsulecrm/collection.rb +14 -0
  13. data/lib/capsulecrm/contact.rb +27 -0
  14. data/lib/capsulecrm/custom_field.rb +41 -0
  15. data/lib/capsulecrm/email.rb +64 -0
  16. data/lib/capsulecrm/history.rb +32 -0
  17. data/lib/capsulecrm/history_item.rb +20 -0
  18. data/lib/capsulecrm/organisation.rb +41 -0
  19. data/lib/capsulecrm/party.rb +114 -0
  20. data/lib/capsulecrm/person.rb +126 -0
  21. data/lib/capsulecrm/phone.rb +15 -0
  22. data/lib/capsulecrm/record_not_found.rb +1 -0
  23. data/lib/capsulecrm/recorn_not_recognised.rb +1 -0
  24. data/lib/capsulecrm/tag.rb +12 -0
  25. data/lib/capsulecrm/version.rb +3 -0
  26. data/lib/capsulecrm/website.rb +19 -0
  27. data/test/create_person_test.rb +36 -0
  28. data/test/fixtures/responses/create_person.yml +59 -0
  29. data/test/fixtures/responses/party_history.yml +45 -0
  30. data/test/fixtures/responses/party_tags.yml +26 -0
  31. data/test/fixtures/responses/person_find_all.yml +28 -0
  32. data/test/fixtures/responses/person_find_all_with_limit.yml +26 -0
  33. data/test/fixtures/responses/person_find_all_with_offset.yml +28 -0
  34. data/test/fixtures/responses/person_find_by_id.yml +102 -0
  35. data/test/fixtures/responses/update_person.yml +85 -0
  36. data/test/fixtures/responses/update_person_without_changes.yml +28 -0
  37. data/test/party_dot_find_test.rb +40 -0
  38. data/test/party_dot_history_test.rb +29 -0
  39. data/test/party_dot_tags_test.rb +30 -0
  40. data/test/person_dot_find_all_test.rb +48 -0
  41. data/test/person_dot_find_by_id_test.rb +61 -0
  42. data/test/test_helper.rb +52 -0
  43. data/test/update_person_test.rb +46 -0
  44. metadata +131 -0
@@ -0,0 +1,28 @@
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/10185261
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:29:07 GMT
21
+ content-length:
22
+ - "709"
23
+ set-cookie:
24
+ - "[SESSION-COOKIE]"
25
+ body: |-
26
+ <?xml version="1.0" encoding="UTF-8" standalone="yes"?><person><id>10185261</id><contacts><address><id>18565115</id><type>Office</type><street>Deputy Prime Minister's Office&#xD;
27
+ 70 Whitehall</street><city>London</city><zip>SW1A 2AS</zip><country>United Kingdom</country></address><email><id>18565116</id><type>Work</type><emailAddress>dpm@example.com</emailAddress></email></contacts><pictureURL>https://d365sd3k9yw37.cloudfront.net/a/543325/theme/default/images/person_avatar_70.png</pictureURL><title>Mr</title><firstName>Nick</firstName><lastName>Clegg</lastName><jobTitle>Deputy Prime Minister</jobTitle><organisationId>10185256</organisationId><organisationName>UK Government</organisationName></person>
28
+ 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,29 @@
1
+ require 'test_helper'
2
+ class PartyDotHistoryTest < 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_load_history
11
+ VCR.use_cassette('party.history') do
12
+ assert_equal 2, @person.history.size
13
+ assert_equal "First subject", @person.history[0].subject
14
+ end
15
+ end
16
+
17
+ def test_add_history
18
+ skip "Should write a cassette to handle adding a note"
19
+ VCR.use_cassette('party.history') do
20
+ @person.add_history "new history"
21
+ assert_equal 2, @person.history.size
22
+ end
23
+ end
24
+
25
+ def teardown
26
+ WebMock.reset!
27
+ end
28
+
29
+ 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
@@ -0,0 +1,48 @@
1
+ require 'test_helper'
2
+
3
+ class PersonDotFindAllTest < Test::Unit::TestCase
4
+
5
+ # nodoc
6
+ def setup
7
+ VCR.use_cassette 'person.find_all' do
8
+ @results = CapsuleCRM::Person.find :all
9
+ end
10
+ end
11
+
12
+
13
+ # nodoc
14
+ def test_return_value_type
15
+ assert_equal CapsuleCRM::Collection, @results.class
16
+ end
17
+
18
+
19
+ # nodoc
20
+ def test_return_value_size
21
+ assert_equal 6, @results.size
22
+ end
23
+
24
+
25
+ # nodoc
26
+ def test_offset_parameter
27
+ VCR.use_cassette 'person.find_all_with_offset' do
28
+ @results = CapsuleCRM::Person.find :all, :offset => 3
29
+ assert_requested :get, /capsulecrm.*start=3/
30
+ end
31
+ end
32
+
33
+
34
+ # nodoc
35
+ def test_limit_parameter
36
+ VCR.use_cassette 'person.find_all_with_limit' do
37
+ @results = CapsuleCRM::Person.find(:all, :limit => 2)
38
+ assert_requested :get, /capsulecrm.*limit=2/
39
+ end
40
+ end
41
+
42
+
43
+ # nodoc
44
+ def teardown
45
+ WebMock.reset!
46
+ end
47
+
48
+ end
@@ -0,0 +1,61 @@
1
+ require 'test_helper'
2
+ class PersonDotFindByIdTest < Test::Unit::TestCase
3
+
4
+ def setup
5
+ VCR.use_cassette('person.find_by_id') do
6
+ @organisation = CapsuleCRM::Organisation.find organisations(:gov)
7
+ @person = CapsuleCRM::Person.find people(:pm)
8
+ @person.organisation # to record the request
9
+ end
10
+ end
11
+
12
+
13
+ # nodoc
14
+ def test_attributes
15
+ assert_equal @person.title, 'Mr'
16
+ assert_equal @person.first_name, 'David'
17
+ assert_equal @person.last_name, 'Cameron'
18
+ assert_equal @person.job_title, 'Prime Minister'
19
+ end
20
+
21
+
22
+ # nodoc
23
+ def test_organisation
24
+ assert_equal @organisation, @person.organisation
25
+ end
26
+
27
+
28
+ # nodoc
29
+ def test_addresses
30
+ assert_equal CapsuleCRM::ChildCollection, @person.addresses.class
31
+ assert_equal 1, @person.addresses.size
32
+ @person.addresses.each { |address| assert address.is_a?(CapsuleCRM::Address) }
33
+ end
34
+
35
+
36
+ # nodoc
37
+ def test_emails
38
+ assert_equal CapsuleCRM::ChildCollection, @person.emails.class
39
+ assert_equal 1, @person.emails.size
40
+ @person.emails.each { |email| assert email.is_a?(CapsuleCRM::Email) }
41
+ end
42
+
43
+
44
+ # nodoc
45
+ def test_phone_numbers
46
+ assert_equal CapsuleCRM::ChildCollection, @person.phone_numbers.class
47
+ assert_equal 1, @person.phone_numbers.size
48
+ @person.phone_numbers.each { |pn| assert pn.is_a?(CapsuleCRM::Phone) }
49
+ end
50
+
51
+ def test_websites
52
+ assert_equal CapsuleCRM::ChildCollection, @person.phone_numbers.class
53
+ assert_equal 1, @person.websites.size
54
+ end
55
+
56
+ def teardown
57
+ WebMock.reset!
58
+ end
59
+
60
+
61
+ end
@@ -0,0 +1,52 @@
1
+ require 'rubygems'
2
+ # require 'ruby-debug'
3
+ require 'test/unit'
4
+ require 'webmock/test_unit'
5
+ require 'vcr'
6
+
7
+
8
+ # .gemspec does this usually
9
+ $: << File.expand_path('../../lib', __FILE__)
10
+ require 'capsulecrm'
11
+
12
+ # initialization - credentials only matter for VCR's first run
13
+ CapsuleCRM.account_name = ENV['CAPSULE_ACCOUNT'] || 'foo'
14
+ CapsuleCRM.api_token = ENV['CAPSULE_TOKEN'] || 'bar'
15
+ CapsuleCRM.initialize!
16
+
17
+
18
+ # nodoc
19
+ VCR.config do |c|
20
+ c.cassette_library_dir = 'test/fixtures/responses'
21
+ c.stub_with :webmock
22
+ c.filter_sensitive_data('[API-TOKEN]') { CapsuleCRM.api_token }
23
+ c.filter_sensitive_data('[ACCOUNT-NAME]') { CapsuleCRM.account_name }
24
+ c.filter_sensitive_data('[SESSION-COOKIE]') do |interaction|
25
+ interaction.response.headers['set-cookie'].first
26
+ end
27
+ end
28
+
29
+
30
+ # nodoc
31
+ class Test::Unit::TestCase
32
+
33
+ # nodoc
34
+ def organisations(key)
35
+ ids = {
36
+ :gov => 10185256,
37
+ :emptyish => 11111111
38
+ }
39
+ ids[key]
40
+ end
41
+
42
+
43
+ # nodoc
44
+ def people(key)
45
+ ids = {
46
+ :dpm => 10185261,
47
+ :pm => 10185257
48
+ }
49
+ ids[key]
50
+ end
51
+
52
+ end
@@ -0,0 +1,46 @@
1
+ require 'test_helper'
2
+ class UpdatePersonTest < Test::Unit::TestCase
3
+
4
+ # nodoc
5
+ def setup
6
+ end
7
+
8
+
9
+ # nodoc
10
+ def test_with_changes
11
+ VCR.use_cassette('update_person') do
12
+
13
+ # get the person, cache the first name
14
+ person = CapsuleCRM::Person.find people(:dpm)
15
+ first_name = person.first_name
16
+ new_name = first_name.reverse
17
+
18
+ # change the name and update
19
+ person.first_name = new_name
20
+ assert person.save
21
+
22
+ # reload and check updates were saved
23
+ person = CapsuleCRM::Person.find person.id
24
+ assert_equal new_name, person.first_name
25
+
26
+ end
27
+ end
28
+
29
+
30
+ # nodoc
31
+ def test_without_changes
32
+ VCR.use_cassette('update_person_without_changes') do
33
+ person = CapsuleCRM::Person.find people(:dpm)
34
+ assert person.save
35
+ assert_requested :put, /capsulecrm/, :times => 0
36
+ end
37
+ end
38
+
39
+
40
+ # nodoc
41
+ def teardown
42
+ WebMock.reset!
43
+ end
44
+
45
+
46
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capsulecrmii
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.5
6
+ platform: ruby
7
+ authors:
8
+ - Ahmed Adam
9
+ - dsimard
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+
14
+ date: 2012-02-24 00:00:00 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: httparty
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: "0.7"
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: activemodel
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ~>
34
+ - !ruby/object:Gem::Version
35
+ version: "3.0"
36
+ type: :runtime
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: activesupport
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: "3.0"
47
+ type: :runtime
48
+ version_requirements: *id003
49
+ description: CapsuleCRM API Gem
50
+ email:
51
+ - ahmed.msgs@gmail.com
52
+ - dsimard@azanka.ca
53
+ executables: []
54
+
55
+ extensions: []
56
+
57
+ extra_rdoc_files: []
58
+
59
+ files:
60
+ - .gitignore
61
+ - Gemfile
62
+ - README.rdoc
63
+ - Rakefile
64
+ - capsulecrm.gemspec
65
+ - examples.rb
66
+ - lib/capsulecrm.rb
67
+ - lib/capsulecrm/address.rb
68
+ - lib/capsulecrm/base.rb
69
+ - lib/capsulecrm/child.rb
70
+ - lib/capsulecrm/child_collection.rb
71
+ - lib/capsulecrm/collection.rb
72
+ - lib/capsulecrm/contact.rb
73
+ - lib/capsulecrm/custom_field.rb
74
+ - lib/capsulecrm/email.rb
75
+ - lib/capsulecrm/history.rb
76
+ - lib/capsulecrm/history_item.rb
77
+ - lib/capsulecrm/organisation.rb
78
+ - lib/capsulecrm/party.rb
79
+ - lib/capsulecrm/person.rb
80
+ - lib/capsulecrm/phone.rb
81
+ - lib/capsulecrm/record_not_found.rb
82
+ - lib/capsulecrm/recorn_not_recognised.rb
83
+ - lib/capsulecrm/tag.rb
84
+ - lib/capsulecrm/version.rb
85
+ - lib/capsulecrm/website.rb
86
+ - test/create_person_test.rb
87
+ - test/fixtures/responses/create_person.yml
88
+ - test/fixtures/responses/party_history.yml
89
+ - test/fixtures/responses/party_tags.yml
90
+ - test/fixtures/responses/person_find_all.yml
91
+ - test/fixtures/responses/person_find_all_with_limit.yml
92
+ - test/fixtures/responses/person_find_all_with_offset.yml
93
+ - test/fixtures/responses/person_find_by_id.yml
94
+ - test/fixtures/responses/update_person.yml
95
+ - test/fixtures/responses/update_person_without_changes.yml
96
+ - test/party_dot_find_test.rb
97
+ - test/party_dot_history_test.rb
98
+ - test/party_dot_tags_test.rb
99
+ - test/person_dot_find_all_test.rb
100
+ - test/person_dot_find_by_id_test.rb
101
+ - test/test_helper.rb
102
+ - test/update_person_test.rb
103
+ homepage: https://github.com/dsimard/capsulecrm
104
+ licenses: []
105
+
106
+ post_install_message:
107
+ rdoc_options: []
108
+
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: "0"
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: "0"
123
+ requirements: []
124
+
125
+ rubyforge_project:
126
+ rubygems_version: 1.8.15
127
+ signing_key:
128
+ specification_version: 3
129
+ summary: CapsuleCRM API Gem
130
+ test_files: []
131
+