heroiclabs / nakama-defold

Defold client for Nakama server.
https://heroiclabs.com
Apache License 2.0
74 stars 12 forks source link

Updated the API design to expand the message body arguments in the API functions #38

Closed britzl closed 2 years ago

britzl commented 2 years ago

This PR updated the API design to expand the message body arguments in the API functions.

Previously:

local client = nakama.create_client(config)

local email = "super@heroes.com"
local password = "batsignal"
local body = nakama.create_api_account_email(email, password)
local session = nakama.authenticate_email(client, body)
pprint(session)

New:

local client = nakama.create_client(config)

local email = "super@heroes.com"
local password = "batsignal"
local session = nakama.authenticate_email(client, email, password)
pprint(session)
tomglenn commented 2 years ago

Hi @britzl,

Thanks for the changes you've made so far, removing the intermediate message body creation step will hugely improve the developer experience. We have a couple more requests that will help bring the Defold SDK in line with our other SDKs.

Please move client functions to the Client object rather than have them on the Nakama object.

Instead of:

local client = nakama.create_client(...)
local result = nakama.add_friends(client, ...)

It should be:

local client = nakama.create_client(...)
local result = client.add_friends(...)

Similar to above, socket functions and events should live on the Socket object.

Instead of:

nakama.on_matchpresence(socket, fn)

It should be:

socket.on_match_presence(fn)

For reference you can take a look at the IClient and ISocket definitions in the .NET SDK. https://github.com/heroiclabs/nakama-dotnet/blob/master/Nakama/IClient.cs https://github.com/heroiclabs/nakama-dotnet/blob/master/Nakama/ISocket.cs

Please let me know if you have any questions or issues.

britzl commented 2 years ago

I've updated the API to follow the recommendations from @tomglenn while remaining true to Lua.

Previously:

local client = nakama.create_client(config)

local email = "super@heroes.com"
local password = "batsignal"
local session = nakama.authenticate_email(client, email, password)
pprint(session)

You now have two options:

local client = nakama.create_client(config)

local email = "super@heroes.com"
local password = "batsignal"
-- same as before
local session = nakama.authenticate_email(client, email, password)
-- new
local session = client:authenticate_email(email, password)

pprint(session)

I've done the same for sockets (and moved the socket code to a separate socket.lua which is generated from the real-time protobuf message definitions):

local client = nakama.create_client(config)
local socket = client:create_socket()
socket:on_match_presence_event(callback)
socket:send_status_update("my status")

I need to do a whole lot of tests before this PR is ready for review, but it's moving the right direction at least!

britzl commented 2 years ago

Update:

docsncode commented 2 years ago

@tomglenn could you resolve conversations that are addressed.

docsncode commented 2 years ago

@britzl @tomglenn how are we tracking a version change? With the major changes we should bump a major version.

tomglenn commented 2 years ago

@britzl @tomglenn how are we tracking a version change? With the major changes we should bump a major version.

Agreed. @britzl can you also update the CHANGELOG to reflect the changes.

britzl commented 2 years ago

Agreed. @britzl can you also update the CHANGELOG to reflect the changes.

Done. I've retroactively added previous releases to the CHANGELOG.