Repository navigation
Update clients and add product endpoint support - #13
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the first API operation,
product(GET /api/product), on both clients, and adds the error handling and test setup the remaining endpoints will build on.Clients (
PriceCharting,AsyncPriceCharting)product(id=None, upc=None, q=None)returns aProductResponse. It needs exactly one ofid,upc, orq. If it gets none, or more than one, it raisesParameterErrorand sends no request, so a bad call doesn't count against the rate limit.base_url(defaulthttps://www.pricecharting.com) andtransportconstructor parameters, in the same order ashttpx2, so the clients can point at a mock server or usehttpx2.MockTransportin tests.Errors (
error.py)PriceChartingErroris the base class for all library errors.ParameterError(also aValueError) is raised for invalid method arguments.APIErroris raised for API error responses. It carriesmessageandstatus_code.Response parsing (
responses.py)_parse(response, model)raisesAPIErrorif the body isn't JSON, the status code isn't 2xx, or the body saysstatus: error. Otherwise it validates the JSON into the given model. It doesn't callraise_for_status(), because that error message would include the token in the URL.Package exports
typesenums can all be imported frompypricecharting, e.g.from pypricecharting import APIError, ProductResponse.Docs and metadata
docs/index.mdhas new sections: getting a product, errors, client options (base_url/transport), and imports.docs/api/errors.md).Tests
producttests for both clients run against a mock transport. They cover each lookup parameter, the API error case, and the parameter validation cases.transportandbase_urlconstructor parameters,APIError,_parse, and the package exports.tests/test_init.pyfails if a public class inmodels,requests,responses, ortypesisn't exported.tests/mocks/mock_pricecharting.py.Type of Change
feature: new endpoint and new public API (errors, constructor parameters, package exports).Checklist
just lintpassesjust testpasses (170 tests, 100% coverage)README.md,docs/,CLAUDE.md)