Skip to content

Commit

Permalink
Add to sites endpoint:
Browse files Browse the repository at this point in the history
- logos
- background images
- theme settings
  • Loading branch information
ppostma committed May 6, 2024
1 parent 11d97a0 commit e185374
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 7 deletions.
2 changes: 2 additions & 0 deletions lib/kentaa/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
require_relative 'api/resources/donation_form'
require_relative 'api/resources/donation'
require_relative 'api/resources/location'
require_relative 'api/resources/logo'
require_relative 'api/resources/manual_donation'
require_relative 'api/resources/newsletter_subscription'
require_relative 'api/resources/order'
Expand All @@ -36,6 +37,7 @@
require_relative 'api/resources/site'
require_relative 'api/resources/sites'
require_relative 'api/resources/team'
require_relative 'api/resources/theme'
require_relative 'api/resources/user'
require_relative 'api/resources/users'
require_relative 'api/resources/video'
Expand Down
23 changes: 23 additions & 0 deletions lib/kentaa/api/resources/logo.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

module Kentaa
module Api
module Resources
class Logo
attr_reader :data

def initialize(data)
@data = data
end

def url
data[:url]
end

def locale
data[:locale]
end
end
end
end
end
26 changes: 26 additions & 0 deletions lib/kentaa/api/resources/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,36 @@ def banners
end
end

def logos
@logos ||= begin
logos = []

if data[:logos]
data[:logos].map do |logo|
logos << Kentaa::Api::Resources::Logo.new(logo)
end
end

logos
end
end

def external_reference
data[:external_reference]
end

def background_image_url
data[:background_image_url]
end

def sign_up_flow_background_image_url
data[:sign_up_flow_background_image_url]
end

def theme
@theme ||= Kentaa::Api::Resources::Theme.new(data[:theme])
end

def donations
@donations ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::Donation, endpoint_path: '/donations')
end
Expand Down
23 changes: 23 additions & 0 deletions lib/kentaa/api/resources/theme.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

module Kentaa
module Api
module Resources
class Theme
attr_reader :data

def initialize(data)
@data = data
end

def primary_color
data[:primary_color]
end

def contrast_color
data[:contrast_color]
end
end
end
end
end
4 changes: 2 additions & 2 deletions spec/fixtures/responses/donation.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"country": "NL"
},
"consent": {
"url": "https://demo1.kentaa.nl/doneren",
"url": "https://demo1.kentaa.nl/donate",
"text": "Ik accepteer de <a href='/algemene-voorwaarden' class='theme-text-color' target='_blank'>Algemene voorwaarden</a>.",
"version": "V2 22-06-2018 13:09"
},
Expand All @@ -65,7 +65,7 @@
"consent_status": "granted",
"granted_at": "2016-03-30T14:41:48Z",
"consent_text": "Ik accepteer de <a href='/algemene-voorwaarden' class='theme-text-color' target='_blank'>Algemene voorwaarden</a>.",
"url": "https://demo1.kentaa.nl/doneren",
"url": "https://demo1.kentaa.nl/donate",
"terms_conditions_version": "V2 22-06-2018 13:09",
"privacy_version": "V1 10-06-2018 11:42"
}
Expand Down
21 changes: 19 additions & 2 deletions spec/fixtures/responses/site.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"owner_email": "[email protected]",
"default_currency": "EUR",
"url": "https://demo1.kentaa.nl/",
"donate_url": "https://demo1.kentaa.nl/doneren",
"donate_url": "https://demo1.kentaa.nl/donate",
"banners": [
{
"id": 14,
Expand All @@ -27,6 +27,23 @@
"link": "http://www.example.com/",
"locale": "nl"
}
]
],
"logos": [
{
"locale": "nl",
"url": "https://cdn.kentaa.nl/header_logos/logo/site_logo/2528/116c9a3acc4a88f9e14bb0b6319045f987f4c160.jpeg"

},
{
"locale": "en",
"url": "https://cdn.kentaa.nl/header_logos/logo/site_logo/2529/2fe74604b1554b6a3f1fb0fc0f0b80efaab9437a.png"
}
],
"background_image_url": "https://cdn.kentaa.nl/background_images/site_theme/background_image/2238/c84048633c78cd54cf3000a244738d8005d265c1.jpg",
"sign_up_flow_background_image_url": "https://cdn.kentaa.nl/background_images/site_setting/sign_up_flow_background_image/3804/0afc0d7f0932b5f8f4ed49b06e768a6eb36e31b3.jpg",
"theme": {
"primary_color": "#6b0a0a",
"contrast_color": "#400b0b"
}
}
}
4 changes: 2 additions & 2 deletions spec/kentaa/api/resources/donation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@
describe '#consent' do
it 'returns the associated consent' do
expect(response.consent).to be_a(Kentaa::Api::Resources::Consent)
expect(response.consent.url).to eq('https://demo1.kentaa.nl/doneren')
expect(response.consent.url).to eq('https://demo1.kentaa.nl/donate')
expect(response.consent.text).to eq("Ik accepteer de <a href='/algemene-voorwaarden' class='theme-text-color' target='_blank'>Algemene voorwaarden</a>.")
expect(response.consent.version).to eq('V2 22-06-2018 13:09')
end
Expand All @@ -307,7 +307,7 @@
expect(consent.consent_type).to eq('terms_conditions')
expect(consent.consent_status).to eq('granted')
expect(consent.consent_text).to eq("Ik accepteer de <a href='/algemene-voorwaarden' class='theme-text-color' target='_blank'>Algemene voorwaarden</a>.")
expect(consent.url).to eq('https://demo1.kentaa.nl/doneren')
expect(consent.url).to eq('https://demo1.kentaa.nl/donate')
expect(consent.terms_conditions_version).to eq('V2 22-06-2018 13:09')
expect(consent.privacy_version).to eq('V1 10-06-2018 11:42')
end
Expand Down
31 changes: 30 additions & 1 deletion spec/kentaa/api/resources/site_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@

describe '#donate_url' do
it 'returns the donate URL' do
expect(response.donate_url).to eq('https://demo1.kentaa.nl/doneren')
expect(response.donate_url).to eq('https://demo1.kentaa.nl/donate')
end
end

Expand All @@ -120,6 +120,15 @@
it 'returns the associated banners' do
expect(response.banners).not_to be_empty
expect(response.banners.count).to eq(1)
expect(response.banners.first).to be_a(Kentaa::Api::Resources::Banner)
end
end

describe '#logos' do
it 'returns the associated logos' do
expect(response.logos).not_to be_empty
expect(response.logos.count).to eq(2)
expect(response.logos.first).to be_a(Kentaa::Api::Resources::Logo)
end
end

Expand All @@ -129,6 +138,26 @@
end
end

describe '#background_image_url' do
it 'returns the background image URL' do
expect(response.background_image_url).to eq('https://cdn.kentaa.nl/background_images/site_theme/background_image/2238/c84048633c78cd54cf3000a244738d8005d265c1.jpg')
end
end

describe '#sign_up_flow_background_image_url' do
it 'returns the background image URL' do
expect(response.sign_up_flow_background_image_url).to eq('https://cdn.kentaa.nl/background_images/site_setting/sign_up_flow_background_image/3804/0afc0d7f0932b5f8f4ed49b06e768a6eb36e31b3.jpg')
end
end

describe '#theme' do
it 'returns the theme settings' do
expect(response.theme).to be_a(Kentaa::Api::Resources::Theme)
expect(response.theme.primary_color).to eq('#6b0a0a')
expect(response.theme.contrast_color).to eq('#400b0b')
end
end

describe '#donations' do
it 'returns the donation resources as a List' do
expect(response.donations).to be_a(Kentaa::Api::Resources::List)
Expand Down

0 comments on commit e185374

Please sign in to comment.