Gamend SDK

SDK for Gamend hooks development. This package provides type specs, documentation, and IDE autocomplete for Gamend modules without requiring the full server.

Installation

Add gamend_sdk to your list of dependencies in mix.exs:

def deps do
[
{:gamend_sdk, "~> 0.1.0", runtime: false, optional: true}
]
end

Usage

This SDK provides stub modules that match the Gamend API:

Core Modules

Behaviour & Types

Implementing Hooks

Create your hooks module using use Gamend.Hooks to get default implementations for all callbacks, then override only the ones you need:

defmodule MyGame.Hooks do
use Gamend.Hooks
@impl true
def after_user_register(user) do
# Give new users starting coins
Gamend.Accounts.update_user(user, %{
metadata: Map.put(user.metadata || %{}, "coins", 100)
})
end
@impl true
def before_group_create(user, attrs) do
# Check if user has enough coins to create a group
coins = get_in(user.metadata, ["coins"]) || 0
if coins >= 50, do: {:ok, attrs}, else: {:error, :not_enough_coins}
end
@impl true
def before_lobby_join(user, lobby, opts) do
# Check level requirements
{:ok, {user, lobby, opts}}
end
# Custom RPC - callable from game clients
def give_coins(amount, _opts) do
caller = Gamend.Hooks.caller_user()
coins = get_in(caller.metadata, ["coins"]) || 0
Gamend.Accounts.update_user(caller, %{
metadata: Map.put(caller.metadata, "coins", coins + amount)
})
end
end

Module APIs

The SDK modules provide the same API as the real Gamend:

# Get user by ID (returns nil if not found)
user = Gamend.Accounts.get_user(user_id)
# Update user metadata
{:ok, user} = Gamend.Accounts.update_user(user, %{metadata: %{level: 5}})
# Submit leaderboard score
{:ok, record} = Gamend.Leaderboards.submit_score(leaderboard_id, user_id, 1000)
# Get lobby members
members = Gamend.Lobbies.get_lobby_members(lobby)

Note

This SDK only provides type specifications and documentation for IDE support. The actual implementations run on the Gamend - these stubs will raise RuntimeError if called directly.