Skip to content

Instantly share code, notes, and snippets.

@y4kupkaya
Created September 20, 2023 17:26
Show Gist options
  • Save y4kupkaya/7ac257e9d383bd184d5d403ef981b1d6 to your computer and use it in GitHub Desktop.
Save y4kupkaya/7ac257e9d383bd184d5d403ef981b1d6 to your computer and use it in GitHub Desktop.
Example API usage for medyamiz.com
class Api {
constructor(apiKey) {
this.api_url = 'https://medyamiz.com/api/v2';
this.api_key = apiKey;
}
// Sipariş ekle
async order(data) {
const post = { key: this.api_key, action: 'add', ...data };
return await this.connect(post);
}
// Sipariş durumunu al
async status(order_id) {
const post = { key: this.api_key, action: 'status', order: order_id };
return await this.connect(post);
}
// Birden çok siparişin durumunu al
async multiStatus(order_ids) {
const post = {
key: this.api_key,
action: 'status',
orders: order_ids.join(","),
};
return await this.connect(post);
}
// Hizmetleri al
async services() {
const post = { key: this.api_key, action: 'services' };
return await this.connect(post);
}
// Siparişi yeniden doldur
async refill(orderId) {
const post = { key: this.api_key, order: orderId };
return await this.connect(post);
}
// Birden çok siparişi yeniden doldur
async multiRefill(orderIds) {
const post = { key: this.api_key, orders: orderIds.join(',') };
return await this.connect(post);
}
// Yeniden doldurma durumunu al
async refillStatus(refillId) {
const post = { key: this.api_key, refill: refillId };
return await this.connect(post);
}
// Birden çok yeniden doldurma durumunu al
async multiRefillStatus(refillIds) {
const post = { key: this.api_key, refills: refillIds.join(',') };
return await this.connect(post);
}
// Bakiyeyi al
async balance() {
const post = { key: this.api_key, action: 'balance' };
return await this.connect(post);
}
// Sunucuya bağlan
async connect(post) {
const formData = new URLSearchParams();
for (const [name, value] of Object.entries(post)) {
formData.append(name, value);
}
const requestOptions = {
method: 'POST',
body: formData,
headers: {
'User-Agent': 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)',
},
};
try {
const response = await fetch(this.api_url, requestOptions);
if (!response.ok) {
throw new Error(`HTTP Hatası! Durum: ${response.status}`);
}
const result = await response.text();
return JSON.parse(result);
} catch (error) {
console.error('Bir hata oluştu:', error);
return false;
}
}
}
// Örnekler
const apiKey = ''; // API anahtarınızı buraya ekleyin
const api = new Api(apiKey);
(async () => {
const services = await api.services(); // Tüm hizmetleri getir
const balance = await api.balance(); // Kullanıcı bakiyesini getir
// Sipariş ekleme örnekleri
const order1 = await api.order({ service: 1, link: 'http://medyamiz.com/test', quantity: 100, runs: 2, interval: 5 }); // Varsayılan
const order2 = await api.order({ service: 1, link: 'http://medyamiz.com/test', comments: "good pic\ngreat photo\n:)\n;)" }); // Özel Yorumlar
// Daha fazla sipariş örneği ekleyin...
// Durum ve yeniden doldurma örnekleri
const status = await api.status(order1.order); // Durumu, ücreti, kalan miktarı, başlangıç sayısını, para birimini getir
const statuses = await api.multiStatus([1, 2, 3]); // Siparişlerin durumunu, ücretini, kalan miktarını, başlangıç sayısını, para birimini getir
const refill = await api.multiRefill([1, 2]);
const refillIds = refill.map(item => item.refill);
if (refillIds.length > 0) {
const refillStatuses = await api.multiRefillStatus(refillIds);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment