Skip to main content

A Python Rest SDK for Gameworks Services

Project description

Gameworks Python SDK

Pypi Version Build Status

Introduction

A Software Development Kit for serving Gameworks applications and services. The SDK currently allows you to connect to the Gameworks Registry API.

Features

  • Is able to connect to Gameworks services through basic authentication tokens
  • Is able to connect to the Registry API service:
    • User Registration
    • Player Profile Creation
    • Publisher Profile Creation

Future Releases

  • Will be able to peform NEM blockchain transactions via the Gameworks Cashier API
  • Will be able to connect to Gameworks services through OAuth 2.0 Protocol

Installation

To install Gameworks SDK (stable build), run this command in your terminal:

$ pip install gameworks

Development

Code is hosted at Gameworks Python SDK Git Repository

$ git clone git://github.com/gameworks-gwx/gameworks-python-sdk.git
$ cd gameworks-python-sdk

Set up a virtual environment to isolate python dependencies.

$ virtualenv venv
$ source venv/bin/activate

Install development dependencies.

$ pip install -r requirements-dev.txt #optional

Run the tests.

$ python -m unittest

Configuration

To get started, import the gameworks SDK python module.

import gameworks

Create a .env file in your respository to set your environment variables. In this context, the .env file is used to configure two environment variables: authorization key for accessing the API GAMEWORKS_KEY and the API environment GAMEWORKS_ENV you would like to connect to. There are two environments provisioned for the SDK which are sandbox and live; by default the SDK points to the sandbox environment. The sandbox environment is used as a playground for development purposes, while the live environment connects to the actual Registry API.

$ touch .env
$ sudo nano .env

.env

export GAMEWORKS_KEY="Authentication Token"
export GAMEWORKS_ENV="live" #sandbox or live

Then, execute commands in the .env file using source

$ source .env

Usage

Session Module

This module allows you to configure your authentication variables, register a user account and login using an existing user account. You may choose to login the Registry API using your Gameworks credentials or use an existing JWT access token provided to you when you previously logged in.

Registering a User Account

When creating a user, use the wallet address provided by the Gameworks Mobile Wallet or a NEM wallet address.

from gameworks import Session

response = Session.register(
    firstName='Luke',
    lastName='Skywalker',
    walletAddress='TBZMQO7ZPBYNBDUR7F75MAKA2S3DHDCIFG775N3D',
    email='luke@therebellion.io',
    password='nooooooooooo!!!!!!???!?!!!'
    passwordConfirmation='nooooooooooo!!!!!!???!?!!!'
)

# At this point, the SDK has already thrown an HTTP call to the Registry API.
print(response.status_code) #Returns the status code of the response (e.g. 200, 404)
print(response.text) #Returns the whole response in text format

Take note that all results are returned as a Response object. You may refer to the requests package response object.

Login using a User Account

Logging in using a user account, will trigger another token to be created. Tokens expire within an hour from the time of creation.

from gameworks import Session

response = Session.login(
    email='luke@therebellion.io',
    password='nooooooooooo!!!!!!???!?!!!'
)

Storing a Token

If you already have an access token, you may choose to bypass the login process and directly use the functionalities of the Gameworks services. As of the alpha release, the token exported as an environment variable is being used thus there is no need to use this function for authentication.

from gameworks import Session

response = Session.store_key(
    key='eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxMTAsImV4cCI6MT...',
    userId=1
)

Registry Module

This module allows you create, update and view a user account, a player profile and a publisher account. All functionlaities contained in this module can be supplmented by tokens/keys. You may add them into the parameters in order to manually activate functionalities without having to create the .env file. See the code below as an example:

from gameworks.registry import User

response = User.find(
    userId=1,
    key='eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxMTAsImV4cCI6MT...'
)

User Resource Functionalities


Find User

* Authentication Token Required

To retrieve your user's account details, you may choose to query for it using the code below:

from gameworks.registry import User

# You may only use your own user id for this function
response = User.find(userId=1)

Update User

* Authentication Token Required

You may choose to update specific data in your account information. You don't need to fill up all the parameters in the account information. Updatable account parameters include: firstName, lastName, walletAddress and pk (private key associated to the NEM wallet address)

from gameworks.registry import User

response = User.update(
    userId=1,
    firstName='Luke',
    lastName='Skywalker',
    walletAddress='TBZMQO7ZPBYNBDUR7F75MAKA2S3DHDCIC3POR2D2',
    pk='woooahtweevwoopvrrruhfdedadahhhhhhhbeepboopdoopwaaaahwoooooaevvr'
)

Confirm User

Once you have registered for a user account and have logged in, you will receive a message containg your confirmation code in the email you have provided. Use the code below to confirm your account programatically. You no longer need to input your userId since the Registry API already knows to which account the code is assigned to.

from gameworks.registry import User

response = User.confirm(code='R2D2')

Resend Code

* Authentication Token Required

In the case that your confirmation code hasn't been emailed yet, you may choose to have it resent using the code below:

from gameworks.registry import User

response = User.resend_code(userId=1)

Player Profile Resource Functionalities


Register Player Profile

* Authentication Token Required

Create a player profile by entering your desired username and your userId as shown in the code below:

from gameworks.registry import Player

response = Player.register(
    userId=1,
    username='JediMasterXIII'
)

Find Player Profile

* Authentication Token Required

To retrieve your player profile, query for it using the code below:

from gameworks.registry import Player

response = Player.find(
    userId=1
)

Update Player Profile

* Authentication Token Required

Update your username by executing the code below:

from gameworks.registry import Player

response = Player.update(
    userId=1,
    username='JediMasterXIX'
)

Publisher Account Resource Functionalities


Register Publisher Account

* Authentication Token Required

Create a publisher account by executing the code below:

from gameworks.registry import Player

response = Player.register(
    userId=1,
    username='JediMasterXIII'
)

Find Publisher Profile

* Authentication Token Required

To retrieve your publisher profile, query for it using the code below:

from gameworks.registry import Player

response = Publisher.find(
    userId=1
)

Update Publisher Profile

* Authentication Token Required

You may choose to update specific data in your publisher account information. You don't need to fill up all the parameters in the account information. Updatable account parameters include: userId, walletAddress (wallet address may not be the same as the user account's wallet address), publisherName, description.

from gameworks.registry import Player

response = Publisher.update(
    userId=1,
    publisherName='The Second Order',
    walletAddress='JABBATHEHUTTBDUR7F75MAKA2S3DHDCIC3POR2D2',
    description='Upon the ashes shall arise the Second Order'
)

License

The MIT License (MIT)

Copyright (C) 2019 Gameworks.io

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Others

Enjoying our platform? Leave us a star on Github to motivate us to create more services for you ;) .

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for gameworks, version 0.2.0
Filename, size File type Python version Upload date Hashes
Filename, size gameworks-0.2.0-py3-none-any.whl (11.2 kB) File type Wheel Python version py3 Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page