rock_rms 2.0.0 → 3.0.0

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 (57) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/lib/rock_rms/client.rb +2 -2
  4. data/lib/rock_rms/resources/batch.rb +4 -2
  5. data/lib/rock_rms/resources/fund.rb +1 -1
  6. data/lib/rock_rms/resources/group.rb +3 -3
  7. data/lib/rock_rms/resources/person.rb +4 -4
  8. data/lib/rock_rms/resources/phone_number.rb +1 -1
  9. data/lib/rock_rms/resources/recurring_donation.rb +2 -2
  10. data/lib/rock_rms/resources/{donation.rb → transaction.rb} +13 -11
  11. data/lib/rock_rms/resources/transaction_detail.rb +2 -2
  12. data/lib/rock_rms/response/base.rb +29 -0
  13. data/lib/rock_rms/response/batch.rb +23 -0
  14. data/lib/rock_rms/{responses → response}/campus.rb +4 -14
  15. data/lib/rock_rms/response/fund.rb +14 -0
  16. data/lib/rock_rms/{responses → response}/group.rb +4 -14
  17. data/lib/rock_rms/response/group_location.rb +22 -0
  18. data/lib/rock_rms/{responses → response}/location.rb +4 -14
  19. data/lib/rock_rms/response/payment_method.rb +16 -0
  20. data/lib/rock_rms/response/person.rb +20 -0
  21. data/lib/rock_rms/response/phone_number.rb +17 -0
  22. data/lib/rock_rms/response/recurring_donation.rb +20 -0
  23. data/lib/rock_rms/response/recurring_donation_details.rb +14 -0
  24. data/lib/rock_rms/response/transaction.rb +28 -0
  25. data/lib/rock_rms/response/transaction_detail.rb +15 -0
  26. data/lib/rock_rms/version.rb +1 -1
  27. data/spec/rock_rms/resources/batch_spec.rb +8 -1
  28. data/spec/rock_rms/resources/group_spec.rb +3 -3
  29. data/spec/rock_rms/resources/person_spec.rb +1 -1
  30. data/spec/rock_rms/resources/phone_number_spec.rb +1 -1
  31. data/spec/rock_rms/resources/recurring_donation_spec.rb +2 -2
  32. data/spec/rock_rms/resources/transaction_detail_spec.rb +1 -1
  33. data/spec/rock_rms/resources/{donation_spec.rb → transaction_spec.rb} +21 -21
  34. data/spec/rock_rms/response/batch_spec.rb +27 -0
  35. data/spec/rock_rms/{responses → response}/campus_spec.rb +1 -1
  36. data/spec/rock_rms/{responses → response}/group_location_spec.rb +2 -2
  37. data/spec/rock_rms/{responses → response}/group_spec.rb +3 -3
  38. data/spec/rock_rms/{responses → response}/location_spec.rb +1 -1
  39. data/spec/rock_rms/{responses → response}/phone_number_spec.rb +1 -1
  40. data/spec/rock_rms/{responses → response}/recurring_donation_details_spec.rb +1 -1
  41. data/spec/rock_rms/{responses → response}/recurring_donation_spec.rb +2 -2
  42. data/spec/rock_rms/{responses → response}/transaction_detail_spec.rb +1 -1
  43. data/spec/rock_rms/{responses/donation_spec.rb → response/transaction_spec.rb} +3 -3
  44. data/spec/support/fixtures/{create_donation.json → create_transaction.json} +0 -0
  45. data/spec/support/fixtures/{donation.json → transaction.json} +0 -0
  46. data/spec/support/fixtures/{donations.json → transactions.json} +0 -0
  47. data/spec/support/rock_mock.rb +3 -3
  48. metadata +32 -29
  49. data/lib/rock_rms/responses/donation.rb +0 -40
  50. data/lib/rock_rms/responses/fund.rb +0 -18
  51. data/lib/rock_rms/responses/group_location.rb +0 -32
  52. data/lib/rock_rms/responses/payment_method.rb +0 -24
  53. data/lib/rock_rms/responses/person.rb +0 -33
  54. data/lib/rock_rms/responses/phone_number.rb +0 -27
  55. data/lib/rock_rms/responses/recurring_donation.rb +0 -32
  56. data/lib/rock_rms/responses/recurring_donation_details.rb +0 -24
  57. data/lib/rock_rms/responses/transaction_detail.rb +0 -25
@@ -0,0 +1,17 @@
1
+ module RockRMS
2
+ module Response
3
+ class PhoneNumber < Base
4
+ MAP = {
5
+ id: 'Id',
6
+ person_id: 'PersonId',
7
+ number: 'Number',
8
+ formatted: 'NumberFormatted',
9
+ formatted_with_cc: 'NumberFormattedWithCountryCode'
10
+ }.freeze
11
+
12
+ def format_single(data)
13
+ to_h(MAP, data)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,20 @@
1
+ module RockRMS
2
+ module Response
3
+ class RecurringDonation < Base
4
+ MAP = {
5
+ id: 'Id',
6
+ foreign_key: 'ForeignKey',
7
+ next_payment_date: 'NextPaymentDate',
8
+ person_id: 'AuthorizedPersonAliasId',
9
+ transaction_details: 'ScheduledTransactionDetails',
10
+ transaction_code: 'TransactionCode'
11
+ }.freeze
12
+
13
+ def format_single(data)
14
+ result = to_h(MAP, data)
15
+ result[:transaction_details] = RecurringDonationDetails.format(result[:transaction_details])
16
+ result
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,14 @@
1
+ module RockRMS
2
+ module Response
3
+ class RecurringDonationDetails < Base
4
+ MAP = {
5
+ amount: 'Amount',
6
+ fund_id: 'AccountId'
7
+ }.freeze
8
+
9
+ def format_single(data)
10
+ to_h(MAP, data)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,28 @@
1
+ module RockRMS
2
+ module Response
3
+ class Transaction < Base
4
+ MAP = {
5
+ id: 'Id',
6
+ date: 'TransactionDateTime',
7
+ person_id: 'AuthorizedPersonAliasId',
8
+ batch_id: 'BatchId',
9
+ recurring_donation_id: 'ScheduledTransactionId',
10
+ summary: 'Summary',
11
+ transaction_code: 'TransactionCode',
12
+ details: 'TransactionDetails'
13
+ }.freeze
14
+
15
+
16
+ def format_single(data)
17
+ response = to_h(MAP, data)
18
+ response[:details] = TransactionDetail.format(response[:details])
19
+ response[:amount] = calculate_total(response[:details])
20
+ response
21
+ end
22
+
23
+ def calculate_total(details)
24
+ details.reduce(0) { |sum, td| sum + td[:amount] }
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,15 @@
1
+ module RockRMS
2
+ module Response
3
+ class TransactionDetail < Base
4
+ MAP = {
5
+ id: 'Id',
6
+ fund_id: 'AccountId',
7
+ amount: 'Amount'
8
+ }.freeze
9
+
10
+ def format_single(response)
11
+ to_h(MAP, response)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
1
  module RockRMS
2
- VERSION = '2.0.0'.freeze
2
+ VERSION = '3.0.0'.freeze
3
3
  end
@@ -22,7 +22,14 @@ RSpec.describe RockRMS::Client::Batch, type: :model do
22
22
 
23
23
  resource = client.find_batch(123)
24
24
 
25
- expect(resource['Id']).to eq(123)
25
+ expect(resource[:id]).to eq(123)
26
+ end
27
+
28
+ it 'formats with Batch' do
29
+ response = double
30
+ expect(RockRMS::Response::Batch).to receive(:format).with(response)
31
+ allow(client).to receive(:get).and_return(response)
32
+ client.find_batch(123)
26
33
  end
27
34
  end
28
35
 
@@ -18,7 +18,7 @@ RSpec.describe RockRMS::Client::Group, type: :model do
18
18
 
19
19
  it 'formats with Group' do
20
20
  response = double
21
- expect(RockRMS::Responses::Group).to receive(:format).with(response)
21
+ expect(RockRMS::Response::Group).to receive(:format).with(response)
22
22
  allow(client).to receive(:get).and_return(response)
23
23
  client.find_group(123)
24
24
  end
@@ -45,7 +45,7 @@ RSpec.describe RockRMS::Client::Group, type: :model do
45
45
 
46
46
  it 'formats with Group' do
47
47
  response = double
48
- expect(RockRMS::Responses::Group).to receive(:format).with(response)
48
+ expect(RockRMS::Response::Group).to receive(:format).with(response)
49
49
  allow(client).to receive(:get).and_return(response)
50
50
  client.list_groups
51
51
  end
@@ -103,7 +103,7 @@ RSpec.describe RockRMS::Client::Group, type: :model do
103
103
  it 'formats with Group' do
104
104
  response = double
105
105
  allow(client).to receive(:get).and_return(response)
106
- expect(RockRMS::Responses::Group).to receive(:format).with(response)
106
+ expect(RockRMS::Response::Group).to receive(:format).with(response)
107
107
  client.list_families_for_person(123)
108
108
  end
109
109
  end
@@ -42,7 +42,7 @@ RSpec.describe RockRMS::Client::Person, type: :model do
42
42
 
43
43
  it 'formats with Person' do
44
44
  response = double
45
- expect(RockRMS::Responses::Person).to receive(:format).with(response)
45
+ expect(RockRMS::Response::Person).to receive(:format).with(response)
46
46
  allow(client).to receive(:get).and_return(response)
47
47
  client.find_person_by_name('Some Name')
48
48
  end
@@ -25,7 +25,7 @@ RSpec.describe RockRMS::Client::PhoneNumber, type: :model do
25
25
 
26
26
  it 'formats with PhoneNumber' do
27
27
  response = double
28
- expect(RockRMS::Responses::PhoneNumber).to receive(:format).with(response)
28
+ expect(RockRMS::Response::PhoneNumber).to receive(:format).with(response)
29
29
  allow(client).to receive(:get).and_return(response)
30
30
  resource
31
31
  end
@@ -19,7 +19,7 @@ RSpec.describe RockRMS::Client::RecurringDonation, type: :model do
19
19
 
20
20
  it 'formats with RecurringDonation' do
21
21
  response = double
22
- expect(RockRMS::Responses::RecurringDonation).to receive(:format).with(response)
22
+ expect(RockRMS::Response::RecurringDonation).to receive(:format).with(response)
23
23
  allow(client).to receive(:get).and_return(response)
24
24
  client.list_recurring_donations
25
25
  end
@@ -42,7 +42,7 @@ RSpec.describe RockRMS::Client::RecurringDonation, type: :model do
42
42
 
43
43
  it 'formats with RecurringDonation' do
44
44
  response = double
45
- expect(RockRMS::Responses::RecurringDonation).to receive(:format).with(response)
45
+ expect(RockRMS::Response::RecurringDonation).to receive(:format).with(response)
46
46
  allow(client).to receive(:get).and_return(response)
47
47
  client.find_recurring_donation(12_345)
48
48
  end
@@ -27,7 +27,7 @@ RSpec.describe RockRMS::Client::TransactionDetail, type: :model do
27
27
 
28
28
  it 'formats with TransactionDetail' do
29
29
  response = double
30
- expect(RockRMS::Responses::TransactionDetail).to receive(:format).with(response)
30
+ expect(RockRMS::Response::TransactionDetail).to receive(:format).with(response)
31
31
  allow(client).to receive(:get).and_return(response)
32
32
  client.find_transaction_detail(123)
33
33
  end
@@ -1,64 +1,64 @@
1
1
  require 'spec_helper'
2
2
 
3
- RSpec.describe RockRMS::Client::Donation, type: :model do
3
+ RSpec.describe RockRMS::Client::Transaction, type: :model do
4
4
  include_context 'resource specs'
5
5
 
6
- describe '#list_donations' do
6
+ describe '#list_transactions' do
7
7
  it 'returns a array' do
8
- resource = client.list_donations
8
+ resource = client.list_transactions
9
9
  expect(resource).to be_a(Array)
10
10
  expect(resource.first).to be_a(Hash)
11
11
  end
12
12
  end
13
13
 
14
- describe '#find_donation(id)' do
14
+ describe '#find_transaction(id)' do
15
15
  it 'returns a hash' do
16
- expect(client.find_donation(123)).to be_a(Hash)
16
+ expect(client.find_transaction(123)).to be_a(Hash)
17
17
  end
18
18
 
19
19
  it 'queries groups' do
20
20
  expect(client).to receive(:get).with('FinancialTransactions/123')
21
21
  .and_call_original
22
22
 
23
- resource = client.find_donation(123)
23
+ resource = client.find_transaction(123)
24
24
 
25
25
  expect(resource[:id]).to eq(1422)
26
26
  end
27
27
 
28
- it 'formats with Donation' do
28
+ it 'formats with Transaction' do
29
29
  response = double
30
- expect(RockRMS::Responses::Donation).to receive(:format).with(response)
30
+ expect(RockRMS::Response::Transaction).to receive(:format).with(response)
31
31
  allow(client).to receive(:get).and_return(response)
32
- client.find_donation(123)
32
+ client.find_transaction(123)
33
33
  end
34
34
  end
35
35
 
36
- describe '#create_donation' do
36
+ describe '#create_transaction' do
37
37
  context 'arguments' do
38
38
  it 'require `authorized_person_id`' do
39
- expect { client.create_donation }
39
+ expect { client.create_transaction }
40
40
  .to raise_error(ArgumentError, /authorized_person_id/)
41
41
  end
42
42
 
43
43
  it 'require `batch_id`' do
44
- expect { client.create_donation }
44
+ expect { client.create_transaction }
45
45
  .to raise_error(ArgumentError, /batch_id/)
46
46
  end
47
47
 
48
48
  it 'require `date`' do
49
- expect { client.create_donation }
49
+ expect { client.create_transaction }
50
50
  .to raise_error(ArgumentError, /date/)
51
51
  end
52
52
 
53
53
  it 'require `funds`' do
54
- expect { client.create_donation }
54
+ expect { client.create_transaction }
55
55
  .to raise_error(ArgumentError, /funds/)
56
56
  end
57
57
 
58
58
  end
59
59
 
60
60
  subject(:resource) do
61
- client.create_donation(
61
+ client.create_transaction(
62
62
  authorized_person_id: 1,
63
63
  batch_id: 1,
64
64
  date: 1,
@@ -94,9 +94,9 @@ RSpec.describe RockRMS::Client::Donation, type: :model do
94
94
  end
95
95
  end
96
96
 
97
- describe '#update_donation' do
97
+ describe '#update_transaction' do
98
98
  subject(:resource) do
99
- client.update_donation(
99
+ client.update_transaction(
100
100
  123,
101
101
  batch_id: 1,
102
102
  summary: 'taco tuesday'
@@ -104,7 +104,7 @@ RSpec.describe RockRMS::Client::Donation, type: :model do
104
104
  end
105
105
 
106
106
  it 'returns nothing' do
107
- expect(client.update_donation(123)).to eq(nil)
107
+ expect(client.update_transaction(123)).to eq(nil)
108
108
  end
109
109
 
110
110
  it 'passes options' do
@@ -119,14 +119,14 @@ RSpec.describe RockRMS::Client::Donation, type: :model do
119
119
  end
120
120
  end
121
121
 
122
- describe '#delete_donation' do
122
+ describe '#delete_transaction' do
123
123
  it 'returns nothing' do
124
- expect(client.delete_donation(123)).to eq(nil)
124
+ expect(client.delete_transaction(123)).to eq(nil)
125
125
  end
126
126
 
127
127
  it 'passes id' do
128
128
  expect(client).to receive(:delete).with('FinancialTransactions/123')
129
- client.delete_donation(123)
129
+ client.delete_transaction(123)
130
130
  end
131
131
  end
132
132
  end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe RockRMS::Response::Batch, type: :model do
4
+ let(:parsed) { JSON.parse(FixturesHelper.read('batches.json')) }
5
+
6
+ describe '.format' do
7
+ subject(:result) { described_class.format(parsed) }
8
+
9
+ context 'when response is array' do
10
+ it 'returns an array' do
11
+ expect(described_class.format([])).to be_a(Array)
12
+ end
13
+ end
14
+
15
+ it 'translates keys' do
16
+ result.zip(parsed) do |r, p|
17
+ expect(r[:id]).to eq(p['Id'])
18
+ expect(r[:name]).to eq(p['Name'])
19
+ expect(r[:control_amount]).to eq(p['ControlAmount'])
20
+ expect(r[:transactions]).to eq(
21
+ RockRMS::Response::Transaction.format(p['Transactions'])
22
+ )
23
+ expect(r[:amount]).to eq(0)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- RSpec.describe RockRMS::Responses::Campus, type: :model do
3
+ RSpec.describe RockRMS::Response::Campus, type: :model do
4
4
  let(:parsed) { JSON.parse(FixturesHelper.read('campuses.json')) }
5
5
 
6
6
  describe '.format' do
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- RSpec.describe RockRMS::Responses::GroupLocation, type: :model do
3
+ RSpec.describe RockRMS::Response::GroupLocation, type: :model do
4
4
  let(:parsed) { JSON.parse(FixturesHelper.read('group_locations.json')) }
5
5
 
6
6
  describe '.format' do
@@ -25,7 +25,7 @@ RSpec.describe RockRMS::Responses::GroupLocation, type: :model do
25
25
  it 'formats with Location' do
26
26
  location = double
27
27
  parsed.first['Location'] = location
28
- expect(RockRMS::Responses::Location).to receive(:format)
28
+ expect(RockRMS::Response::Location).to receive(:format)
29
29
  .with(location)
30
30
  .and_return(some_key: :value)
31
31
  result
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- RSpec.describe RockRMS::Responses::Group, type: :model do
3
+ RSpec.describe RockRMS::Response::Group, type: :model do
4
4
  let(:parsed) { JSON.parse(FixturesHelper.read('groups_with_members.json')) }
5
5
 
6
6
  describe '.format' do
@@ -29,7 +29,7 @@ RSpec.describe RockRMS::Responses::Group, type: :model do
29
29
  let(:parsed) { JSON.parse(FixturesHelper.read('groups_with_locations.json')) }
30
30
 
31
31
  it 'formats with GroupLocations' do
32
- expect(RockRMS::Responses::GroupLocation).to receive(:format)
32
+ expect(RockRMS::Response::GroupLocation).to receive(:format)
33
33
  .with(parsed.first['GroupLocations'])
34
34
  .and_return([{ some_key: :value }])
35
35
  result
@@ -41,7 +41,7 @@ RSpec.describe RockRMS::Responses::Group, type: :model do
41
41
  let(:parsed) { JSON.parse(FixturesHelper.read('groups_with_campus.json')) }
42
42
 
43
43
  it 'formats with Campus' do
44
- expect(RockRMS::Responses::Campus).to receive(:format)
44
+ expect(RockRMS::Response::Campus).to receive(:format)
45
45
  .with(parsed.first['Campus'])
46
46
  .and_return([{ some_key: :value }])
47
47
  result
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- RSpec.describe RockRMS::Responses::Location, type: :model do
3
+ RSpec.describe RockRMS::Response::Location, type: :model do
4
4
  let(:parsed) { JSON.parse(FixturesHelper.read('locations.json')) }
5
5
 
6
6
  describe '.format' do
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- RSpec.describe RockRMS::Responses::PhoneNumber, type: :model do
3
+ RSpec.describe RockRMS::Response::PhoneNumber, type: :model do
4
4
  let(:parsed) { JSON.parse(FixturesHelper.read('phone_numbers.json')) }
5
5
 
6
6
  describe '.format' do
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- RSpec.describe RockRMS::Responses::RecurringDonationDetails, type: :model do
3
+ RSpec.describe RockRMS::Response::RecurringDonationDetails, type: :model do
4
4
  let(:parsed) { JSON.parse(FixturesHelper.read('recurring_donation_details.json')) }
5
5
 
6
6
  describe '.format' do
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- RSpec.describe RockRMS::Responses::RecurringDonation, type: :model do
3
+ RSpec.describe RockRMS::Response::RecurringDonation, type: :model do
4
4
  let(:parsed) { JSON.parse(FixturesHelper.read('recurring_donations.json')) }
5
5
 
6
6
  describe '.format' do
@@ -19,7 +19,7 @@ RSpec.describe RockRMS::Responses::RecurringDonation, type: :model do
19
19
  expect(r[:next_payment_date]).to eq(p['NextPaymentDate'])
20
20
  expect(r[:person_id]).to eq(p['AuthorizedPersonAliasId'])
21
21
  expect(r[:transaction_details]).to eq(
22
- RockRMS::Responses::RecurringDonationDetails.format(p['ScheduledTransactionDetails'])
22
+ RockRMS::Response::RecurringDonationDetails.format(p['ScheduledTransactionDetails'])
23
23
  )
24
24
  expect(r[:transaction_code]).to eq(p['TransactionCode'])
25
25
  end