Skip to content

Commit

Permalink
Add ContentChannel fetching, updating (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
nthj authored Nov 13, 2024
1 parent bfa436d commit bc25cc5
Show file tree
Hide file tree
Showing 30 changed files with 335 additions and 13 deletions.
3 changes: 3 additions & 0 deletions lib/rock_rms/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class Client
include RockRMS::Client::BlockType
include RockRMS::Client::Fund
include RockRMS::Client::Campus
include RockRMS::Client::ContentChannel
include RockRMS::Client::ContentChannelType
include RockRMS::Client::ContentChannelItem
include RockRMS::Client::DefinedType
include RockRMS::Client::DefinedValue
include RockRMS::Client::ExceptionLog
Expand Down
31 changes: 31 additions & 0 deletions lib/rock_rms/resources/content_channel.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module RockRMS
class Client
module ContentChannel
def list_content_channels(options = {})
res = get(content_channel_path, options)
Response::ContentChannel.format(res)
end

def find_content_channel(id)
res = get(content_channel_path(id))
Response::ContentChannel.format(res)
end

def update_content_channel(
id:,
foreign_key: nil
)
options = { foreign_key: foreign_key }.compact

patch(content_channel_path(id), options)
end

private

def content_channel_path(id = nil)
id ? "ContentChannels/#{id}" : 'ContentChannels'
end
end
end
end

10 changes: 10 additions & 0 deletions lib/rock_rms/resources/content_channel_item.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module RockRMS
class Client
module ContentChannelItem
def list_content_channel_items(options = {})
res = get(content_channel_items_path, options)
Response::ContentChannelItem.format(res)
end
end
end
end
11 changes: 11 additions & 0 deletions lib/rock_rms/resources/content_channel_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module RockRMS
class Client
module ContentChannelType
def list_content_channel_types(options = {})
res = get('ContentChannelTypes', options)
Response::ContentChannelType.format(res)
end
end
end
end

3 changes: 2 additions & 1 deletion lib/rock_rms/response/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class Base
modified_date_time: 'ModifiedDateTime',
created_by_person_alias_id: 'CreatedByPersonAliasId',
attributes: 'Attributes',
attribute_values: 'AttributeValues'
attribute_values: 'AttributeValues',
foreign_key: 'ForeignKey'
}.freeze

def self.format(data)
Expand Down
3 changes: 1 addition & 2 deletions lib/rock_rms/response/batch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ class Batch < Base
end_date: 'BatchEndDateTime',
campus_id: 'CampusId',
is_campus: 'Campus',
status: 'Status',
foreign_key: 'ForeignKey'
status: 'Status'
}.freeze

def format_single(data)
Expand Down
17 changes: 17 additions & 0 deletions lib/rock_rms/response/content_channel.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module RockRMS
module Response
class ContentChannel < Base
MAP = {
name: 'Name',
description: 'Description',
is_active: 'IsActive',
icon_css_class: 'IconCssClass',
content_channel_type_id: 'ContentChannelTypeId'
}.freeze

def format_single(data)
to_h(MAP, data)
end
end
end
end
18 changes: 18 additions & 0 deletions lib/rock_rms/response/content_channel_item.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module RockRMS
module Response
class ContentChannelItem < Base
MAP = {
content_channel_id: 'ContentChannelId',
title: 'Title',
content: 'Content',
order: 'Order',
start_date: 'StartDateTime',
expire_date: 'ExpireDateTime',
}

def format_single(data)
to_h(MAP, data)
end
end
end
end
13 changes: 13 additions & 0 deletions lib/rock_rms/response/content_channel_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module RockRMS
module Response
class ContentChannelType < Base
MAP = {
name: 'Name'
}.freeze

def format_single(data)
to_h(MAP, data)
end
end
end
end
1 change: 0 additions & 1 deletion lib/rock_rms/response/payment_detail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ class PaymentDetail < Base
MAP = {
exp_month: 'ExpirationMonth',
exp_year: 'ExpirationYear',
foreign_key: 'ForeignKey',
payment_type_id: 'CurrencyTypeValueId',
masked_number: 'AccountNumberMasked'
}.freeze
Expand Down
1 change: 0 additions & 1 deletion lib/rock_rms/response/recurring_donation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ class RecurringDonation < Base
MAP = {
active: 'IsActive',
financial_gateway_id: 'FinancialGatewayId',
foreign_key: 'ForeignKey',
frequency: 'TransactionFrequencyValueId',
end_date: 'EndDate',
gateway_schedule_id: 'GatewayScheduleId',
Expand Down
1 change: 0 additions & 1 deletion lib/rock_rms/response/saved_payment_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ module RockRMS
module Response
class SavedPaymentMethod < Base
MAP = {
foreign_key: 'ForeignKey',
gateway_id: 'FinancialGatewayId',
gateway_person_id: 'GatewayPersonIdentifier',
is_default: 'IsDefault',
Expand Down
1 change: 0 additions & 1 deletion lib/rock_rms/response/system_communication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ class SystemCommunication < Base
from: 'From',
subject: 'Subject',
body: 'Body',
foreign_key: 'ForeignKey'
}.freeze

def format_single(data)
Expand Down
3 changes: 1 addition & 2 deletions lib/rock_rms/response/system_email.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ class SystemEmail < Base
title: 'Title',
from: 'From',
subject: 'Subject',
body: 'Body',
foreign_key: 'ForeignKey'
body: 'Body'
}.freeze

def format_single(data)
Expand Down
14 changes: 14 additions & 0 deletions spec/rock_rms/resources/content_channel_item_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'spec_helper'

RSpec.describe RockRMS::Client::ContentChannelType, type: :model do
include_context 'resource specs'

describe '#list_content_channel_types(options = {})' do
it 'returns a list of content channel types' do
result = client.list_content_channel_types
expect(result).to be_an(Array)
expect(result.first).to have_key(:id)
expect(result.first).to have_key(:name)
end
end
end
47 changes: 47 additions & 0 deletions spec/rock_rms/resources/content_channel_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
require 'spec_helper'

RSpec.describe RockRMS::Client::ContentChannel, type: :model do
include_context 'resource specs'

describe '#list_content_channels(options = {})' do
it 'returns a list of content channels' do
result = client.list_content_channels
expect(result).to be_an(Array)
expect(result.first).to have_key(:id)
expect(result.first).to have_key(:name)
end
end

describe '#find_content_channel(id)' do
it 'returns a hash' do
expect(client.find_content_channel(123)).to be_a(Hash)
end

it 'queries' do
expect(client).to receive(:get).with('ContentChannels/123')
.and_call_original

resource = client.find_content_channel(123)

expect(resource[:id]).to eq(345)
end

it 'formats with ContentChannel' do
response = double
expect(RockRMS::Response::ContentChannel).to receive(:format).with(response)
allow(client).to receive(:get).and_return(response)
client.find_content_channel(123)
end
end

describe '#update_content_channel' do
it 'does not raise error' do
expect { client.update_content_channel(id: 123) }.not_to raise_error
end

it 'sends a patch request' do
expect(client).to receive(:patch).with('ContentChannels/123', { foreign_key: 3925 })
client.update_content_channel(id: 123, foreign_key: 3925)
end
end
end
14 changes: 14 additions & 0 deletions spec/rock_rms/resources/content_channel_type_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'spec_helper'

RSpec.describe RockRMS::Client::ContentChannelType, type: :model do
include_context 'resource specs'

describe '#list_content_channel_types(options = {})' do
it 'returns a list of content channel types' do
result = client.list_content_channel_types
expect(result).to be_an(Array)
expect(result.first).to have_key(:id)
expect(result.first).to have_key(:name)
end
end
end
5 changes: 3 additions & 2 deletions spec/rock_rms/response/attribute_value_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

it 'has the correct number keys' do
keys = result.first.keys
expect(keys.count).to eq(12)
expect(keys.count).to eq(13)
end

it 'translates keys' do
Expand All @@ -32,11 +32,12 @@
created_date_time: nil,
description: nil,
entity_type_id: 7,
foreign_key: nil,
guid: "abcd",
id: 22,
key: "JobPulse",
modified_date_time: nil,
name: "Job Pulse"
name: "Job Pulse",
})
end
end
Expand Down
33 changes: 33 additions & 0 deletions spec/rock_rms/response/content_channel_item_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require 'spec_helper'

RSpec.describe RockRMS::Response::ContentChannelItem, type: :model do
let(:parsed) { JSON.parse(FixturesHelper.read('content_channel_items.json')) }

describe '.format' do
subject(:result) { described_class.format(parsed) }

context 'when response is array' do
it 'returns an array' do
expect(described_class.format([])).to be_a(Array)
end
end

it 'has the correct number keys' do
keys = result.first.keys
expect(keys.count).to eq(14)
end

it 'translates keys' do
result.zip(parsed) do |r, p|
expect(r[:id]).to eq(p['Id'])
expect(r[:foreign_key]).to eq(p['ForeignKey'])
expect(r[:content_channel_id]).to eq(p['ContentChannelId'])
expect(r[:title]).to eq(p['Title'])
expect(r[:content]).to eq(p['Content'])
expect(r[:order]).to eq(p['Order'])
expect(r[:start_date]).to eq(p['StartDateTime'])
expect(r[:expire_date]).to eq(p['ExpireDateTime'])
end
end
end
end
32 changes: 32 additions & 0 deletions spec/rock_rms/response/content_channel_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'spec_helper'

RSpec.describe RockRMS::Response::ContentChannel, type: :model do
let(:parsed) { JSON.parse(FixturesHelper.read('content_channels.json')) }

describe '.format' do
subject(:result) { described_class.format(parsed) }

context 'when response is array' do
it 'returns an array' do
expect(described_class.format([])).to be_a(Array)
end
end

it 'has the correct number keys' do
keys = result.first.keys
expect(keys.count).to eq(13)
end

it 'translates keys' do
result.zip(parsed) do |r, p|
expect(r[:id]).to eq(p['Id'])
expect(r[:foreign_key]).to eq(p['ForeignKey'])
expect(r[:name]).to eq(p['Name'])
expect(r[:description]).to eq(p['Description'])
expect(r[:is_active]).to eq(p['IsActive'])
expect(r[:icon_css_class]).to eq(p['IconCssClass'])
expect(r[:content_channel_type_id]).to eq(p['ContentChannelTypeId'])
end
end
end
end
27 changes: 27 additions & 0 deletions spec/rock_rms/response/content_channel_type_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require 'spec_helper'

RSpec.describe RockRMS::Response::ContentChannelType, type: :model do
let(:parsed) { JSON.parse(FixturesHelper.read('content_channel_types.json')) }

describe '.format' do
subject(:result) { described_class.format(parsed) }

context 'when response is array' do
it 'returns an array' do
expect(described_class.format([])).to be_a(Array)
end
end

it 'has the correct number keys' do
keys = result.first.keys
expect(keys.count).to eq(9)
end

it 'translates keys' do
result.zip(parsed) do |r, p|
expect(r[:id]).to eq(p['Id'])
expect(r[:name]).to eq(p['Name'])
end
end
end
end
2 changes: 1 addition & 1 deletion spec/rock_rms/response/defined_value_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

it 'has the correct number keys' do
keys = result.first.keys
expect(keys.count).to eq(11)
expect(keys.count).to eq(12)
end

it 'translates keys' do
Expand Down
2 changes: 1 addition & 1 deletion spec/rock_rms/response/recurring_donation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
expected_keys = %i[
active
financial_gateway_id
foreign_key
frequency
end_date
gateway_schedule_id
Expand All @@ -38,6 +37,7 @@
created_by_person_alias_id
attributes
attribute_values
foreign_key
]

expect(response.keys).to eq(expected_keys)
Expand Down
Loading

0 comments on commit bc25cc5

Please sign in to comment.