Skip to content

Commit

Permalink
add get_accounts api
Browse files Browse the repository at this point in the history
  • Loading branch information
bobdos committed May 29, 2018
1 parent 4b3bd25 commit d0d1630
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 10 deletions.
34 changes: 28 additions & 6 deletions steem-corona.lua
@@ -1,9 +1,9 @@
module(..., package.seeall)

function get_config(callback)

local params = {}
params.body = ""


network.request(
"https://api.steemjs.com/get_config",
"GET",
Expand All @@ -12,9 +12,9 @@ function get_config(callback)
end

function get_version(callback)

local params = {}
params.body = ""


network.request(
"https://api.steemjs.com/get_version",
"GET",
Expand All @@ -24,13 +24,35 @@ end

function get_account_count(callback)
local params = {}
params.body = ""


network.request(
"https://api.steemjs.com/get_account_count",
"GET",
callback,
params)
end

function get_accounts(account_array, callback)

local string_begin = "["
local string_end = "]"
local names = string_begin

for i = 1, #account_array do
if(i < #account_array) then
names = names .. "%22" .. account_array[i] .. "%22" .. ","
else
names = names .. "%22" .. account_array[i] .. "%22"
end
end

names = names .. string_end

local params = {}

network.request(
"https://api.steemjs.com/get_accounts?names="..names,
"GET",
callback,
params)
end
33 changes: 29 additions & 4 deletions test.lua
@@ -1,28 +1,53 @@
local steem = require("steem-corona-sdk.steem-corona")
local json = require("json")

local account_array = {"steemsdk.test"}

--[[ test case: get_config ]]
steem.get_config(
function(event)
if event.isError then
print( "Network error: ", event.response )
else
print("response: "..event.response)
end
end)
end
)

--[[ test case: get_version ]]
steem.get_version(
function(event)
if event.isError then
print( "Network error: ", event.response )
else
print("response: "..event.response)
end
end)
end
)

steem.get_account_count(function(event)
--[[ test case: get_account_count ]]
steem.get_account_count(
function(event)
if event.isError then
print( "Network error: ", event.response )
else
print("response: "..event.response)
end
end)
end
)

--[[ test case: get_accounts ]]
steem.get_accounts(
account_array,
function(event)
if event.isError then
print( "Network error: ", event.response )
else
print("response: "..json.prettify(event.response))
local decoded_response = json.decode(event.response)
print("id: "..decoded_response[1]["id"].."\n"..
"name: "..decoded_response[1]["name"])
end
end
)

0 comments on commit d0d1630

Please sign in to comment.