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
35 changes: 35 additions & 0 deletions lib/beyond_api/services/shop/feature.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# frozen_string_literal: true

module BeyondApi
module Shop
# @example How to instantiate a client
# @client = BeyondApi::Shop::Feature.new(api_url: 'https://example.com/api', access_token: 'your_token')
class Feature < BaseService
# List all features that are assigned to a specific shop identified by the current hostname.
#
# @see https://developer.epages.com/beyond-docs/#list_feature_assignments
#
# @return [Hash]
#
# @example
# @client.all
def all
get('shop/features')
end

# Retrieve the details of a specific feature assignment of a merchant’s shop identified by the current hostname.
#
# @see https://developer.epages.com/beyond-docs/#show_feature_assignment_details
#
# @param feature_name [String] The feature name
#
# @return [Hash]
#
# @example
# @client.find('product-management.max-products')
def find(feature_name)
get("shop/features/#{feature_name}")
end
end
end
end
79 changes: 79 additions & 0 deletions lib/beyond_api/services/shop/language.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# frozen_string_literal: true

module BeyondApi
module Shop
# @example How to instantiate a client
# @client = BeyondApi::Shop::Language.new(api_url: 'https://example.com/api', access_token: 'your_token')
class Language < BaseService
# Create a language for a specified shop.
#
# @see https://developer.epages.com/beyond-docs/#create_language
#
# @param locale [String] the locale
#
# @return [Hash]
#
# @example
# @client.create('de-DE')
def create(locale)
post('shop/languages', locale:)
end

# Retrieve detailed information about a single language of the shop. The language is specified by its id.
#
# @see https://developer.epages.com/beyond-docs/#show_language_details
#
# @param id [String] The language UUID
#
# @return [Hash]
#
# @example
# @client.find('750958a7-7924-4028-8f44-260f8fb11cbb')
def find(id)
get("shop/languages/#{id}")
end

# Retrieve the currently active languages of a specified shop in a paged way.
#
# @see https://developer.epages.com/beyond-docs/#list_languages
#
# @option params [Boolean] :paginated
# @option params [Integer] :size the page size
# @option params [Integer] :page the page number
#
# @return [Hash]
#
# @example
# @client.all(size: 100, page: 0)
def all(params = {})
fetch_all_pages('shop/languages', params)
end

# Retrieve all languages that can be created for a shop. Languages that are not on the list are not supported.
#
# @see https://developer.epages.com/beyond-docs/#list_supported_languages
#
# @return [Hash]
#
# @example
# @client.supported_languages
def supported_languages
get('shop/languages/supported')
end

# Delete a language from a specified shop.
#
# @see https://developer.epages.com/beyond-docs/#delete_language
#
# @param id [String] the language UUID
#
# @return [Hash] an empty hash
#
# @example
# @client.delete('750958a7-7924-4028-8f44-260f8fb11cbb')
def delete(id)
super("shop/languages/#{id}")
end
end
end
end
22 changes: 22 additions & 0 deletions spec/beyond_api/services/shop/feature_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

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

describe '.all' do
it 'returns all shop features' do
response = client.all

expect(response).not_to be nil
expect(response.dig(:embedded, :features)).to be_kind_of(Array)
expect(response[:page]).to be_kind_of(Hash)
end
end

describe '.find' do
it 'returns a shop feature' do
response = client.find('product-management.max-products')
expect(response[:name]).to eq('product-management.max-products')
end
end
end
42 changes: 42 additions & 0 deletions spec/beyond_api/services/shop/language_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# frozen_string_literal: true

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

describe '.all' do
it 'returns all shop languages' do
response = client.all

expect(response).not_to be nil
expect(response.dig(:embedded, :languages)).to be_kind_of(Array)
expect(response[:page]).to be_kind_of(Hash)
end
end

context 'with language' do
before(:each) do
@response = client.create('it-IT')
end

describe '.create' do
it 'creates a new shop language' do
expect(@response).not_to be nil
expect(@response[:locale]).to eq('it-IT')
end
end

describe '.find' do
it 'returns a shop language' do
response = client.find(@response[:id])
expect(response[:locale]).to eq('it-IT')
end
end

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

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

Loading