mirror of https://github.com/Chocobozzz/PeerTube
Fix Ruby and Python REST API examples
The previous examples where wrong, since they used a POST request. I used the requests library for Python, since that is what most people would want to use. I removed the http.verify_mode in the Ruby example since I don't think it is good practice to tell people to not verify HTTPS requestspull/2258/head
parent
e8e09e27ff
commit
f6d51cfe2a
|
@ -160,35 +160,25 @@ paths:
|
||||||
http -b GET https://peertube2.cpy.re/api/v1/accounts/{name}/videos
|
http -b GET https://peertube2.cpy.re/api/v1/accounts/{name}/videos
|
||||||
- lang: Ruby
|
- lang: Ruby
|
||||||
source: |
|
source: |
|
||||||
require 'uri'
|
|
||||||
require 'net/http'
|
require 'net/http'
|
||||||
|
require 'json'
|
||||||
|
|
||||||
url = URI("https://peertube2.cpy.re/api/v1/accounts/{name}/videos")
|
uri = URI.parse("https://peertube2.cpy.re/api/v1/accounts/{name}/videos")
|
||||||
|
|
||||||
http = Net::HTTP.new(url.host, url.port)
|
http = Net::HTTP.new(uri.host, uri.port)
|
||||||
http.use_ssl = true
|
http.use_ssl = true
|
||||||
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
||||||
|
|
||||||
request = Net::HTTP::Post.new(url)
|
response = http.get(uri.request_uri)
|
||||||
request["content-type"] = 'application/json'
|
|
||||||
response = http.request(request)
|
puts JSON.parse(response.read_body)
|
||||||
puts response.read_body
|
|
||||||
- lang: Python
|
- lang: Python
|
||||||
source: |
|
source: |
|
||||||
import http.client
|
import requests
|
||||||
|
|
||||||
conn = http.client.HTTPSConnection("https://peertube2.cpy.re/api/v1")
|
r = requests.get("https://peertube2.cpy.re/api/v1//accounts/{name}/videos")
|
||||||
|
json = r.json()
|
||||||
|
|
||||||
headers = {
|
print(json)
|
||||||
'content-type': "application/json"
|
|
||||||
}
|
|
||||||
|
|
||||||
conn.request("POST", "/accounts/{name}/videos", None, headers)
|
|
||||||
|
|
||||||
res = conn.getresponse()
|
|
||||||
data = res.read()
|
|
||||||
|
|
||||||
print(data.decode("utf-8"))
|
|
||||||
/accounts:
|
/accounts:
|
||||||
get:
|
get:
|
||||||
tags:
|
tags:
|
||||||
|
|
Loading…
Reference in New Issue