Skip to content
This repository was archived by the owner on Jul 19, 2022. It is now read-only.

Commit 8bb2e76

Browse files
author
Brandon Tweed
authored
Merge pull request #43 from podio/view-support
Add filter_by_view method for Item and some cleanup.
2 parents 673fa8c + fdede62 commit 8bb2e76

12 files changed

+262
-63
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ dist
88
.virtualenv
99
*.egg
1010
*.egg-info
11+
idea
12+
env

pypodio2/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# -*- coding: utf-8 -*-
1+
# -*- coding: utf-8 -*-

pypodio2/adapters.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
try:
2-
import json
3-
except ImportError:
4-
import simplejson as json
1+
2+
import json
53

64
from .client import FailedRequest
75

6+
87
def json_response(resp):
98
try:
109
return json.loads(resp)
1110
except:
1211
raise FailedRequest(resp)
1312

13+
1414
def http_request(method, *args, **kwargs):
1515
print("Called")

pypodio2/areas.py

+94-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
try:
3-
import json
4-
except ImportError:
5-
import simplejson as json
2+
import json
63

74
try:
85
from urllib.parse import urlencode
@@ -44,6 +41,7 @@ def get_options(silent=False, hook=True):
4441
else:
4542
return ''
4643

44+
4745
class Embed(Area):
4846

4947
def __init__(self, *args, **kwargs):
@@ -55,6 +53,7 @@ def create(self, attributes):
5553
attributes = json.dumps(attributes)
5654
return self.transport.POST(url='/embed/', body=attributes, type='application/json')
5755

56+
5857
class Contact(Area):
5958

6059
def __init__(self, *args, **kwargs):
@@ -79,13 +78,13 @@ def searchApp(self, app_id, attributes):
7978
return self.transport.POST(url='/search/app/%d/' % app_id, body=attributes, type='application/json')
8079

8180

82-
8381
class Item(Area):
8482
def find(self, item_id, basic=False, **kwargs):
8583
"""
8684
Get item
8785
8886
:param item_id: Item ID
87+
:param basic: ?
8988
:type item_id: int
9089
:return: Item info
9190
:rtype: dict
@@ -101,6 +100,9 @@ def filter(self, app_id, attributes, **kwargs):
101100
return self.transport.POST(url="/item/app/%d/filter/" % app_id, body=attributes,
102101
type="application/json", **kwargs)
103102

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+
104106
def find_all_by_external_id(self, app_id, external_id):
105107
return self.transport.GET(url='/item/app/%d/v2/?external_id=%r' % (app_id, external_id))
106108

@@ -271,7 +273,7 @@ def create(self, attributes, silent=False, hook=True):
271273
Podio will send no notifications to subscribed users and not post
272274
updates to the stream. If 'hook' is false webhooks will not be called.
273275
"""
274-
#if not isinstance(attributes, dict):
276+
# if not isinstance(attributes, dict):
275277
# raise TypeError('Must be of type dict')
276278
attributes = json.dumps(attributes)
277279
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):
284286
If 'silent' is true, Podio will send no notifications and not post
285287
updates to the stream. If 'hook' is false webhooks will not be called.
286288
"""
287-
#if not isinstance(attributes, dict):
289+
# if not isinstance(attributes, dict):
288290
# raise TypeError('Must be of type dict')
289291
attributes = json.dumps(attributes)
290292
return self.transport.POST(body=attributes,
@@ -323,6 +325,7 @@ def find_by_url(self, space_url, id_only=True):
323325
Returns a space ID given the URL of the space.
324326
325327
:param space_url: URL of the Space
328+
:param id_only: ?
326329
:return: space_id: Space url
327330
:rtype: str
328331
"""
@@ -526,3 +529,87 @@ def copy(self, file_id):
526529
"""Copy a file to generate a new file_id"""
527530

528531
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+

pypodio2/client.py

+2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55

66
class FailedRequest(Exception):
77
def __init__(self, error):
8+
super(FailedRequest).__init__()
89
self.error = error
910

1011
def __str__(self):
1112
return repr(self.error)
1213

1314

15+
# noinspection PyMethodMayBeStatic
1416
class Client(object):
1517
"""
1618
The Podio API client. Callers should use the factory method OAuthClient to create instances.

0 commit comments

Comments
 (0)