• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

blockexchange / blockexchange / 13110168475

03 Feb 2025 09:18AM UTC coverage: 48.213% (+0.6%) from 47.564%
13110168475

push

github

BuckarooBanzay
http/json overhaul

51 of 102 new or added lines in 14 files covered. (50.0%)

1 existing line in 1 file now uncovered.

985 of 2043 relevant lines covered (48.21%)

1734.77 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.84
/api/schema.lua
1
---------
2
-- schema api calls
3

4
local http, url = ...
1✔
5

6
--- creates a new schema
7
-- @param token the token in string format
8
-- @param create_schema the new schema as table
9
-- @return a promise with the result
10
function blockexchange.api.create_schema(token, create_schema)
2✔
11
  return Promise.json(http, url .. "/api/schema", {
1✔
12
    method = "POST",
13
    data = create_schema,
1✔
14
    headers = {
1✔
15
      "Authorization: " .. token
1✔
16
    }
1✔
17
  })
1✔
18
end
19

20
--- updates the stats of an existing schema
21
-- @param token the token in string format
22
-- @param schema_uid the schema_uid to update
23
-- @return a promise with the result
24
function blockexchange.api.update_schema_stats(token, schema_uid)
2✔
25
  return Promise.http(http, url .. "/api/schema/" .. schema_uid .. "/update", {
2✔
26
    method = "POST",
27
    data = { done = true },
1✔
28
    timeout = 120,
29
    headers = {
1✔
30
      "Authorization: " .. token
1✔
31
    }
1✔
32
  }):next(function(res)
1✔
33
    if res.code == 200 or res.code == 204 then
1✔
34
      return true
1✔
35
    else
NEW
36
      return Promise.rejected("unexpected http code: " .. res.code)
×
37
    end
38
  end)
39
end
40

41
local function response_handler(res)
42
  if res.code == 200 then
4✔
43
    return res.json()
4✔
NEW
44
  elseif res.code == 404 then
×
NEW
45
    return nil
×
46
  else
NEW
47
    return Promise.rejected("unexpected http code: " .. res.code)
×
48
  end
49
end
50

51
--- search for a schema by uid
52
-- @param schema_uid the schema_uid
53
-- @return a promise with the result
54
function blockexchange.api.get_schema_by_uid(schema_uid, download)
2✔
55
  local schema_url = url .. "/api/schema/" .. schema_uid
2✔
56
  if download then
2✔
57
    -- increment download counter
58
    schema_url = schema_url .. "?download=true"
1✔
59
  end
60

61
  return Promise.http(http, schema_url):next(response_handler)
4✔
62
end
63

64
--- search for a schema by username and schemaname
65
-- @param user_name the username
66
-- @param schema_name the name of the schema
67
-- @param download true/false to count as additional download in the stats
68
-- @return a promise with the result
69
function blockexchange.api.get_schema_by_name(user_name, schema_name, download)
2✔
70
  return Promise.http(http, url .. "/api/search/schema", {
4✔
71
    method = "POST",
72
    data = {
2✔
73
      user_name = user_name,
2✔
74
      schema_name = schema_name
2✔
75
    }
2✔
76
  }):next(response_handler):next(function(search_result)
4✔
77
    -- extract uid
78
    if #search_result ~= 1 then
2✔
79
      -- no results, resolve with nil-promise
80
      return nil
×
81
    else
82
      -- download schematic
83
      return blockexchange.api.get_schema_by_uid(search_result[1].schema.uid, download)
2✔
84
    end
85
  end)
86
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc