Code Monkey home page Code Monkey logo

Comments (2)

ronniehicks avatar ronniehicks commented on July 22, 2024

I believe it is. It's not very well documented, and I had to dig into the implementation to find it, but since this library uses the requests library, and aiohttp for async, behind the scenes you should be able to create a custom auth handler for requests (example shown here) and pass that as a keyword arg to your http methods. Here's my 22:30 guess at what that might look like. I'll be working on a problem similar to this in the morning so will update once I get that working.

from requests.auth import AuthBase

class SignatureAuth(AuthBase):
    def __init__(self, adp_token, private_key):
        self.adp_token = adp_token
        self.private_key = private_key

    def __call__(self, r):
        r.headers.update(self.sign_request(r.url, r.method, r.body, self.adp_token, self.private_key))
        return r

# some predefined resource, SignedResource
signature_auth = SignatureAuth(adp_token, private_key)

test_api = API(api_root_url="https://test.com")
test_api.add_resource(resource_name="test", resource_class=SignedResource)
test_api.retrieve(queryParam, auth=signature_auth)

from python-simple-rest-client.

mkb79 avatar mkb79 commented on July 22, 2024

Hi. Thank you very much.

My solution looks like similar to yours. I have create a class who inherits from requests.auth.AuthBase.

Next I create a own Resource class who inherits from simple_rest_client.resource.Resource.

class UserResource(Resource):
    actions = {
        'library': {'method': 'GET', 'url': "0.0/library/books"},
        'retrieve_wishlist': {'method': 'GET', 'url': '1.0/wishlist'},
        'add_to_wishlist': {'method': 'POST', 'url': '1.0/wishlist'},
        'remove_from_wishlist': {'method': 'DELETE', 'url': '1.0/wishlist/{}'}, 
}

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.session.auth = PrivateKeyAuth(adp_token, private_key)


default_header = {
        "Accept": 'application/json',
        'Content-Type': 'application/json'
    } 


# create api instance
audible_api = API(
    api_root_url='https://api.audible.de', headers=default_header,
    json_encode_body=True
)
# add events resource with EventResource
audible_api.add_resource(resource_name='user', resource_class=UserResource)
# show resource actions

params = {'response_groups': 'product_desc'}
response = audible_api.user.retrieve_wishlist(params=params)

from python-simple-rest-client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.