Skip to content

gist:new api #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 8, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## CHANGE LOG

### v6.1.5

2014-04-08 issue [#98](https://github.com/qiniu/python-sdk/pull/98)

- [#98] 增加fetch、prefetch、pfop三个接口的范例代码

### v6.1.4

2014-03-28 issue [#95](https://github.com/qiniu/python-sdk/pull/95)
Expand Down
31 changes: 31 additions & 0 deletions docs/gist/fetch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#coding=utf-8
import sys
sys.path.insert(0, "../../")

from base64 import urlsafe_b64encode as b64e
from qiniu.auth import digest

access_key = ""
secret_key = ""

target_url = ""
dest_bucket = ""
dest_key = ""

encoded_url = b64e(target_url)
dest_entry = "%s:%s" % (dest_bucket, dest_key)
encoded_entry = b64e(dest_entry)


api_host = "iovip.qbox.me"
api_path = "/fetch/%s/to/%s" % (encoded_url, encoded_entry)

mac = digest.Mac(access=access_key, secret=secret_key)
client = digest.Client(host=api_host, mac=mac)

ret, err = client.call(path=api_path)
if err is not None:
print "failed"
print err
else:
print "success"
37 changes: 37 additions & 0 deletions docs/gist/pfop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#coding=utf-8
import sys
sys.path.insert(0, "../../")

from urllib import quote
from qiniu.auth import digest

access_key = ""
secret_key = ""

bucket = ""
key = ""
fops = ""
notify_url = ""
force = False

api_host = "api.qiniu.com"
api_path = "/pfop/"
body = "bucket=%s&key=%s&fops=%s&notifyURL=%s" % \
(quote(bucket), quote(key), quote(fops), quote(notify_url))

body = "%s&force=1" % (body,) if force is not False else body

content_type = "application/x-www-form-urlencoded"
content_length = len(body)

mac = digest.Mac(access=access_key, secret=secret_key)
client = digest.Client(host=api_host, mac=mac)

ret, err = client.call_with(path=api_path, body=body,
content_type=content_type, content_length=content_length)
if err is not None:
print "failed"
print err
else:
print "success"
print ret
29 changes: 29 additions & 0 deletions docs/gist/prefetch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#coding=utf-8
import sys
sys.path.insert(0, "../../")

from base64 import urlsafe_b64encode as b64e
from qiniu.auth import digest

access_key = ""
secret_key = ""

bucket = ""
key = ""

entry = "%s:%s" % (bucket, key)
encoded_entry = b64e(entry)


api_host = "iovip.qbox.me"
api_path = "/prefetch/%s" % (encoded_entry,)

mac = digest.Mac(access=access_key, secret=secret_key)
client = digest.Client(host=api_host, mac=mac)

ret, err = client.call(path=api_path)
if err is not None:
print "failed"
print err
else:
print "success"