Skip to content

Commit 74e211c

Browse files
authored
Merge pull request #137 from jkeyes/pydoc-api-operations
Add pydocs to the _operations packages.
2 parents a7015d8 + f9860dc commit 74e211c

File tree

12 files changed

+45
-23
lines changed

12 files changed

+45
-23
lines changed

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Changelog
22
=========
33

4+
* 3.0b4
5+
* Added conversation.mark_read method. (`#136 <https://github.com/jkeyes/python-intercom/pull/136>`_)
46
* 3.0b3
57
* Added TokenUnauthorizedError. (`#134 <https://github.com/jkeyes/python-intercom/pull/134>`_)
68
* Added UTC datetime everywhere. (`#130 <https://github.com/jkeyes/python-intercom/pull/130>`_)

intercom/api_operations/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
# -*- coding: utf-8 -*-
2+
"""Package for operations that can be performed on a resource."""

intercom/api_operations/all.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# -*- coding: utf-8 -*-
2+
"""Operation to retrieve all instances of a particular resource."""
23

34
from intercom import utils
45
from intercom.collection_proxy import CollectionProxy
56

67

78
class All(object):
9+
"""A mixin that provides `all` functionality."""
810

911
def all(self):
12+
"""Return a CollectionProxy for the resource."""
1013
collection = utils.resource_class_to_collection_name(
1114
self.collection_class)
1215
finder_url = "/%s" % (collection)

intercom/api_operations/convert.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
# -*- coding: utf-8 -*-
2+
"""Operation to convert a contact into a user."""
23

34

45
class Convert(object):
6+
"""A mixin that provides `convert` functionality."""
57

68
def convert(self, contact, user):
9+
"""Convert the specified contact into the specified user."""
710
self.client.post(
811
'/contacts/convert',
912
{

intercom/api_operations/count.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# -*- coding: utf-8 -*-
2+
"""Operation to retrieve count for a particular resource."""
23

34
from intercom import utils
45

56

67
class Count(object):
8+
"""A mixin that provides `count` functionality."""
79

810
@classmethod
911
def count(cls):
12+
"""Return the count for the resource."""
1013
from intercom import Intercom
1114
response = Intercom.get("/counts/")
1215
return response[utils.resource_class_to_name(cls)]['count']

intercom/api_operations/delete.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
# -*- coding: utf-8 -*-
2+
"""Operation to delete an instance of a particular resource."""
23

34
from intercom import utils
45

56

67
class Delete(object):
8+
"""A mixin that provides `delete` functionality."""
79

810
def delete(self, obj):
11+
"""Delete the specified instance of this resource."""
912
collection = utils.resource_class_to_collection_name(
1013
self.collection_class)
1114
self.client.delete("/%s/%s" % (collection, obj.id), {})

intercom/api_operations/find.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# -*- coding: utf-8 -*-
2+
"""Operation to find an instance of a particular resource."""
23

34
from intercom import HttpError
45
from intercom import utils
56

67

78
class Find(object):
9+
"""A mixin that provides `find` functionality."""
810

911
def find(self, **params):
12+
"""Find the instance of the resource based on the supplied parameters."""
1013
collection = utils.resource_class_to_collection_name(
1114
self.collection_class)
1215
if 'id' in params:

intercom/api_operations/find_all.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# -*- coding: utf-8 -*-
2+
"""Operation to find all instances of a particular resource."""
23

34
from intercom import utils
45
from intercom.collection_proxy import CollectionProxy
56

67

78
class FindAll(object):
9+
"""A mixin that provides `find_all` functionality."""
810

911
def find_all(self, **params):
12+
"""Find all instances of the resource based on the supplied parameters."""
1013
collection = utils.resource_class_to_collection_name(
1114
self.collection_class)
1215
if 'id' in params and 'type' not in params:

intercom/api_operations/load.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# -*- coding: utf-8 -*-
2+
"""Operation to load an instance of a particular resource."""
23

34
from intercom import HttpError
45
from intercom import utils
56

67

78
class Load(object):
9+
"""A mixin that provides `load` functionality."""
810

911
def load(self, resource):
12+
"""Load the resource from the latest data in Intercom."""
1013
collection = utils.resource_class_to_collection_name(
1114
self.collection_class)
1215
if hasattr(resource, 'id'):

intercom/api_operations/save.py

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,22 @@
11
# -*- coding: utf-8 -*-
2+
"""Operation to create or save an instance of a particular resource."""
23

34
from intercom import utils
45

56

67
class Save(object):
8+
"""A mixin that provides `create` and `save` functionality."""
79

810
def create(self, **params):
11+
"""Create an instance of the resource from the supplied parameters."""
912
collection = utils.resource_class_to_collection_name(
1013
self.collection_class)
1114
response = self.client.post("/%s/" % (collection), params)
1215
if response: # may be empty if we received a 202
1316
return self.collection_class(**response)
1417

15-
# def from_dict(self, pdict):
16-
# for key, value in list(pdict.items()):
17-
# setattr(self, key, value)
18-
19-
# @property
20-
# def to_dict(self):
21-
# a_dict = {}
22-
# for name in list(self.__dict__.keys()):
23-
# if name == "changed_attributes":
24-
# continue
25-
# a_dict[name] = self.__dict__[name] # direct access
26-
# return a_dict
27-
28-
# @classmethod
29-
# def from_api(cls, response):
30-
# obj = cls()
31-
# obj.from_response(response)
32-
# return obj
33-
34-
# def from_response(self, response):
35-
# self.from_dict(response)
36-
# return self
37-
3818
def save(self, obj):
19+
"""Save the instance of the resource."""
3920
collection = utils.resource_class_to_collection_name(
4021
obj.__class__)
4122
params = obj.attributes
@@ -50,12 +31,15 @@ def save(self, obj):
5031
return obj.from_response(response)
5132

5233
def id_present(self, obj):
34+
"""Return whether the obj has an `id` attribute with a value."""
5335
return getattr(obj, 'id', None) and obj.id != ""
5436

5537
def posted_updates(self, obj):
38+
"""Return whether the updates to this object have been posted to Intercom."""
5639
return getattr(obj, 'update_verb', None) == 'post'
5740

5841
def identity_hash(self, obj):
42+
"""Return the identity_hash for this object."""
5943
identity_vars = getattr(obj, 'identity_vars', [])
6044
parts = {}
6145
for var in identity_vars:

intercom/extended_api_operations/reply.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,40 @@
11
# -*- coding: utf-8 -*-
2+
"""Operations to manage conversations."""
23

34
from intercom import utils
45

56

67
class Reply(object):
8+
"""A mixin that provides methods to manage a conversation.
9+
10+
This includes opening and closing them, assigning them to users, and
11+
replying them.
12+
"""
713

814
def reply(self, **reply_data):
15+
"""Add a reply, created from the supplied paramters, to the conversation."""
916
return self.__reply(reply_data)
1017

1118
def close_conversation(self, **reply_data):
19+
"""Close the conversation."""
1220
reply_data['type'] = 'admin'
1321
reply_data['message_type'] = 'close'
1422
return self.__reply(reply_data)
1523

1624
def open_conversation(self, **reply_data):
25+
"""Open the conversation."""
1726
reply_data['type'] = 'admin'
1827
reply_data['message_type'] = 'open'
1928
return self.__reply(reply_data)
2029

2130
def assign(self, **reply_data):
31+
"""Assign the conversation to an admin user."""
2232
reply_data['type'] = 'admin'
2333
reply_data['message_type'] = 'assignment'
2434
return self.__reply(reply_data)
2535

2636
def __reply(self, reply_data):
37+
"""Send the Conversation requests to Intercom and handl the responses."""
2738
from intercom import Intercom
2839
collection = utils.resource_class_to_collection_name(self.__class__)
2940
url = "/%s/%s/reply" % (collection, self.id)

intercom/extended_api_operations/users.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# -*- coding: utf-8 -*-
2+
"""Operation to return all users for a particular Company."""
23

34
from intercom import utils
45
from intercom.collection_proxy import CollectionProxy
56

67

78
class Users(object):
9+
"""A mixin that provides `users` functionality to Company."""
810

911
def users(self, id):
12+
"""Return a CollectionProxy to all the users for the specified Company."""
1013
collection = utils.resource_class_to_collection_name(
1114
self.collection_class)
1215
finder_url = "/%s/%s/users" % (collection, id)

0 commit comments

Comments
 (0)