-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ContentChannel fetching, updating (#64)
- Loading branch information
Showing
30 changed files
with
335 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.