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

lint with yapf and isort #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions pychargifysimple/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ def __init__(self, api_key, subdomain):
self.api_key = api_key
self.subdomain = subdomain
self.url = '{subdomain}.{host}'.format(
subdomain=self.subdomain, host=self.host)
subdomain=self.subdomain, host=self.host
)

def _call_api(self, path, method, params=None, data=None):
request = getattr(requests, method)
url = 'https://{url}/{path}'.format(url=self.url, path=path)
extra_parameters = {
'auth': (self.api_key, 'x')
}
extra_parameters = {'auth': (self.api_key, 'x')}

if data:
extra_parameters['json'] = data
Expand Down
3 changes: 2 additions & 1 deletion pychargifysimple/context_manager.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# -*- coding: utf-8 -*-
from contextlib import contextmanager

import mechanicalsoup
from fake_useragent import UserAgent

import mechanicalsoup
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't must add a line break between fake_useragent and mechanicalsoup import.

Copy link
Author

Choose a reason for hiding this comment

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

IMHO and from isort point of view module import import <module> should be separate from sub-module import from <module> import <sub-module> by a line break, that's why this line break is added



@contextmanager
def login(user, password):
Expand Down
25 changes: 14 additions & 11 deletions pychargifysimple/subscription.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from pychargifysimple.base import Chargify
from .base import Chargify


class ChargifySubscription(Chargify):
Expand Down Expand Up @@ -41,8 +41,12 @@ def get_subscription(self, subscription):
@return: The subscription detail
@rtype : dict
"""
return self._call_api('{base}/{subscription}.json'.format(
base=self.base, subscription=subscription), method='get').json()
return self._call_api(
'{base}/{subscription}.json'.format(
base=self.base, subscription=subscription
),
method='get'
).json()

def change_next_billing_at(self, subscription, next_billing_at):
"""To change the next billing date of a subscription.
Expand All @@ -57,7 +61,8 @@ def change_next_billing_at(self, subscription, next_billing_at):
@rtype : dict
"""
url = '{base}/{subscription}.json'.format(
base=self.base, subscription=subscription)
base=self.base, subscription=subscription
)
data = {
'subscription': {
'next_billing_at': next_billing_at.isoformat()
Expand All @@ -79,12 +84,9 @@ def change_expires_at(self, subscription, expires_at):
@rtype : dict
"""
url = '{base}/{subscription}.json'.format(
base=self.base, subscription=subscription)
data = {
'subscription': {
'expires_at': expires_at.isoformat()
}
}
base=self.base, subscription=subscription
)
data = {'subscription': {'expires_at': expires_at.isoformat()}}

return self._call_api(url, 'put', data=data).json()

Expand All @@ -101,7 +103,8 @@ def delete_subscription(self, subscription, customer):
@rtype : dict
"""
url = '{base}/{subscription}/purge.json'.format(
base=self.base, subscription=subscription, customer=customer)
base=self.base, subscription=subscription, customer=customer
)
data = {'ack': customer}

return self._call_api(url, 'post', params=data).json()
13 changes: 8 additions & 5 deletions pychargifysimple/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
"""A module to manage the web part of chargify like delete subscription."""
import logging

from mechanicalsoup.browser import LinkNotFoundError

from pychargifysimple.context_manager import login
from .context_manager import login

from mechanicalsoup.browser import LinkNotFoundError

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -42,14 +41,18 @@ def delete_subscription(self, subscription):
with login(self.user, self.password) as browser:
browser.open(
'{url}/subscriptions/{subscription}/delete'.format(
url=self.url, subscription=subscription))
url=self.url, subscription=subscription
)
)

try:
browser.select_form('#delete_subscription_form')
except LinkNotFoundError:
logger.error(
'The subscription {subscription} not found'.format(
subscription=subscription))
subscription=subscription
)
)
return

browser.submit_selected()
9 changes: 3 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# http://www.opensource.org/licenses/MIT-license
# Copyright (c) 2015, Hobbestigrou <[email protected]>

from setuptools import setup, find_packages
from setuptools import find_packages, setup

setup(
name='pychargifysimple',
Expand All @@ -35,11 +35,8 @@
],
packages=find_packages(),
include_package_data=False,
install_requires=[
'MechanicalSoup', 'fake-useragent'
],
install_requires=['MechanicalSoup', 'fake-useragent'],
entry_points={
'console_scripts': [
],
'console_scripts': [],
},
)