Skip to content

Commit b150767

Browse files
authored
EPT-2986 Add comments (#79)
* Add comments * Update documentation
1 parent 8341f7c commit b150767

File tree

14 files changed

+402
-12
lines changed

14 files changed

+402
-12
lines changed

lib/beyond_api/services/authentication/signer.rb

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,41 @@
22

33
module BeyondApi
44
module Authentication
5+
# @example How to instantiate a client
6+
# @client = BeyondApi::Authentication::Signer.new(api_url: 'https://example.com/api', access_token: 'your_token')
57
class Signer < BaseService
6-
def all(params = {})
7-
get('signers', params)
8+
# List all signers.
9+
#
10+
# @see https://developer.epages.com/beyond-docs/#list_signers
11+
#
12+
# @return [Hash]
13+
# #
14+
# @example
15+
# @client.all
16+
def all
17+
get('signers')
818
end
919

20+
# Create a signer.
21+
#
22+
# @see https://developer.epages.com/beyond-docs/#create_signer
23+
#
24+
# @return [Hash]
25+
#
26+
# @example
27+
# @client.create
1028
def create
1129
post('signers')
1230
end
1331

32+
# Delete a signer. If at least one signer has been created, you cannot delete the last signer.
33+
#
34+
# @see https://developer.epages.com/beyond-docs/#delete_signer
35+
#
36+
# @return [Hash]
37+
#
38+
# @example
39+
# @client.delete('aa859c3c-702c-4310-9b23-638fbc468f33')
1440
def delete(id)
1541
super("signers/#{id}") # Concerns::Connection delete method
1642
end

lib/beyond_api/services/authentication/token.rb

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,47 @@
22

33
module BeyondApi
44
module Authentication
5+
# @example How to instantiate a client
6+
# @client = BeyondApi::Authentication::Token.new(api_url: 'https://example.com/api')
57
class Token < BaseService
6-
include Concerns::Connection # @session, @authorization
7-
88
def initialize(**params)
99
super
10-
1110
@authorization = :basic
1211
@camelize_keys = false
1312
end
1413

14+
# Create a JsonWebToken from a refresh token.
15+
#
16+
# @see https://developer.epages.com/beyond-docs/#create_a_jsonwebtoken_from_refresh_token
17+
#
18+
# @return [Hash]
19+
#
20+
# @example
21+
# @client.refresh_token('your_refresh_token')
1522
def refresh(refresh_token)
1623
post('oauth/token', {}, { grant_type: 'refresh_token', refresh_token: })
1724
end
1825

26+
# Create a JsonWebToken from a refresh token.
27+
#
28+
# @see https://developer.epages.com/beyond-docs/#create_a_jsonwebtoken_from_refresh_token
29+
#
30+
# @return [Hash]
31+
#
32+
# @example
33+
# @client.get('GY_GTp')
1934
def get(code)
2035
post('oauth/token', {}, { grant_type: 'authorization_code', code: })
2136
end
2237

38+
# Create a a JsonWebToken using the client_credentials grant type.
39+
#
40+
# @see https://developer.epages.com/beyond-docs/#create_a_jsonwebtoken_from_client_credentials
41+
#
42+
# @return [Hash]
43+
#
44+
# @example
45+
# @client.client_credentials
2346
def client_credentials
2447
post('oauth/token', {}, { grant_type: 'client_credentials' })
2548
end

lib/beyond_api/services/checkout/shipping_zone.rb

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,23 @@
22

33
module BeyondApi
44
module Checkout
5+
# @example How to instantiate a client
6+
# @client = BeyondApi::Checkout::ShippingZone.new(api_url: 'https://example.com/api', access_token: 'your_token')
57
class ShippingZone < BaseService
6-
def all
7-
get('shipping-zones')
8+
# List all shipping zones in a paged way.
9+
#
10+
# @see https://developer.epages.com/beyond-docs/#list_shipping_zones
11+
#
12+
# @option params [Boolean] :paginated
13+
# @option params [Integer] :size the page size
14+
# @option params [Integer] :page the page number
15+
#
16+
# @return [Hash]
17+
#
18+
# @example
19+
# @client.all(size: 100, page: 0)
20+
def all(params = {})
21+
fetch_all_pages('shipping-zones', params)
822
end
923
end
1024
end

lib/beyond_api/services/product_management/category.rb

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,77 @@
22

33
module BeyondApi
44
module ProductManagement
5+
# @example How to instantiate a client
6+
# @client = BeyondApi::ProductManagement::Category.new(api_url: 'https://example.com/api', access_token: 'your_token')
57
class Category < BaseService
8+
# Retrieve the details of a category.
9+
#
10+
# @see https://developer.epages.com/beyond-docs/#show_category_details
11+
#
12+
# @param id [String] the category UUID
13+
#
14+
# @return [Hash]
15+
#
16+
# @example
17+
# @client.find('e97226a6-9412-481f-b1d7-e64fc58df88e')
618
def find(id)
719
get("categories/#{id}")
820
end
921

22+
# List all available categories in a paged manner.
23+
#
24+
# @see https://developer.epages.com/beyond-docs/#list_categories
25+
#
26+
# @option params [Boolean] :paginated
27+
# @option params [Integer] :size the page size
28+
# @option params [Integer] :page the page number
29+
#
30+
# @return [Hash]
31+
#
32+
# @example
33+
# @client.all(size: 100, page: 0)
1034
def all(params = {})
1135
fetch_all_pages('categories', params)
1236
end
1337

38+
# Create a product category.
39+
#
40+
# @see https://developer.epages.com/beyond-docs/#create_category
41+
#
42+
# @param body [Hash] the request body
43+
#
44+
# @return [Hash]
45+
#
46+
# @example
47+
# @client.create(name: 'Power Bars', type: 'SMART', default_sort: 'NEWEST_FIRST')
1448
def create(body)
1549
post('categories', body)
1650
end
1751

52+
# Update all product category properties.
53+
#
54+
# @see https://developer.epages.com/beyond-docs/#update_all_category_properties
55+
#
56+
# @param body [Hash] the request body
57+
#
58+
# @return [Hash]
59+
#
60+
# @example
61+
# @client.update(name: 'High Protein Power Bars', type: 'SMART', default_sort: 'NEWEST_FIRST')
1862
def update(id, body)
1963
put("categories/#{id}", body)
2064
end
2165

66+
# Delete a product category.
67+
#
68+
# @see https://developer.epages.com/beyond-docs/#list_categories
69+
#
70+
# @param id [String] the category UUID
71+
#
72+
# @return [Hash] an empty hash
73+
#
74+
# @example
75+
# @client.delete('c8cc52ec-fe57-4d4d-a2e3-f1756e767724')
2276
def delete(id)
2377
super("categories/#{id}") # Concerns::Connection delete method
2478
end

lib/beyond_api/services/product_management/image.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,20 @@
22

33
module BeyondApi
44
module ProductManagement
5+
# @example How to instantiate a client
6+
# @client = BeyondApi::ProductManagement::Image.new(api_url: 'https://example.com/api', access_token: 'your_token')
57
class Image < BaseService
8+
# Retrieve the images of a product.
9+
#
10+
# @see https://developer.epages.com/beyond-docs/#list_product_images
11+
#
12+
# @option params [Integer] :size the page size
13+
# @option params [Integer] :page the page number
14+
#
15+
# @return [Hash]
16+
#
17+
# @example
18+
# @client.all(size: 100, page: 0)
619
def all(id, params = {})
720
get("products/#{id}/images", params)
821
end

lib/beyond_api/services/product_management/product.rb

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,117 @@
22

33
module BeyondApi
44
module ProductManagement
5+
# @example How to instantiate a client
6+
# @client = BeyondApi::ProductManagement::Product.new(api_url: 'https://example.com/api', access_token: 'your_token')
57
class Product < BaseService
8+
# List all products in a paged manner.
9+
#
10+
# @see https://developer.epages.com/beyond-docs/#list_products
11+
#
12+
# @option params [Boolean] :paginated
13+
# @option params [Integer] :size the page size
14+
# @option params [Integer] :page the page number
15+
#
16+
# @return [Hash]
17+
#
18+
# @example
19+
# @client.all(size: 100, page: 0)
620
def all(params = {})
721
fetch_all_pages('products', params)
822
end
923

24+
# Create a product.
25+
#
26+
# @see https://developer.epages.com/beyond-docs/#create_product
27+
#
28+
# @param body [Hash] the request body
29+
#
30+
# @return [Hash]
31+
#
32+
# @example
33+
# product_data = {
34+
# sku: '123456789-001',
35+
# name: 'Rioja Castillo de Puerto (2013)',
36+
# description: 'Spain\nRioja Tempranillo',
37+
# manufacturer: 'Grape Vineyard',
38+
# essential_features: 'Dry. 12% alcohol. Best vine variety.',
39+
# tags: ['Bestseller', 'Red Wine', 'Sale'],
40+
# product_identifiers: [
41+
# {
42+
# type: 'EAN',
43+
# value: '9780134308135'
44+
# }
45+
# ],
46+
# sales_price: {
47+
# tax_model: 'GROSS',
48+
# amount: 8.7,
49+
# currency: 'EUR'
50+
# },
51+
# list_price: {
52+
# tax_model: 'GROSS',
53+
# amount: 10.95,
54+
# currency: 'EUR'
55+
# },
56+
# manufacturer_price: {
57+
# tax_model: 'GROSS',
58+
# amount: 11.95,
59+
# currency: 'EUR'
60+
# },
61+
# visible: true,
62+
# tax_class: 'REGULAR',
63+
# shipping_weight: {
64+
# value: 1175.0,
65+
# display_unit: 'GRAMS'
66+
# },
67+
# max_order_quantity: 6,
68+
# shipping_dimension: {
69+
# length: 1500,
70+
# width: 1000,
71+
# height: 2000
72+
# },
73+
# ref_price: {
74+
# ref_quantity: 1,
75+
# unit: 'LITER',
76+
# quantity: 0.75,
77+
# price: {
78+
# tax_model: 'GROSS',
79+
# amount: 11.6,
80+
# currency: 'EUR'
81+
# }
82+
# },
83+
# shipping_period: {
84+
# min: 2,
85+
# max: 4,
86+
# display_unit: 'WEEKS'
87+
# },
88+
# pickup_period: {
89+
# min: 1,
90+
# max: 2,
91+
# display_unit: 'WEEKS'
92+
# },
93+
# product_labels: [
94+
# {
95+
# type: 'NEW',
96+
# active_from: '2024-08-19T13:04:55.897122293',
97+
# active_until: '2024-09-16T13:04:55.897122293'
98+
# }
99+
# ]
100+
# }
101+
# @client.create(product_data)
10102
def create(body)
11103
post('products', body)
12104
end
13105

106+
# Retrieve the details of a product.
107+
#
108+
# @see https://developer.epages.com/beyond-docs/#show_product_details
109+
#
110+
# @param id [String] the product UUID
111+
#
112+
# @return [Hash]
113+
#
114+
# @example
115+
# @client.find('985efde9-577c-4752-9556-af5ed8a81b1b')
14116
def find(id)
15117
get("products/#{id}")
16118
end

lib/beyond_api/services/product_management/variation.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,22 @@
22

33
module BeyondApi
44
module ProductManagement
5+
# @example How to instantiate a client
6+
# @client = BeyondApi::ProductManagement::Variation.new(api_url: 'https://example.com/api', access_token: 'your_token')
57
class Variation < BaseService
8+
# Retrieve the variations of a variation product in a paged manner.
9+
#
10+
# @see https://developer.epages.com/beyond-docs/#list_variations
11+
#
12+
# @param id [String] the product UUID
13+
# @option params [Boolean] :paginated
14+
# @option params [Integer] :size the page size
15+
# @option params [Integer] :page the page number
16+
#
17+
# @return [Hash]
18+
#
19+
# @example
20+
# @client.all(size: 100, page: 0)
621
def all(id, params = {})
722
get("products/#{id}/variations", params)
823
end

lib/beyond_api/services/product_management/variation_image.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,23 @@
22

33
module BeyondApi
44
module ProductManagement
5+
# @example How to instantiate a client
6+
# @client = BeyondApi::ProductManagement::VariationImage.new(api_url: 'https://example.com/api', access_token: 'your_token')
57
class VariationImage < BaseService
8+
# Retrieve the images of a single variation of a variation product in a paged manner.
9+
#
10+
# @see https://developer.epages.com/beyond-docs/#list_variation_images
11+
#
12+
# @param product_id [String] the product UUID
13+
# @param variation_id [String] the variation UUID
14+
# @option params [Boolean] :paginated
15+
# @option params [Integer] :size the page size
16+
# @option params [Integer] :page the page number
17+
#
18+
# @return [Hash]
19+
#
20+
# @example
21+
# @client.all(size: 100, page: 0)
622
def all(product_id, variation_id, _params = {})
723
get("products/#{product_id}/variations/#{variation_id}/images")
824
end

0 commit comments

Comments
 (0)