Skip to content

Add pydocs to the _operations packages. #137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Changelog
=========

* 3.0b4
* Added conversation.mark_read method. (`#136 <https://github.com/jkeyes/python-intercom/pull/136>`_)
* 3.0b3
* Added TokenUnauthorizedError. (`#134 <https://github.com/jkeyes/python-intercom/pull/134>`_)
* Added UTC datetime everywhere. (`#130 <https://github.com/jkeyes/python-intercom/pull/130>`_)
Expand Down
1 change: 1 addition & 0 deletions intercom/api_operations/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# -*- coding: utf-8 -*-
"""Package for operations that can be performed on a resource."""
3 changes: 3 additions & 0 deletions intercom/api_operations/all.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# -*- coding: utf-8 -*-
"""Operation to retrieve all instances of a particular resource."""

from intercom import utils
from intercom.collection_proxy import CollectionProxy


class All(object):
"""A mixin that provides `all` functionality."""

def all(self):
"""Return a CollectionProxy for the resource."""
collection = utils.resource_class_to_collection_name(
self.collection_class)
finder_url = "/%s" % (collection)
Expand Down
3 changes: 3 additions & 0 deletions intercom/api_operations/convert.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# -*- coding: utf-8 -*-
"""Operation to convert a contact into a user."""


class Convert(object):
"""A mixin that provides `convert` functionality."""

def convert(self, contact, user):
"""Convert the specified contact into the specified user."""
self.client.post(
'/contacts/convert',
{
Expand Down
3 changes: 3 additions & 0 deletions intercom/api_operations/count.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# -*- coding: utf-8 -*-
"""Operation to retrieve count for a particular resource."""

from intercom import utils


class Count(object):
"""A mixin that provides `count` functionality."""

@classmethod
def count(cls):
"""Return the count for the resource."""
from intercom import Intercom
response = Intercom.get("/counts/")
return response[utils.resource_class_to_name(cls)]['count']
3 changes: 3 additions & 0 deletions intercom/api_operations/delete.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# -*- coding: utf-8 -*-
"""Operation to delete an instance of a particular resource."""

from intercom import utils


class Delete(object):
"""A mixin that provides `delete` functionality."""

def delete(self, obj):
"""Delete the specified instance of this resource."""
collection = utils.resource_class_to_collection_name(
self.collection_class)
self.client.delete("/%s/%s" % (collection, obj.id), {})
Expand Down
3 changes: 3 additions & 0 deletions intercom/api_operations/find.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# -*- coding: utf-8 -*-
"""Operation to find an instance of a particular resource."""

from intercom import HttpError
from intercom import utils


class Find(object):
"""A mixin that provides `find` functionality."""

def find(self, **params):
"""Find the instance of the resource based on the supplied parameters."""
collection = utils.resource_class_to_collection_name(
self.collection_class)
if 'id' in params:
Expand Down
3 changes: 3 additions & 0 deletions intercom/api_operations/find_all.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# -*- coding: utf-8 -*-
"""Operation to find all instances of a particular resource."""

from intercom import utils
from intercom.collection_proxy import CollectionProxy


class FindAll(object):
"""A mixin that provides `find_all` functionality."""

def find_all(self, **params):
"""Find all instances of the resource based on the supplied parameters."""
collection = utils.resource_class_to_collection_name(
self.collection_class)
if 'id' in params and 'type' not in params:
Expand Down
3 changes: 3 additions & 0 deletions intercom/api_operations/load.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# -*- coding: utf-8 -*-
"""Operation to load an instance of a particular resource."""

from intercom import HttpError
from intercom import utils


class Load(object):
"""A mixin that provides `load` functionality."""

def load(self, resource):
"""Load the resource from the latest data in Intercom."""
collection = utils.resource_class_to_collection_name(
self.collection_class)
if hasattr(resource, 'id'):
Expand Down
30 changes: 7 additions & 23 deletions intercom/api_operations/save.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,22 @@
# -*- coding: utf-8 -*-
"""Operation to create or save an instance of a particular resource."""

from intercom import utils


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

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

# def from_dict(self, pdict):
# for key, value in list(pdict.items()):
# setattr(self, key, value)

# @property
# def to_dict(self):
# a_dict = {}
# for name in list(self.__dict__.keys()):
# if name == "changed_attributes":
# continue
# a_dict[name] = self.__dict__[name] # direct access
# return a_dict

# @classmethod
# def from_api(cls, response):
# obj = cls()
# obj.from_response(response)
# return obj

# def from_response(self, response):
# self.from_dict(response)
# return self

def save(self, obj):
"""Save the instance of the resource."""
collection = utils.resource_class_to_collection_name(
obj.__class__)
params = obj.attributes
Expand All @@ -50,12 +31,15 @@ def save(self, obj):
return obj.from_response(response)

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

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

def identity_hash(self, obj):
"""Return the identity_hash for this object."""
identity_vars = getattr(obj, 'identity_vars', [])
parts = {}
for var in identity_vars:
Expand Down
11 changes: 11 additions & 0 deletions intercom/extended_api_operations/reply.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,40 @@
# -*- coding: utf-8 -*-
"""Operations to manage conversations."""

from intercom import utils


class Reply(object):
"""A mixin that provides methods to manage a conversation.

This includes opening and closing them, assigning them to users, and
replying them.
"""

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

def close_conversation(self, **reply_data):
"""Close the conversation."""
reply_data['type'] = 'admin'
reply_data['message_type'] = 'close'
return self.__reply(reply_data)

def open_conversation(self, **reply_data):
"""Open the conversation."""
reply_data['type'] = 'admin'
reply_data['message_type'] = 'open'
return self.__reply(reply_data)

def assign(self, **reply_data):
"""Assign the conversation to an admin user."""
reply_data['type'] = 'admin'
reply_data['message_type'] = 'assignment'
return self.__reply(reply_data)

def __reply(self, reply_data):
"""Send the Conversation requests to Intercom and handl the responses."""
from intercom import Intercom
collection = utils.resource_class_to_collection_name(self.__class__)
url = "/%s/%s/reply" % (collection, self.id)
Expand Down
3 changes: 3 additions & 0 deletions intercom/extended_api_operations/users.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# -*- coding: utf-8 -*-
"""Operation to return all users for a particular Company."""

from intercom import utils
from intercom.collection_proxy import CollectionProxy


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

def users(self, id):
"""Return a CollectionProxy to all the users for the specified Company."""
collection = utils.resource_class_to_collection_name(
self.collection_class)
finder_url = "/%s/%s/users" % (collection, id)
Expand Down