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

blockexchange / blockexchange / 13327716991

14 Feb 2025 10:53AM UTC coverage: 50.79% (+2.4%) from 48.384%
13327716991

push

github

web-flow
refactor to async/await (#74)

237 of 556 new or added lines in 15 files covered. (42.63%)

5 existing lines in 4 files now uncovered.

964 of 1898 relevant lines covered (50.79%)

1870.06 hits per line

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

91.43
/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
36
      return Promise.rejected("unexpected http code: " .. res.code)
×
37
    end
38
  end)
39
end
40

41
--- search for a schema by uid
42
-- @param schema_uid the schema_uid
43
-- @return a promise with the result
44
function blockexchange.api.get_schema_by_uid(schema_uid, download)
2✔
45
  local schema_url = url .. "/api/schema/" .. schema_uid
2✔
46
  if download then
2✔
47
    -- increment download counter
48
    schema_url = schema_url .. "?download=true"
1✔
49
  end
50

51
  return Promise.json(http, schema_url)
2✔
52
end
53

54
--- search for a schema by username and schemaname
55
-- @param user_name the username
56
-- @param schema_name the name of the schema
57
-- @param download true/false to count as additional download in the stats
58
-- @return a promise with the result
59
function blockexchange.api.get_schema_by_name(user_name, schema_name, download)
2✔
60
  return Promise.async(function(await)
2✔
61
    local search_result, err = await(Promise.json(http, url .. "/api/search/schema", {
6✔
62
      method = "POST",
63
      data = {
2✔
64
        user_name = user_name,
2✔
65
        schema_name = schema_name
2✔
66
      }
2✔
67
    }))
68

69
    if err then
2✔
NEW
70
      error("search failed: " .. err, 0)
×
71
    end
72

73
    if not search_result or #search_result ~= 1 then
2✔
74
      -- no results, resolve with nil-promise
75
      return nil
×
76
    else
77
      -- download schematic
78
      return await(blockexchange.api.get_schema_by_uid(search_result[1].schema.uid, download))
4✔
79
    end
80
  end)
81
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