1
1
# -*- coding: utf-8 -*-
2
- try :
3
- import json
4
- except ImportError :
5
- import simplejson as json
2
+ import json
6
3
7
4
try :
8
5
from urllib .parse import urlencode
@@ -44,6 +41,7 @@ def get_options(silent=False, hook=True):
44
41
else :
45
42
return ''
46
43
44
+
47
45
class Embed (Area ):
48
46
49
47
def __init__ (self , * args , ** kwargs ):
@@ -55,6 +53,7 @@ def create(self, attributes):
55
53
attributes = json .dumps (attributes )
56
54
return self .transport .POST (url = '/embed/' , body = attributes , type = 'application/json' )
57
55
56
+
58
57
class Contact (Area ):
59
58
60
59
def __init__ (self , * args , ** kwargs ):
@@ -79,13 +78,13 @@ def searchApp(self, app_id, attributes):
79
78
return self .transport .POST (url = '/search/app/%d/' % app_id , body = attributes , type = 'application/json' )
80
79
81
80
82
-
83
81
class Item (Area ):
84
82
def find (self , item_id , basic = False , ** kwargs ):
85
83
"""
86
84
Get item
87
85
88
86
:param item_id: Item ID
87
+ :param basic: ?
89
88
:type item_id: int
90
89
:return: Item info
91
90
:rtype: dict
@@ -101,6 +100,9 @@ def filter(self, app_id, attributes, **kwargs):
101
100
return self .transport .POST (url = "/item/app/%d/filter/" % app_id , body = attributes ,
102
101
type = "application/json" , ** kwargs )
103
102
103
+ def filter_by_view (self , app_id , view_id ):
104
+ return self .transport .POST (url = "/item/app/{}/filter/{}" .format (app_id , view_id ))
105
+
104
106
def find_all_by_external_id (self , app_id , external_id ):
105
107
return self .transport .GET (url = '/item/app/%d/v2/?external_id=%r' % (app_id , external_id ))
106
108
@@ -271,7 +273,7 @@ def create(self, attributes, silent=False, hook=True):
271
273
Podio will send no notifications to subscribed users and not post
272
274
updates to the stream. If 'hook' is false webhooks will not be called.
273
275
"""
274
- #if not isinstance(attributes, dict):
276
+ # if not isinstance(attributes, dict):
275
277
# raise TypeError('Must be of type dict')
276
278
attributes = json .dumps (attributes )
277
279
return self .transport .POST (url = '/task/%s' % self .get_options (silent = silent , hook = hook ),
@@ -284,7 +286,7 @@ def create_for(self, ref_type, ref_id, attributes, silent=False, hook=True):
284
286
If 'silent' is true, Podio will send no notifications and not post
285
287
updates to the stream. If 'hook' is false webhooks will not be called.
286
288
"""
287
- #if not isinstance(attributes, dict):
289
+ # if not isinstance(attributes, dict):
288
290
# raise TypeError('Must be of type dict')
289
291
attributes = json .dumps (attributes )
290
292
return self .transport .POST (body = attributes ,
@@ -323,6 +325,7 @@ def find_by_url(self, space_url, id_only=True):
323
325
Returns a space ID given the URL of the space.
324
326
325
327
:param space_url: URL of the Space
328
+ :param id_only: ?
326
329
:return: space_id: Space url
327
330
:rtype: str
328
331
"""
@@ -526,3 +529,87 @@ def copy(self, file_id):
526
529
"""Copy a file to generate a new file_id"""
527
530
528
531
return self .transport .POST (url = '/file/%s/copy' % file_id )
532
+
533
+
534
+ class View (Area ):
535
+
536
+ def create (self , app_id , attributes ):
537
+ """
538
+ Creates a new view on the specified app
539
+
540
+ :param app_id: the application id
541
+ :param attributes: the body of the request as a dictionary
542
+ """
543
+ if not isinstance (attributes , dict ):
544
+ raise TypeError ('Must be of type dict' )
545
+ attributes = json .dumps (attributes )
546
+ return self .transport .POST (url = '/view/app/{}/' .format (app_id ),
547
+ body = attributes , type = 'application/json' )
548
+
549
+ def delete (self , view_id ):
550
+ """
551
+ Delete the associated view
552
+
553
+ :param view_id: id of the view to delete
554
+ """
555
+ return self .transport .DELETE (url = '/view/{}' .format (view_id ))
556
+
557
+ def get (self , app_id , view_specifier ):
558
+ """
559
+ Retrieve the definition of a given view, provided the app_id and the view_id
560
+
561
+ :param app_id: the app id
562
+ :param view_specifier:
563
+ Can be one of the following:
564
+ 1. The view ID
565
+ 2. The view's name
566
+ 3. "last" to look up the last view used
567
+ """
568
+ return self .transport .GET (url = '/view/app/{}/{}' .format (app_id , view_specifier ))
569
+
570
+ def get_views (self , app_id , include_standard_views = False ):
571
+ """
572
+ Get all of the views for the specified app
573
+
574
+ :param app_id: the app containing the views
575
+ :param include_standard_views: defaults to false. Set to true if you wish to include standard views.
576
+ """
577
+ include_standard = "true" if include_standard_views is True else "false"
578
+ return self .transport .GET (url = '/view/app/{}/?include_standard_views={}' .format (app_id , include_standard ))
579
+
580
+ def make_default (self , view_id ):
581
+ """
582
+ Makes the view with the given id the default view for the app. The view must be of type
583
+ "saved" and must be active. In addition the user most have right to update the app.
584
+
585
+ :param view_id: the unique id of the view you wish to make the default
586
+ """
587
+ return self .transport .POST (url = '/view/{}/default' .format (view_id ))
588
+
589
+ def update_last_view (self , app_id , attributes ):
590
+ """
591
+ Updates the last view for the active user
592
+
593
+ :param app_id: the app id
594
+ :param attributes: the body of the request in dictionary format
595
+ """
596
+ if not isinstance (attributes , dict ):
597
+ raise TypeError ('Must be of type dict' )
598
+ attribute_data = json .dumps (attributes )
599
+ return self .transport .PUT (url = '/view/app/{}/last' .format (app_id ),
600
+ body = attribute_data , type = 'application/json' )
601
+
602
+ def update_view (self , view_id , attributes ):
603
+ """
604
+ Update an existing view using the details supplied via the attributes parameter
605
+
606
+ :param view_id: the view's id
607
+ :param attributes: a dictionary containing the modifications to be made to the view
608
+ :return:
609
+ """
610
+ if not isinstance (attributes , dict ):
611
+ raise TypeError ('Must be of type dict' )
612
+ attribute_data = json .dumps (attributes )
613
+ return self .transport .PUT (url = '/view/{}' .format (view_id ),
614
+ body = attribute_data , type = 'application/json' )
615
+
0 commit comments