Skip to content

Commit 67401f1

Browse files
committed
Merge pull request #8 from ryanahall/rhall/add_companies
add companies api endpoint support
2 parents 42b57c4 + b720431 commit 67401f1

File tree

3 files changed

+105
-1
lines changed

3 files changed

+105
-1
lines changed

blockscore/api/companies.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# returns company api instance
2+
3+
COMPANIES_PATH = '/companies'
4+
5+
class Companies():
6+
7+
def __init__(self, client):
8+
self.client = client
9+
10+
#
11+
# '/companies' POST
12+
#
13+
def create(self, options = {}):
14+
return self.client.post(COMPANIES_PATH, options)
15+
16+
#
17+
# '/companies/:id' GET
18+
#
19+
def retrieve(self, id, options = {}):
20+
body = options['query'] if 'query' in options else {}
21+
return self.client.get('%s/%s' % (COMPANIES_PATH, str(id)), body)
22+
23+
#
24+
# '/companies' GET
25+
#
26+
def all(self, count = None, offset = None, options = {}):
27+
body = options['body'] if 'body' in options else {}
28+
29+
if count:
30+
body['count'] = count
31+
if offset:
32+
body['offset'] = offset
33+
34+
return self.client.get(COMPANIES_PATH, body)
35+

blockscore/client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
# Assign all the api classes
44
from .api.verification import Verification
55
from .api.question_set import QuestionSet
6+
from .api.companies import Companies
67

78
class Client():
89

910
def __init__(self, auth = {}, options = {}):
1011
self.http_client = HttpClient(auth, options)
1112
self.verification = Verification(self.http_client)
12-
self.question_set = QuestionSet(self.http_client)
13+
self.question_set = QuestionSet(self.http_client)
14+
self.companies = Companies(self.http_client)
15+

test/companies.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
if __name__ == '__main__' and __package__ is None:
2+
from os import sys, path
3+
sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))
4+
import blockscore
5+
import unittest
6+
import os, sys
7+
8+
class TestBlockscoreCompanies(unittest.TestCase):
9+
10+
def setUp(self):
11+
try:
12+
self.client = blockscore.Client({'api_key': os.environ['BLOCKSCORE_API']})
13+
except KeyError:
14+
sys.stderr.write("To run tests, you must have a BLOCKSCORE_API environment variable with a test api key\n")
15+
sys.exit(2)
16+
17+
self.test_company = {
18+
"entity_name": "BlockScore",
19+
"tax_id": "123410000",
20+
"incorp_date": "1980-08-25",
21+
"incorp_state": "DE",
22+
"incorp_country_code": "US",
23+
"incorp_type": "corporation",
24+
"dbas": "BitRemite",
25+
"registration_number": "123123123",
26+
"email": "[email protected]",
27+
"url": "https://blockscore.com",
28+
"phone_number": "6505555555",
29+
"ip_address": "67.160.8.182",
30+
"address": {
31+
"street1": "1 Infinite Loop",
32+
"street2": None,
33+
"city": "Cupertino",
34+
"state": "CA",
35+
"postal_code": "95014",
36+
"country_code": "US",
37+
}
38+
}
39+
40+
def test_list_companies(self):
41+
response = self.client.companies.all()
42+
self.assertEqual(200, response.code)
43+
44+
response = self.client.companies.all(count=2)
45+
self.assertEqual(200, response.code)
46+
47+
response = self.client.companies.all(count=2, offset=2)
48+
self.assertEqual(200, response.code)
49+
50+
def test_retrieve_company(self):
51+
response = self.client.companies.create(self.test_company)
52+
body = response.body
53+
54+
response = self.client.companies.retrieve(body['id'])
55+
body = response.body
56+
57+
self.assertEqual(200, response.code)
58+
self.assertEqual(self.test_company['entity_name'], body['entity_name'])
59+
60+
def test_create_company(self):
61+
response = self.client.companies.create(self.test_company)
62+
self.assertEqual(201, response.code)
63+
64+
if __name__ == '__main__':
65+
unittest.main()
66+

0 commit comments

Comments
 (0)