Skip to content

Commit

Permalink
Release v0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
fern-api[bot] committed Jun 14, 2023
1 parent d4bcbaa commit 8e6bc30
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 49 deletions.
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

[tool.poetry]
name = "mercoa"
version = "v0.1.0"
version = "v0.1.1"
description = ""
authors = []
packages = [
Expand All @@ -10,10 +10,10 @@ packages = [

[tool.poetry.dependencies]
python = "^3.7"
httpx = "0.23.3"
backports-cached_property = "1.0.2"
pydantic = "^1.9.2"
types-backports = "0.1.3"
backports-cached_property = "1.0.2"
httpx = "0.23.3"

[tool.poetry.dev-dependencies]
mypy = "0.971"
Expand Down
4 changes: 2 additions & 2 deletions src/mercoa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
CommentRequest,
CommentResponse,
CounterpartyResponse,
CreateVendorRequest,
CurrencyCode,
CustomId,
CustomPaymentMethodRequest,
Expand Down Expand Up @@ -114,6 +113,7 @@
Responsibilities,
Rule,
Rule_Approver,
SetApprover,
TaxID,
TransactionId,
TransactionResponse,
Expand Down Expand Up @@ -176,7 +176,6 @@
"CommentRequest",
"CommentResponse",
"CounterpartyResponse",
"CreateVendorRequest",
"CurrencyCode",
"CustomId",
"CustomPaymentMethodRequest",
Expand Down Expand Up @@ -252,6 +251,7 @@
"Rule",
"Rule_Approver",
"SSN",
"SetApprover",
"TaxID",
"TransactionId",
"TransactionResponse",
Expand Down
4 changes: 2 additions & 2 deletions src/mercoa/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
CommentId,
CommentRequest,
CommentResponse,
CreateVendorRequest,
CurrencyCode,
DocumentResponse,
InvoiceId,
Expand All @@ -80,6 +79,7 @@
InvoiceRequest,
InvoiceResponse,
InvoiceStatus,
SetApprover,
)
from .ocr import Attachments, EmailOcrRequest, OcrMailbox, OCRResponse
from .organization import (
Expand Down Expand Up @@ -174,7 +174,6 @@
"CommentRequest",
"CommentResponse",
"CounterpartyResponse",
"CreateVendorRequest",
"CurrencyCode",
"CustomId",
"CustomPaymentMethodRequest",
Expand Down Expand Up @@ -249,6 +248,7 @@
"Rule",
"Rule_Approver",
"SSN",
"SetApprover",
"TaxID",
"TransactionId",
"TransactionResponse",
Expand Down
4 changes: 2 additions & 2 deletions src/mercoa/resources/invoice/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
CommentId,
CommentRequest,
CommentResponse,
CreateVendorRequest,
CurrencyCode,
DocumentResponse,
InvoiceId,
Expand All @@ -18,6 +17,7 @@
InvoiceRequest,
InvoiceResponse,
InvoiceStatus,
SetApprover,
)

__all__ = [
Expand All @@ -28,7 +28,6 @@
"CommentId",
"CommentRequest",
"CommentResponse",
"CreateVendorRequest",
"CurrencyCode",
"DocumentResponse",
"InvoiceId",
Expand All @@ -38,4 +37,5 @@
"InvoiceRequest",
"InvoiceResponse",
"InvoiceStatus",
"SetApprover",
]
16 changes: 8 additions & 8 deletions src/mercoa/resources/invoice/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def get_documents(self, invoice_id: InvoiceId) -> typing.List[DocumentResponse]:
return pydantic.parse_obj_as(typing.List[DocumentResponse], _response_json) # type: ignore
raise ApiError(status_code=_response.status_code, body=_response_json)

def approve(self, invoice_id: InvoiceId, *, request: ApprovalRequest) -> InvoiceResponse:
def approve(self, invoice_id: InvoiceId, *, request: ApprovalRequest) -> CommentResponse:
_response = httpx.request(
"POST",
urllib.parse.urljoin(f"{self._environment.value}/", f"invoice/{invoice_id}/approve"),
Expand All @@ -124,10 +124,10 @@ def approve(self, invoice_id: InvoiceId, *, request: ApprovalRequest) -> Invoice
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, body=_response.text)
if 200 <= _response.status_code < 300:
return pydantic.parse_obj_as(InvoiceResponse, _response_json) # type: ignore
return pydantic.parse_obj_as(CommentResponse, _response_json) # type: ignore
raise ApiError(status_code=_response.status_code, body=_response_json)

def reject(self, invoice_id: InvoiceId, *, request: ApprovalRequest) -> InvoiceResponse:
def reject(self, invoice_id: InvoiceId, *, request: ApprovalRequest) -> CommentResponse:
_response = httpx.request(
"POST",
urllib.parse.urljoin(f"{self._environment.value}/", f"invoice/{invoice_id}/reject"),
Expand All @@ -141,7 +141,7 @@ def reject(self, invoice_id: InvoiceId, *, request: ApprovalRequest) -> InvoiceR
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, body=_response.text)
if 200 <= _response.status_code < 300:
return pydantic.parse_obj_as(InvoiceResponse, _response_json) # type: ignore
return pydantic.parse_obj_as(CommentResponse, _response_json) # type: ignore
raise ApiError(status_code=_response.status_code, body=_response_json)

def get_comments(self, invoice_id: InvoiceId) -> typing.List[CommentResponse]:
Expand Down Expand Up @@ -337,7 +337,7 @@ async def get_documents(self, invoice_id: InvoiceId) -> typing.List[DocumentResp
return pydantic.parse_obj_as(typing.List[DocumentResponse], _response_json) # type: ignore
raise ApiError(status_code=_response.status_code, body=_response_json)

async def approve(self, invoice_id: InvoiceId, *, request: ApprovalRequest) -> InvoiceResponse:
async def approve(self, invoice_id: InvoiceId, *, request: ApprovalRequest) -> CommentResponse:
async with httpx.AsyncClient() as _client:
_response = await _client.request(
"POST",
Expand All @@ -352,10 +352,10 @@ async def approve(self, invoice_id: InvoiceId, *, request: ApprovalRequest) -> I
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, body=_response.text)
if 200 <= _response.status_code < 300:
return pydantic.parse_obj_as(InvoiceResponse, _response_json) # type: ignore
return pydantic.parse_obj_as(CommentResponse, _response_json) # type: ignore
raise ApiError(status_code=_response.status_code, body=_response_json)

async def reject(self, invoice_id: InvoiceId, *, request: ApprovalRequest) -> InvoiceResponse:
async def reject(self, invoice_id: InvoiceId, *, request: ApprovalRequest) -> CommentResponse:
async with httpx.AsyncClient() as _client:
_response = await _client.request(
"POST",
Expand All @@ -370,7 +370,7 @@ async def reject(self, invoice_id: InvoiceId, *, request: ApprovalRequest) -> In
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, body=_response.text)
if 200 <= _response.status_code < 300:
return pydantic.parse_obj_as(InvoiceResponse, _response_json) # type: ignore
return pydantic.parse_obj_as(CommentResponse, _response_json) # type: ignore
raise ApiError(status_code=_response.status_code, body=_response_json)

async def get_comments(self, invoice_id: InvoiceId) -> typing.List[CommentResponse]:
Expand Down
4 changes: 2 additions & 2 deletions src/mercoa/resources/invoice/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from .comment_id import CommentId
from .comment_request import CommentRequest
from .comment_response import CommentResponse
from .create_vendor_request import CreateVendorRequest
from .currency_code import CurrencyCode
from .document_response import DocumentResponse
from .invoice_id import InvoiceId
Expand All @@ -17,6 +16,7 @@
from .invoice_request import InvoiceRequest
from .invoice_response import InvoiceResponse
from .invoice_status import InvoiceStatus
from .set_approver import SetApprover

__all__ = [
"ApprovalRequest",
Expand All @@ -26,7 +26,6 @@
"CommentId",
"CommentRequest",
"CommentResponse",
"CreateVendorRequest",
"CurrencyCode",
"DocumentResponse",
"InvoiceId",
Expand All @@ -36,4 +35,5 @@
"InvoiceRequest",
"InvoiceResponse",
"InvoiceStatus",
"SetApprover",
]
10 changes: 3 additions & 7 deletions src/mercoa/resources/invoice/types/approver.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
import datetime as dt
import typing

import pydantic

from ....core.datetime_utils import serialize_datetime
from ...entity_users.types.entity_user_id import EntityUserId
from .approver_action import ApproverAction
from .set_approver import SetApprover


class Approver(pydantic.BaseModel):
user_id: EntityUserId = pydantic.Field(alias="userId")
date: dt.datetime
class Approver(SetApprover):
roles: typing.List[str]
action: ApproverAction

def json(self, **kwargs: typing.Any) -> str:
Expand All @@ -25,5 +22,4 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]:

class Config:
frozen = True
allow_population_by_field_name = True
json_encoders = {dt.datetime: serialize_datetime}
17 changes: 4 additions & 13 deletions src/mercoa/resources/invoice/types/invoice_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
from ...entity.types.entity_id import EntityId
from ...entity_users.types.entity_user_id import EntityUserId
from ...payment_method.types.payment_method_id import PaymentMethodId
from .create_vendor_request import CreateVendorRequest
from .currency_code import CurrencyCode
from .invoice_line_item_request import InvoiceLineItemRequest
from .invoice_status import InvoiceStatus
from .set_approver import SetApprover


class InvoiceRequest(pydantic.BaseModel):
Expand All @@ -35,20 +35,11 @@ class InvoiceRequest(pydantic.BaseModel):
service_end_date: typing.Optional[dt.datetime] = pydantic.Field(alias="serviceEndDate")
payer_id: typing.Optional[EntityId] = pydantic.Field(alias="payerId")
payment_source_id: typing.Optional[PaymentMethodId] = pydantic.Field(alias="paymentSourceId")
approvers: typing.Optional[typing.List[SetApprover]] = pydantic.Field(
description=("Set approvers for this invoice.\n")
)
vendor_id: typing.Optional[EntityId] = pydantic.Field(alias="vendorId")
payment_destination_id: typing.Optional[PaymentMethodId] = pydantic.Field(alias="paymentDestinationId")
create_vendor: typing.Optional[CreateVendorRequest] = pydantic.Field(
alias="createVendor",
description=(
"When paying to a new vendor, use the createVendor object. Mercoa will create the vendor entity and tie it to this invoice. This object is ignored when updating an invoice.\n"
),
)
update_vendor: typing.Optional[CreateVendorRequest] = pydantic.Field(
alias="updateVendor",
description=(
"When paying to an existing vendor with an incomplete profile, use the updateVendor object. Mercoa will update the vendor entity tied to this invoice. This object is ignored if the vendor already has already been created with complete information and when creating a new invoice.\n"
),
)
line_items: typing.Optional[typing.List[InvoiceLineItemRequest]] = pydantic.Field(alias="lineItems")
metadata: typing.Optional[typing.Dict[str, str]] = pydantic.Field(
description=(
Expand Down
2 changes: 2 additions & 0 deletions src/mercoa/resources/invoice/types/invoice_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pydantic

from ....core.datetime_utils import serialize_datetime
from ...entity.types.approval_policy_response import ApprovalPolicyResponse
from ...entity.types.entity_id import EntityId
from ...entity.types.entity_response import EntityResponse
from ...entity_users.types.entity_user_response import EntityUserResponse
Expand Down Expand Up @@ -53,6 +54,7 @@ class InvoiceResponse(pydantic.BaseModel):
transactions: typing.Optional[typing.List[TransactionResponse]]
line_items: typing.Optional[typing.List[InvoiceLineItemResponse]] = pydantic.Field(alias="lineItems")
approvers: typing.List[Approver]
approval_policy: typing.List[ApprovalPolicyResponse] = pydantic.Field(alias="approvalPolicy")
metadata: typing.Dict[str, str] = pydantic.Field(description=("Metadata associated with this invoice.\n"))
created_by: typing.Optional[EntityUserResponse] = pydantic.Field(
alias="createdBy", description=("Entity user who created this invoice.\n")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
import pydantic

from ....core.datetime_utils import serialize_datetime
from ...entity.types.entity_request import EntityRequest
from ...payment_method.types.payment_method_request import PaymentMethodRequest
from ...entity_users.types.entity_user_id import EntityUserId


class CreateVendorRequest(pydantic.BaseModel):
vendor: EntityRequest
payment_method: typing.Optional[PaymentMethodRequest] = pydantic.Field(alias="paymentMethod")
class SetApprover(pydantic.BaseModel):
user_id: EntityUserId = pydantic.Field(alias="userId")
date: dt.datetime

def json(self, **kwargs: typing.Any) -> str:
kwargs_with_defaults: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs}
Expand Down
9 changes: 4 additions & 5 deletions src/mercoa/resources/ocr/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from ...core.remove_none_from_headers import remove_none_from_headers
from ...environment import MercoaEnvironment
from ..organization.types.organization_id import OrganizationId
from .types.email_ocr_request import EmailOcrRequest
from .types.ocr_response import OCRResponse


Expand Down Expand Up @@ -40,12 +39,12 @@ def ocr(self, *, mime_type: str, image: str) -> OCRResponse:
return pydantic.parse_obj_as(OCRResponse, _response_json) # type: ignore
raise ApiError(status_code=_response.status_code, body=_response_json)

def email_inbox(self, *, org: OrganizationId, items: typing.List[EmailOcrRequest]) -> None:
def email_inbox(self, *, org: OrganizationId, request: typing.Any) -> None:
_response = httpx.request(
"POST",
urllib.parse.urljoin(f"{self._environment.value}/", "emailOcr"),
params={"org": org},
json=jsonable_encoder({"items": items}),
json=jsonable_encoder(request),
headers=remove_none_from_headers(
{"Authorization": f"Bearer {self._token}" if self._token is not None else None}
),
Expand Down Expand Up @@ -84,13 +83,13 @@ async def ocr(self, *, mime_type: str, image: str) -> OCRResponse:
return pydantic.parse_obj_as(OCRResponse, _response_json) # type: ignore
raise ApiError(status_code=_response.status_code, body=_response_json)

async def email_inbox(self, *, org: OrganizationId, items: typing.List[EmailOcrRequest]) -> None:
async def email_inbox(self, *, org: OrganizationId, request: typing.Any) -> None:
async with httpx.AsyncClient() as _client:
_response = await _client.request(
"POST",
urllib.parse.urljoin(f"{self._environment.value}/", "emailOcr"),
params={"org": org},
json=jsonable_encoder({"items": items}),
json=jsonable_encoder(request),
headers=remove_none_from_headers(
{"Authorization": f"Bearer {self._token}" if self._token is not None else None}
),
Expand Down

0 comments on commit 8e6bc30

Please sign in to comment.