Skip to content

Commit 2bfbbaa

Browse files
committed
Merge pull request #98 from dtynn/feature/new_api
gist:new api
2 parents 57eadd0 + 1673ec7 commit 2bfbbaa

File tree

4 files changed

+103
-0
lines changed

4 files changed

+103
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
## CHANGE LOG
22

3+
### v6.1.5
4+
5+
2014-04-08 issue [#98](https://github.com/qiniu/python-sdk/pull/98)
6+
7+
- [#98] 增加fetch、prefetch、pfop三个接口的范例代码
8+
39
### v6.1.4
410

511
2014-03-28 issue [#95](https://github.com/qiniu/python-sdk/pull/95)

docs/gist/fetch.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#coding=utf-8
2+
import sys
3+
sys.path.insert(0, "../../")
4+
5+
from base64 import urlsafe_b64encode as b64e
6+
from qiniu.auth import digest
7+
8+
access_key = ""
9+
secret_key = ""
10+
11+
target_url = ""
12+
dest_bucket = ""
13+
dest_key = ""
14+
15+
encoded_url = b64e(target_url)
16+
dest_entry = "%s:%s" % (dest_bucket, dest_key)
17+
encoded_entry = b64e(dest_entry)
18+
19+
20+
api_host = "iovip.qbox.me"
21+
api_path = "/fetch/%s/to/%s" % (encoded_url, encoded_entry)
22+
23+
mac = digest.Mac(access=access_key, secret=secret_key)
24+
client = digest.Client(host=api_host, mac=mac)
25+
26+
ret, err = client.call(path=api_path)
27+
if err is not None:
28+
print "failed"
29+
print err
30+
else:
31+
print "success"

docs/gist/pfop.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#coding=utf-8
2+
import sys
3+
sys.path.insert(0, "../../")
4+
5+
from urllib import quote
6+
from qiniu.auth import digest
7+
8+
access_key = ""
9+
secret_key = ""
10+
11+
bucket = ""
12+
key = ""
13+
fops = ""
14+
notify_url = ""
15+
force = False
16+
17+
api_host = "api.qiniu.com"
18+
api_path = "/pfop/"
19+
body = "bucket=%s&key=%s&fops=%s&notifyURL=%s" % \
20+
(quote(bucket), quote(key), quote(fops), quote(notify_url))
21+
22+
body = "%s&force=1" % (body,) if force is not False else body
23+
24+
content_type = "application/x-www-form-urlencoded"
25+
content_length = len(body)
26+
27+
mac = digest.Mac(access=access_key, secret=secret_key)
28+
client = digest.Client(host=api_host, mac=mac)
29+
30+
ret, err = client.call_with(path=api_path, body=body,
31+
content_type=content_type, content_length=content_length)
32+
if err is not None:
33+
print "failed"
34+
print err
35+
else:
36+
print "success"
37+
print ret

docs/gist/prefetch.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#coding=utf-8
2+
import sys
3+
sys.path.insert(0, "../../")
4+
5+
from base64 import urlsafe_b64encode as b64e
6+
from qiniu.auth import digest
7+
8+
access_key = ""
9+
secret_key = ""
10+
11+
bucket = ""
12+
key = ""
13+
14+
entry = "%s:%s" % (bucket, key)
15+
encoded_entry = b64e(entry)
16+
17+
18+
api_host = "iovip.qbox.me"
19+
api_path = "/prefetch/%s" % (encoded_entry,)
20+
21+
mac = digest.Mac(access=access_key, secret=secret_key)
22+
client = digest.Client(host=api_host, mac=mac)
23+
24+
ret, err = client.call(path=api_path)
25+
if err is not None:
26+
print "failed"
27+
print err
28+
else:
29+
print "success"

0 commit comments

Comments
 (0)