|
| 1 | +from fivehundredpx import settings |
| 2 | +from fivehundredpx.auth import * |
| 3 | +from fivehundredpx.bind import bind_api |
| 4 | +from fivehundredpx.utils import * |
| 5 | + |
| 6 | +class FiveHundredPXAPI(object): |
| 7 | + |
| 8 | + def __init__(self,auth_handler=None,host=None,secure=True,version=None,retry_count=None,retry_delay=None,retry_errors=None): |
| 9 | + self.format = 'json' |
| 10 | + self.auth_handler = auth_handler |
| 11 | + self.secure = secure |
| 12 | + self.host = host or settings.API_HOST |
| 13 | + self.version = version or settings.API_VERSION |
| 14 | + self.retry_count = retry_count or settings.RETRY_COUNT |
| 15 | + self.retry_delay = retry_delay or settings.RETRY_DELAY |
| 16 | + self.retry_errors = retry_errors |
| 17 | + |
| 18 | + photos = bind_api(path='/photos') |
| 19 | + photos_search = bind_api(path='/photos/search') |
| 20 | + photos_id = bind_api(path='/photos/{id}', allowed_params=['id']) |
| 21 | + photos_post = bind_api(path='/photos', method='POST', require_auth=True) |
| 22 | + photos_delete = bind_api(path='/photos/{id}', method='DELETE', allowed_params=['id'],require_auth=True) |
| 23 | + photos_comments = bind_api(path='/photos/{id}/comments', allowed_params=['id']) |
| 24 | + photos_comments_post = bind_api(path='/photos/{id}/comments', method='POST', allowed_params=['id'], require_auth=True) |
| 25 | + photos_favorite_post = bind_api(path='/photos/{id}/favorite', method='POST', allowed_params=['id'], require_auth=True) |
| 26 | + photos_favorite_delete = bind_api(path='/photos/{id}/favorite', method='DELETE', allowed_params=['id'], require_auth=True) |
| 27 | + photos_tags_post = bind_api(path='/photos/{id}/tags', method='POST', allowed_params=['id'], require_auth=True) |
| 28 | + photos_tags_delete = bind_api(path='/photos/{id}/tags', method='DELETE', allowed_params=['id'], require_auth=True) |
| 29 | + photos_vote_post = bind_api(path='/photos/{id}/vote', method='POST', allowed_params=['id'], require_auth=True) |
| 30 | + |
| 31 | + def upload_photo(self, filename=None,fp=None,file_type=None, **kwargs): |
| 32 | + headers,body = create_body_by_filepath(filename,'file',kwargs) if fp==None else create_body_by_fp(fp, 'file', file_type, kwargs) |
| 33 | + return bind_api( |
| 34 | + path = '/upload', |
| 35 | + method = 'POST', |
| 36 | + require_auth = True |
| 37 | + )(self,http_body=body, headers=headers) |
| 38 | + |
| 39 | + def photos_update(self, id, **kwargs): |
| 40 | + headers,body = create_body(kwargs) |
| 41 | + return bind_api( |
| 42 | + path='/photos/{id}', |
| 43 | + method = 'PUT', |
| 44 | + allowed_params=['id'], |
| 45 | + require_auth = True |
| 46 | + )(self,id=id, http_body=body, headers=headers) |
| 47 | + |
| 48 | + users = bind_api(path='/users', require_auth=True) |
| 49 | + users_show = bind_api(path='/users/show') |
| 50 | + users_friends = bind_api(path='/users/{id}/friends', allowed_params=['id']) |
| 51 | + users_followers = bind_api(path='/users/{id}/followers', allowed_params=['id']) |
| 52 | + users_friends_post = bind_api(path='/users/{id}/friends', method='POST', allowed_params=['id']) |
| 53 | + users_friends_delete = bind_api(path='/users/{id}/friends', method='DELETE', allowed_params=['id']) |
| 54 | + |
| 55 | + blogs = bind_api(path='/blogs') |
| 56 | + blogs_id = bind_api(path='/blogs/{id}', allowed_params=['id']) |
| 57 | + blogs_comments = bind_api(path='/blogs/{id}/comments', allowed_params=['id']) |
| 58 | + blogs_comments_post = bind_api(path='/blogs/{id}/comments', require_auth=True, allowed_params=['id'], method='POST') |
| 59 | + blogs_post = bind_api(path='/blogs', require_auth=True, method='POST') |
| 60 | + blogs_delete = bind_api(path='/blogs/{id}', require_auth=True, allowed_params=['id'], method='DELETE') |
| 61 | + |
| 62 | + def blogs_update(self, id, **kwargs): |
| 63 | + headers,body = create_body(kwargs) |
| 64 | + return bind_api( |
| 65 | + path='/blogs/{id}', |
| 66 | + method = 'PUT', |
| 67 | + allowed_params=['id'], |
| 68 | + require_auth = True |
| 69 | + )(self,id=id, http_body=body, headers=headers) |
| 70 | + |
| 71 | + collections = bind_api(path='/collections') |
| 72 | + collections_id = bind_api(path='/collections/{id}', allowed_params=['id']) |
| 73 | + collections_post = bind_api(path='/collections', require_auth=True, method='POST') |
| 74 | + collections_update = bind_api(path='/collections/{id}', require_auth=True, method='POST', allowed_params=['id']) |
| 75 | + collections_delete = bind_api(path='/collections/{id}', require_auth=True, method='DELETE', allowed_params=['id']) |
0 commit comments