Skip to content
This repository was archived by the owner on Jan 4, 2025. It is now read-only.

Add Feeds utility to convert dict FeedOptions to string#181

Merged
GriceTurrble merged 2 commits intodevelopfrom
feature-feeds-accept-dict-options
Jun 26, 2020
Merged

Add Feeds utility to convert dict FeedOptions to string#181
GriceTurrble merged 2 commits intodevelopfrom
feature-feeds-accept-dict-options

Conversation

@GriceTurrble
Copy link
Copy Markdown
Member

As an enhancement to #166 , this adds a utility function, feed_options_str, that converts a dict of feed options to the appropriate string value.

This is an optional enhancement: users can supply a string value to feed_options themselves, and this will be passed straight to the request. Otherwise, a dict like the following example:

feed_options = {
    "shippingid": "283845474",
    "totalAmount": 3.25,
    "totalvatamount": 1.23,
    "invoicenumber": "INT-3431-XJE3",
    "documenttype": "CreditNote",
    "transactionid": "amzn:crow:429491192ksjfhe39s",
}

...will be converted to a string by feed_options_str:

print(feed_options_str(feed_options))
>>> "metadata:shippingid=283845474;metadata:totalAmount=3.25;metadata:totalvatamount=1.23;metadata:invoicenumber=INT-3431-XJE3;metadata:documenttype=CreditNote;metadata:transactionid=amzn:crow:429491192ksjfhe39s"

This is in accordance with Amazon documentation, here (PDF) (see 6.4 Invoice Upload Feed Type).

  • All keys are prefixed by "metadata:".
  • Keys are case-insensitive, so no conversion is performed.
  • Values are simply cast to strings, though we make a special case for True and False as in other contexts, converting these literals to "true" and "false", respectively.
  • Keys and values are joined as key=value.
  • Key-value pairs are joined in the final string with ; as a separator.
  • A falsey value for the feed_options dict will return None, instead.
  • If the utility is reached with a non-empty non-dict value for feed_options, a ValueError is raised noting the problem.

Copy link
Copy Markdown
Member

@Bobspadger Bobspadger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all looks fine to me.

@GriceTurrble GriceTurrble merged commit 945a5a2 into develop Jun 26, 2020
Lacrymology added a commit to Shiphero/python-amazon-mws that referenced this pull request Jul 10, 2020
* upstream/develop:
  Add Feeds utility to convert dict FeedOptions to string (python-amazon-mws#181)
  Ensure correct decoding of bytes (python-amazon-mws#168)
  Compatibility fix (python-amazon-mws#124)
  Implement a couple of function for the OutboundShipments API. (python-amazon-mws#96)
  Added OutboundShipments.create_fulfillment_order (python-amazon-mws#95)
  added UpdateReportAcknowledgements (python-amazon-mws#101)
  Update feeds.py (python-amazon-mws#166)
  added easyship api support for indian marketplace (python-amazon-mws#169)
  Moving Slack link up, removing gitter chat link
  add all current marketplaces and alphabetize by country code (python-amazon-mws#155)
  Updated slack invite link
  Slack invite link (python-amazon-mws#152)
  Slack invite link
  fix clean_params (python-amazon-mws#106)
  add in NL marketplace information
  Fix flake8 warnings
  Update develop branch CI + package metadata
  include mws.apis in setup.py
  Fix bug: Remove trailing comma
@GriceTurrble GriceTurrble deleted the feature-feeds-accept-dict-options branch July 15, 2020 14:36
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants