From b7204319a9c096d12992a844b45b35b8cc8317c8 Mon Sep 17 00:00:00 2001 From: Ryan Hall Date: Mon, 2 Mar 2015 15:49:36 -0800 Subject: [PATCH] add companies api endpoint support --- blockscore/api/companies.py | 35 ++++++++++++++++++++ blockscore/client.py | 5 ++- test/companies.py | 66 +++++++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 blockscore/api/companies.py create mode 100644 test/companies.py diff --git a/blockscore/api/companies.py b/blockscore/api/companies.py new file mode 100644 index 0000000..a42e414 --- /dev/null +++ b/blockscore/api/companies.py @@ -0,0 +1,35 @@ +# returns company api instance + +COMPANIES_PATH = '/companies' + +class Companies(): + + def __init__(self, client): + self.client = client + + # + # '/companies' POST + # + def create(self, options = {}): + return self.client.post(COMPANIES_PATH, options) + + # + # '/companies/:id' GET + # + def retrieve(self, id, options = {}): + body = options['query'] if 'query' in options else {} + return self.client.get('%s/%s' % (COMPANIES_PATH, str(id)), body) + + # + # '/companies' GET + # + def all(self, count = None, offset = None, options = {}): + body = options['body'] if 'body' in options else {} + + if count: + body['count'] = count + if offset: + body['offset'] = offset + + return self.client.get(COMPANIES_PATH, body) + diff --git a/blockscore/client.py b/blockscore/client.py index 2eb9ff2..c3c79e7 100644 --- a/blockscore/client.py +++ b/blockscore/client.py @@ -3,10 +3,13 @@ # Assign all the api classes from .api.verification import Verification from .api.question_set import QuestionSet +from .api.companies import Companies class Client(): def __init__(self, auth = {}, options = {}): self.http_client = HttpClient(auth, options) self.verification = Verification(self.http_client) - self.question_set = QuestionSet(self.http_client) \ No newline at end of file + self.question_set = QuestionSet(self.http_client) + self.companies = Companies(self.http_client) + diff --git a/test/companies.py b/test/companies.py new file mode 100644 index 0000000..92cb30e --- /dev/null +++ b/test/companies.py @@ -0,0 +1,66 @@ +if __name__ == '__main__' and __package__ is None: + from os import sys, path + sys.path.append(path.dirname(path.dirname(path.abspath(__file__)))) +import blockscore +import unittest +import os, sys + +class TestBlockscoreCompanies(unittest.TestCase): + + def setUp(self): + try: + self.client = blockscore.Client({'api_key': os.environ['BLOCKSCORE_API']}) + except KeyError: + sys.stderr.write("To run tests, you must have a BLOCKSCORE_API environment variable with a test api key\n") + sys.exit(2) + + self.test_company = { + "entity_name": "BlockScore", + "tax_id": "123410000", + "incorp_date": "1980-08-25", + "incorp_state": "DE", + "incorp_country_code": "US", + "incorp_type": "corporation", + "dbas": "BitRemite", + "registration_number": "123123123", + "email": "test@example.com", + "url": "https://blockscore.com", + "phone_number": "6505555555", + "ip_address": "67.160.8.182", + "address": { + "street1": "1 Infinite Loop", + "street2": None, + "city": "Cupertino", + "state": "CA", + "postal_code": "95014", + "country_code": "US", + } + } + + def test_list_companies(self): + response = self.client.companies.all() + self.assertEqual(200, response.code) + + response = self.client.companies.all(count=2) + self.assertEqual(200, response.code) + + response = self.client.companies.all(count=2, offset=2) + self.assertEqual(200, response.code) + + def test_retrieve_company(self): + response = self.client.companies.create(self.test_company) + body = response.body + + response = self.client.companies.retrieve(body['id']) + body = response.body + + self.assertEqual(200, response.code) + self.assertEqual(self.test_company['entity_name'], body['entity_name']) + + def test_create_company(self): + response = self.client.companies.create(self.test_company) + self.assertEqual(201, response.code) + +if __name__ == '__main__': + unittest.main() +