Skip to content

Commit b96d022

Browse files
committed
Merge pull request #62 from jkeyes/readme
Readme Review
2 parents 3657841 + 0285ddd commit b96d022

File tree

6 files changed

+86
-42
lines changed

6 files changed

+86
-42
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,16 +393,19 @@ Note that models generated from webhook notifications might differ slightly from
393393
### Errors
394394
You do not need to deal with the HTTP response from an API call directly. If there is an unsuccessful response then an error that is a subclass of `intercom.Error` will be raised. If desired, you can get at the http_code of an `Error` via it's `http_code` method.
395395

396-
The list of different error subclasses are listed below. As they all inherit off `Error` you can choose to except `Error` or the more specific error subclass:
396+
The list of different error subclasses are listed below. As they all inherit off `IntercomError` you can choose to except `IntercomError` or the more specific error subclass:
397397

398398
```python
399399
AuthenticationError
400400
ServerError
401401
ServiceUnavailableError
402402
ResourceNotFound
403+
BadGatewayError
403404
BadRequestError
404405
RateLimitExceeded
405-
AttributeNotSetError # Raised when you try to call a getter that does not exist on an object
406+
MultipleMatchingUsersError
407+
HttpError
408+
UnexpectedError
406409
```
407410

408411

intercom/company.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@
1313
class Company(Resource, Delete, Count, Find, All, Save, Load, Users):
1414
update_verb = 'post'
1515
identity_vars = ['id', 'company_id']
16+
17+
@property
18+
def flat_store_attributes(self):
19+
return ['custom_attributes']

intercom/errors.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
# -*- coding: utf-8 -*-
22

33

4-
class ArgumentError(ValueError):
5-
pass
6-
7-
8-
class HttpError(Exception):
9-
pass
10-
11-
124
class IntercomError(Exception):
135

146
def __init__(self, message=None, context=None):
@@ -17,6 +9,14 @@ def __init__(self, message=None, context=None):
179
self.context = context
1810

1911

12+
class ArgumentError(ValueError, IntercomError):
13+
pass
14+
15+
16+
class HttpError(IntercomError):
17+
pass
18+
19+
2020
class ResourceNotFound(IntercomError):
2121
pass
2222

intercom/tag.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,21 @@ def untag_companies(cls, name, companies):
4848
return cls._tag_collection(name, 'companies', companies, untag=True)
4949

5050
@classmethod
51-
def find_all_for_user(cls, id=None, email=None, user_id=None):
52-
params = {}
53-
if id:
54-
params['id'] = id
55-
if email:
56-
params['email'] = email
57-
if user_id:
58-
params['user_id'] = user_id
51+
def find_all_for_user(cls, **kwargs):
52+
return cls.find_all_for('user', **kwargs)
53+
54+
@classmethod
55+
def find_all_for_company(cls, **kwargs):
56+
return cls.find_all_for('company', **kwargs)
57+
58+
@classmethod
59+
def find_all_for(cls, taggable_type, **kwargs):
60+
params = {
61+
'taggable_type': taggable_type
62+
}
63+
res_id = kwargs.pop('id', None)
64+
if res_id:
65+
params['taggable_id'] = res_id
66+
params.update(kwargs)
67+
5968
return Tag.find_all(**params)

tests/integration/test_company.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ def test_add_user_custom_attributes(self):
5454
self.assertEqual(len(user.companies), 2)
5555
self.assertEqual(user.companies[0].company_id, "9")
5656

57+
# check the custom attributes
58+
company = Company.find(company_id=6)
59+
self.assertEqual(
60+
company.custom_attributes['referral_source'], "Google")
61+
5762
def test_find_by_company_id(self):
5863
# Find a company by company_id
5964
company = Company.find(company_id=self.company.company_id)

tests/integration/test_tags.py

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import unittest
55
from intercom import Intercom
66
from intercom import Tag
7+
from intercom import User
8+
from intercom import Company
79
from . import delete
810
from . import get_or_create_company
911
from . import get_or_create_user
@@ -32,47 +34,68 @@ def teardown_class(cls):
3234

3335
def test_tag_users(self):
3436
# Tag users
35-
tag = Tag.tag_users("blue", [self.user.id])
36-
self.assertEqual(tag.name, "blue")
37+
tag = Tag.tag_users('blue', [self.user.id])
38+
self.assertEqual(tag.name, 'blue')
39+
user = User.find(email=self.user.email)
40+
self.assertEqual(1, len(user.tags))
3741

3842
def test_untag_users(self):
3943
# Untag users
40-
tag = Tag.untag_users("blue", [self.user.id])
41-
self.assertEqual(tag.name, "blue")
44+
tag = Tag.untag_users('blue', [self.user.id])
45+
self.assertEqual(tag.name, 'blue')
46+
user = User.find(email=self.user.email)
47+
self.assertEqual(0, len(user.tags))
4248

4349
def test_all(self):
4450
# Iterate over all tags
4551
for tag in Tag.all():
4652
self.assertIsNotNone(tag.id)
4753

48-
# def test_all_for_user_by_id(self):
49-
# # Iterate over all tags for user
50-
# tags = Tag.find_all_for_user(id=self.user.id)
51-
# for tag in tags:
52-
# self.assertIsNotNone(tag.id)
54+
def test_all_for_user_by_id(self):
55+
# Iterate over all tags for user
56+
tags = Tag.find_all_for_user(id=self.user.id)
57+
for tag in tags:
58+
self.assertIsNotNone(tag.id)
5359

54-
# def test_all_for_user_by_email(self):
55-
# # Iterate over all tags for user
56-
# tags = Tag.find_all_for_user(email=self.user.email)
57-
# for tag in tags:
58-
# self.assertIsNotNone(tag.id)
60+
def test_all_for_user_by_email(self):
61+
# Iterate over all tags for user
62+
tags = Tag.find_all_for_user(email=self.user.email)
63+
for tag in tags:
64+
self.assertIsNotNone(tag.id)
5965

60-
# def test_all_for_user_by_user_id(self):
61-
# # Iterate over all tags for user
62-
# tags = Tag.find_all_for_user(user_id=self.user.user_id)
63-
# for tag in tags:
64-
# self.assertIsNotNone(tag.id)
66+
def test_all_for_user_by_user_id(self):
67+
# Iterate over all tags for user
68+
tags = Tag.find_all_for_user(user_id=self.user.user_id)
69+
for tag in tags:
70+
self.assertIsNotNone(tag.id)
6571

6672
def test_tag_companies(self):
6773
# Tag companies
6874
tag = Tag.tag_companies("red", [self.user.companies[0].id])
6975
self.assertEqual(tag.name, "red")
76+
company = Company.find(id=self.user.companies[0].id)
77+
self.assertEqual(1, len(company.tags))
7078

7179
def test_untag_companies(self):
7280
# Untag companies
73-
tag = Tag.untag_companies("blue", [self.user.companies[0].id])
74-
self.assertEqual(tag.name, "blue")
81+
tag = Tag.untag_companies("red", [self.user.companies[0].id])
82+
self.assertEqual(tag.name, "red")
83+
company = Company.find(id=self.user.companies[0].id)
84+
self.assertEqual(0, len(company.tags))
85+
86+
# Iterate over all tags for company
87+
def test_all_for_company_by_id(self):
88+
# Iterate over all tags for user
89+
red_tag = Tag.tag_companies("red", [self.company.id])
90+
tags = Tag.find_all_for_company(id=self.company.id)
91+
for tag in tags:
92+
self.assertEqual(red_tag.id, tag.id)
93+
Tag.untag_companies("red", [self.company.id])
7594

76-
# # Iterate over all tags for company
77-
# Tag.find_all_for_company(id='43357e2c3c77661e25000026')
78-
# Tag.find_all_for_company(company_id='6')
95+
def test_all_for_company_by_company_id(self):
96+
# Iterate over all tags for user
97+
red_tag = Tag.tag_companies("red", [self.company.id])
98+
tags = Tag.find_all_for_company(company_id=self.company.id)
99+
for tag in tags:
100+
self.assertEqual(red_tag.id, tag.id)
101+
Tag.untag_companies("red", [self.company.id])

0 commit comments

Comments
 (0)