Optisway’de bir proje, bir web sitesinin veya uygulamanın testlerini adresi ve açıklamasıyla bir araya getirir. Tek bir projeyle sınırlı bir anahtar yalnızca o projeyi görür; kapsamı olmayan bir anahtar organizasyonun tüm projelerini görür.
Project
Test sayısı ve en son çalıştırmasıyla bir proje.
Alanlar: Project
Alan
Tür
Açıklama
id
string
Projenin ondalık bir dize olarak kimliği.
name
string
Projenin uygulamada gösterilen adı.
url
string
Projenin kapsadığı web sitesi adresi.
description
string
Projenin açıklaması; açıklama yazılmamışsa boş bir dize.
testCount
integer
Projedeki test sayısı.
lastRun
RunSummary | null
Projedeki herhangi bir testin en yeni çalıştırması (RunSummary) ya da ilk çalıştırmadan önce null.
createdAt
ISO 8601 string
Projenin oluşturulduğu zaman (UTC).
updatedAt
ISO 8601 string
Projenin son değiştirildiği zaman (UTC).
links.self
string
Bu projenin yolu (GET /projects/{id}).
links.tests
string
Bu projenin testlerini listeleyen yol (GET /tests?project={id}).
Anahtarın kuruluşuna ait projeleri listeler; projeye bağlı bir anahtar yalnızca kendi projesini görür. read erişimi gerekir ve liste sayfalara bölünmez. Örnek, tek projesi (42) olan bir kuruluşu gösterir.
// Java 11+: save as Main.java and run `java Main.java`import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public classMain {
public static void main(String[] args) throwsException {
String url = "https://optisway.com/api/v1/projects";
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
.header("Authorization", "Bearer " + System.getenv("OPTISWAY_API_KEY"))
.build();
HttpResponse<String> response = HttpClient.newHttpClient()
.send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() >= 300) {
String error = response.body();
System.err.println(response.statusCode() + " " + field(error, "error") + ": "
+ field(error, "message"));
System.exit(1);
}
// { "items": [...], "next": ... } -- any JSON library (Jackson, Gson, org.json) parses it;// this example stays dependency-free and prints the raw JSON.System.out.println(response.body());
}
/** The first string value of a JSON key (dependency-free; Jackson or Gson parse JSON properly). */static String field(String json, String key) {
Matcher match = Pattern.compile("\"" + key + "\"\\s*:\\s*(?:\"((?:[^\"\\\\]|\\\\.)*)\"|null)")
.matcher(json);
return match.find() ? match.group(1) : null;
}
}
package main
import (
"encoding/json""fmt""net/http""os"
)
func main() {
url := "https://optisway.com/api/v1/projects"
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
panic(err)
}
req.Header.Set("Authorization", "Bearer "+os.Getenv("OPTISWAY_API_KEY"))
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
if resp.StatusCode >= 300 {
var envelope struct {
Error string`json:"error"`
Message string`json:"message"`
}
_ = json.NewDecoder(resp.Body).Decode(&envelope)
fmt.Fprintf(os.Stderr, "%d %s: %s\n", resp.StatusCode, envelope.Error, envelope.Message)
os.Exit(1)
}
var body map[string]anyif err := json.NewDecoder(resp.Body).Decode(&body); err != nil {
panic(err)
}
for _, raw := range body["items"].([]any) {
item := raw.(map[string]any)
fmt.Println(item["id"], item["name"])
}
}
// .NET 8: `dotnet new console`, replace Program.cs with this file, then `dotnet run`usingSystem.Net.Http.Headers;
usingSystem.Net.Http.Json;
usingSystem.Text.Json;
using var client = newHttpClient();
client.DefaultRequestHeaders.Authorization =
newAuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("OPTISWAY_API_KEY"));
var url = "https://optisway.com/api/v1/projects";
using var response = await client.GetAsync(url);
if (!response.IsSuccessStatusCode)
{
var envelope = await response.Content.ReadFromJsonAsync<JsonElement>();
var error = envelope.GetProperty("error");
var message = envelope.GetProperty("message");
Console.Error.WriteLine($"{(int)response.StatusCode}{error}: {message}");
Environment.Exit(1);
}
var body = await response.Content.ReadFromJsonAsync<JsonElement>();
foreach (var item in body.GetProperty("items").EnumerateArray())
{
Console.WriteLine(string.Join(" ",
item.GetProperty("id"), item.GetProperty("name")));
}
Örnek yanıt
Döndürür:items dizisinde Project nesneleri bulunan bir nesne.
unauthorized401 Anahtar eksik, hatalı biçimli, bilinmiyor, iptal edilmiş veya süresi dolmuş ya da onu oluşturan kişi artık üye değil.
rate_limited429 Anahtar çok fazla istek gönderdi; Retry-After içindeki saniye kadar bekleyin.
unavailable503 Bizim tarafımızda geçici bir sorun var; daha sonra tekrar deneyin.
Projeyi getirGET/projects/{id}
Bir projeyi sayısal kimliğiyle getirir. read erişimi gerekir; anahtarın kapsamı dışındaki bir proje, hiç var olmayan bir proje gibi 404 not_found yanıtı verir. Örnek, lastRun değeri başarısız çalıştırma 4821 olan 42 numaralı projeyi getirir.
Gereken anahtar erişimi: Okuma
Parametreler
Parametreler: GET /projects/{id}
Ad
Konum
Tür
Zorunlu
Açıklama
Örnek
id
Yol
string (numeric project id)
Evet
Projenin Project.id alanında döndürülen sayısal kimliği.
// .NET 8: `dotnet new console`, replace Program.cs with this file, then `dotnet run`usingSystem.Net.Http.Headers;
usingSystem.Net.Http.Json;
usingSystem.Text.Json;
using var client = newHttpClient();
client.DefaultRequestHeaders.Authorization =
newAuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("OPTISWAY_API_KEY"));
var url = "https://optisway.com/api/v1/projects/42";
using var response = await client.GetAsync(url);
if (!response.IsSuccessStatusCode)
{
var envelope = await response.Content.ReadFromJsonAsync<JsonElement>();
var error = envelope.GetProperty("error");
var message = envelope.GetProperty("message");
Console.Error.WriteLine($"{(int)response.StatusCode}{error}: {message}");
Environment.Exit(1);
}
var body = await response.Content.ReadFromJsonAsync<JsonElement>();
Console.WriteLine($"ID: {body.GetProperty("id")}");
Console.WriteLine($"Name: {body.GetProperty("name")}");