Skip to content

Commit

Permalink
Merge pull request #4 from beckf/ls-new-api
Browse files Browse the repository at this point in the history
updated for api v3
  • Loading branch information
beckf authored Nov 30, 2022
2 parents 9a382f7 + e04129a commit 5fb0db5
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 88 deletions.
Binary file added .DS_Store
Binary file not shown.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Lightspeed HQ API Python Library
**Updated for Lightspeed API V3**

Gives easy access to the Lightspeed retail point of sale api.

To use create a new object with settings in a dictionary. Then just specify
the endpoints and paramaters in your request.
the endpoints and parameters in your request.

For API documentation see: https://developers.lightspeedhq.com/retail/introduction/introduction/

Expand Down
Binary file modified dist/lightspeed_api-0.1.tar.gz
Binary file not shown.
Binary file added dist/lightspeed_api-0.3.tar.gz
Binary file not shown.
139 changes: 72 additions & 67 deletions lightspeed_api.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,77 +1,12 @@
Metadata-Version: 2.1
Name: lightspeed-api
Version: 0.1
Version: 0.3
Summary: Simple library for interacting with the Lightspeed HQ API
Home-page: https://github.com/beckf/lightspeed_api
Author: Forrest Beck
Author-email: [email protected]
License: MIT License
Download-URL: https://github.com/beckf/lightspeed_api/archive/v.01.tar.gz
Description: # Lightspeed HQ API Python Library
Gives easy access to the Lightspeed retail point of sale api.

To use create a new object with settings in a dictionary. Then just specify
the endpoints and paramaters in your request.

For API documentation see: https://developers.lightspeedhq.com/retail/introduction/introduction/

Some examples of uses:

```python
# Create a new dictionary with some settings that we will need.
import lightspeed_api

c = {'account_id': '12345678',
'client_id': 'developer_client_id',
'client_secret': 'developer_client_secret',
'refresh_token': 'special_refresh_token'
}

ls = lightspeed_api.Lightspeed(c)

# Get a customer record
ls.get('Customer/1234')

# Delete a customer by id number
ls.delete('Customer/1234')

# Create a new customer
formatted = {'Customer':
{'firstName': 'Joe',
'lastName': 'Smith',
'companyRegistrationNumber': '1234',
'customerTypeID': 1,
'Contact': {
'custom': '',
'noEmail': 'false',
'noPhone': 'false',
'noMail': 'false',
'Emails': {
'ContactEmail': {
'address': '[email protected]',
'useType': 'Primary'
}
},
'Addresses': {
'ContactAddress': {
'address1': '1212 Street Drive',
'address2': '',
'city': 'New York',
'state': 'New York',
'zip': '12345',
'country': 'USA',
'countryCode': '',
'stateCode': ''
}
}
},
}
}
ls.create("Customer", formatted["Customer"])



```
Download-URL: https://github.com/beckf/lightspeed_api/archive/v.03.tar.gz
Keywords: Lightspeed,HQ,API,POS
Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Expand All @@ -83,4 +18,74 @@ Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.10
Description-Content-Type: text/markdown

# Lightspeed HQ API Python Library
**Updated for Lightspeed API V3**

Gives easy access to the Lightspeed retail point of sale api.

To use create a new object with settings in a dictionary. Then just specify
the endpoints and parameters in your request.

For API documentation see: https://developers.lightspeedhq.com/retail/introduction/introduction/

Some examples of uses:

```python
# Create a new dictionary with some settings that we will need.
import lightspeed_api

c = {'account_id': '12345678',
'client_id': 'developer_client_id',
'client_secret': 'developer_client_secret',
'refresh_token': 'special_refresh_token'
}

ls = lightspeed_api.Lightspeed(c)

# Get a customer record
ls.get('Customer/1234')

# Delete a customer by id number
ls.delete('Customer/1234')

# Create a new customer
formatted = {'Customer':
{'firstName': 'Joe',
'lastName': 'Smith',
'companyRegistrationNumber': '1234',
'customerTypeID': 1,
'Contact': {
'custom': '',
'noEmail': 'false',
'noPhone': 'false',
'noMail': 'false',
'Emails': {
'ContactEmail': {
'address': '[email protected]',
'useType': 'Primary'
}
},
'Addresses': {
'ContactAddress': {
'address1': '1212 Street Drive',
'address2': '',
'city': 'New York',
'state': 'New York',
'zip': '12345',
'country': 'USA',
'countryCode': '',
'stateCode': ''
}
}
},
}
}
ls.create("Customer", formatted["Customer"])



```

Binary file not shown.
30 changes: 13 additions & 17 deletions lightspeed_api/lightspeed_api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import requests
import datetime
import math
import json
import time
from urllib import parse
Expand All @@ -19,7 +18,7 @@ def __init__(self, config):

self.token_url = "https://cloud.lightspeedapp.com/oauth/access_token.php"
if "account_id" in config:
self.api_url = "https://api.lightspeedapp.com/API/Account/" + config["account_id"] + "/"
self.api_url = "https://api.lightspeedapp.com/API/V3/Account/" + config["account_id"] + "/"
else:
self.api_url = ""
# Initialize token as expired.
Expand Down Expand Up @@ -167,21 +166,18 @@ def get(self, source, parameters=None):

r = self.request_bucket("get", url)

if int(r['@attributes']['count']) >= 100:
page_count = math.ceil(int(r['@attributes']['count']) / 100)
page = 1
offset = 0
while page <= page_count:
if page > 1:
offset += 100
p = self.request_bucket("get", url + "&offset=" + str(offset))

# Append new data to original request
for i in p:
if type(p[i]) == list:
r[i].extend(p[i])

page += 1
if r['@attributes']['next']:
next_page = r['@attributes']['next']
while True:
p = self.request_bucket("get", next_page)
next_page = p['@attributes']['next']
# Append new data to original request
for i in p:
if type(p[i]) == list:
r[i].extend(p[i])

if not next_page:
break
return r

def create(self, source, data, parameters=None):
Expand Down
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
setup(
name='lightspeed_api',
packages=['lightspeed_api'],
version='0.1',
version='0.3',
description='Simple library for interacting with the Lightspeed HQ API',
long_description=long_description,
long_description_content_type='text/markdown',
license='MIT License',
author='Forrest Beck',
author_email='[email protected]',
url='https://github.com/beckf/lightspeed_api',
download_url='https://github.com/beckf/lightspeed_api/archive/v.01.tar.gz',
download_url='https://github.com/beckf/lightspeed_api/archive/v.03.tar.gz',
keywords=['Lightspeed', 'HQ','API', 'POS'],
install_requires=['requests'],
classifiers=[
Expand All @@ -29,6 +29,7 @@
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7'
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.10'
],
)

0 comments on commit 5fb0db5

Please sign in to comment.