@quenty/httppromise 3.2.1-canary.8533eea.0 → 3.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,7 +3,15 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- ## [3.2.1-canary.8533eea.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/httppromise@3.2.0...@quenty/httppromise@3.2.1-canary.8533eea.0) (2021-12-18)
6
+ ## [3.3.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/httppromise@3.3.0...@quenty/httppromise@3.3.1) (2021-12-30)
7
+
8
+ **Note:** Version bump only for package @quenty/httppromise
9
+
10
+
11
+
12
+
13
+
14
+ # [3.3.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/httppromise@3.2.0...@quenty/httppromise@3.3.0) (2021-12-18)
7
15
 
8
16
  **Note:** Version bump only for package @quenty/httppromise
9
17
 
package/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  ## HttpPromise
2
2
  <div align="center">
3
- <a href="http://quenty.github.io/api/">
4
- <img src="https://img.shields.io/badge/docs-website-green.svg" alt="Documentation" />
3
+ <a href="http://quenty.github.io/NevermoreEngine/">
4
+ <img src="https://github.com/Quenty/NevermoreEngine/actions/workflows/docs.yml/badge.svg" alt="Documentation status" />
5
5
  </a>
6
6
  <a href="https://discord.gg/mhtGUS8">
7
- <img src="https://img.shields.io/badge/discord-nevermore-blue.svg" alt="Discord" />
7
+ <img src="https://img.shields.io/discord/385151591524597761?color=5865F2&label=discord&logo=discord&logoColor=white" alt="Discord" />
8
8
  </a>
9
9
  <a href="https://github.com/Quenty/NevermoreEngine/actions">
10
10
  <img src="https://github.com/Quenty/NevermoreEngine/actions/workflows/build.yml/badge.svg" alt="Build and release status" />
@@ -13,57 +13,9 @@
13
13
 
14
14
  HttpPromise - Wrapper functions around http requests in Roblox.
15
15
 
16
+ <div align="center"><a href="https://quenty.github.io/NevermoreEngine/api/HttpPromise">View docs →</a></div>
17
+
16
18
  ## Installation
17
19
  ```
18
20
  npm install @quenty/httppromise --save
19
- ```
20
-
21
- ## Usage
22
-
23
- ```lua
24
- -- Make a request
25
- local requestPromise = HttpPromise.request({
26
- Headers = {
27
- ["Content-Type"] = "application/json";
28
- };
29
- Url = DISCORD_LOG_URL;
30
- Body = HttpService:JSONEncode(data);
31
- Method = "POST";
32
- })
33
-
34
- ```
35
-
36
- ### Decoding JSON
37
- ```lua
38
- -- Decode JSON results
39
- requestPromise = requestPromise
40
- :Then(HttpPromise.decodeJson)
41
- ```
42
-
43
- ### Logging failed results
44
- ```lua
45
- -- Log failed results
46
- requestPromise = requestPromise
47
- :Catch(HttpPromise.logFailedRequests)
48
-
49
- ```
50
-
51
- ### Generic request
52
- By combining functions in HttpPromise, we can get a generic request result in a very clean way.
53
-
54
- ```lua
55
- -- All together now!
56
-
57
- local function logToDiscord(body)
58
- return HttpPromise.request({
59
- Headers = {
60
- ["Content-Type"] = "application/json";
61
- };
62
- Url = DISCORD_LOG_URL;
63
- Body = HttpService:JSONEncode(data);
64
- Method = "POST";
65
- })
66
- :Then(HttpPromise.decodeJson)
67
- :Catch(HttpPromise.logFailedRequests)
68
- end
69
- ```
21
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/httppromise",
3
- "version": "3.2.1-canary.8533eea.0",
3
+ "version": "3.3.1",
4
4
  "description": "HttpPromise - Wrapper functions around http requests in Roblox.",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -27,11 +27,11 @@
27
27
  "Quenty"
28
28
  ],
29
29
  "dependencies": {
30
- "@quenty/loader": "3.1.1",
31
- "@quenty/promise": "3.2.1-canary.8533eea.0"
30
+ "@quenty/loader": "^3.1.2",
31
+ "@quenty/promise": "^3.3.1"
32
32
  },
33
33
  "publishConfig": {
34
34
  "access": "public"
35
35
  },
36
- "gitHead": "8533eeade3bf6835c0295785c1c326b9abee3222"
36
+ "gitHead": "d146c77d0a8e452824de0ab0b4b03ba0370bcc1b"
37
37
  }
@@ -1,5 +1,25 @@
1
- --- Provides a wrapper around HttpService with a promise API
2
- -- @module HttpPromise
1
+ --[=[
2
+ Provides a wrapper around HttpService with a promise API
3
+
4
+ By combining functions in HttpPromise, we can get a generic request result in a very clean way.
5
+ ```lua
6
+ local function logToDiscord(body)
7
+ return HttpPromise.request({
8
+ Headers = {
9
+ ["Content-Type"] = "application/json";
10
+ };
11
+ Url = DISCORD_LOG_URL;
12
+ Body = HttpService:JSONEncode(data);
13
+ Method = "POST";
14
+ })
15
+ :Then(HttpPromise.decodeJson)
16
+ :Catch(HttpPromise.logFailedRequests)
17
+ end
18
+ ```
19
+
20
+ @server
21
+ @class HttpPromise
22
+ ]=]
3
23
 
4
24
  local require = require(script.Parent.loader).load(script)
5
25
 
@@ -12,6 +32,23 @@ local DEBUG_RESPONSE = false
12
32
 
13
33
  local HttpPromise = {}
14
34
 
35
+ --[=[
36
+ Decodes JSON from the response
37
+
38
+ ```lua
39
+ local requestPromise = HttpPromise.request({
40
+ Headers = {
41
+ ["Content-Type"] = "application/json";
42
+ };
43
+ Url = DISCORD_LOG_URL;
44
+ Body = HttpService:JSONEncode(data);
45
+ Method = "POST";
46
+ })
47
+ ```
48
+
49
+ @param request table
50
+ @return Promise<table>
51
+ ]=]
15
52
  function HttpPromise.request(request)
16
53
  if DEBUG_REQUEST then
17
54
  print("Sending request", HttpService:JSONEncode(request))
@@ -42,6 +79,17 @@ function HttpPromise.request(request)
42
79
  end)
43
80
  end
44
81
 
82
+ --[=[
83
+ Makes a GET JSON request and then expects JSON as a result from said request
84
+
85
+ ```lua
86
+ HttpPromise.json("https://quenty.org/banned/4397833/status")
87
+ :Then(print)
88
+ ```
89
+
90
+ @param request table | string
91
+ @return Promise<table>
92
+ ]=]
45
93
  function HttpPromise.json(request)
46
94
  if type(request) == "string" then
47
95
  request = {
@@ -54,6 +102,16 @@ function HttpPromise.json(request)
54
102
  :Then(HttpPromise.decodeJson)
55
103
  end
56
104
 
105
+ --[=[
106
+ Logs failed requests and any errors retrieved
107
+
108
+ ```lua
109
+ HttpPromise.json("https://quenty.org/banned/4397833/status")
110
+ :Catch(HttpPromise.logFailedRequests)
111
+ ```
112
+
113
+ @param ... any -- A list of requests to retrieve. Meant to be used
114
+ ]=]
57
115
  function HttpPromise.logFailedRequests(...)
58
116
  for _, item in pairs({...}) do
59
117
  if type(item) == "string" then
@@ -64,6 +122,12 @@ function HttpPromise.logFailedRequests(...)
64
122
  end
65
123
  end
66
124
 
125
+ --[=[
126
+ Decodes JSON from the response
127
+
128
+ @param response { Body: string }
129
+ @return table
130
+ ]=]
67
131
  function HttpPromise.decodeJson(response)
68
132
  assert(response, "Bad response")
69
133