Skip to content
This repository was archived by the owner on May 2, 2019. It is now read-only.
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
33 changes: 32 additions & 1 deletion moltin/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from . url import sanitize_url_fragment
from . exception import *

import sys

class BaseEndpoint(object):

Expand Down Expand Up @@ -89,3 +89,34 @@ def __init__(self, request, endpoint):

def payment(self, method, order_id, params):
return self.request.post(self._url_with("payment", method, order_id), params)


class EntryEndpoint(BaseEndpoint):

def __init__(self, request, endpoint, flow_slug = None):
super(EntryEndpoint, self).__init__(request, endpoint)
self.id = flow_slug
self.endpoint = self._url_with(flow_slug)

def list(self):
return self.request.get(self._url_with("entries"))

def find_by(self, params):
try:
return self.request.get(self._url_with("entries"), payload=params)
except RequestError: # If we can't find the resource
return None

def create_entry(self, params):
return self.request.post(self._url_with("entries"), params)

def update_entry(self, entry_id, params):
return self.request.put(
self._url_with("entries", entry_id), params)

def get_entry(self, entry_id):
return self.request.get(self._url_with("entries", entry_id))

def delete_entry(self, entry_id):
return self.request.delete(self._url_with("entries", entry_id))

3 changes: 2 additions & 1 deletion moltin/moltin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .authenticator import Authenticator
from .request import Request
from .token import TokenContainer, TokenFactory
from .endpoints import Endpoint, CartEndpoint, CheckoutEndpoint
from .endpoints import Endpoint, CartEndpoint, EntryEndpoint, CheckoutEndpoint
from .curry import curry

def create_endpoint_object(name, inherits_from):
Expand Down Expand Up @@ -60,6 +60,7 @@ class Moltin:

custom_endpoints = {
"Cart": (CartEndpoint, "carts"),
"Entry": (EntryEndpoint, "flows"),
}

custom_endpoints_without_extra_params = {
Expand Down
2 changes: 1 addition & 1 deletion moltin/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def get(self, url, payload=None):
return with_error_handling(requests.get,
self.make_url(url),
headers=self.headers,
data=payload)
params=payload)

def post(self, trailing_uri, payload, auth=False):
if auth:
Expand Down