SDK Ruby – SoftAfrik Push API
Client Ruby officiel pour SoftAfrik Push API en HTTP.
1. Installation
Installez la gem ‘http’ :
gem install http
Structure recommandée
/your-project
softafrik_push_client.rb
example_push.rb
2. SDK Ruby – softafrik_push_client.rb
require "http"
require "json"
class SoftAfrikPushClient
def initialize(api_key, base_url = "https://softafrik-push-api.brillanciel.com")
@api_key = api_key
@base_url = base_url.chomp("/")
end
def post(path, payload)
res = HTTP.headers(
"X-API-KEY" => @api_key,
"Content-Type" => "application/json"
).post("#{@base_url}#{path}", json: payload)
JSON.parse(res.body.to_s)
end
def register_user(external_user_ref, meta = {})
post("/api/users/register", {
external_user_ref: external_user_ref,
meta: meta
})
end
def register_device(puid, app_name, platform, device_token,
device_uid=nil, lang=nil, country=nil)
payload = {
puid: puid,
app_name: app_name,
platform: platform,
device_token: device_token
}
payload[:device_uid] = device_uid if device_uid
payload[:lang] = lang if lang
payload[:country] = country if country
post("/api/devices/register", payload)
end
def push_to_user(puid, title, body, data = {})
post("/api/push/to-user", {
puid: puid,
title: title,
body: body,
data: data
})
end
end
3. Exemple complet
require "./softafrik_push_client"
client = SoftAfrikPushClient.new("VOTRE_API_KEY")
user = client.register_user("user_123", { full_name: "John Doe" })
puid = user["puid"]
resp = client.push_to_user(
puid,
"Transfert reçu",
"Vous avez reçu 20 000 XOF",
{ transaction_id: 9932 }
)
puts resp
Endpoints
POST /api/users/registerPOST /api/devices/registerPOST /api/devices/unregisterPOST /api/push/to-userPOST /api/push/to-devicePOST /api/push/broadcast
client = SoftAfrikPushClient.new("API_KEY")
puts client.push_to_user("sa_100x_xx", "Ping", "Hello!")