capsule_crm 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/Guardfile +17 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/capsule_crm.gemspec +31 -0
- data/features/organizations.feature +4 -0
- data/lib/capsule_crm.rb +26 -0
- data/lib/capsule_crm/associations.rb +10 -0
- data/lib/capsule_crm/associations/belongs_to.rb +12 -0
- data/lib/capsule_crm/associations/has_many.rb +12 -0
- data/lib/capsule_crm/associations/has_many_proxy.rb +3 -0
- data/lib/capsule_crm/configuration.rb +8 -0
- data/lib/capsule_crm/connection.rb +47 -0
- data/lib/capsule_crm/contact.rb +6 -0
- data/lib/capsule_crm/hash_helper.rb +17 -0
- data/lib/capsule_crm/organization.rb +84 -0
- data/lib/capsule_crm/party.rb +2 -0
- data/lib/capsule_crm/person.rb +190 -0
- data/lib/capsule_crm/results_proxy.rb +18 -0
- data/lib/capsule_crm/version.rb +3 -0
- data/spec/lib/capsule_crm/person_spec.rb +196 -0
- data/spec/spec_helper.rb +25 -0
- data/spec/support/all_parties.json +26 -0
- data/spec/support/create-person.json +33 -0
- data/spec/support/helpers.rb +8 -0
- data/spec/support/person.json +9 -0
- data/spec/support/update-person.json +5 -0
- metadata +221 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 395464813fddf0c08a191e17b395fed06e65c158
|
4
|
+
data.tar.gz: 391e2918c9f05a3ad4c9362e19bb8adc2b6a4481
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b5c63e469b2590cafc343352b6127e8251bcb11285f598dfeb0de7296ee279fc24200e34379ba63c9a832f3c68c6ff907da56f5f9e8ad20ffd5e3e135167e6f0
|
7
|
+
data.tar.gz: d0d215942a05b56c9c1d71181749be9ec3e77ec1b486485e197f35c18c3ba7b3e8915572742c8d648b6848a5a5937905560ac010e364a8ed8d7d8a9484537cb9
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
notification :tmux
|
5
|
+
|
6
|
+
guard 'rspec' do
|
7
|
+
watch(%r{^spec/.+_spec\.rb$})
|
8
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
9
|
+
watch('spec/spec_helper.rb') { "spec" }
|
10
|
+
|
11
|
+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
12
|
+
|
13
|
+
# Turnip features and steps
|
14
|
+
watch(%r{^spec/acceptance/(.+)\.feature$})
|
15
|
+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
|
16
|
+
end
|
17
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Matt Beedle
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# CapsuleCrm
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'capsule_crm'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install capsule_crm
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/capsule_crm.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'capsule_crm/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "capsule_crm"
|
8
|
+
gem.version = CapsuleCrm::VERSION
|
9
|
+
gem.authors = ["Matt Beedle"]
|
10
|
+
gem.email = ["mattbeedle@googlemail.com"]
|
11
|
+
gem.description = %q{Gem to communicate with CapsuleCRM}
|
12
|
+
gem.summary = %q{Gem to communicate with CapsuleCRM}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_runtime_dependency('activemodel')
|
21
|
+
gem.add_runtime_dependency('activesupport')
|
22
|
+
gem.add_runtime_dependency('faraday')
|
23
|
+
gem.add_runtime_dependency('virtus')
|
24
|
+
|
25
|
+
gem.add_development_dependency('cucumber')
|
26
|
+
gem.add_development_dependency('guard')
|
27
|
+
gem.add_development_dependency('guard-rspec')
|
28
|
+
gem.add_development_dependency('rb-fsevent')
|
29
|
+
gem.add_development_dependency('rspec')
|
30
|
+
gem.add_development_dependency('webmock')
|
31
|
+
end
|
data/lib/capsule_crm.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'active_model'
|
2
|
+
require 'faraday'
|
3
|
+
require 'virtus'
|
4
|
+
require 'capsule_crm/connection'
|
5
|
+
require 'capsule_crm/hash_helper'
|
6
|
+
require 'capsule_crm/results_proxy'
|
7
|
+
require 'capsule_crm/associations/belongs_to'
|
8
|
+
require 'capsule_crm/associations/has_many'
|
9
|
+
require 'capsule_crm/associations/has_many_proxy'
|
10
|
+
require 'capsule_crm/configuration'
|
11
|
+
require 'capsule_crm/organization'
|
12
|
+
require 'capsule_crm/person'
|
13
|
+
require 'capsule_crm/version'
|
14
|
+
|
15
|
+
module CapsuleCRM
|
16
|
+
|
17
|
+
class << self
|
18
|
+
attr_accessor :configuration
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.configure
|
22
|
+
self.configuration = CapsuleCRM::Configuration.new
|
23
|
+
yield(self.configuration)
|
24
|
+
self.configuration
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module CapsuleCRM
|
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
|
+
def self.get(path, params = {})
|
11
|
+
response = faraday.get(path, params) do |req|
|
12
|
+
req.headers.update default_request_headers
|
13
|
+
end
|
14
|
+
JSON.parse response.body
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.post(path, params)
|
18
|
+
JSON.parse faraday.post(path, params).body
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.put(path, params)
|
22
|
+
JSON.parse faraday.put(path, params).body
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.delete(path, params)
|
26
|
+
JSON.parse faraday.delete(path, params).body
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def self.default_request_headers
|
32
|
+
{
|
33
|
+
'Accept' => 'application/json',
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.faraday
|
38
|
+
Faraday.new("http://#{subdomain}.capsulecrm.com").tap do |connection|
|
39
|
+
connection.basic_auth(CapsuleCRM.configuration.api_token, '')
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.subdomain
|
44
|
+
CapsuleCRM.configuration.subdomain
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'active_support/inflector'
|
2
|
+
|
3
|
+
module CapsuleCRM
|
4
|
+
class HashHelper
|
5
|
+
def self.underscore_keys!(hash)
|
6
|
+
hash.keys.each do |key|
|
7
|
+
hash[key.to_s.underscore] = hash.delete(key)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.camelize_keys!(hash)
|
12
|
+
hash.keys.each do |key|
|
13
|
+
hash[key.to_s.camelize] = hash.delete(key)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'active_support/core_ext'
|
2
|
+
|
3
|
+
class CapsuleCRM::Organization
|
4
|
+
include ::Virtus
|
5
|
+
|
6
|
+
include CapsuleCRM::Associations
|
7
|
+
|
8
|
+
extend ActiveModel::Naming
|
9
|
+
extend ActiveModel::Callbacks
|
10
|
+
extend ActiveModel::Conversion
|
11
|
+
include ActiveModel::Validations
|
12
|
+
include ActiveModel::Validations::Callbacks
|
13
|
+
|
14
|
+
attribute :name
|
15
|
+
attribute :about
|
16
|
+
|
17
|
+
# has_many :people
|
18
|
+
|
19
|
+
validates :name, presence: true
|
20
|
+
|
21
|
+
# Public: Get all organizations from Capsule. The list can be restricted
|
22
|
+
# and/or paginated with various query parameters sent through the options
|
23
|
+
# hash.
|
24
|
+
#
|
25
|
+
# options - The Hash of allowed query parameters for Capsule (default: {}):
|
26
|
+
# :q - The String search term that will be matched against name,
|
27
|
+
# telephone number and exact match on searchable custom fields
|
28
|
+
# :email - The String email address to search for
|
29
|
+
# :tag - The String tag to search for
|
30
|
+
# :start - The Integer first record to be returned in pagination.
|
31
|
+
# The results start with an index of 1
|
32
|
+
# :limit - The Integer maximum number of matching records to be
|
33
|
+
# returned
|
34
|
+
#
|
35
|
+
# Examples
|
36
|
+
#
|
37
|
+
# Organization.all
|
38
|
+
#
|
39
|
+
# Organization.all(q: "a search query", start: 10, limit: 20)
|
40
|
+
#
|
41
|
+
# Returns a ResultsProxy of organizations
|
42
|
+
def self.all(options = {})
|
43
|
+
options.delete_if { |key, value| !allowed_filtering_options.include?(key) }
|
44
|
+
delete_invalid_options(options)
|
45
|
+
CapsuleCRM::ResultsProxy.new(
|
46
|
+
CapsuleCRM::Connection.get('/api/party', options).map do |result|
|
47
|
+
new(result)
|
48
|
+
end
|
49
|
+
)
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.find(id)
|
53
|
+
new CapsuleCRM::Connection.get("/api/party/#{id}")
|
54
|
+
end
|
55
|
+
|
56
|
+
def save
|
57
|
+
if new_record?
|
58
|
+
create(attributes)
|
59
|
+
else
|
60
|
+
update(attributes)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def create(attributes = {})
|
65
|
+
CapsuleCRM::Connection.post('/api/organization', attributes)
|
66
|
+
end
|
67
|
+
|
68
|
+
def update_attributes(attributes = {})
|
69
|
+
CapsuleCRM::Connection.put("/api/organization/#{id}", attributes)
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def delete_invalid_all_options(options)
|
75
|
+
options.stringify_keys!
|
76
|
+
options.delete_if do |key, value|
|
77
|
+
!allowed_filtering_options.include?(key)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def allowed_filtering_options
|
82
|
+
%w(q email last_modified tag start limit)
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,190 @@
|
|
1
|
+
class CapsuleCRM::Person
|
2
|
+
include Virtus
|
3
|
+
|
4
|
+
include CapsuleCRM::Associations::HasMany
|
5
|
+
|
6
|
+
extend ActiveModel::Naming
|
7
|
+
extend ActiveModel::Callbacks
|
8
|
+
include ActiveModel::Conversion
|
9
|
+
include ActiveModel::Validations
|
10
|
+
include ActiveModel::Validations::Callbacks
|
11
|
+
|
12
|
+
attribute :id
|
13
|
+
attribute :title
|
14
|
+
attribute :first_name
|
15
|
+
attribute :last_name
|
16
|
+
attribute :job_title
|
17
|
+
attribute :about
|
18
|
+
attribute :organisation_name
|
19
|
+
attribute :organisation_id
|
20
|
+
|
21
|
+
validates :first_name, presence: { if: :first_name_required? }
|
22
|
+
validates :last_name, presence: { if: :last_name_required? }
|
23
|
+
|
24
|
+
has_many :addresses
|
25
|
+
has_many :emails
|
26
|
+
has_many :phones
|
27
|
+
has_many :websites
|
28
|
+
|
29
|
+
# Public: Set the attributes of a person
|
30
|
+
#
|
31
|
+
# attributes - The Hash of attributes (default: {}):
|
32
|
+
# :first_name - The String person first name
|
33
|
+
# :last_name - The String person last name
|
34
|
+
# :job_title - The String job title
|
35
|
+
# :about - The String information about the person
|
36
|
+
# :organisation_name - The String name of the organisation. If
|
37
|
+
# this organisation does not exist in capsule then a new one
|
38
|
+
# will be created on save
|
39
|
+
# :organisation_id - The Integer ID of the organisation in
|
40
|
+
# capsulecrm.
|
41
|
+
#
|
42
|
+
# Examples
|
43
|
+
#
|
44
|
+
# CapsuleCRM::Person.new
|
45
|
+
#
|
46
|
+
# Returns a CapsuleCRM::Person
|
47
|
+
def attributes=(attributes)
|
48
|
+
CapsuleCRM::HashHelper.underscore_keys!(attributes)
|
49
|
+
super(attributes)
|
50
|
+
self
|
51
|
+
end
|
52
|
+
|
53
|
+
# Public: Get all people from Capsule. The list can be restricted
|
54
|
+
# and/or paginated with various query parameters sent through the options
|
55
|
+
# hash.
|
56
|
+
#
|
57
|
+
# options - The Hash of allowed query parameters for Capsule (default: {}):
|
58
|
+
# :q - The String search term that will be matched against name,
|
59
|
+
# telephone number and exact match on searchable custom fields
|
60
|
+
# :email - The String email address to search for
|
61
|
+
# :tag - The String tag to search for
|
62
|
+
# :start - The Integer first record to be returned in pagination.
|
63
|
+
# The results start with an index of 1
|
64
|
+
# :limit - The Integer maximum number of matching records to be
|
65
|
+
# returned
|
66
|
+
#
|
67
|
+
# Examples
|
68
|
+
#
|
69
|
+
# CapsuleCRM::Person.all
|
70
|
+
#
|
71
|
+
# CapsuleCRM::Person.all(q: "a search query", start: 10, limit: 20)
|
72
|
+
#
|
73
|
+
# Returns a ResultsProxy of organisations
|
74
|
+
def self.all(options = {})
|
75
|
+
init_collection(
|
76
|
+
CapsuleCRM::Connection.get('/api/party', options)['parties']['person']
|
77
|
+
)
|
78
|
+
end
|
79
|
+
|
80
|
+
# Public: Get a person by ID
|
81
|
+
#
|
82
|
+
# id - The Integer person ID
|
83
|
+
#
|
84
|
+
# Examples
|
85
|
+
#
|
86
|
+
# CapsuleCRM::Person.find(1)
|
87
|
+
#
|
88
|
+
# Returns a CapsuleCRM::Person
|
89
|
+
def self.find(id)
|
90
|
+
new CapsuleCRM::Connection.get("/api/party/#{id}")['person']
|
91
|
+
end
|
92
|
+
|
93
|
+
# Public: Create a new person in capsulecrm
|
94
|
+
#
|
95
|
+
# attributes - The Hash of person attributes (default: {}):
|
96
|
+
# :first_name - The String first name
|
97
|
+
# :last_name - The String last name
|
98
|
+
# :job_title - The String job title
|
99
|
+
# :about - The String information about the person
|
100
|
+
# :organisation_name - The String organisation name. If now
|
101
|
+
# :organisation_id is supplied, then a new one will be created
|
102
|
+
# with this name
|
103
|
+
# :organisation_id - The Integer ID of the organisation this
|
104
|
+
# person belongs to
|
105
|
+
#
|
106
|
+
# Examples
|
107
|
+
#
|
108
|
+
# CapsuleCRM::Person.create(first_name: 'Matt', last_name: 'Beedle')
|
109
|
+
#
|
110
|
+
# Returns a CapsuleCRM::Person
|
111
|
+
def self.create(attributes = {})
|
112
|
+
new CapsuleCRM::Connection.post('/api/person', attributes)['person']
|
113
|
+
end
|
114
|
+
|
115
|
+
# Public: If the person already exists in capsule then update them,
|
116
|
+
# otherwise create a new person
|
117
|
+
#
|
118
|
+
# Examples
|
119
|
+
#
|
120
|
+
# person = CapsuleCRM::Person.new(first_name: 'Matt')
|
121
|
+
# person.save
|
122
|
+
#
|
123
|
+
# person = CapsuleCRM::Person.find(1)
|
124
|
+
# person.first_name = 'Matt'
|
125
|
+
# person.save
|
126
|
+
#
|
127
|
+
# Returns a CapsuleCRM::Person
|
128
|
+
def save
|
129
|
+
if new_record?
|
130
|
+
self.attributes = CapsuleCRM::Person.create(attributes).attributes
|
131
|
+
else
|
132
|
+
update_attributes attributes
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
# Public: Update the person in capsule
|
137
|
+
#
|
138
|
+
# attributes - The Hash of person attributes (default: {}):
|
139
|
+
# :first_name - The String first name
|
140
|
+
# :last_name - The String last name
|
141
|
+
# :job_title - The String job title
|
142
|
+
# :about - The String information about the person
|
143
|
+
# :organisation_name - The String organisation name
|
144
|
+
# :organisation_id - The String organisation id
|
145
|
+
#
|
146
|
+
# Examples
|
147
|
+
#
|
148
|
+
# person = CapsuleCRM::Person.find(1)
|
149
|
+
# person.update_attributes first_name: 'Matt', last_name: 'Beedle'
|
150
|
+
#
|
151
|
+
# Returns a CapsuleCRM::Person
|
152
|
+
def update_attributes(attributes = {})
|
153
|
+
self.attributes =
|
154
|
+
CapsuleCRM::Connection.put("/api/person/#{id}", attributes)['person']
|
155
|
+
end
|
156
|
+
|
157
|
+
# Public: Determine whether this CapsuleCRM::Person is a new record or not
|
158
|
+
#
|
159
|
+
# Returns a Boolean
|
160
|
+
def new_record?
|
161
|
+
!id
|
162
|
+
end
|
163
|
+
|
164
|
+
private
|
165
|
+
|
166
|
+
# Private: Build a ResultsProxy from a Array of CapsuleCRM::Person attributes
|
167
|
+
#
|
168
|
+
# collection - The Array of CapsuleCRM::Person attributes hashes
|
169
|
+
#
|
170
|
+
# Returns a CapsuleCRM::ResultsProxy
|
171
|
+
def self.init_collection(collection)
|
172
|
+
CapsuleCRM::ResultsProxy.new(collection.map { |item| new item })
|
173
|
+
end
|
174
|
+
|
175
|
+
# Private: Determines whether the person first name is required. Either the
|
176
|
+
# first or the last name is always required
|
177
|
+
#
|
178
|
+
# Returns a Boolean
|
179
|
+
def first_name_required?
|
180
|
+
last_name.blank?
|
181
|
+
end
|
182
|
+
|
183
|
+
# Private: Determines whether the person last name is required. Either the
|
184
|
+
# first or the last name is always required
|
185
|
+
#
|
186
|
+
# Return a Boolean
|
187
|
+
def last_name_required?
|
188
|
+
first_name.blank?
|
189
|
+
end
|
190
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module CapsuleCRM
|
2
|
+
class ResultsProxy < BasicObject
|
3
|
+
|
4
|
+
def initialize(target)
|
5
|
+
@target = target
|
6
|
+
end
|
7
|
+
|
8
|
+
protected
|
9
|
+
|
10
|
+
def method_missing(name, *args, &block)
|
11
|
+
target.send(name, *args, &block)
|
12
|
+
end
|
13
|
+
|
14
|
+
def target
|
15
|
+
@target ||= []
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,196 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CapsuleCRM::Person do
|
4
|
+
|
5
|
+
before { configure }
|
6
|
+
|
7
|
+
describe '.all' do
|
8
|
+
before do
|
9
|
+
stub_request(:get, /\/api\/party$/).
|
10
|
+
to_return(body: File.read('spec/support/all_parties.json'))
|
11
|
+
end
|
12
|
+
|
13
|
+
subject { CapsuleCRM::Person.all }
|
14
|
+
|
15
|
+
it { should be_a(Array) }
|
16
|
+
|
17
|
+
it { subject.length.should eql(2) }
|
18
|
+
|
19
|
+
it 'should only contain people' do
|
20
|
+
subject.all? { |item| item.is_a?(CapsuleCRM::Person) }.should be_true
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '.find' do
|
25
|
+
before do
|
26
|
+
stub_request(:get, /.*/).
|
27
|
+
to_return(body: File.read('spec/support/person.json'))
|
28
|
+
end
|
29
|
+
|
30
|
+
subject { CapsuleCRM::Person.find(1) }
|
31
|
+
|
32
|
+
it { should be_a(CapsuleCRM::Person) }
|
33
|
+
|
34
|
+
it { subject.first_name.should eql('Eric') }
|
35
|
+
|
36
|
+
it { subject.last_name.should eql('Schmidt') }
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#attributes=' do
|
40
|
+
let(:person) { CapsuleCRM::Person.new }
|
41
|
+
|
42
|
+
before do
|
43
|
+
person.attributes= { firstName: 'Matt', lastName: 'Beedle' }
|
44
|
+
end
|
45
|
+
|
46
|
+
it { person.first_name.should eql('Matt') }
|
47
|
+
|
48
|
+
it { person.last_name.should eql('Beedle') }
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '.create' do
|
52
|
+
context 'when the person saves successfully' do
|
53
|
+
before do
|
54
|
+
stub_request(:post, /.*/).
|
55
|
+
to_return(body: File.read('spec/support/create-person.json'))
|
56
|
+
end
|
57
|
+
|
58
|
+
subject { CapsuleCRM::Person.create }
|
59
|
+
|
60
|
+
it { should be_a(CapsuleCRM::Person) }
|
61
|
+
|
62
|
+
it { subject.about.should eql('A comment here') }
|
63
|
+
|
64
|
+
it { subject.first_name.should eql('Eric') }
|
65
|
+
|
66
|
+
it { subject.last_name.should eql('Schmidt') }
|
67
|
+
|
68
|
+
it { subject.organisation_name.should eql('Google Inc') }
|
69
|
+
|
70
|
+
it { subject.job_title.should eql('Chairman') }
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#update_attributes' do
|
75
|
+
context 'when the person saves successfully' do
|
76
|
+
before do
|
77
|
+
stub_request(:put, /.*/).
|
78
|
+
to_return(body: File.read('spec/support/update-person.json'))
|
79
|
+
end
|
80
|
+
|
81
|
+
let(:person) { CapsuleCRM::Person.new(id: 1) }
|
82
|
+
|
83
|
+
before { person.update_attributes first_name: 'James' }
|
84
|
+
|
85
|
+
it { person.first_name.should eql('James') }
|
86
|
+
|
87
|
+
it { person.id.should eql(1) }
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe '#save' do
|
92
|
+
context 'when the person is a new record' do
|
93
|
+
before do
|
94
|
+
stub_request(:post, /.*/).
|
95
|
+
to_return(body: File.read('spec/support/create-person.json'))
|
96
|
+
end
|
97
|
+
|
98
|
+
let(:person) { CapsuleCRM::Person.new }
|
99
|
+
|
100
|
+
before { person.save }
|
101
|
+
|
102
|
+
it { person.about.should eql('A comment here') }
|
103
|
+
|
104
|
+
it { person.first_name.should eql('Eric') }
|
105
|
+
|
106
|
+
it { person.last_name.should eql('Schmidt') }
|
107
|
+
|
108
|
+
it { person.organisation_name.should eql('Google Inc') }
|
109
|
+
|
110
|
+
it { person.job_title.should eql('Chairman') }
|
111
|
+
end
|
112
|
+
|
113
|
+
context 'when the person is not a new record' do
|
114
|
+
before do
|
115
|
+
stub_request(:put, /.*/).
|
116
|
+
to_return(body: File.read('spec/support/update-person.json'))
|
117
|
+
end
|
118
|
+
|
119
|
+
let(:person) { CapsuleCRM::Person.new(id: 1) }
|
120
|
+
|
121
|
+
before { person.save }
|
122
|
+
|
123
|
+
it { person.first_name.should eql('James') }
|
124
|
+
|
125
|
+
it { person.id.should eql(1) }
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe '#new_record?' do
|
130
|
+
context 'when the person is a new record' do
|
131
|
+
let(:person) { CapsuleCRM::Person.new }
|
132
|
+
|
133
|
+
subject { person.new_record? }
|
134
|
+
|
135
|
+
it { should be_true }
|
136
|
+
end
|
137
|
+
|
138
|
+
context 'when the person is not a new record' do
|
139
|
+
let(:person) { CapsuleCRM::Person.new(id: 1) }
|
140
|
+
|
141
|
+
subject { person.new_record? }
|
142
|
+
|
143
|
+
it { should be_false }
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
describe '.init_collection' do
|
148
|
+
subject do
|
149
|
+
CapsuleCRM::Person.init_collection(
|
150
|
+
JSON.parse(
|
151
|
+
File.read('spec/support/all_parties.json')
|
152
|
+
)['parties']['person']
|
153
|
+
)
|
154
|
+
end
|
155
|
+
|
156
|
+
it { should be_a(Array) }
|
157
|
+
|
158
|
+
it { subject.length.should eql(2) }
|
159
|
+
|
160
|
+
it do
|
161
|
+
subject.all? { |item| item.is_a?(CapsuleCRM::Person) }.should be_true
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
describe '#first_name_required?' do
|
166
|
+
let(:person) { CapsuleCRM::Person.new }
|
167
|
+
|
168
|
+
subject { person.send(:first_name_required?) }
|
169
|
+
|
170
|
+
context 'when there is no last name' do
|
171
|
+
it { should be_true }
|
172
|
+
end
|
173
|
+
|
174
|
+
context 'when there is a last name' do
|
175
|
+
before { person.last_name = 'Beedle' }
|
176
|
+
|
177
|
+
it { should be_false }
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
describe '#last_name_required?' do
|
182
|
+
let(:person) { CapsuleCRM::Person.new }
|
183
|
+
|
184
|
+
subject { person.send(:last_name_required?) }
|
185
|
+
|
186
|
+
context 'when there is no first name' do
|
187
|
+
it { should be_true }
|
188
|
+
end
|
189
|
+
|
190
|
+
context 'when there is a first name' do
|
191
|
+
before { person.first_name = 'Matt' }
|
192
|
+
|
193
|
+
it { should be_false }
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'webmock/rspec'
|
4
|
+
require 'support/helpers'
|
5
|
+
require 'capsule_crm'
|
6
|
+
|
7
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
8
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
9
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
10
|
+
# loaded once.
|
11
|
+
#
|
12
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
13
|
+
RSpec.configure do |config|
|
14
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
15
|
+
config.run_all_when_everything_filtered = true
|
16
|
+
config.filter_run :focus
|
17
|
+
|
18
|
+
# Run specs in random order to surface order dependencies. If you find an
|
19
|
+
# order dependency and want to debug it, you can fix the order by providing
|
20
|
+
# the seed, which is printed after each run.
|
21
|
+
# --seed 1234
|
22
|
+
config.order = 'random'
|
23
|
+
|
24
|
+
config.include Helpers
|
25
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
{
|
2
|
+
"parties": {
|
3
|
+
"organisation": {
|
4
|
+
"id": "50",
|
5
|
+
"createdOn": "2011-09-14T15:22:01Z",
|
6
|
+
"name": "Google Inc",
|
7
|
+
"updatedOn": "2011-12-14T10:45:46Z"
|
8
|
+
},
|
9
|
+
"person": [
|
10
|
+
{
|
11
|
+
"id": "100",
|
12
|
+
"lastName": "Schmidt",
|
13
|
+
"createdOn": "2011-09-14T15:22:01Z",
|
14
|
+
"firstName": "Eric",
|
15
|
+
"updatedOn": "2011-12-14T10:45:46Z"
|
16
|
+
},
|
17
|
+
{
|
18
|
+
"id": "101",
|
19
|
+
"lastName": "Page",
|
20
|
+
"createdOn": "2011-09-14T15:22:01Z",
|
21
|
+
"firstName": "Larry ",
|
22
|
+
"updatedOn": "2011-11-15T10:50:48Z"
|
23
|
+
}
|
24
|
+
]
|
25
|
+
}
|
26
|
+
}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
{
|
2
|
+
"person": {
|
3
|
+
"jobTitle": "Chairman",
|
4
|
+
"about": "A comment here",
|
5
|
+
"lastName": "Schmidt",
|
6
|
+
"title": "Mr",
|
7
|
+
"organisationName": "Google Inc",
|
8
|
+
"firstName": "Eric",
|
9
|
+
"contacts": {
|
10
|
+
"email": {
|
11
|
+
"type": "Home",
|
12
|
+
"emailAddress": "e.schmidt@google.com"
|
13
|
+
},
|
14
|
+
"website": {
|
15
|
+
"type": "work",
|
16
|
+
"webAddress": "www.google.com",
|
17
|
+
"webService": "URL"
|
18
|
+
},
|
19
|
+
"address": {
|
20
|
+
"country": "United States",
|
21
|
+
"city": "Mountain View",
|
22
|
+
"state": "CA",
|
23
|
+
"type": "Office",
|
24
|
+
"zip": "94043",
|
25
|
+
"street": "1600 Amphitheatre Parkway"
|
26
|
+
},
|
27
|
+
"phone": {
|
28
|
+
"phoneNumber": "+1 888 555555",
|
29
|
+
"type": "Mobile"
|
30
|
+
}
|
31
|
+
}
|
32
|
+
}
|
33
|
+
}
|
metadata
ADDED
@@ -0,0 +1,221 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capsule_crm
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matt Beedle
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-04-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activemodel
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: faraday
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: virtus
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: cucumber
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: guard
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: guard-rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rb-fsevent
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rspec
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: webmock
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - '>='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
description: Gem to communicate with CapsuleCRM
|
154
|
+
email:
|
155
|
+
- mattbeedle@googlemail.com
|
156
|
+
executables: []
|
157
|
+
extensions: []
|
158
|
+
extra_rdoc_files: []
|
159
|
+
files:
|
160
|
+
- .gitignore
|
161
|
+
- .rspec
|
162
|
+
- Gemfile
|
163
|
+
- Guardfile
|
164
|
+
- LICENSE.txt
|
165
|
+
- README.md
|
166
|
+
- Rakefile
|
167
|
+
- capsule_crm.gemspec
|
168
|
+
- features/organizations.feature
|
169
|
+
- lib/capsule_crm.rb
|
170
|
+
- lib/capsule_crm/associations.rb
|
171
|
+
- lib/capsule_crm/associations/belongs_to.rb
|
172
|
+
- lib/capsule_crm/associations/has_many.rb
|
173
|
+
- lib/capsule_crm/associations/has_many_proxy.rb
|
174
|
+
- lib/capsule_crm/configuration.rb
|
175
|
+
- lib/capsule_crm/connection.rb
|
176
|
+
- lib/capsule_crm/contact.rb
|
177
|
+
- lib/capsule_crm/hash_helper.rb
|
178
|
+
- lib/capsule_crm/organization.rb
|
179
|
+
- lib/capsule_crm/party.rb
|
180
|
+
- lib/capsule_crm/person.rb
|
181
|
+
- lib/capsule_crm/results_proxy.rb
|
182
|
+
- lib/capsule_crm/version.rb
|
183
|
+
- spec/lib/capsule_crm/person_spec.rb
|
184
|
+
- spec/spec_helper.rb
|
185
|
+
- spec/support/all_parties.json
|
186
|
+
- spec/support/create-person.json
|
187
|
+
- spec/support/helpers.rb
|
188
|
+
- spec/support/person.json
|
189
|
+
- spec/support/update-person.json
|
190
|
+
homepage: ''
|
191
|
+
licenses: []
|
192
|
+
metadata: {}
|
193
|
+
post_install_message:
|
194
|
+
rdoc_options: []
|
195
|
+
require_paths:
|
196
|
+
- lib
|
197
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - '>='
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0'
|
202
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
203
|
+
requirements:
|
204
|
+
- - '>='
|
205
|
+
- !ruby/object:Gem::Version
|
206
|
+
version: '0'
|
207
|
+
requirements: []
|
208
|
+
rubyforge_project:
|
209
|
+
rubygems_version: 2.0.3
|
210
|
+
signing_key:
|
211
|
+
specification_version: 4
|
212
|
+
summary: Gem to communicate with CapsuleCRM
|
213
|
+
test_files:
|
214
|
+
- features/organizations.feature
|
215
|
+
- spec/lib/capsule_crm/person_spec.rb
|
216
|
+
- spec/spec_helper.rb
|
217
|
+
- spec/support/all_parties.json
|
218
|
+
- spec/support/create-person.json
|
219
|
+
- spec/support/helpers.rb
|
220
|
+
- spec/support/person.json
|
221
|
+
- spec/support/update-person.json
|