My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# -*- coding: utf-8 -*-
# Marcelo Barros de Almeida
# marcelobarrosalmeida (at) gmail.com
# License: GPL3

import simplejson as json
import urllib

class QikApi(object):
""" Simple class for Qik videos proxy support
"""
def __init__(self, api_key, qik_usr):
""" Create a new Qik API instance with given API key and user name
"""
self.qik_url = 'http://engine.qik.com/api/jsonrpc?apikey=' + api_key
self.qik_usr = qik_usr
self.qik_id = -1

def __urlopener(self):
""" Return an urlopener with Qik required headers already set
"""
urlopener = urllib.URLopener()
urlopener.addheaders = [('Host','engine.qik.com'),
('Content-Type','application/json; charset=UTF-8')]
return urlopener

def __open(self,url,params=""):
""" Open a given URL using GET or POST and Qik headers
"""
if params:
f = self.__urlopener().open(url,params) #post
else:
f = self.__urlopener().open(url) #get

return f

def __qik_request(self,data):
""" Qik request. Encode data in json format, do the request and
decode json response
"""
data = json.dumps(data)
f = self.__open(self.qik_url,data)
res = json.loads(f.read())[0]
return res

def __check_id(self,qik_id):
""" Check if user ID was retrieved or not. If not, download it
"""
if qik_id == -1:
if self.qik_id == -1:
self.qik_id = self.get_user_public_profile()[u'id']
qik_id = self.qik_id
return qik_id

def get_public_user_streams(self,usr=''):
""" Return all public stream for a given user
(or for the current user, if it not provided)
"""
if not usr:
usr = self.qik_usr
data = {'method': 'qik.stream.public_user_streams','params': [usr]}
return self.__qik_request(data)

def get_user_public_profile(self,usr=''):
""" Return public profile for a given user
(or for the current user, if it not provided)
"""
if not usr:
usr = self.qik_usr
data = {'method': 'qik.user.public_profile','params': [usr]}
return self.__qik_request(data)

def get_user_public_detailed_profile(self,usr=''):
""" Return detailed public profile for a given user
(or for the current user, if it not provided)
"""
if not usr:
usr = self.qik_usr
data = {'method': 'qik.user.public_detailed_profile','params': [usr]}
return self.__qik_request(data)

def get_user_followers(self,qik_id=-1):
""" Return the list of followers for a given user
(or for the current user, if it not provided)
"""
qik_id = self.__check_id(qik_id)
data = {'method': 'qik.user.followers','params': [qik_id]}
return self.__qik_request(data)

def get_user_following(self,qik_id=-1):
""" Return the list of following for a given user
(or for the current user, if it not provided)
"""
qik_id = self.__check_id(qik_id)
data = {'method': 'qik.user.following','params': [qik_id]}
return self.__qik_request(data)

def get_public_stream_info(self,vid_id):
""" Get detailed information about some public video
"""
data = {'method': 'qik.stream.public_info','params': [vid_id]}
return self.__qik_request(data)

Change log

r647 by marcelobarrosalmeida on Aug 7, 2009   Diff
addind license
Go to: 
Project members, sign in to write a code review

Older revisions

r646 by marcelobarrosalmeida on Aug 7, 2009   Diff
Qik API first import
All revisions of this file

File info

Size: 3620 bytes, 102 lines

File properties

svn:eol-style
native
Powered by Google Project Hosting