Skip to content

Commit

Permalink
Merge pull request #12 from SonicRift/dev
Browse files Browse the repository at this point in the history
v0.5.0 Enhancements
  • Loading branch information
ShaneSutro authored Feb 22, 2021
2 parents 24b7889 + 8a56b57 commit a2c4f76
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ vboard.post('And just like that, we were off.')
```
![Board with plain text example](../media/basictext.png?raw=true)

If you already have your Subscription ID or you do not want to store it, you can call `Board()` directly and pass your API Key, API Secret and Subscription ID directly. Note that if you choose to not store these credentials, you will need to provide them each time you call a method on a `Board`.
If you already have your Subscription ID or you do not want to store it, you can call `Board()` directly and pass your API Key, API Secret and Subscription ID directly.
Note that if you choose to not store these credentials, you will need to provide them each time you call a method on a `Board`.
If you do choose to store them, they will be stored in a file called `credentials.txt` in the root directory of your project; remember to add `credentials.txt` to your `.gitignore` to avoid commiting your keys to GitHub. Alternatively, you may create a `config.py` file in your code and store the information there; again, add `config.py` to your `.gitignore`. Never upload API keys or API Secrets to a repository.
You can also create an instance of Installable with only your API Key and API Secret, then provide a subscription ID directly when instantiating a new `Board` by setting `getSubscription=False` when instantiating the Installable.

#### config.py
```python
Expand All @@ -79,8 +81,12 @@ vboard.post('Love is all you need')
Currently this module supports the following:
- Creating an Installable object by passing in an API Key and API Secret
- This will find and store the Subscription ID for you
- Passing `getSubscription=False` overrides this - if you set this to False, remember to pass in a Subscription ID when instantiating a new `Board`

- Creating an instance of Board, either by passing in an Installable or by passing in an API Key, API Secret _and_ Subscription ID
- Creating an instance of Board by passing in one of the following:
- An Installable, instantiated with API Key and API Secret
- By passing in an API Key, API Secret _and_ Subscription ID directly to `Board()`
- By passing in an Installable where `getSubscription=False` and manually providing the Subscription ID to `Board`.

The board currently has 2 methods available, the `.post()` method, which takes in a string and sends it to the board, and the `.raw()` method, which allows you to place characters precisely where you'd like them.

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="Vestaboard",
version="0.4.0",
version="0.5.0",
author="Shane Sutro",
author_email="[email protected]",
description="A Vestaboard Wrapper",
Expand Down
9 changes: 9 additions & 0 deletions tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ def test_valid_raw_input_does_not_fail():
vestaboard.Board().raw(validRawChar)
remove_fake_cred_file()

def test_board_can_be_instantiated_with_an_installable_and_sub_id():
apiKey = 'fakeApiKey'
apiSecret = 'fakeApiSecret'
subId = 'fakeSubId'

i = vestaboard.Installable(apiKey=apiKey, apiSecret=apiSecret, getSubscription=False, saveCredentials=False)
vb = vestaboard.Board(i, subscriptionId=subId)
vb.post('Should not error')

def create_fake_cred_file():
with open(os.path.dirname(os.path.dirname(__file__)) + '/credentials.txt', 'w') as f:
f.write('fakeApiKey\n')
Expand Down
14 changes: 6 additions & 8 deletions vestaboard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,15 @@ def __init__(self, Installable=False, apiKey=False, apiSecret=False, subscriptio
else:
self.apiKey = Installable.apiKey
self.apiSecret = Installable.apiSecret
self.subscriptionId = Installable.subscriptionId
self.subscriptionId = Installable.subscriptionId or subscriptionId

def post(self, text):
headers = {
"X-Vestaboard-Api-Key" : self.apiKey,
"X-Vestaboard-Api-Secret" : self.apiSecret
}
finalText = Formatter()._standard(text)
r = requests.post(vbUrls.post.format(self.subscriptionId), headers=headers, json=finalText)
print(r.status_code)
print(r.text)
requests.post(vbUrls.post.format(self.subscriptionId), headers=headers, json=finalText)

def raw(self, charList):
if len(charList) != 6:
Expand All @@ -68,9 +66,7 @@ def raw(self, charList):
"X-Vestaboard-Api-Secret" : self.apiSecret
}
finalText = Formatter()._raw(charList)
r = requests.post(vbUrls.post.format(self.subscriptionId), headers=headers, json=finalText)
print(r.status_code)
print(r.text)
requests.post(vbUrls.post.format(self.subscriptionId), headers=headers, json=finalText)

class Installable:
def __init__(self, apiKey=False, apiSecret=False, getSubscription=True, saveCredentials=True):
Expand All @@ -97,6 +93,8 @@ def __init__(self, apiKey=False, apiSecret=False, getSubscription=True, saveCred
cred.close()
if getSubscription:
self.subscriptionId = self.get_subscriptions(saveCredentials)[0]['_id']
else:
self.subscriptionId = False

def get_subscriptions(self, save=True):
if not self.apiKey or not self.apiSecret:
Expand All @@ -111,7 +109,7 @@ def get_subscriptions(self, save=True):
cred.write(response.json()['subscriptions'][0]['_id'] + '\n')
cred.close()

print(response.json()['subscriptions'])
print('Subscription id(s):', response.json()['subscriptions'])
return response.json()['subscriptions']

def get_creds():
Expand Down

0 comments on commit a2c4f76

Please sign in to comment.