diff --git a/lib/beyond_api/services/authentication/signer.rb b/lib/beyond_api/services/authentication/signer.rb index 7e1996a..ec3704c 100644 --- a/lib/beyond_api/services/authentication/signer.rb +++ b/lib/beyond_api/services/authentication/signer.rb @@ -2,15 +2,41 @@ module BeyondApi module Authentication + # @example How to instantiate a client + # @client = BeyondApi::Authentication::Signer.new(api_url: 'https://example.com/api', access_token: 'your_token') class Signer < BaseService - def all(params = {}) - get('signers', params) + # List all signers. + # + # @see https://developer.epages.com/beyond-docs/#list_signers + # + # @return [Hash] + # # + # @example + # @client.all + def all + get('signers') end + # Create a signer. + # + # @see https://developer.epages.com/beyond-docs/#create_signer + # + # @return [Hash] + # + # @example + # @client.create def create post('signers') end + # Delete a signer. If at least one signer has been created, you cannot delete the last signer. + # + # @see https://developer.epages.com/beyond-docs/#delete_signer + # + # @return [Hash] + # + # @example + # @client.delete('aa859c3c-702c-4310-9b23-638fbc468f33') def delete(id) super("signers/#{id}") # Concerns::Connection delete method end diff --git a/lib/beyond_api/services/authentication/token.rb b/lib/beyond_api/services/authentication/token.rb index c0bd137..222d84d 100644 --- a/lib/beyond_api/services/authentication/token.rb +++ b/lib/beyond_api/services/authentication/token.rb @@ -2,24 +2,47 @@ module BeyondApi module Authentication + # @example How to instantiate a client + # @client = BeyondApi::Authentication::Token.new(api_url: 'https://example.com/api') class Token < BaseService - include Concerns::Connection # @session, @authorization - def initialize(**params) super - @authorization = :basic @camelize_keys = false end + # Create a JsonWebToken from a refresh token. + # + # @see https://developer.epages.com/beyond-docs/#create_a_jsonwebtoken_from_refresh_token + # + # @return [Hash] + # + # @example + # @client.refresh_token('your_refresh_token') def refresh(refresh_token) post('oauth/token', {}, { grant_type: 'refresh_token', refresh_token: }) end + # Create a JsonWebToken from a refresh token. + # + # @see https://developer.epages.com/beyond-docs/#create_a_jsonwebtoken_from_refresh_token + # + # @return [Hash] + # + # @example + # @client.get('GY_GTp') def get(code) post('oauth/token', {}, { grant_type: 'authorization_code', code: }) end + # Create a a JsonWebToken using the client_credentials grant type. + # + # @see https://developer.epages.com/beyond-docs/#create_a_jsonwebtoken_from_client_credentials + # + # @return [Hash] + # + # @example + # @client.client_credentials def client_credentials post('oauth/token', {}, { grant_type: 'client_credentials' }) end diff --git a/lib/beyond_api/services/checkout/shipping_zone.rb b/lib/beyond_api/services/checkout/shipping_zone.rb index ab7d788..e40aae1 100644 --- a/lib/beyond_api/services/checkout/shipping_zone.rb +++ b/lib/beyond_api/services/checkout/shipping_zone.rb @@ -2,9 +2,23 @@ module BeyondApi module Checkout + # @example How to instantiate a client + # @client = BeyondApi::Checkout::ShippingZone.new(api_url: 'https://example.com/api', access_token: 'your_token') class ShippingZone < BaseService - def all - get('shipping-zones') + # List all shipping zones in a paged way. + # + # @see https://developer.epages.com/beyond-docs/#list_shipping_zones + # + # @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('shipping-zones', params) end end end diff --git a/lib/beyond_api/services/product_management/category.rb b/lib/beyond_api/services/product_management/category.rb index 647650a..775af2d 100644 --- a/lib/beyond_api/services/product_management/category.rb +++ b/lib/beyond_api/services/product_management/category.rb @@ -2,23 +2,77 @@ module BeyondApi module ProductManagement + # @example How to instantiate a client + # @client = BeyondApi::ProductManagement::Category.new(api_url: 'https://example.com/api', access_token: 'your_token') class Category < BaseService + # Retrieve the details of a category. + # + # @see https://developer.epages.com/beyond-docs/#show_category_details + # + # @param id [String] the category UUID + # + # @return [Hash] + # + # @example + # @client.find('e97226a6-9412-481f-b1d7-e64fc58df88e') def find(id) get("categories/#{id}") end + # List all available categories in a paged manner. + # + # @see https://developer.epages.com/beyond-docs/#list_categories + # + # @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('categories', params) end + # Create a product category. + # + # @see https://developer.epages.com/beyond-docs/#create_category + # + # @param body [Hash] the request body + # + # @return [Hash] + # + # @example + # @client.create(name: 'Power Bars', type: 'SMART', default_sort: 'NEWEST_FIRST') def create(body) post('categories', body) end + # Update all product category properties. + # + # @see https://developer.epages.com/beyond-docs/#update_all_category_properties + # + # @param body [Hash] the request body + # + # @return [Hash] + # + # @example + # @client.update(name: 'High Protein Power Bars', type: 'SMART', default_sort: 'NEWEST_FIRST') def update(id, body) put("categories/#{id}", body) end + # Delete a product category. + # + # @see https://developer.epages.com/beyond-docs/#list_categories + # + # @param id [String] the category UUID + # + # @return [Hash] an empty hash + # + # @example + # @client.delete('c8cc52ec-fe57-4d4d-a2e3-f1756e767724') def delete(id) super("categories/#{id}") # Concerns::Connection delete method end diff --git a/lib/beyond_api/services/product_management/image.rb b/lib/beyond_api/services/product_management/image.rb index 6fd17b5..14b937d 100644 --- a/lib/beyond_api/services/product_management/image.rb +++ b/lib/beyond_api/services/product_management/image.rb @@ -2,7 +2,20 @@ module BeyondApi module ProductManagement + # @example How to instantiate a client + # @client = BeyondApi::ProductManagement::Image.new(api_url: 'https://example.com/api', access_token: 'your_token') class Image < BaseService + # Retrieve the images of a product. + # + # @see https://developer.epages.com/beyond-docs/#list_product_images + # + # @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(id, params = {}) get("products/#{id}/images", params) end diff --git a/lib/beyond_api/services/product_management/product.rb b/lib/beyond_api/services/product_management/product.rb index c947f3f..a30b427 100644 --- a/lib/beyond_api/services/product_management/product.rb +++ b/lib/beyond_api/services/product_management/product.rb @@ -2,15 +2,117 @@ module BeyondApi module ProductManagement + # @example How to instantiate a client + # @client = BeyondApi::ProductManagement::Product.new(api_url: 'https://example.com/api', access_token: 'your_token') class Product < BaseService + # List all products in a paged manner. + # + # @see https://developer.epages.com/beyond-docs/#list_products + # + # @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('products', params) end + # Create a product. + # + # @see https://developer.epages.com/beyond-docs/#create_product + # + # @param body [Hash] the request body + # + # @return [Hash] + # + # @example + # product_data = { + # sku: '123456789-001', + # name: 'Rioja Castillo de Puerto (2013)', + # description: 'Spain\nRioja Tempranillo', + # manufacturer: 'Grape Vineyard', + # essential_features: 'Dry. 12% alcohol. Best vine variety.', + # tags: ['Bestseller', 'Red Wine', 'Sale'], + # product_identifiers: [ + # { + # type: 'EAN', + # value: '9780134308135' + # } + # ], + # sales_price: { + # tax_model: 'GROSS', + # amount: 8.7, + # currency: 'EUR' + # }, + # list_price: { + # tax_model: 'GROSS', + # amount: 10.95, + # currency: 'EUR' + # }, + # manufacturer_price: { + # tax_model: 'GROSS', + # amount: 11.95, + # currency: 'EUR' + # }, + # visible: true, + # tax_class: 'REGULAR', + # shipping_weight: { + # value: 1175.0, + # display_unit: 'GRAMS' + # }, + # max_order_quantity: 6, + # shipping_dimension: { + # length: 1500, + # width: 1000, + # height: 2000 + # }, + # ref_price: { + # ref_quantity: 1, + # unit: 'LITER', + # quantity: 0.75, + # price: { + # tax_model: 'GROSS', + # amount: 11.6, + # currency: 'EUR' + # } + # }, + # shipping_period: { + # min: 2, + # max: 4, + # display_unit: 'WEEKS' + # }, + # pickup_period: { + # min: 1, + # max: 2, + # display_unit: 'WEEKS' + # }, + # product_labels: [ + # { + # type: 'NEW', + # active_from: '2024-08-19T13:04:55.897122293', + # active_until: '2024-09-16T13:04:55.897122293' + # } + # ] + # } + # @client.create(product_data) def create(body) post('products', body) end + # Retrieve the details of a product. + # + # @see https://developer.epages.com/beyond-docs/#show_product_details + # + # @param id [String] the product UUID + # + # @return [Hash] + # + # @example + # @client.find('985efde9-577c-4752-9556-af5ed8a81b1b') def find(id) get("products/#{id}") end diff --git a/lib/beyond_api/services/product_management/variation.rb b/lib/beyond_api/services/product_management/variation.rb index 223b14f..f7fffaf 100644 --- a/lib/beyond_api/services/product_management/variation.rb +++ b/lib/beyond_api/services/product_management/variation.rb @@ -2,7 +2,22 @@ module BeyondApi module ProductManagement + # @example How to instantiate a client + # @client = BeyondApi::ProductManagement::Variation.new(api_url: 'https://example.com/api', access_token: 'your_token') class Variation < BaseService + # Retrieve the variations of a variation product in a paged manner. + # + # @see https://developer.epages.com/beyond-docs/#list_variations + # + # @param id [String] the product UUID + # @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(id, params = {}) get("products/#{id}/variations", params) end diff --git a/lib/beyond_api/services/product_management/variation_image.rb b/lib/beyond_api/services/product_management/variation_image.rb index fa4c9d0..62e538e 100644 --- a/lib/beyond_api/services/product_management/variation_image.rb +++ b/lib/beyond_api/services/product_management/variation_image.rb @@ -2,7 +2,23 @@ module BeyondApi module ProductManagement + # @example How to instantiate a client + # @client = BeyondApi::ProductManagement::VariationImage.new(api_url: 'https://example.com/api', access_token: 'your_token') class VariationImage < BaseService + # Retrieve the images of a single variation of a variation product in a paged manner. + # + # @see https://developer.epages.com/beyond-docs/#list_variation_images + # + # @param product_id [String] the product UUID + # @param variation_id [String] the variation UUID + # @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(product_id, variation_id, _params = {}) get("products/#{product_id}/variations/#{variation_id}/images") end diff --git a/lib/beyond_api/services/product_view/category.rb b/lib/beyond_api/services/product_view/category.rb index 9f16499..5dc7b93 100644 --- a/lib/beyond_api/services/product_view/category.rb +++ b/lib/beyond_api/services/product_view/category.rb @@ -2,15 +2,69 @@ module BeyondApi module ProductView + # @example How to instantiate a client + # @client = BeyondApi::ProductView::Category.new(api_url: 'https://example.com/api', access_token: 'your_token') class Category < BaseService + # List all product categories in a paged manner. + # + # @see https://developer.epages.com/beyond-docs/#list_product_categories + # + # @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('product-view/categories', params) end + # Retrieve the details of a category. + # + # @see https://developer.epages.com/beyond-docs/#show_product_category_details + # + # @param id [String] the category UUID + # + # @return [Hash] + # + # @example + # @client.find('823c12ed-1f1b-47c6-8fc8-51fb7338be84') def find(id) get("product-view/categories/#{id}") end + # Preview products included in category in a paged manner. + # + # @see https://developer.epages.com/beyond-docs/#preview_products_included_in_category + # + # @param body [Hash] the product filters + # @option params [Boolean] :paginated + # @option params [Integer] :size the page size + # @option params [Integer] :page the page number + # + # @return [Hash] + # + # @example + # body = { + # filters: [ + # { + # key: "manufacturer", + # values: ["Grape Vineyard"] + # }, + # { + # key: "all_tags", + # values: ["Power Bar", "Bestseller", "High Protein"] + # }, + # { + # key: "price_range", + # min: 3.7, + # max: 13.7 + # } + # ] + # } + # @client.preview(body, { size: 100, page: 0 }) def preview(body, params = {}) post('product-view/categories/preview', body, params) end diff --git a/lib/beyond_api/services/shop/address.rb b/lib/beyond_api/services/shop/address.rb index 800872d..5e5470a 100644 --- a/lib/beyond_api/services/shop/address.rb +++ b/lib/beyond_api/services/shop/address.rb @@ -2,7 +2,17 @@ module BeyondApi module Shop + # @example How to instantiate a client + # @client = BeyondApi::Shop::Address.new(api_url: 'https://example.com/api', access_token: 'your_token') class Address < BaseService + # Retrieve the details of a shop's address. + # + # @see https://developer.epages.com/beyond-docs/#show_address_details + # + # @return [Hash] + # + # @example + # @client.show def show get('shop/address') end diff --git a/lib/beyond_api/services/shop/shop.rb b/lib/beyond_api/services/shop/shop.rb index 757c314..b722e72 100644 --- a/lib/beyond_api/services/shop/shop.rb +++ b/lib/beyond_api/services/shop/shop.rb @@ -2,7 +2,17 @@ module BeyondApi module Shop + # @example How to instantiate a client + # @client = BeyondApi::Shop::Shop.new(api_url: 'https://example.com/api', access_token: 'your_token') class Shop < BaseService + # Retrieve the details of a shop. + # + # @see https://developer.epages.com/beyond-docs/#show_shop_details + # + # @return [Hash] + # + # @example + # @client.show def show get('shop') end diff --git a/lib/beyond_api/services/storefront/script_tag.rb b/lib/beyond_api/services/storefront/script_tag.rb index 79ffebe..d101d7e 100644 --- a/lib/beyond_api/services/storefront/script_tag.rb +++ b/lib/beyond_api/services/storefront/script_tag.rb @@ -2,6 +2,8 @@ module BeyondApi 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 def all(params = {}) params.merge!(client_id: BeyondApi.configuration.client_id) if params[:only_own] diff --git a/lib/beyond_api/services/webhook/subscription.rb b/lib/beyond_api/services/webhook/subscription.rb index 51e3a97..794584b 100644 --- a/lib/beyond_api/services/webhook/subscription.rb +++ b/lib/beyond_api/services/webhook/subscription.rb @@ -2,25 +2,80 @@ module BeyondApi module Webhook + # @example How to instantiate a client + # @client = BeyondApi::Webhook::Subscription.new(api_url: 'https://example.com/api', access_token: 'your_token') class Subscription < BaseService + # List all webhooks subscriptions in a paged manner. + # + # @see https://developer.epages.com/beyond-docs/#list_webhook_subscriptions + # + # @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 = {}) get('webhook-subscriptions', params) end + # Create a webhook subscription. + # + # @see https://developer.epages.com/beyond-docs/#create_webhook_subscription + # + # @param body [Hash] the request body + # + # @return [Hash] + # + # @example + # webhook_data = { + # callback_uri: 'http://example.com/test', + # event_types: ['order.created', 'product.created'] + # } + # @client.create(webhook_data) def create(body) post('webhook-subscriptions', body) end + # Delete all webhook subscriptions. + # + # @param body [Hash] the request body + # + # @return [Hash] + # + # @example + # @client.delete_all def delete_all all.dig(:embedded, :subscriptions).each do |subscription| delete(subscription[:id]) end end + # Delete a webhook subscription. + # + # @see https://developer.epages.com/beyond-docs/#delete_webhook_subscription + # + # @param id [String] the webhook subscription UUID + # + # @return [Hash] an empty hash + # + # @example + # @client.delete('84ce4b3a-9a10-46d0-afcd-a71bcd0c0e9a') def delete(id) super("webhook-subscriptions/#{id}") # Concerns::Connection delete method end + # Retrieve the details of a webhook subscription. + # + # @see https://developer.epages.com/beyond-docs/#show_webhook_subscription_details + # + # @param id [String] the webhook subscription UUID + # + # @return [Hash] + # + # @example + # @client.find('a2e39f0f-7728-40ca-88e4-cb8cea9ecf5e') def find(id) get("webhook-subscriptions/#{id}") end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 665b37b..aa49eab 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -33,11 +33,7 @@ end def auth_client - BeyondApi::Authentication::Token.new( - api_url: ENV.fetch('API_URL', nil), - client_id: ENV.fetch('CLIENT_ID', nil), - client_secret: ENV.fetch('CLIENT_SECRET', nil) - ) + BeyondApi::Authentication::Token.new(api_url: ENV.fetch('API_URL', nil)) end def beyond_access_token