Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: continuous-integration

on:
pull_request:
branches: [master]
push:
branches: [master]

jobs:
tests:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
python-version: [3.7, 3.8, 3.9]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install Python dependencies
uses: py-actions/py-dependency-install@v3
- name: Run Tests
run: nosetests -a '!broken'
33 changes: 33 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Publish Python 🐍 distributions 📦 to PyPI and TestPyPI

on:
release:
types: [released]

jobs:
build-n-publish:
name: Build and publish Python 🐍 distributions 📦 to PyPI and TestPyPI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x"
- name: Install pypa/build
run: >-
python -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: >-
python -m
build
--sdist
--wheel
--outdir dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
5 changes: 0 additions & 5 deletions .travis.yml

This file was deleted.

27 changes: 25 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Bigcommerce API Python Client
Wrapper over the ``requests`` library for communicating with the Bigcommerce v2 API.

Install with ``pip install bigcommerce`` or ``easy_install bigcommerce``. Tested with
python 3.8, and only requires ``requests`` and ``pyjwt``.
python 3.7-3.9, and only requires ``requests`` and ``pyjwt``.

Usage
-----
Expand Down Expand Up @@ -116,7 +116,30 @@ it can be used to access V3 APIs using the OAuthConnection object:
api_path='/stores/{}/v3/{}')
v3client.get('/catalog/products', include_fields='name,sku', limit=5, page=1)

Managing OAuth Rate Limits
Accessing GraphQL Admin API
~~~~~~~~~~~~~~~~~~~~~~~~~~~
There is a basic GraphQL client which allows you to submit GraphQL queries to the GraphQL Admin API.

::

gql = bigcommerce.connection.GraphQLConnection(
client_id=client_id,
store_hash=store_hash,
access_token=access_token
)
# Make a basic query
time_query_result = gql.query("""
query {
system {
time
}
}
""")
# Fetch the schema
schema = gql.introspection_query()


Managing Rate Limits
~~~~~~~~~~~~~~~~~~~~~~~~~~

You can optionally pass a ``rate_limiting_management`` object into ``bigcommerce.api.BigcommerceApi`` or ``bigcommerce.connection.OAuthConnection`` for automatic rate limiting management, ex:
Expand Down
119 changes: 118 additions & 1 deletion bigcommerce/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def verify_payload_jwt(signed_payload, client_secret, client_id):
"""
return jwt.decode(signed_payload,
client_secret,
algorithms=["HS256"],
algorithms=["HS256", "HS512"],
audience=client_id,
options={
'verify_iss': False
Expand Down Expand Up @@ -287,3 +287,120 @@ def _handle_response(self, url, res, suppress_empty=True):
callback()

return result


class GraphQLConnection(OAuthConnection):
def __init__(self, client_id, store_hash, access_token=None, host='api.bigcommerce.com',
api_path='/stores/{}/graphql', rate_limiting_management=None):
self.client_id = client_id
self.store_hash = store_hash
self.host = host
self.api_path = api_path
self.graphql_path = "https://" + self.host + self.api_path.format(self.store_hash)
self.timeout = 7.0 # can attach to session?
self.rate_limiting_management = rate_limiting_management

self._session = requests.Session()
self._session.headers = {"Accept": "application/json",
"Accept-Encoding": "gzip"}
if access_token and store_hash:
self._session.headers.update(self._oauth_headers(client_id, access_token))

self._last_response = None # for debugging

self.rate_limit = {}

def query(self, query, variables={}):
return self.post(self.graphql_path, dict(query=query, variables=variables))

def introspection_query(self):
return self.query("""
fragment FullType on __Type {
kind
name
fields(includeDeprecated: true) {
name
args {
...InputValue
}
type {
...TypeRef
}
isDeprecated
deprecationReason
}
inputFields {
...InputValue
}
interfaces {
...TypeRef
}
enumValues(includeDeprecated: true) {
name
isDeprecated
deprecationReason
}
possibleTypes {
...TypeRef
}
}
fragment InputValue on __InputValue {
name
type {
...TypeRef
}
defaultValue
}
fragment TypeRef on __Type {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
}
}
}
}
}
}
}
}
query IntrospectionQuery {
__schema {
queryType {
name
}
mutationType {
name
}
types {
...FullType
}
directives {
name
locations
args {
...InputValue
}
}
}
}
""")
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ coverage==5.5
mock==4.0.3
nose==1.3.7
nose-cov==1.6
requests==2.25.1
pyjwt==2.1.0
requests==2.31.0
pyjwt==2.4.0
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()


VERSION = '0.22.3'
VERSION = '0.23.4'

setup(
name='bigcommerce',
Expand Down