diff --git a/README.md b/README.md index 70ffb2b7..f6b2676e 100644 --- a/README.md +++ b/README.md @@ -8,12 +8,6 @@ Python bindings for the Intercom API (https://api.intercom.io). [Package Documentation](http://readthedocs.org/docs/python-intercom/). -## Upgrading information - -Version 2 of python-intercom is **not backwards compatible** with previous versions. - -One change you will need to make as part of the upgrade is to set `Intercom.app_api_key` and not set `Intercom.api_key`. - ## Installation pip install python-intercom @@ -23,10 +17,10 @@ One change you will need to make as part of the upgrade is to set `Intercom.app_ ### Configure your access credentials ```python -Intercom.app_id = "my_app_id" -Intercom.app_api_key = "my-super-crazy-api-key" +Intercom.personal_access_token = "my_personal_access_token" ``` +Note that certain resources will require an extended scope access token : [Setting up Personal Access Tokens](https://developers.intercom.com/docs/personal-access-tokens>) ### Resources @@ -438,5 +432,5 @@ nosetests tests/unit Integration tests: ```bash -INTERCOM_APP_ID=xxx INTERCOM_APP_API_KEY=xxx nosetests tests/integration +INTERCOM_PERSONAL_ACCESS_TOKEN=xxx nosetests tests/integration ``` diff --git a/README.rst b/README.rst index 82fc989c..843a8ac3 100644 --- a/README.rst +++ b/README.rst @@ -10,15 +10,6 @@ Python bindings for the Intercom API (https://api.intercom.io). `Package Documentation `__. -Upgrading information ---------------------- - -Version 2 of python-intercom is **not backwards compatible** with -previous versions. - -One change you will need to make as part of the upgrade is to set -``Intercom.app_api_key`` and not set ``Intercom.api_key``. - Installation ------------ @@ -34,8 +25,9 @@ Configure your access credentials .. code:: python - Intercom.app_id = "my_app_id" - Intercom.app_api_key = "my-super-crazy-api-key" + Intercom.personal_access_token = "my_personal_access_token" + +Note that certain resources will require an extended scope access token : `Setting up Personal Access Tokens `_ Resources ~~~~~~~~~ @@ -474,7 +466,7 @@ Integration tests: .. code:: bash - INTERCOM_APP_ID=xxx INTERCOM_APP_API_KEY=xxx nosetests tests/integration + INTERCOM_PERSONAL_ACCESS_TOKEN=xxx nosetests tests/integration .. |PyPI Version| image:: https://img.shields.io/pypi/v/python-intercom.svg :target: https://pypi.python.org/pypi/python-intercom diff --git a/docs/development.rst b/docs/development.rst index 21f2256c..94cc62c4 100644 --- a/docs/development.rst +++ b/docs/development.rst @@ -15,7 +15,7 @@ Run the integration tests: :: # THESE SHOULD ONLY BE RUN ON A TEST APP! - INTERCOM_APP_ID=xxx INTERCOM_APP_API_KEY=xxx nosetests tests/integration + INTERCOM_PERSONAL_ACCESS_TOKEN=xxx nosetests tests/integration Generate the Documentation -------------------------- diff --git a/docs/index.rst b/docs/index.rst index 0c2f7efc..4319dc55 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -28,13 +28,12 @@ Usage Authentication --------------- -Intercom documentation: `Authentication `_. +Intercom documentation: `Authentication `_. :: from intercom import Intercom - Intercom.app_id = 'dummy-app-id' - Intercom.app_api_key = 'dummy-api-key' + Intercom.personal_access_token = 'dummy-personal-access-token' Users ----- diff --git a/intercom/__init__.py b/intercom/__init__.py index c7ef2e61..e8c65784 100644 --- a/intercom/__init__.py +++ b/intercom/__init__.py @@ -34,16 +34,13 @@ COMPATIBILITY_WARNING_TEXT = "It looks like you are upgrading from \ an older version of python-intercom. Please note that this new version \ (%s) is not backwards compatible." % (__version__) -COMPATIBILITY_WORKAROUND_TEXT = "To get rid of this error please set \ -Intercom.app_api_key and don't set Intercom.api_key." -CONFIGURATION_REQUIRED_TEXT = "You must set both Intercom.app_id and \ -Intercom.app_api_key to use this client." +CONFIGURATION_REQUIRED_TEXT = "You must set Intercom.personal_access_token \ +to use this client." class IntercomType(type): # noqa - app_id = None - app_api_key = None + personal_access_token = None _hostname = "api.intercom.io" _protocol = "https" _endpoints = None @@ -54,7 +51,7 @@ class IntercomType(type): # noqa @property def _auth(self): - return (self.app_id, self.app_api_key) + return (self.personal_access_token, '') @property def _random_endpoint(self): @@ -74,11 +71,11 @@ def _alternative_random_endpoint(self): @property def target_base_url(self): - if None in [self.app_id, self.app_api_key]: + if self.personal_access_token is None: raise ArgumentError('%s %s' % ( CONFIGURATION_REQUIRED_TEXT, RELATED_DOCS_TEXT)) if self._target_base_url is None: - basic_auth_part = '%s:%s@' % (self.app_id, self.app_api_key) + basic_auth_part = '%s:%s@' % (self.personal_access_token, '') if self.current_endpoint: self._target_base_url = re.sub( r'(https?:\/\/)(.*)', diff --git a/tests/integration/issues/test_72.py b/tests/integration/issues/test_72.py index c576cae0..cb4e719a 100644 --- a/tests/integration/issues/test_72.py +++ b/tests/integration/issues/test_72.py @@ -7,8 +7,7 @@ from intercom import Event from intercom import User -Intercom.app_id = os.environ.get('INTERCOM_APP_ID') -Intercom.app_api_key = os.environ.get('INTERCOM_APP_API_KEY') +Intercom.personal_access_token = os.environ.get('INTERCOM_PERSONAL_ACCESS_TOKEN') class Issue72Test(unittest.TestCase): diff --git a/tests/integration/issues/test_73.py b/tests/integration/issues/test_73.py index cc5ce90c..87420042 100644 --- a/tests/integration/issues/test_73.py +++ b/tests/integration/issues/test_73.py @@ -8,8 +8,7 @@ from intercom import Intercom from intercom import User -Intercom.app_id = os.environ.get('INTERCOM_APP_ID') -Intercom.app_api_key = os.environ.get('INTERCOM_APP_API_KEY') +Intercom.personal_access_token = os.environ.get('INTERCOM_PERSONAL_ACCESS_TOKEN') class Issue73Test(unittest.TestCase): diff --git a/tests/integration/test_admin.py b/tests/integration/test_admin.py index 22d59381..e896b941 100644 --- a/tests/integration/test_admin.py +++ b/tests/integration/test_admin.py @@ -5,8 +5,7 @@ from intercom import Intercom from intercom import Admin -Intercom.app_id = os.environ.get('INTERCOM_APP_ID') -Intercom.app_api_key = os.environ.get('INTERCOM_APP_API_KEY') +Intercom.personal_access_token = os.environ.get('INTERCOM_PERSONAL_ACCESS_TOKEN') class AdminTest(unittest.TestCase): diff --git a/tests/integration/test_company.py b/tests/integration/test_company.py index e7e285b1..7c098380 100644 --- a/tests/integration/test_company.py +++ b/tests/integration/test_company.py @@ -10,8 +10,7 @@ from . import get_or_create_company from . import get_timestamp -Intercom.app_id = os.environ.get('INTERCOM_APP_ID') -Intercom.app_api_key = os.environ.get('INTERCOM_APP_API_KEY') +Intercom.personal_access_token = os.environ.get('INTERCOM_PERSONAL_ACCESS_TOKEN') class CompanyTest(unittest.TestCase): diff --git a/tests/integration/test_conversations.py b/tests/integration/test_conversations.py index 0a5655cb..af2f98f2 100644 --- a/tests/integration/test_conversations.py +++ b/tests/integration/test_conversations.py @@ -10,8 +10,7 @@ from . import get_or_create_user from . import get_timestamp -Intercom.app_id = os.environ.get('INTERCOM_APP_ID') -Intercom.app_api_key = os.environ.get('INTERCOM_APP_API_KEY') +Intercom.personal_access_token = os.environ.get('INTERCOM_PERSONAL_ACCESS_TOKEN') class ConversationTest(unittest.TestCase): diff --git a/tests/integration/test_count.py b/tests/integration/test_count.py index 806c33cd..51435ddb 100644 --- a/tests/integration/test_count.py +++ b/tests/integration/test_count.py @@ -15,8 +15,7 @@ from . import get_or_create_user from . import delete -Intercom.app_id = os.environ.get('INTERCOM_APP_ID') -Intercom.app_api_key = os.environ.get('INTERCOM_APP_API_KEY') +Intercom.personal_access_token = os.environ.get('INTERCOM_PERSONAL_ACCESS_TOKEN') class CountTest(unittest.TestCase): diff --git a/tests/integration/test_notes.py b/tests/integration/test_notes.py index eba0a03b..815dc668 100644 --- a/tests/integration/test_notes.py +++ b/tests/integration/test_notes.py @@ -8,8 +8,7 @@ from . import get_or_create_user from . import get_timestamp -Intercom.app_id = os.environ.get('INTERCOM_APP_ID') -Intercom.app_api_key = os.environ.get('INTERCOM_APP_API_KEY') +Intercom.personal_access_token = os.environ.get('INTERCOM_PERSONAL_ACCESS_TOKEN') class NoteTest(unittest.TestCase): diff --git a/tests/integration/test_segments.py b/tests/integration/test_segments.py index d9b54f80..f9438db5 100644 --- a/tests/integration/test_segments.py +++ b/tests/integration/test_segments.py @@ -7,8 +7,7 @@ from intercom import Intercom from intercom import Segment -Intercom.app_id = os.environ.get('INTERCOM_APP_ID') -Intercom.app_api_key = os.environ.get('INTERCOM_APP_API_KEY') +Intercom.personal_access_token = os.environ.get('INTERCOM_PERSONAL_ACCESS_TOKEN') class SegmentTest(unittest.TestCase): diff --git a/tests/integration/test_tags.py b/tests/integration/test_tags.py index cf7579a5..4cf4663a 100644 --- a/tests/integration/test_tags.py +++ b/tests/integration/test_tags.py @@ -11,8 +11,7 @@ from . import get_or_create_user from . import get_timestamp -Intercom.app_id = os.environ.get('INTERCOM_APP_ID') -Intercom.app_api_key = os.environ.get('INTERCOM_APP_API_KEY') +Intercom.personal_access_token = os.environ.get('INTERCOM_PERSONAL_ACCESS_TOKEN') class TagTest(unittest.TestCase): diff --git a/tests/integration/test_user.py b/tests/integration/test_user.py index 73fcd9f2..ce833c70 100644 --- a/tests/integration/test_user.py +++ b/tests/integration/test_user.py @@ -8,8 +8,7 @@ from . import get_or_create_user from . import delete -Intercom.app_id = os.environ.get('INTERCOM_APP_ID') -Intercom.app_api_key = os.environ.get('INTERCOM_APP_API_KEY') +Intercom.personal_access_token = os.environ.get('INTERCOM_PERSONAL_ACCESS_TOKEN') class UserTest(unittest.TestCase): diff --git a/tests/unit/test_intercom.py b/tests/unit/test_intercom.py index b6534d82..5bb89935 100644 --- a/tests/unit/test_intercom.py +++ b/tests/unit/test_intercom.py @@ -15,25 +15,22 @@ class ExpectingArgumentsTest(unittest.TestCase): def setUp(self): # noqa self.intercom = intercom.Intercom - self.intercom.app_id = 'abc123' - self.intercom.app_api_key = 'super-secret-key' + self.intercom.personal_access_token = 'super-personal-access-token' @istest - def it_raises_argumenterror_if_no_app_id_or_app_api_key_specified(self): # noqa - self.intercom.app_id = None - self.intercom.app_api_key = None + def it_raises_argumenterror_if_no_personal_access_token_specified(self): # noqa + self.intercom.personal_access_token = None with assert_raises(intercom.ArgumentError): self.intercom.target_base_url @istest - def it_returns_the_app_id_and_app_api_key_previously_set(self): - eq_(self.intercom.app_id, 'abc123') - eq_(self.intercom.app_api_key, 'super-secret-key') + def it_returns_the_personal_access_token_previously_set(self): + eq_(self.intercom.personal_access_token, 'super-personal-access-token') @istest def it_defaults_to_https_to_api_intercom_io(self): eq_(self.intercom.target_base_url, - 'https://abc123:super-secret-key@api.intercom.io') + 'https://super-personal-access-token:@api.intercom.io') class OverridingProtocolHostnameTest(unittest.TestCase): @@ -54,20 +51,20 @@ def it_allows_overriding_of_the_endpoint_and_protocol(self): self.intercom.hostname = "localhost:3000" eq_( self.intercom.target_base_url, - "http://abc123:super-secret-key@localhost:3000") + "http://super-personal-access-token:@localhost:3000") @istest def it_prefers_endpoints(self): self.intercom.endpoint = "https://localhost:7654" eq_(self.intercom.target_base_url, - "https://abc123:super-secret-key@localhost:7654") + "https://super-personal-access-token:@localhost:7654") # turn off the shuffle with mock.patch("random.shuffle") as mock_shuffle: mock_shuffle.return_value = ["http://example.com", "https://localhost:7654"] # noqa self.intercom.endpoints = ["http://example.com", "https://localhost:7654"] # noqa eq_(self.intercom.target_base_url, - 'http://abc123:super-secret-key@example.com') + 'http://super-personal-access-token:@example.com') @istest def it_has_endpoints(self):