Skip to content

Commit

Permalink
Merge pull request #12 from chmoder/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
chmoder authored Nov 4, 2022
2 parents 739d2f1 + 50d6f54 commit 4a00573
Show file tree
Hide file tree
Showing 27 changed files with 1,141 additions and 42 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@ pip install poetry
poetry install
```

## Build Docs
### Build Docs
```
poetry run sphinx-apidoc -f -o ./docs ../strike_api
cd docs && poetry run make clean && poetry run make html
cd docs
poetry run sphinx-apidoc -f -o . ../strike_api
poetry run make clean && poetry run make html
```

### Run Tests
```
poetry run pytest --record-mode=once
```
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "strike-api"
version = "0.1.4"
version = "0.1.5"
description = "A python client for the strike api"
authors = ["Thomas Cross <[email protected]>"]
readme = "README.md"
Expand Down
11 changes: 7 additions & 4 deletions strike_api/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@


def get_account(
account_id: typing.Optional[str],
handle: typing.Optional[str],
account_id: typing.Optional[str] = None,
handle: typing.Optional[str] = None,
) -> dict:
"""Fetch public account profile info by id or handle
Expand All @@ -18,9 +18,12 @@ def get_account(
"""

if account_id:
url = ""
if account_id and not handle:
url = f"https://api.strike.me/v1/accounts/{account_id}/profile"
if handle:
elif handle and not account_id:
url = f"https://api.strike.me/v1/accounts/handle/{handle}/profile"
else:
raise ValueError("use either account_id or handle")

return call_api("GET", url)
40 changes: 29 additions & 11 deletions strike_api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,33 @@
import requests


def set_default_headers(headers: typing.Optional[dict] = None) -> dict:
"""Sets the default headers for strike api HTTP requests
Args:
headers (typing.Optional[dict], optional): HTTP Headers. Defaults to None.
Returns:
dict: headers with default headers included
"""
strike_api_key = os.environ.get("STRIKE_API_KEY")
if not strike_api_key:
raise EnvironmentError("STRIKE_API_KEY not found in environment variables")

if not headers:
headers = {}

headers["Accept"] = "application/json"
headers["Authorization"] = f"Bearer {strike_api_key}"

return headers


def call_api(
method: str,
url: str,
headers: typing.Optional[dict] = None,
params: typing.Optional[typing.Union[dict, str]] = None,
data: typing.Optional[typing.Union[dict, str]] = None,
) -> typing.Union[typing.List[dict], dict]:
"""Generic method to interact with strike API endpoints
Expand All @@ -15,24 +38,19 @@ def call_api(
method (str): HTTP Method
url (str): Fully qualifed url to interact with a strike endpoint
headers (typing.Optional[dict], optional): HTTP Headers. Defaults to None.
data (typing.Optional[typing.Union[dict, str]], optional): Data to pass to Strike. Defaults to None.
params (typing.Optional[typing.Union[dict, str]], optional): params to pass to Strike as query string. Defaults to None.
data (typing.Optional[typing.Union[dict, str]], optional): Data to pass to Strike as body. Defaults to None.
Raises:
EnvironmentError: The Strike API key must be in env
Returns:
dict: response from api call
"""
strike_api_key = os.environ.get("STRIKE_API_KEY")
if not strike_api_key:
raise EnvironmentError("STRIKE_API_KEY not found in environment variables")

if not headers:
headers = {}

headers["Accept"] = "application/json"
headers["Authorization"] = f"Bearer {strike_api_key}"
headers = set_default_headers(headers)

response = requests.request(method, url, headers=headers, data=data)
response = requests.request(method, url, headers=headers, params=params, data=data)

return response.json()
if response.content:
return response.json()
14 changes: 7 additions & 7 deletions strike_api/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,29 @@ def get_event(
Returns:
dict: event schema
"""
url = "https://api.strike.me/v1/events/:eventId"
url = f"https://api.strike.me/v1/events/{event_id}"

return call_api("GET", url)


def get_events(
filter: str = None, orderby: str = None, skip: int = None, top: int = None
) -> typing.List[dict]:
filter_: str = None, orderby: str = None, skip: int = None, top: int = None
) -> dict:
"""Get Events
Required scopes: partner.webhooks.manage
OData filtering syntax can be seen `here <https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-odata/7d6c4117-317d-4860-915b-7e321be017e3>`_. Ordering syntax can be seen `here <https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-odata/793b1e83-95ee-4446-8434-f5b634f20d1e>`_.
Args:
filter (str, optional): Filter the results using OData syntax. Supported properties: created, eventType, deliverySuccess. Defaults to None.
filter_ (str, optional): Filter the results using OData syntax. Supported properties: created, eventType, deliverySuccess. Defaults to None.
orderby (str, optional): Order the results using OData syntax. Supported properties: created. Defaults to None.
skip (int, optional): Skip the specified number of entries. Defaults to None.
top (int, optional): Get the top X number of records. Default value: 50. Max value: 100. Defaults to None.
Returns:
typing.List[dict]: events
dict: events
"""
url = "https://api.strike.me/v1/events"

payload = {}
payload = {"filter": filter_, "orderby": orderby, "skip": skip, "top": top}

return call_api("GET", url, data=payload)
return call_api("GET", url, params=payload)
18 changes: 9 additions & 9 deletions strike_api/invoices.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@


def get_invoices(
filter: str = None, orderby: str = None, skip: int = None, top: int = None
) -> typing.List[dict]:
filter_: str = None, orderby: str = None, skip: int = None, top: int = None
) -> dict:
"""Get Invoices
Required scopes: partner.webhooks.manage
OData filtering syntax can be seen `here <https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-odata/7d6c4117-317d-4860-915b-7e321be017e3>`_. Ordering syntax can be seen `here <https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-odata/793b1e83-95ee-4446-8434-f5b634f20d1e>`_.
Args:
filter (str, optional): Filter the results using OData syntax. Supported properties: invoiceId, created, currency, state, issuerId, receiverId, payerId, correlationId. Defaults to None.
filter_ (str, optional): Filter the results using OData syntax. Supported properties: invoiceId, created, currency, state, issuerId, receiverId, payerId, correlationId. Defaults to None.
orderby (str, optional): Order the results using OData syntax. Supported properties: created. Defaults to None.
skip (int, optional): Skip the specified number of entries. Defaults to None.
top (int, optional): Get the top X number of records. Default value: 50. Max value: 100. Defaults to None.
Returns:
typing.List[dict]: invoices
dict: invoices
"""
url = "https://api.strike.me/v1/invoices"

payload = {}
payload = {"filter": filter_, "orderby": orderby, "skip": skip, "top": top}

return call_api("GET", url, data=payload)
return call_api("GET", url, params=payload)


def get_invoice(invoice_id: str) -> dict:
Expand Down Expand Up @@ -60,7 +60,7 @@ def issue_invoice(
amount (str, optional): Currency amount in decimal format. Defaults to None.
Returns:
dict: _description_
dict: invoice
"""
if handle:
url = f"https://api.strike.me/v1/invoices/handle/{handle}"
Expand All @@ -87,7 +87,7 @@ def issue_quote(invoice_id: str) -> dict:
invoice_id (str): Id of invoice for which the quote is requested
Returns:
dict: invoice
dict: quote
"""
url = f"https://api.strike.me/v1/invoices/{invoice_id}/quote"

Expand All @@ -103,7 +103,7 @@ def cancel_invoice(invoice_id: str) -> dict:
invoice_id (str): Id of invoice for which the cancellation is requested
Returns:
dict: schema
dict: invoice
"""
url = f"https://api.strike.me/v1/invoices/{invoice_id}/cancel"

Expand Down
53 changes: 53 additions & 0 deletions tests/cassettes/test_accounts/test_get_account_by_handle.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
interactions:
- request:
body: null
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- python-requests/2.28.1
method: GET
uri: https://api.strike.me/v1/accounts/handle/chmoder/profile
response:
body:
string: !!binary |
H4sIAAAAAAAAA4TMMWvDMBCG4f9ys2TX2FZtQShtsnRtm6lkOMsnW1SRjCQbSvB/L2lIIFDoeN97
PCcY0fWWQIIaj76nAAxwwYRhHyxIGFOaoszzmIL5In5JMYvJBxwoG7wfLOFkYqb8Me/1oxBCPfBS
dJpXhD3vqG+5RtJt0TS6FV02ueFpIEcBk/FuUwhRVHVdV0XVtGVdAgOF7o0UmYVApjATAzWHQE4Z
iiA/T9fzGyS8fGyBgYk70jjbtL0VjTbSuTwvaCx29oaZ+OoWbxRdxt/Hld2p+/fd3+pV+A89j+th
/QEAAP//AwDeIof1YAEAAA==
headers:
CF-Cache-Status:
- DYNAMIC
CF-RAY:
- 764f6aeac9776293-ORD
Connection:
- keep-alive
Content-Encoding:
- gzip
Content-Type:
- application/json; charset=utf-8
Date:
- Fri, 04 Nov 2022 18:29:52 GMT
Server:
- cloudflare
Set-Cookie:
- __cf_bm=7GqT5wMBvJIiMj3rDFQ90P0.ys2zFIqu.I4e.CM_n0U-1667586592-0-AT5/vY2q81+2h9LWtvq39Z6Npncf3bRAQNLNUqcR6DOWyPa638v9faS1PYDId71+M9bON9jyiSNRF9OwiL46bJI=;
path=/; expires=Fri, 04-Nov-22 18:59:52 GMT; domain=.strike.me; HttpOnly;
Secure; SameSite=None
Strict-Transport-Security:
- max-age=300; includeSubDomains
Transfer-Encoding:
- chunked
Via:
- 1.1 google
X-Content-Type-Options:
- nosniff
status:
code: 200
message: OK
version: 1
51 changes: 51 additions & 0 deletions tests/cassettes/test_accounts/test_get_account_by_id.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
interactions:
- request:
body: null
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- python-requests/2.28.1
method: GET
uri: https://api.strike.me/v1/accounts/953680ce-2149-4ce2-a5e3-82bb9a57be41/profile
response:
body:
string: !!binary |
H4sIAAAAAAAAAyTIwQqCQBAG4FeR/7zEEgYxZxMDc0P0LMPu1CkXnNmT+O4Rfcdvh20c5Z5A8N2j
n26hvzy79kr+7wyHxMagHWpsRUG1rx1iTgLCEKalDfPQwOEjqvz+7SiayxalWrNVr1zWdMJxfAEA
AP//AwDzsjQ3bQAAAA==
headers:
CF-Cache-Status:
- DYNAMIC
CF-RAY:
- 7649af249a312ab6-ORD
Connection:
- keep-alive
Content-Encoding:
- gzip
Content-Type:
- application/json
Date:
- Fri, 04 Nov 2022 01:47:52 GMT
Server:
- cloudflare
Set-Cookie:
- __cf_bm=FsHZNADblvBrXGC6qw_93zIq9W9ONZYlHIZ8JnYQJ1w-1667526472-0-AVYFQmS8/4h4gkseObjHZtKnujUjLl+bhsgvC5LkaTESA5MZk+gOBpeFtnP0CQ0tIm/8tyVlbcuJGZiR/QHtqJo=;
path=/; expires=Fri, 04-Nov-22 02:17:52 GMT; domain=.strike.me; HttpOnly;
Secure; SameSite=None
Strict-Transport-Security:
- max-age=300; includeSubDomains
Transfer-Encoding:
- chunked
Via:
- 1.1 google
X-Content-Type-Options:
- nosniff
status:
code: 404
message: Not Found
version: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
interactions:
- request:
body: null
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- python-requests/2.28.1
method: GET
uri: https://api.strike.me/v1/accounts/953680ce-2149-4ce2-a5e3-82bb9a57be41/profile
response:
body:
string: !!binary |
H4sIAAAAAAAAAyTIsQrCMBAG4Fcp/xxKhghys0qFtqGlznIkp5MN9C5T6buL+I3fDts4yT2D4Luh
X66xP03zuSP/F+CQ2Ri0Q42tKij44JBKFhDGuDxv8TFe4PARVX7/dhYtdUvSrMWaV6lrbnEcXwAA
AP//AwByTZfpbQAAAA==
headers:
CF-Cache-Status:
- DYNAMIC
CF-RAY:
- 764f6ae81aa52c13-ORD
Connection:
- keep-alive
Content-Encoding:
- gzip
Content-Type:
- application/json
Date:
- Fri, 04 Nov 2022 18:29:52 GMT
Server:
- cloudflare
Set-Cookie:
- __cf_bm=qQpE7XjMACr7I6GusAWp5XtVq8mB6kNJ5Nzj4xQQEo8-1667586592-0-ARIjG1UtDEpOsujFpu0K3buCCa4SAMsHGJEnw1rkx+9Jv0OAUJIyvaZ5ZQqPsiMXpcd2JyZpgdsudWm67Fpnc1E=;
path=/; expires=Fri, 04-Nov-22 18:59:52 GMT; domain=.strike.me; HttpOnly;
Secure; SameSite=None
Strict-Transport-Security:
- max-age=300; includeSubDomains
Transfer-Encoding:
- chunked
Via:
- 1.1 google
X-Content-Type-Options:
- nosniff
status:
code: 404
message: Not Found
version: 1
Loading

0 comments on commit 4a00573

Please sign in to comment.