The 3.x.x
and 4.x.x
releases are a full rewrite based on our API schema docs
Here we have "before and after" of how a few API calls looked like with our v2 version, and how they can be written using the new library.
from tremendous import Tremendous
client = Tremendous("[SANDBOX_ACCESS_TOKEN]", "https://testflight.tremendous.com/api/v2")
from tremendous import Configuration, ApiClient, TremendousApi
configuration = Configuration(server_index=Configuration.Environment["testflight"], access_token="[SANDBOX_ACCESS_TOKEN]")
api = ApiClient(configuration)
client = TremendousApi(api)
order_data = {
"external_id": external_id,
"payment": {
"funding_source_id": funding_source_id,
},
"reward": {
"value": {
"denomination": 20,
"currency_code": "USD"
},
"campaign_id": campaign_id,
"delivery": {
"method": "EMAIL",
},
"recipient": {
"email": "[email protected]",
"name": "Sam Stevens"
}
}
}
order = client.orders.create(order_data)
from tremendous import CreateOrderRequest, SingleRewardOrder
request = CreateOrderRequest(
SingleRewardOrder(
payment = {
"funding_source_id": "balance"
},
reward = {
"value": {
"denomination": 20,
"currency_code": "USD"
},
"campaign_id": campaign_id,
"delivery": {
"method": "EMAIL",
},
"recipient": {
"email": "[email protected]",
"name": "Sam Stevens"
}
}
)
)
response = client.create_order(request)
response.order.id # => "the order id"
order = client.orders.show("[ORDER_ID]")
print("Order was created at %s" % order.created_at)
order = client.get_order("[ORDER_ID]").order
print("Order was created at %s" % order.created_at)
funding_sources = client.funding_sources.list
for funding_source in funding_sources:
print("* %s => %s" % (funding_source.method, funding_source.id))
funding_sources = client.list_funding_sources().funding_sources
for funding_source in funding_sources:
print("* %s => %s" % (funding_source.method, funding_source.id))
On v2
, failed requests would always raise ValueError
with the response body
from tremendous import Tremendous
client = Tremendous("INVALID_TOKEN", "https://testflight.tremendous.com/api/v2")
try:
client.products.list()
except ValueError as error:
print("API request failed! %s" % error)
On v2
, all errors raised by the lib are subclasses of Tremendous.ApiException
from tremendous import Configuration, ApiClient, TremendousApi, ApiException
configuration = Configuration(access_token="INVALID_TOKEN")
api = ApiClient(configuration)
client = TremendousApi(api)
try:
client.list_orders()
except ApiException as error:
print("API request failed! Status: %s, Reason: %s" % (error.status, error.reason))