|
1 | | -# coding=utf-8 |
2 | | -# |
3 | | -# Copyright 2013 keyes.ie |
4 | | -# |
5 | | -# License: http://jkeyes.mit-license.org/ |
6 | | -# |
7 | | -""" Tag module. |
| 1 | +from intercom.user import Resource |
| 2 | +from intercom.api_operations.count import Count |
| 3 | +from intercom.api_operations.find import Find |
8 | 4 |
|
9 | | ->>> from intercom import Intercom |
10 | | ->>> Intercom.app_id = 'dummy-app-id' |
11 | | ->>> Intercom.api_key = 'dummy-api-key' |
12 | | ->>> from intercom.tag import Tag |
13 | 5 |
|
14 | | -""" |
15 | | - |
16 | | -from . import Intercom |
17 | | - |
18 | | - |
19 | | -class Tag(dict): |
20 | | - """ Represents a tag. """ |
21 | | - |
22 | | - @classmethod |
23 | | - def find(cls, **params): |
24 | | - """ Find a tag using params. |
25 | | -
|
26 | | - >>> tag = Tag.find(name="Free Trial") |
27 | | - >>> tag.id != None |
28 | | - True |
29 | | - >>> tag.name |
30 | | - u'Free Trial' |
31 | | - >>> tag.tagged_user_count |
32 | | - 2 |
33 | | -
|
34 | | - """ |
35 | | - resp = Intercom.get_tag(**params) |
36 | | - return cls(resp) |
37 | | - |
38 | | - @classmethod |
39 | | - def find_by_name(cls, name): |
40 | | - """ Find a tag by name. |
41 | | -
|
42 | | - >>> tag = Tag.find_by_name("Free Trial") |
43 | | - >>> tag.id != None |
44 | | - True |
45 | | - >>> tag.name |
46 | | - u'Free Trial' |
47 | | - >>> tag.tagged_user_count |
48 | | - 2 |
49 | | -
|
50 | | - """ |
51 | | - return Tag.find(name=name) |
52 | | - |
53 | | - @classmethod |
54 | | - def create( |
55 | | - cls, name, tag_or_untag, user_ids=None, emails=None): |
56 | | - """ Create a new tag an optionally tag user. |
57 | | -
|
58 | | - >>> tag = Tag.create(user_ids=["abc123", "def456"], |
59 | | - ... name="Free Trial", tag_or_untag="tag") |
60 | | - >>> tag.id != None |
61 | | - True |
62 | | - >>> tag.name |
63 | | - u'Free Trial' |
64 | | - >>> tag.tagged_user_count |
65 | | - 2 |
66 | | -
|
67 | | - """ |
68 | | - resp = Intercom.create_tag( |
69 | | - name, tag_or_untag, user_ids=user_ids, emails=emails) |
70 | | - return cls(resp) |
71 | | - |
72 | | - def save(self): |
73 | | - """ Update a tag: |
74 | | -
|
75 | | - >>> tag = Tag() |
76 | | - >>> tag.user_ids = ["abc123", "def456"] |
77 | | - >>> tag.name = "Free Trial" |
78 | | - >>> tag.tag_or_untag = "tag" |
79 | | - >>> tag.save() |
80 | | - >>> tag.tagged_user_count |
81 | | - 2 |
82 | | -
|
83 | | - """ |
84 | | - resp = Intercom.update_tag( |
85 | | - self.name, self.get('tag_or_untag', None), |
86 | | - user_ids=self.get('user_ids', None), |
87 | | - emails=self.get('emails', None)) |
88 | | - self.update(resp) |
89 | | - |
90 | | - @property |
91 | | - def name(self): |
92 | | - """ Get the name of the tag. """ |
93 | | - return dict.get(self, 'name', None) |
94 | | - |
95 | | - @name.setter |
96 | | - def name(self, name): |
97 | | - """ Get the name of the tag. """ |
98 | | - self['name'] = name |
99 | | - |
100 | | - @property |
101 | | - def id(self): |
102 | | - """ The id of the tag. """ |
103 | | - return dict.get(self, 'id', None) |
104 | | - |
105 | | - @property |
106 | | - def segment(self): |
107 | | - """ Get the segment of the tag. """ |
108 | | - return dict.get(self, 'segment', None) |
109 | | - |
110 | | - @property |
111 | | - def tagged_user_count(self): |
112 | | - """ Get the tagged_user_count of the tag. """ |
113 | | - return dict.get(self, 'tagged_user_count', None) |
114 | | - |
115 | | - @property |
116 | | - def tag_or_untag(self): |
117 | | - """ The tag_or_untag of the tag. """ |
118 | | - raise AttributeError("tag_or_untag is a write-only property") |
119 | | - |
120 | | - @tag_or_untag.setter |
121 | | - def tag_or_untag(self, tag_or_untag): |
122 | | - """ The tag_or_untag of the tag. """ |
123 | | - self['tag_or_untag'] = tag_or_untag |
124 | | - |
125 | | - @property |
126 | | - def user_ids(self): |
127 | | - """ The user_ids of the tag. """ |
128 | | - raise AttributeError("user_ids is a write-only property") |
129 | | - |
130 | | - @user_ids.setter |
131 | | - def user_ids(self, user_ids): |
132 | | - """ The user_ids of the tag. """ |
133 | | - self['user_ids'] = user_ids |
134 | | - |
135 | | - @property |
136 | | - def emails(self): |
137 | | - """ The emails of the tag. """ |
138 | | - raise AttributeError("emails is a write-only property") |
139 | | - |
140 | | - @emails.setter |
141 | | - def emails(self, emails): |
142 | | - """ The emails of the tag. """ |
143 | | - self['emails'] = emails |
| 6 | +class Tag(Resource, Find, Count): |
| 7 | + pass |
0 commit comments