virtuous 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/test.yml +26 -0
  3. data/.gitignore +5 -0
  4. data/.reek.yml +36 -0
  5. data/.rubocop.yml +87 -0
  6. data/.ruby-version +1 -0
  7. data/.yardopts +1 -0
  8. data/CHANGELOG.md +18 -0
  9. data/Gemfile +17 -0
  10. data/LICENSE +21 -0
  11. data/README.md +54 -0
  12. data/Rakefile +24 -0
  13. data/lib/virtuous/client/contact.rb +220 -0
  14. data/lib/virtuous/client/contact_address.rb +78 -0
  15. data/lib/virtuous/client/gift.rb +394 -0
  16. data/lib/virtuous/client/gift_designation.rb +59 -0
  17. data/lib/virtuous/client/individual.rb +125 -0
  18. data/lib/virtuous/client/recurring_gift.rb +86 -0
  19. data/lib/virtuous/client.rb +272 -0
  20. data/lib/virtuous/error.rb +54 -0
  21. data/lib/virtuous/helpers/hash_helper.rb +28 -0
  22. data/lib/virtuous/helpers/string_helper.rb +31 -0
  23. data/lib/virtuous/parse_oj.rb +24 -0
  24. data/lib/virtuous/version.rb +5 -0
  25. data/lib/virtuous.rb +12 -0
  26. data/logo/virtuous.svg +1 -0
  27. data/spec/spec_helper.rb +25 -0
  28. data/spec/support/client_factory.rb +10 -0
  29. data/spec/support/fixtures/contact.json +112 -0
  30. data/spec/support/fixtures/contact_address.json +20 -0
  31. data/spec/support/fixtures/contact_addresses.json +42 -0
  32. data/spec/support/fixtures/contact_gifts.json +80 -0
  33. data/spec/support/fixtures/gift.json +55 -0
  34. data/spec/support/fixtures/gift_designation_query_options.json +2701 -0
  35. data/spec/support/fixtures/gift_designations.json +175 -0
  36. data/spec/support/fixtures/gifts.json +112 -0
  37. data/spec/support/fixtures/import.json +0 -0
  38. data/spec/support/fixtures/individual.json +46 -0
  39. data/spec/support/fixtures/recurring_gift.json +26 -0
  40. data/spec/support/fixtures_helper.rb +5 -0
  41. data/spec/support/virtuous_mock.rb +101 -0
  42. data/spec/virtuous/client_spec.rb +270 -0
  43. data/spec/virtuous/error_spec.rb +74 -0
  44. data/spec/virtuous/resources/contact_address_spec.rb +75 -0
  45. data/spec/virtuous/resources/contact_spec.rb +137 -0
  46. data/spec/virtuous/resources/gift_designation_spec.rb +70 -0
  47. data/spec/virtuous/resources/gift_spec.rb +249 -0
  48. data/spec/virtuous/resources/individual_spec.rb +95 -0
  49. data/spec/virtuous/resources/recurring_gift_spec.rb +67 -0
  50. data/spec/virtuous_spec.rb +7 -0
  51. data/virtuous.gemspec +25 -0
  52. metadata +121 -0
@@ -0,0 +1,249 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Virtuous::Client::Gift, type: :model do
4
+ include_context 'resource specs'
5
+
6
+ describe '#get_contact_gifts(contact_id, **options)' do
7
+ subject(:resource) do
8
+ client.get_contact_gifts(
9
+ 1,
10
+ sort_by: 'GiftDate',
11
+ skip: 10,
12
+ take: 10
13
+ )
14
+ end
15
+
16
+ it 'returns a list of gifts' do
17
+ expect(subject[:list]).to be_a(Array)
18
+ end
19
+
20
+ it 'passes options' do
21
+ expect(client).to receive(:get)
22
+ .with(
23
+ 'api/Gift/ByContact/1',
24
+ {
25
+ 'sortBy' => 'GiftDate',
26
+ 'skip' => 10,
27
+ 'take' => 10
28
+ }
29
+ )
30
+ .and_call_original
31
+ resource
32
+ end
33
+ end
34
+
35
+ describe '#get_gift(id)' do
36
+ it 'returns a hash' do
37
+ expect(client.get_gift(1)).to be_a(Hash)
38
+ end
39
+
40
+ it 'queries gifts' do
41
+ expect(client).to receive(:get).with('api/Gift/1').and_call_original
42
+
43
+ resource = client.get_gift(1)
44
+
45
+ expect(resource[:id]).to eq(1)
46
+ end
47
+ end
48
+
49
+ describe '#find_gift_by_transaction_id(id)' do
50
+ let(:transaction_source) { 'source' }
51
+ let(:transaction_id) { 42 }
52
+
53
+ it 'returns a hash' do
54
+ expect(client.find_gift_by_transaction_id(transaction_source, transaction_id)).to be_a(Hash)
55
+ end
56
+
57
+ it 'queries gifts' do
58
+ expect(client).to receive(:get).with("api/Gift/#{transaction_source}/#{transaction_id}")
59
+ .and_call_original
60
+
61
+ resource = client.find_gift_by_transaction_id(transaction_source, transaction_id)
62
+
63
+ expect(resource[:transaction_source]).to eq(transaction_source)
64
+ expect(resource[:transaction_id]).to eq(transaction_id)
65
+ end
66
+ end
67
+
68
+ describe '#import_gift(data)' do
69
+ subject(:resource) do
70
+ client.import_gift(
71
+ gift_type: 'Cash', amount: 10.5, currency_code: 'USD', gift_date: Date.today,
72
+ contact: {
73
+ contact_type: 'Organization', name: 'Org name', first_name: 'John',
74
+ last_name: 'Doe', email: 'john_doe@email.com'
75
+ }
76
+ )
77
+ end
78
+
79
+ it 'passes options' do
80
+ expect(client).to receive(:post)
81
+ .with(
82
+ 'api/v2/Gift/Transaction',
83
+ {
84
+ 'giftType' => 'Cash', 'amount' => 10.5, 'currencyCode' => 'USD',
85
+ 'giftDate' => Date.today, 'contact' => {
86
+ 'contactType' => 'Organization', 'name' => 'Org name', 'firstName' => 'John',
87
+ 'lastName' => 'Doe', 'email' => 'john_doe@email.com'
88
+ }
89
+ }
90
+ )
91
+ .and_call_original
92
+ resource
93
+ end
94
+ end
95
+
96
+ describe '#import_gifts(data)' do
97
+ subject(:resource) do
98
+ client.import_gifts(
99
+ transaction_source: 'Source', transactions: [
100
+ {
101
+ gift_type: 'Cash', amount: 10.5, currency_code: 'USD', gift_date: Date.today,
102
+ contact: {
103
+ contact_type: 'Organization', name: 'Org name', first_name: 'John',
104
+ last_name: 'Doe', email: 'john_doe@email.com'
105
+ }
106
+ },
107
+ {
108
+ gift_type: 'Cash', amount: 5.0, currency_code: 'USD', gift_date: Date.today,
109
+ contact: {
110
+ contact_type: 'Organization', name: 'Org name', first_name: 'John',
111
+ last_name: 'Doe', email: 'john_doe@email.com'
112
+ }
113
+ }
114
+ ]
115
+ )
116
+ end
117
+
118
+ it 'passes options' do
119
+ expect(client).to receive(:post)
120
+ .with(
121
+ 'api/v2/Gift/Transactions',
122
+ {
123
+ 'transactionSource' => 'Source', 'transactions' => [
124
+ {
125
+ 'giftType' => 'Cash', 'amount' => 10.5, 'currencyCode' => 'USD',
126
+ 'giftDate' => Date.today, 'contact' => {
127
+ 'contactType' => 'Organization', 'name' => 'Org name', 'firstName' => 'John',
128
+ 'lastName' => 'Doe', 'email' => 'john_doe@email.com'
129
+ }
130
+ },
131
+ {
132
+ 'giftType' => 'Cash', 'amount' => 5.0, 'currencyCode' => 'USD',
133
+ 'giftDate' => Date.today, 'contact' => {
134
+ 'contactType' => 'Organization', 'name' => 'Org name', 'firstName' => 'John',
135
+ 'lastName' => 'Doe', 'email' => 'john_doe@email.com'
136
+ }
137
+ }
138
+ ]
139
+
140
+ }
141
+ )
142
+ .and_call_original
143
+ resource
144
+ end
145
+ end
146
+
147
+ describe '#create_gift(data)' do
148
+ subject(:resource) do
149
+ client.create_gift(
150
+ contact_id: 1, gift_type: 'Cash', amount: 10.5, currency_code: 'USD',
151
+ gift_date: Date.today
152
+ )
153
+ end
154
+
155
+ it 'passes options' do
156
+ expect(client).to receive(:post)
157
+ .with(
158
+ 'api/Gift',
159
+ {
160
+ 'contactId' => 1, 'giftType' => 'Cash', 'amount' => 10.5, 'currencyCode' => 'USD',
161
+ 'giftDate' => Date.today
162
+ }
163
+ )
164
+ .and_call_original
165
+ resource
166
+ end
167
+
168
+ it 'returns a hash' do
169
+ expect(resource).to be_a(Hash)
170
+ end
171
+ end
172
+
173
+ describe '#create_gifts(data)' do
174
+ subject(:resource) do
175
+ client.create_gifts(
176
+ [
177
+ {
178
+ contact_id: 1, gift_type: 'Cash', amount: 10.5, currency_code: 'USD',
179
+ gift_date: Date.today
180
+ },
181
+ {
182
+ contact_id: 2, gift_type: 'Cash', amount: 5.0, currency_code: 'USD',
183
+ gift_date: Date.today
184
+ }
185
+ ]
186
+ )
187
+ end
188
+
189
+ it 'passes options' do
190
+ expect(client).to receive(:post)
191
+ .with(
192
+ 'api/Gift/Bulk',
193
+ [
194
+ {
195
+ 'contactId' => 1, 'giftType' => 'Cash', 'amount' => 10.5, 'currencyCode' => 'USD',
196
+ 'giftDate' => Date.today
197
+ },
198
+ {
199
+ 'contactId' => 2, 'giftType' => 'Cash', 'amount' => 5.0, 'currencyCode' => 'USD',
200
+ 'giftDate' => Date.today
201
+ }
202
+ ]
203
+ )
204
+ .and_call_original
205
+ resource
206
+ end
207
+
208
+ it 'returns a array' do
209
+ expect(resource).to be_a(Array)
210
+ end
211
+ end
212
+
213
+ describe '#update_gift(id, data)' do
214
+ subject(:resource) do
215
+ client.update_gift(
216
+ 1, gift_type: 'Cash', amount: 5.0, currency_code: 'USD',
217
+ gift_date: Date.today
218
+ )
219
+ end
220
+
221
+ it 'passes options' do
222
+ expect(client).to receive(:put)
223
+ .with(
224
+ 'api/Gift/1',
225
+ {
226
+ 'giftType' => 'Cash', 'amount' => 5.0, 'currencyCode' => 'USD',
227
+ 'giftDate' => Date.today
228
+ }
229
+ )
230
+ .and_call_original
231
+ resource
232
+ end
233
+
234
+ it 'returns a hash' do
235
+ expect(resource).to be_a(Hash)
236
+ end
237
+ end
238
+
239
+ describe '#delete_gift(id)' do
240
+ subject(:resource) { client.delete_gift(1) }
241
+
242
+ it 'calls delete on the gift' do
243
+ expect(client).to receive(:delete)
244
+ .with('api/Gift/1')
245
+ .and_call_original
246
+ resource
247
+ end
248
+ end
249
+ end
@@ -0,0 +1,95 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Virtuous::Client::Individual, type: :model do
4
+ include_context 'resource specs'
5
+
6
+ describe '#find_individual_by_email(email)' do
7
+ it 'returns a hash' do
8
+ expect(client.find_individual_by_email('email@test.com')).to be_a(Hash)
9
+ end
10
+
11
+ it 'queries individuals' do
12
+ expect(client).to receive(:get).with('api/ContactIndividual/Find',
13
+ { email: 'email@test.com' }).and_call_original
14
+
15
+ resource = client.find_individual_by_email('email@test.com')
16
+
17
+ expect(resource[:id]).to eq(2)
18
+ end
19
+ end
20
+
21
+ describe '#get_individual(id)' do
22
+ it 'returns a hash' do
23
+ expect(client.get_individual(2)).to be_a(Hash)
24
+ end
25
+
26
+ it 'queries individuals' do
27
+ expect(client).to receive(:get).with('api/ContactIndividual/2').and_call_original
28
+
29
+ resource = client.get_individual(2)
30
+
31
+ expect(resource[:id]).to eq(2)
32
+ end
33
+ end
34
+
35
+ describe '#create_individual(data)' do
36
+ subject(:resource) do
37
+ client.create_individual(first_name: 'John', last_name: 'Doe', contact_id: 1)
38
+ end
39
+
40
+ it 'passes options' do
41
+ expect(client).to receive(:post)
42
+ .with(
43
+ 'api/ContactIndividual',
44
+ {
45
+ 'firstName' => 'John',
46
+ 'lastName' => 'Doe',
47
+ 'contactId' => 1
48
+ }
49
+ )
50
+ .and_call_original
51
+ resource
52
+ end
53
+
54
+ it 'returns a hash' do
55
+ expect(resource).to be_a(Hash)
56
+ end
57
+ end
58
+
59
+ describe '#update_individual(id, data)' do
60
+ subject(:resource) do
61
+ client.update_individual(
62
+ 2,
63
+ first_name: 'John', last_name: 'Doe'
64
+ )
65
+ end
66
+
67
+ it 'passes options' do
68
+ expect(client).to receive(:put)
69
+ .with(
70
+ 'api/ContactIndividual/2',
71
+ {
72
+ 'firstName' => 'John',
73
+ 'lastName' => 'Doe'
74
+ }
75
+ )
76
+ .and_call_original
77
+ resource
78
+ end
79
+
80
+ it 'returns a hash' do
81
+ expect(resource).to be_a(Hash)
82
+ end
83
+ end
84
+
85
+ describe '#delete_individual(id)' do
86
+ subject(:resource) { client.delete_individual(2) }
87
+
88
+ it 'calls delete on the individual' do
89
+ expect(client).to receive(:delete)
90
+ .with('api/ContactIndividual/2')
91
+ .and_call_original
92
+ resource
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Virtuous::Client::RecurringGift, type: :model do
4
+ include_context 'resource specs'
5
+
6
+ describe '#get_recurring_gift(id)' do
7
+ it 'returns a hash' do
8
+ expect(client.get_recurring_gift(1)).to be_a(Hash)
9
+ end
10
+
11
+ it 'queries gifts' do
12
+ expect(client).to receive(:get).with('api/RecurringGift/1').and_call_original
13
+
14
+ resource = client.get_recurring_gift(1)
15
+
16
+ expect(resource[:id]).to eq(1)
17
+ end
18
+ end
19
+
20
+ describe '#create_recurring_gift(data)' do
21
+ subject(:resource) do
22
+ client.create_recurring_gift(
23
+ contact_id: 1, start_date: Date.today, frequency: 'Monthly', amount: 1000
24
+ )
25
+ end
26
+
27
+ it 'passes options' do
28
+ expect(client).to receive(:post)
29
+ .with(
30
+ 'api/RecurringGift',
31
+ {
32
+ 'contactId' => 1, 'startDate' => Date.today, 'frequency' => 'Monthly', 'amount' => 1000
33
+ }
34
+ )
35
+ .and_call_original
36
+ resource
37
+ end
38
+
39
+ it 'returns a hash' do
40
+ expect(resource).to be_a(Hash)
41
+ end
42
+ end
43
+
44
+ describe '#update_recurring_gift(id, data)' do
45
+ subject(:resource) do
46
+ client.update_recurring_gift(
47
+ 1, start_date: Date.today, frequency: 'Daily', amount: 500
48
+ )
49
+ end
50
+
51
+ it 'passes options' do
52
+ expect(client).to receive(:put)
53
+ .with(
54
+ 'api/RecurringGift/1',
55
+ {
56
+ 'startDate' => Date.today, 'frequency' => 'Daily', 'amount' => 500
57
+ }
58
+ )
59
+ .and_call_original
60
+ resource
61
+ end
62
+
63
+ it 'returns a hash' do
64
+ expect(resource).to be_a(Hash)
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Virtuous do
4
+ it 'has a version number' do
5
+ expect(described_class::VERSION).to_not be_nil
6
+ end
7
+ end
data/virtuous.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ require 'English'
2
+ $LOAD_PATH.push File.expand_path('lib', __dir__)
3
+ require 'virtuous/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'virtuous'
7
+ s.version = Virtuous::VERSION
8
+ s.authors = ['Taylor Brooks']
9
+ s.homepage = 'https://github.com/taylorbrooks/virtuous'
10
+ s.summary = 'A Ruby wrapper for the Virtuous CRM API'
11
+ s.description = 'A Ruby wrapper for the Virtuous CRM API'
12
+ s.license = 'MIT'
13
+
14
+ s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
15
+ s.executables = s.files.grep(%r{^bin/}).map { |f| File.basename(f) }
16
+
17
+ s.required_ruby_version = '>= 2.7'
18
+
19
+ s.require_paths = ['lib']
20
+
21
+ s.add_runtime_dependency 'faraday', '> 2.0'
22
+ s.add_runtime_dependency 'oj'
23
+
24
+ s.metadata['rubygems_mfa_required'] = 'true'
25
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: virtuous
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Taylor Brooks
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-01-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: oj
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
+ description: A Ruby wrapper for the Virtuous CRM API
42
+ email:
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - ".github/workflows/test.yml"
48
+ - ".gitignore"
49
+ - ".reek.yml"
50
+ - ".rubocop.yml"
51
+ - ".ruby-version"
52
+ - ".yardopts"
53
+ - CHANGELOG.md
54
+ - Gemfile
55
+ - LICENSE
56
+ - README.md
57
+ - Rakefile
58
+ - lib/virtuous.rb
59
+ - lib/virtuous/client.rb
60
+ - lib/virtuous/client/contact.rb
61
+ - lib/virtuous/client/contact_address.rb
62
+ - lib/virtuous/client/gift.rb
63
+ - lib/virtuous/client/gift_designation.rb
64
+ - lib/virtuous/client/individual.rb
65
+ - lib/virtuous/client/recurring_gift.rb
66
+ - lib/virtuous/error.rb
67
+ - lib/virtuous/helpers/hash_helper.rb
68
+ - lib/virtuous/helpers/string_helper.rb
69
+ - lib/virtuous/parse_oj.rb
70
+ - lib/virtuous/version.rb
71
+ - logo/virtuous.svg
72
+ - spec/spec_helper.rb
73
+ - spec/support/client_factory.rb
74
+ - spec/support/fixtures/contact.json
75
+ - spec/support/fixtures/contact_address.json
76
+ - spec/support/fixtures/contact_addresses.json
77
+ - spec/support/fixtures/contact_gifts.json
78
+ - spec/support/fixtures/gift.json
79
+ - spec/support/fixtures/gift_designation_query_options.json
80
+ - spec/support/fixtures/gift_designations.json
81
+ - spec/support/fixtures/gifts.json
82
+ - spec/support/fixtures/import.json
83
+ - spec/support/fixtures/individual.json
84
+ - spec/support/fixtures/recurring_gift.json
85
+ - spec/support/fixtures_helper.rb
86
+ - spec/support/virtuous_mock.rb
87
+ - spec/virtuous/client_spec.rb
88
+ - spec/virtuous/error_spec.rb
89
+ - spec/virtuous/resources/contact_address_spec.rb
90
+ - spec/virtuous/resources/contact_spec.rb
91
+ - spec/virtuous/resources/gift_designation_spec.rb
92
+ - spec/virtuous/resources/gift_spec.rb
93
+ - spec/virtuous/resources/individual_spec.rb
94
+ - spec/virtuous/resources/recurring_gift_spec.rb
95
+ - spec/virtuous_spec.rb
96
+ - virtuous.gemspec
97
+ homepage: https://github.com/taylorbrooks/virtuous
98
+ licenses:
99
+ - MIT
100
+ metadata:
101
+ rubygems_mfa_required: 'true'
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '2.7'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubygems_version: 3.4.10
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: A Ruby wrapper for the Virtuous CRM API
121
+ test_files: []