Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions lib/beyond_api/services/storefront/newsletter_target.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# frozen_string_literal: true

module BeyondApi
module Storefront
# @example How to instantiate a client
# @client = BeyondApi::Storefront::NewsletterTarget.new(api_url: 'https://example.com/api', access_token: 'your_token')
class NewsletterTarget < BaseService
# Retrieve the details of a newsletter target.
#
# @see https://developer.epages.com/beyond-docs/#show_newsletter_target_details
#
# @param id [String] The newsletter target id.
#
# @return [Hash]
#
# @example
# newsletter_target = @client.show('id')
def show(id)
get("newsletter-target/#{id}")
end

# Create a newsletter target.
#
# @see https://developer.epages.com/beyond-docs/#create_newsletter_target
#
# @param submit_url [String] The URL stating where to submit the newsletter form to.
#
# @return [Hash]
#
# @example
# newsletter_target = @client.create('https://example.com/cgi-bin/subscribe.php')
def create(submit_url)
post('newsletter-target', submit_url:)
end

# Update a newsletter target.
#
# @see https://developer.epages.com/beyond-docs/#update_newsletter_target
#
# @param id [String] The newsletter target id.
# @param submit_url [String] The URL stating where to submit the newsletter form to.
#
# @return [Hash]
#
# @example
# newsletter_target = @client.update('id', 'https://example.com/cgi-bin/otherSubscribe.php')
def update(id, submit_url)
put("newsletter-target/#{id}", submit_url:)
end

# Delete a newsletter target.
#
# @see https://developer.epages.com/beyond-docs/#delete_newsletter_target
#
# @param id [String] The newsletter target id.
#
# @return [Hash]
#
# @example
# newsletter_target = @client.delete('id')
def delete(id)
super("newsletter-target/#{id}")
end
end
end
end
63 changes: 62 additions & 1 deletion lib/beyond_api/services/storefront/script_tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,79 @@ module Storefront
# @example How to instantiate a client
# @client = BeyondApi::Storefront::ScriptTag.new(api_url: 'https://example.com/api', access_token: 'your_token')
class ScriptTag < BaseService
# Retrieve all script tags.
#
# @see https://developer.epages.com/beyond-docs/#list_script_tags
#
# @param params [Hash] A customizable set of options.
# @option params [Boolean] :only_own If set to true, only the script tags created by the client will be returned.
#
# @return [Hash]
#
# @example
# script_tags = @client.all
# script_tags = @client.all(only_own: true)
def all(params = {})
params.merge!(client_id: BeyondApi.configuration.client_id) if params[:only_own]

get('script-tags', params)
end

# Retrieve the details of a script tag.
#
# @see https://developer.epages.com/beyond-docs/#show_script_tag_details
#
# @param id [String] The script tag id.
#
# @return [Hash]
#
# @example
# script_tag = @client.show('id')
def show(id)
get("script-tags/#{id}")
end

# Create a script tag.
#
# @see https://developer.epages.com/beyond-docs/#create_script_tag
#
# @param script_url [String] The URL of the script.
#
# @return [Hash]
#
# @example
# script_tag = @client.create('https://example.com/scripts/exampleScript.js')
def create(script_url)
post('script-tags', script_url:)
end

# Update a script tag.
#
# @see https://developer.epages.com/beyond-docs/#update_script_tag
#
# @param id [String] The script tag id.
# @param script_url [String] The URL of the script.
#
# @return [Hash]
#
# @example
# script_tag = @client.update('id', 'https://example.com/scripts/otherExampleScript.js')
def update(id, script_url)
put("script-tags/#{id}", script_url:)
end

# Delete a script tag.
#
# @see https://developer.epages.com/beyond-docs/#delete_script_tag
#
# @param id [String] The script tag id.
#
# @return [Hash]
#
# @example
# script_tag = @client.delete('id')
def delete(id)
super("script-tags/#{id}") # Concerns::Connection delete method
super("script-tags/#{id}")
end
end
end
Expand Down
48 changes: 48 additions & 0 deletions spec/beyond_api/services/storefront/newsletter_target_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# frozen_string_literal: true

RSpec.describe BeyondApi::Storefront::NewsletterTarget, vcr: true do
let(:client) { described_class.new(api_url: ENV.fetch('API_URL', nil), access_token: beyond_access_token) }

context 'with newsletter target' do
before(:each) do
@newsletter_target = client.create('https://example.com/cgi-bin/subscribe.php')
end

describe '.create' do
it 'creates a new newsletter target' do
expect(@newsletter_target).not_to be nil
expect(@newsletter_target[:submit_url]).to eq('https://example.com/cgi-bin/subscribe.php')
end
end

describe '.delete' do
it 'deletes a newsletter target' do
response = client.delete(@newsletter_target[:id])
expect(response).to eq({})
end
end

describe '.show' do
it 'returns a newsletter target' do
response = client.show(@newsletter_target[:id])

expect(response).not_to be nil
expect(response[:submit_url]).to eq('https://example.com/cgi-bin/subscribe.php')
end
end

describe '.update' do
it 'updates a newsletter target' do
response = client.update(@newsletter_target[:id], 'https://example.com/cgi-bin/otherSubscribe.php')

expect(response).not_to be nil
expect(response[:submit_url]).to eq('https://example.com/cgi-bin/otherSubscribe.php')
end
end

after(:each) do
client.delete(@newsletter_target[:id])
rescue BeyondApi::Error # rubocop:disable Lint/SuppressedException
end
end
end
18 changes: 18 additions & 0 deletions spec/beyond_api/services/storefront/script_tag_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,24 @@
end
end

describe '.show' do
it 'returns a script tag' do
response = client.show(@script_tag[:id])

expect(response).not_to be nil
expect(response[:script_url]).to eq('https://example.com/scripts/exampleScript.js')
end
end

describe '.update' do
it 'updates a script tag' do
response = client.update(@script_tag[:id], 'https://example.com/scripts/exampleScriptUpdated.js')

expect(response).not_to be nil
expect(response[:script_url]).to eq('https://example.com/scripts/exampleScriptUpdated.js')
end
end

after(:each) do
client.delete(@script_tag[:id])
rescue BeyondApi::Error # rubocop:disable Lint/SuppressedException
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading