Skip to content

Commit

Permalink
Add convenience methods for the API classes
Browse files Browse the repository at this point in the history
  • Loading branch information
hakanensari committed Sep 27, 2024
1 parent b460805 commit d7a4e36
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 18 deletions.
36 changes: 18 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Provides programmatic access to Amazon's catalog data, such as item titles, desc
**Example:**

```ruby
client = Peddler::API::CatalogItems20220401.new("<AWS_REGION>", "<ACCESS_TOKEN>")
client = Peddler.catalog_items_20220401("<AWS_REGION>", "<ACCESS_TOKEN>")
response = client.get_catalog_item(
marketplaceIds: ["ATVPDKIKX0DER"],
asin: "B08N5WRWNW"
Expand All @@ -109,7 +109,7 @@ Allows you to retrieve order information, including order details, buyer informa
**Example:**

```ruby
client = Peddler::API::OrdersV0.new("<AWS_REGION>", "<ACCESS_TOKEN>")
client = Peddler.orders_v0("<AWS_REGION>", "<ACCESS_TOKEN>")
response = client.get_orders(
marketplaceIds: ["ATVPDKIKX0DER"],
createdAfter: "2023-01-01T00:00:00Z"
Expand All @@ -124,7 +124,7 @@ Enables you to upload data to Amazon for updating listings, prices, inventory, a
**Example:**

```ruby
client = Peddler::API::Feeds20210630.new("<AWS_REGION>", "<ACCESS_TOKEN>")
client = Peddler.feeds_20210630("<AWS_REGION>", "<ACCESS_TOKEN>")
# Create a feed document to get an upload URL
response = client.create_feed_document(
contentType: "text/xml; charset=UTF-8"
Expand Down Expand Up @@ -152,7 +152,7 @@ Allows you to request and download various reports, such as order and inventory
**Example:**

```ruby
client = Peddler::API::Reports20210630.new("<AWS_REGION>", "<ACCESS_TOKEN>")
client = Peddler.reports_20210630("<AWS_REGION>", "<ACCESS_TOKEN>")
response = client.create_report(
reportType: "GET_FLAT_FILE_OPEN_LISTINGS_DATA",
marketplaceIds: ["ATVPDKIKX0DER"]
Expand All @@ -167,7 +167,7 @@ Enables you to manage your product listings on Amazon, including creating, updat
**Example:**

```ruby
client = Peddler::API::ListingsItems20210801.new("<AWS_REGION>", "<ACCESS_TOKEN>")
client = Peddler.listings_items_20210801("<AWS_REGION>", "<ACCESS_TOKEN>")
response = client.put_listings_item(
"<SELLER_ID>",
"SKU123",
Expand All @@ -193,7 +193,7 @@ Allows you to subscribe to notifications for specific events like order status u
**Example:**

```ruby
client = Peddler::API::NotificationsV1.new("<AWS_REGION>", "<ACCESS_TOKEN>")
client = Peddler.notifications_v1("<AWS_REGION>", "<ACCESS_TOKEN>")
# Create a destination
response = client.create_destination(
name: "MySQSQueue",
Expand All @@ -220,7 +220,7 @@ Provides information about fees that may be charged for selling products on Amaz
**Example:**

```ruby
client = Peddler::API::ProductFeesV0.new("<AWS_REGION>", "<ACCESS_TOKEN>")
client = Peddler.product_fees_v0("<AWS_REGION>", "<ACCESS_TOKEN>")
response = client.get_my_fees_estimate_for_sku(
sellerId: "<YOUR_SELLER_ID>",
sku: "SKU123",
Expand All @@ -247,7 +247,7 @@ Allows you to create and manage fulfillment orders using Amazon's fulfillment ne
**Example:**

```ruby
client = Peddler::API::FulfillmentOutbound20200701.new("<AWS_REGION>", "<ACCESS_TOKEN>")
client = Peddler.fulfillment_outbound_20200701("<AWS_REGION>", "<ACCESS_TOKEN>")
response = client.create_fulfillment_order(
body: {
sellerFulfillmentOrderId: "ORDER123",
Expand Down Expand Up @@ -282,7 +282,7 @@ Allows you to create shipping labels for orders using Amazon's negotiated shippi
**Example:**

```ruby
client = Peddler::API::MerchantFulfillmentV0.new("<AWS_REGION>", "<ACCESS_TOKEN>")
client = Peddler.merchant_fulfillment_v0("<AWS_REGION>", "<ACCESS_TOKEN>")
response = client.get_eligible_shipping_services(
body: {
shipmentRequestDetails: {
Expand Down Expand Up @@ -328,7 +328,7 @@ Allows vendors to retrieve purchase orders and order details from Amazon.
**Example:**

```ruby
client = Peddler::API::VendorOrders20211228.new("<AWS_REGION>", "<ACCESS_TOKEN>")
client = Peddler.vendor_orders_20211228("<AWS_REGION>", "<ACCESS_TOKEN>")
response = client.get_purchase_orders(
shipToPartyId: "<PARTY_ID>",
limit: 10,
Expand All @@ -344,7 +344,7 @@ Enables vendors to manage shipping labels and shipping information for direct fu
**Example:**

```ruby
client = Peddler::API::VendorDirectFulfillmentShipping20211228.new("<AWS_REGION>", "<ACCESS_TOKEN>")
client = Peddler.vendor_direct_fulfillment_shipping_20211228("<AWS_REGION>", "<ACCESS_TOKEN>")
response = client.get_packing_slip(
purchaseOrderNumber: "PO123456789"
)
Expand All @@ -358,7 +358,7 @@ Allows vendors to receive orders for direct fulfillment and provide shipment con
**Example:**

```ruby
client = Peddler::API::VendorDirectFulfillmentOrders20211228.new("<AWS_REGION>", "<ACCESS_TOKEN>")
client = Peddler.vendor_direct_fulfillment_orders_20211228("<AWS_REGION>", "<ACCESS_TOKEN>")
response = client.get_orders(
createdAfter: "2023-01-01T00:00:00Z",
limit: 10
Expand All @@ -373,7 +373,7 @@ Enables vendors to update inventory levels for direct fulfillment items.
**Example:**

```ruby
client = Peddler::API::VendorDirectFulfillmentInventory20211228.new("<AWS_REGION>", "<ACCESS_TOKEN>")
client = Peddler.vendor_direct_fulfillment_inventory_20211228("<AWS_REGION>", "<ACCESS_TOKEN>")
response = client.submit_inventory_update(
body: {
inventory: [
Expand Down Expand Up @@ -405,7 +405,7 @@ Provides functionalities for purchasing shipping labels and tracking shipments.
**Example:**

```ruby
client = Peddler::API::ShippingV2.new("<AWS_REGION>", "<ACCESS_TOKEN>")
client = Peddler.shipping_v2("<AWS_REGION>", "<ACCESS_TOKEN>")
response = client.purchase_shipment(
body: {
clientReferenceId: "CLIENT_REF_123",
Expand Down Expand Up @@ -452,7 +452,7 @@ Allows you to create restricted data tokens to access personally identifiable in
**Example:**

```ruby
client = Peddler::API::Tokens20210301.new("<AWS_REGION>", "<ACCESS_TOKEN>")
client = Peddler.tokens_20210301("<AWS_REGION>", "<ACCESS_TOKEN>")
response = client.create_restricted_data_token(
body: {
restrictedResources: [
Expand All @@ -467,7 +467,7 @@ response = client.create_restricted_data_token(
restricted_data_token = response.parse["restrictedDataToken"]

# Use the token in subsequent API calls
orders_client = Peddler::API::Orders20211201.new("<AWS_REGION>", restricted_data_token)
orders_client = Peddler.orders_20211201("<AWS_REGION>", restricted_data_token)
response = orders_client.get_order(
orderId: "123-1234567-1234567"
)
Expand All @@ -481,7 +481,7 @@ Provides information about financial events for your seller account, such as ord
**Example:**

```ruby
client = Peddler::API::FinancesV0.new
client = Peddler.finances_v0("<AWS_REGION>", "<ACCESS_TOKEN>")
response = client.list_financial_events(
postedAfter: "2023-01-01T00:00:00Z",
maxResultsPerPage: 100
Expand All @@ -496,7 +496,7 @@ Provides information about seller's marketplaces and participation status.
**Example:**

```ruby
client = Peddler::API::SellersV1.new
client = Peddler.sellers_v1("<AWS_REGION>", "<ACCESS_TOKEN>")
response = client.get_marketplace_participations
participations = response.parse["payload"]
```
Expand Down
17 changes: 17 additions & 0 deletions bin/templates/entrypoint.rb.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,20 @@
<% end -%>
require "peddler/marketplace"
require "peddler/token"

module Peddler
class << self
# Define convenience methods for instantiating the API classes
Peddler::API.constants.each do |const_name|
method_name = const_name.to_s
.gsub("FBA", "Fba")
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
.gsub(/(\d{4})(\d{2})(\d{2})/, '_\1_\2_\3')
.downcase
define_method(method_name) do |*args|
Peddler::API.const_get(const_name).new(*args)
end
end
end
end

16 changes: 16 additions & 0 deletions lib/peddler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,19 @@
require "peddler/api/vendor_transaction_status_v1"
require "peddler/marketplace"
require "peddler/token"

module Peddler
class << self
# Define convenience methods for instantiating the API classes
Peddler::API.constants.each do |const_name|
method_name = const_name.to_s
.gsub("FBA", "Fba")
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
.gsub(/(\d{4})(\d{2})(\d{2})/, '_\1_\2_\3')
.downcase
define_method(method_name) do |*args|
Peddler::API.const_get(const_name).new(*args)
end
end
end
end
5 changes: 5 additions & 0 deletions test/peddler_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@ class PeddlerTest < Minitest::Test
def test_entrypoint
refute_empty(Peddler::API.constants)
end

def test_convenience_methods
assert_instance_of(Peddler::API::FBAInventoryV1, Peddler.fba_inventory_v1("us-east-1", "access_token"))
assert_instance_of(Peddler::API::Reports20210630, Peddler.reports_2021_06_30("us-east-1", "access_token"))
end
end

0 comments on commit d7a4e36

Please sign in to comment.