API پارسااسپیس ۲

shape
shape
shape
shape
shape
shape
shape
shape
یک API می تواند رابط میان یک برنامه و سیستم عامل را مشخص کند

در مقاله قبل در مورد API پارسااسپیس 1 توضیح دادیم در این مقاله در مورد API پارسااسپیس 2 توضیح میدهیم .

تغییر نام

تغییر نام فایل مورد نظر به نام دلخواه

نمونه کدها:

.NET

var client = new RestClient(“http://api.parsaspace.com/v1/files/rename”);
var request = new RestRequest(Method.POST);
request.AddHeader(“authorization”,”Bearer yourtoken”);
request.AddHeader(“content-type”, “application/x-www-form-urlencoded”);
request.AddParameter(“domain”,”yourdomain”);
request.AddParameter(“source”,”/”);
request.AddParameter(“destinition”,”/”);
IRestResponse response = client.Execute(request);

PHP

$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => “http://api.parsaspace.com/v1/files/rename”,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_RETURNTRANSFER=>true,
CURLOPT_CUSTOMREQUEST => “POST”,
CURLOPT_POSTFIELDS => “source=%2Ftest-1&destination=%2Ftest-4&domain=yourdomain&type=json”,
CURLOPT_HTTPHEADER => array(
“authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1bmlxdWVfbmFtZSI6InNhZWlkbWFyb3VmaTY2QGd”,
“cache-control: no-cache”,
“content-type: application/x-www-form-urlencoded”,
),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo “cURL Error #:” . $err;
} else {
echo $response;
}

Java

HttpResponse response = Unirest.post(“http://api.parsaspace.com/v1/files/rename”)
.header(“content-type”, “application/x-www-form-urlencoded”)
.header(“authorization”, “Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1bmlxdWVfbmFtZSI6InNhZWlkbWFyb3VmaTY2QGd”)
.body(“source=%2Ftest-1&destination=%2Ftest-4&domain=yourdomain&type=json”)
.asString();

python

import requests
url = “http://api.parsaspace.com/v1/files/rename”

payload = “source=%2Ftest-1&destination=%2Ftest-4&domain=yourdomain&type=json”
headers = {
‘content-type’: “application/x-www-form-urlencoded”,
‘authorization’: “Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1bmlxdWVfbmFtZSI6InNhZWlkbWFyb3VmaTY2QGd”,
}

esponse = requests.request(“POST”, url, data=payload, headers=headers)

print(response.text)

Node.js

var request = require(“request”);
var options = { method: ‘POST’,
url: ‘http://api.parsaspace.com/v1/files/rename’,
headers:
{
authorization: ‘Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1bmlxdWVfbmFtZSI6InNhZWlkbWFyb3VmaTY2QGd’,
‘content-type’: ‘application/x-www-form-urlencoded’ },
form:
{ source: ‘/test-1’,
destination: ‘/test-4’,
domain: ‘yourdomain’,
type: ‘json’ } };
request(options, function (error, response, body) {
if (error) throw new Error(error);

console.log(body);
});

نمونه پاسخ ( خطاها 

خطا 200:

{
“result”: “ok”,
}

{
“result”: “operation failed”,
}

خطا 400

{
“result”: “error”,
“message”: “Object already exist.”,
}

خطا 403:

{
“result”: “error”,
“message”: “Sorry!Access denied”,
}

در این مقاله در مورد API پارسااسپیس 2 توضیح دادیم در مقاله بعد در مورد API پارسااسپیس3 توضیح میدهیم

منبع

دیدگاهتان را بنویسید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *