Skip to content

Commit

Permalink
Add defaults in generated code
Browse files Browse the repository at this point in the history
  • Loading branch information
hakanensari committed Sep 20, 2024
1 parent 686470e commit 31631d9
Show file tree
Hide file tree
Showing 16 changed files with 918 additions and 910 deletions.
6 changes: 5 additions & 1 deletion bin/generate-code
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,11 @@ module Generator
required_params = parameters.select { |p| p["required"] }&.map { |p| snakecase(p["name"]) } || []
optional_params = parameters.reject do |p|
p["required"]
end&.map { |p| "#{snakecase(p["name"])}: #{p["default"] ? p["default"] : "nil"}" } || []
end&.map do |p|
default_value = p["default"]
formatted_default = default_value.is_a?(String) ? "\"#{default_value}\"" : default_value
"#{snakecase(p["name"])}: #{formatted_default ? formatted_default : "nil"}"
end || []
params = required_params + optional_params

single_line = "def #{method_name}(#{params.join(", ")})"
Expand Down
2 changes: 1 addition & 1 deletion lib/peddler/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def http
def meter(rate_limit)
# HTTP v6.0 will implement retriable. Until then, point to their GitHub repo, or it's a no-op.
# https://github.com/httprb/http/pull/790
delay = sandbox? ? 0.2 : 1.0 / rate
delay = sandbox? ? 0.2 : 1.0 / rate_limit
retriable(delay: delay, retry_statuses: [429]) if @http.respond_to?(:retriable)

self
Expand Down
4 changes: 2 additions & 2 deletions lib/peddler/api/catalog_items_2020_12_01.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class CatalogItems20201201 < API
# marketplace.
# @param [Float] rate_limit Requests per second
# @return [Hash] The API response
def search_catalog_items(keywords, marketplace_ids, included_data: summaries, brand_names: nil,
def search_catalog_items(keywords, marketplace_ids, included_data: "summaries", brand_names: nil,
classification_ids: nil, page_size: 10, page_token: nil, keywords_locale: nil, locale: nil, rate_limit: 2.0)
cannot_sandbox!

Expand Down Expand Up @@ -59,7 +59,7 @@ def search_catalog_items(keywords, marketplace_ids, included_data: summaries, br
# marketplace.
# @param [Float] rate_limit Requests per second
# @return [Hash] The API response
def get_catalog_item(asin, marketplace_ids, included_data: summaries, locale: nil, rate_limit: 2.0)
def get_catalog_item(asin, marketplace_ids, included_data: "summaries", locale: nil, rate_limit: 2.0)
cannot_sandbox!

path = "/catalog/2020-12-01/items/#{asin}"
Expand Down
4 changes: 2 additions & 2 deletions lib/peddler/api/product_type_definitions_2020_09_01.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ def search_definitions_product_types(marketplace_ids, keywords: nil, item_name:
# default language of the first marketplace in the request.
# @param [Float] rate_limit Requests per second
# @return [Hash] The API response
def get_definitions_product_type(product_type, marketplace_ids, seller_id: nil, product_type_version: LATEST,
requirements: LISTING, requirements_enforced: ENFORCED, locale: DEFAULT, rate_limit: 5.0)
def get_definitions_product_type(product_type, marketplace_ids, seller_id: nil, product_type_version: "LATEST",
requirements: "LISTING", requirements_enforced: "ENFORCED", locale: "DEFAULT", rate_limit: 5.0)
cannot_sandbox!

path = "/definitions/2020-09-01/productTypes/#{product_type}"
Expand Down
4 changes: 2 additions & 2 deletions lib/peddler/api/sales_v1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ class SalesV1 < API
# TestSKU, if you want the response to include order metrics for only SKU TestSKU.
# @param [Float] rate_limit Requests per second
# @return [Hash] The API response
def get_order_metrics(marketplace_ids, interval, granularity, granularity_time_zone: nil, buyer_type: All,
fulfillment_network: nil, first_day_of_week: Monday, asin: nil, sku: nil, rate_limit: 0.5)
def get_order_metrics(marketplace_ids, interval, granularity, granularity_time_zone: nil, buyer_type: "All",
fulfillment_network: nil, first_day_of_week: "Monday", asin: nil, sku: nil, rate_limit: 0.5)
cannot_sandbox!

path = "/sales/v1/orderMetrics"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class VendorDirectFulfillmentOrders20211228 < API
# @param [Float] rate_limit Requests per second
# @return [Hash] The API response
def get_orders(created_after, created_before, ship_from_party_id: nil, status: nil, limit: nil, sort_order: nil,
next_token: nil, include_details: true, rate_limit: 10.0)
next_token: nil, include_details: "true", rate_limit: 10.0)

path = "/vendor/directFulfillment/orders/2021-12-28/purchaseOrders"
params = {
Expand Down
2 changes: 1 addition & 1 deletion lib/peddler/api/vendor_direct_fulfillment_orders_v1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class VendorDirectFulfillmentOrdersV1 < API
# @param [Float] rate_limit Requests per second
# @return [Hash] The API response
def get_orders(created_after, created_before, ship_from_party_id: nil, status: nil, limit: nil, sort_order: nil,
next_token: nil, include_details: true, rate_limit: 10.0)
next_token: nil, include_details: "true", rate_limit: 10.0)
cannot_sandbox!

path = "/vendor/directFulfillment/orders/v1/purchaseOrders"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class VendorDirectFulfillmentShipping20211228 < API
# limit. The token value is returned in the previous API call.
# @param [Float] rate_limit Requests per second
# @return [Hash] The API response
def get_shipping_labels(created_after, created_before, ship_from_party_id: nil, limit: nil, sort_order: ASC,
def get_shipping_labels(created_after, created_before, ship_from_party_id: nil, limit: nil, sort_order: "ASC",
next_token: nil, rate_limit: 10.0)

path = "/vendor/directFulfillment/shipping/2021-12-28/shippingLabels"
Expand Down Expand Up @@ -159,7 +159,7 @@ def get_customer_invoice(purchase_order_number, rate_limit: 10.0)
# limit. The token value is returned in the previous API call.
# @param [Float] rate_limit Requests per second
# @return [Hash] The API response
def get_packing_slips(created_after, created_before, ship_from_party_id: nil, limit: nil, sort_order: ASC,
def get_packing_slips(created_after, created_before, ship_from_party_id: nil, limit: nil, sort_order: "ASC",
next_token: nil, rate_limit: 10.0)

path = "/vendor/directFulfillment/shipping/2021-12-28/packingSlips"
Expand Down
4 changes: 2 additions & 2 deletions lib/peddler/api/vendor_direct_fulfillment_shipping_v1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class VendorDirectFulfillmentShippingV1 < API
# limit. The token value is returned in the previous API call.
# @param [Float] rate_limit Requests per second
# @return [Hash] The API response
def get_shipping_labels(created_after, created_before, ship_from_party_id: nil, limit: nil, sort_order: ASC,
def get_shipping_labels(created_after, created_before, ship_from_party_id: nil, limit: nil, sort_order: "ASC",
next_token: nil, rate_limit: 10.0)
cannot_sandbox!

Expand Down Expand Up @@ -158,7 +158,7 @@ def get_customer_invoice(purchase_order_number, rate_limit: 10.0)
# limit. The token value is returned in the previous API call.
# @param [Float] rate_limit Requests per second
# @return [Hash] The API response
def get_packing_slips(created_after, created_before, ship_from_party_id: nil, limit: nil, sort_order: ASC,
def get_packing_slips(created_after, created_before, ship_from_party_id: nil, limit: nil, sort_order: "ASC",
next_token: nil, rate_limit: 10.0)
cannot_sandbox!

Expand Down
2 changes: 1 addition & 1 deletion test/peddler/api/feeds_2021_06_30_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def setup

def test_create_feed_document
res = @api.create_feed_document(
"contentType" => "application/json; charset=UTF-8",
{ "contentType" => "application/json; charset=UTF-8" },
)

assert_predicate(res.status, :created?)
Expand Down
6 changes: 4 additions & 2 deletions test/peddler/api/reports_2021_06_30_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ def setup

def test_create_report
res = @api.create_report(
"reportType" => "GET_MERCHANTS_LISTINGS_FYP_REPORT",
"marketplaceIds" => ["A1F83G8C2ARO7P"],
{
"reportType" => "GET_MERCHANTS_LISTINGS_FYP_REPORT",
"marketplaceIds" => ["A1F83G8C2ARO7P"],
},
)

assert_predicate(res.status, :accepted?)
Expand Down

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

Loading

0 comments on commit 31631d9

Please sign in to comment.