Skip to content

Resources: Add all resources #6

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

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
717460d
feat(structure): add project base structure and initial placeholder f…
eletroswing May 6, 2024
2b79ff3
tests(structure): create test files
eletroswing May 6, 2024
4a2cbf8
fix(dir_name): woovi to openpix
eletroswing May 6, 2024
ce28679
fix(http): fix http client
eletroswing May 7, 2024
97355e7
add account resource
eletroswing May 7, 2024
2b85ac1
add resource
eletroswing May 7, 2024
7ce2fab
add charge_refund resource
eletroswing May 8, 2024
1b2fbe1
feat(resource): adding charge resource
eletroswing May 12, 2024
8b66555
feat(resource): transfer resource
eletroswing May 12, 2024
c99b756
feat(resource): customer resource
eletroswing May 29, 2024
1be051f
feat(resource): refund resource
eletroswing May 29, 2024
0652e88
fix(customer): adding docs for customer
eletroswing May 29, 2024
cec93f6
feat(resource): payment resource
eletroswing May 29, 2024
dd4de11
feat(resource): partner resource
eletroswing May 29, 2024
0735b23
fix(partner): adding doc to partner
eletroswing May 30, 2024
1ccb5a3
): adding doc to partner
eletroswing May 30, 2024
48c10ff
feat(resource): add pix_qr_code resource
eletroswing May 30, 2024
242462c
fix(small): small fixes and adding myself as an author
eletroswing May 30, 2024
e90dff2
feat(resource): add subscription resource
eletroswing May 30, 2024
c5daf9e
feat(resource): add transaction resource
eletroswing May 30, 2024
77e6e46
feat(pagination): add a pagination object
eletroswing May 30, 2024
364c2c5
feat(resource): webhook resource
eletroswing May 30, 2024
3572d35
feat(resource): subaccount resource
eletroswing May 30, 2024
b5ef161
fix(type): import type error
eletroswing May 30, 2024
fffeda6
fix(usable): already to use?
eletroswing May 30, 2024
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
8 changes: 8 additions & 0 deletions openpix/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""
Module: woovi/__init__.py
"""
from openpix.sdk import SDK as createClient

__all__ = (
'createClient',
)
8 changes: 8 additions & 0 deletions openpix/http/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""
Module: http/__init__.py
"""
from openpix.http.http_client import HttpClient

__all__ = (
'HttpClient',
)
105 changes: 105 additions & 0 deletions openpix/http/http_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import requests
from requests.adapters import HTTPAdapter
from urllib3.util import Retry
from urllib.parse import urlencode, urljoin

class HttpClient:
"""
Default implementation to call all REST API's
"""

def __init__(self, app_id):
self._app_id = app_id
self.base_url = "https://api.openpix.com.br"

def request(self, method, path, query, maxretries=None, data = None, **kwargs):
"""Makes a call to the API.

All **kwargs are passed verbatim to ``requests.request``.
"""
if(query):
query_string = urlencode({k: v for k, v in query.items() if v is not None})
url = urljoin(self.base_url + path, '?' + query_string)
else:
url = self.base_url + path

if(data):
data = {k: v for k, v in data.items() if v is not None}

headers = kwargs.get('headers', {})
headers['Authorization'] = self._app_id
kwargs['headers'] = headers

retry_strategy = Retry(
total=maxretries,
status_forcelist=[429, 500, 502, 503, 504]
)
http = requests.Session()
http.mount("https://", HTTPAdapter(max_retries=retry_strategy))

with http as session:
api_result = session.request(method, url, data=data,**kwargs)

response = api_result.json()
if api_result.status_code > 299:
raise ValueError(response)

return response

def get(self, path, query = None, params=None, timeout=None, maxretries=None):
"""Makes a GET request to the API"""
return self.request(
method="GET",
path=path,
query=query,
params=params,
timeout=timeout,
maxretries=maxretries,
)

def post(self, path, query = None, data=None, params=None, timeout=None, maxretries=None):
"""Makes a POST request to the API"""
return self.request(
method="POST",
path=path,
query=query,
data=data,
params=params,
timeout=timeout,
maxretries=maxretries,
)

def patch(self, path, query = None, data=None, params=None, timeout=None, maxretries=None):
"""Makes a PATCH request to the API"""
return self.request(
method="PATCH",
path=path,
query=query,
data=data,
params=params,
timeout=timeout,
maxretries=maxretries,
)

def put(self, path, query = None, data=None, params=None, timeout=None, maxretries=None):
"""Makes a PUT request to the API"""
return self.request(
method="PUT",
path=path,
query=query,
data=data,
params=params,
timeout=timeout,
maxretries=maxretries,
)

def delete(self, path, query = None, params=None, timeout=None, maxretries=None):
"""Makes a DELETE request to the API"""
return self.request(
method="DELETE",
path=path,
query=query,
params=params,
timeout=timeout,
maxretries=maxretries,
)
36 changes: 36 additions & 0 deletions openpix/resources/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""
Module: resources/__init__.py
"""
from openpix.http.http_client import HttpClient

from openpix.resources.account import Account
from openpix.resources.cashback_fidelity import CashbackFidelity
from openpix.resources.charge_refund import ChargeRefund
from openpix.resources.charge import Charge
from openpix.resources.customer import Customer
from openpix.resources.partner import Partner
from openpix.resources.payment import Payment
from openpix.resources.pix_qr_code import PixQrCode
from openpix.resources.refund import Refund
from openpix.resources.sub_account import SubAccount
from openpix.resources.subscription import Subscription
from openpix.resources.transactions import Transactions
from openpix.resources.transfer import Transfer
from openpix.resources.webhook import Webhook

__all__ = (
'Account',
'CashbackFidelity',
'ChargeRefund',
'Charge',
'Customer',
'Partner',
'Payment',
'PixQrCode',
'Refund',
'SubAccount',
'Subscription',
'Transactions',
'Transfer',
'Webhook'
)
41 changes: 41 additions & 0 deletions openpix/resources/account.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""
Module: account
"""
from openpix.http import HttpClient
import openpix.resources.account_types as account_types
from openpix.types import PagePayload

class Account:
"""
Access to Accounts

[Click here for more info](https://developers.woovi.com/api#tag/account) # pylint: disable=line-too-long
"""
def __init__(self, HttpClient: HttpClient):
self._client = HttpClient

"""Get one account.
Args:
accountId (str): the account unique identifier
[Click here for more info](https://developers.woovi.com/api#tag/account)
"""
def get(self, accountId: str) -> account_types.AccountInfo:
return self._client.get(path=f'/api/v1/account/{accountId}')

"""Get a list of accounts.
Args:
limit (int): number of content per page
skip (int): number of how many contents will be ignored
[Click here for more info](https://developers.woovi.com/api#tag/account/paths/~1api~1v1~1account~1/get)
"""
def list(self, page: PagePayload = PagePayload()) -> account_types.AccountList:
return self._client.get(path=f'/api/v1/account', query={"limit": page.limit, "skip": page.skip})

"""Make a withdraw.
Args:
accountId (str): the account unique identifier
value (int): the value for the withdraw
[Click here for more info](https://developers.woovi.com/api#tag/account/paths/~1api~1v1~1account~1%7BaccountId%7D~1withdraw/post)
"""
def withdraw(self, accountId: str, value: int) -> account_types.AccountWithdraw:
return self._client.post(path=f'/api/v1/account/{accountId}', data={value: value})
38 changes: 38 additions & 0 deletions openpix/resources/account_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from openpix.types import PageInfo
from typing import List

class BalanceInfo:
def __init__(self, total: int, blocked: int, available: int):
self.total = total
self.blocked = blocked
self.available = available

class AccountInfo:
def __init__(self, accountId: str, isDefault: bool, balance: BalanceInfo):
self.accountId = accountId
self.balance = balance
self.isDefault = isDefault

class TransactionInfo:
def __init__(self, endToEndId: str, value: int):
self.endToEndId = endToEndId
self.value = value

class WithdrawInfo:
def __init__(self, account: AccountInfo, transaction: TransactionInfo):
self.account = account
self.transaction = transaction

class AccountGet:
def __init__(self, account: AccountInfo):
self.account = account


class AccountList:
def __init__(self, pageInfo: PageInfo, accounts: List[AccountInfo]):
self.pageInfo = pageInfo
self.accounts = accounts

class AccountWithdraw:
def __init__(self, withdraw: WithdrawInfo):
self.withdraw = withdraw
31 changes: 31 additions & 0 deletions openpix/resources/cashback_fidelity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""
Module: cashback_fidelity
"""
from openpix.http import HttpClient
import openpix.resources.cashback_fidelity_types as cashback_fidelity_types

class CashbackFidelity:
"""
Access to CashbackFidelity

[Click here for more info](https://developers.woovi.com/api#tag/cashback-fidelity) # pylint: disable=line-too-long
"""
def __init__(self, HttpClient: HttpClient):
self._client = HttpClient

"""Get one fidelity.
Args:
taxID (str): the user's tax id document
[Click here for m ore info](https://developers.woovi.com/api#tag/cashback-fidelity/paths/~1api~1v1~1cashback-fidelity~1balance~1%7BtaxID%7D/get)
"""
def get(self, taxID: str) -> cashback_fidelity_types.CashbackGet:
return self._client.get(path=f'/api/v1/cashback-fidelity/balance/{taxID}')

"""Create one fidelity.
Args:
taxID (str): the user's tax id document
value (int): the fidelity value
[Click here for more info](https://developers.woovi.com/api#tag/cashback-fidelity/paths/~1api~1v1~1cashback-fidelity/post)
"""
def create(self, taxID: str, value: int) -> cashback_fidelity_types.CashbackCreate:
return self._client.post(path=f'/api/v1/cashback-fidelity', data={value: value, taxID: taxID})
13 changes: 13 additions & 0 deletions openpix/resources/cashback_fidelity_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class CashbackInfo:
def __init__(self, value: int):
self.value: value

class CashbackGet:
def __init__(self, balance: int, status: str):
self.balance = balance
self.status = status

class CashbackCreate:
def __init__(self, cashback: CashbackInfo, message: str):
self.cashback = cashback
self.message = message
Loading