Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better way of handling the authorization tokens #16

Closed
bstoilov opened this issue Oct 8, 2019 · 1 comment
Closed

Better way of handling the authorization tokens #16

bstoilov opened this issue Oct 8, 2019 · 1 comment
Labels
enhancement New feature or request

Comments

@bstoilov
Copy link
Owner

bstoilov commented Oct 8, 2019

Currently a registry is used to store the cookies and some headers.

This is hard to read and maintain.

A much simpler solution is to keep cookies in file and read them like plain string.

    def _load_headers(self):
        cookies = self.registry.get(Registry.Key.COOKIES)
        csrftoken = ''
        cookie_str = ''
        for c in cookies:
            if c.name == 'csrftoken':
                csrftoken = c.value
            cookie_str += c.name + '=' + c.value + '; '
        cookie_str = cookie_str.strip()

        headers = {
            'cookie': cookie_str,
            'x-csrftoken': csrftoken,
            'user-agent': AGENT_STRING
        }

        return headers

this is all the data we need to make requests

After this change all requests can be simplified to the following structure

        options = {
        }

        data_obj = {
            'options': options,
            'context': {}
        }

        data = {
            'source_url': '/pin/{}/'.format(pin_id),
            'data': json.dumps(data_obj)
        }

        headers = self._load_headers()
        return requests.post(url=url, headers=headers, data=data)
@bstoilov bstoilov added the enhancement New feature or request label Oct 8, 2019
@bstoilov
Copy link
Owner Author

This is addressed in this PR:

#20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant