anear-js-api 0.4.4 → 0.4.6
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/lib/api/AnearApi.js +4 -0
- package/lib/api/ApiService.js +14 -14
- package/lib/messaging/AnearMessaging.js +7 -2
- package/package.json +2 -2
package/lib/api/AnearApi.js
CHANGED
package/lib/api/ApiService.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
"use strict"
|
|
2
|
+
|
|
2
3
|
const ErrorResponse = require('./ErrorResponse')
|
|
3
4
|
const qs = require('qs')
|
|
4
5
|
const fetch = require('cross-fetch')
|
|
5
6
|
|
|
6
|
-
const DeveloperApiURL =
|
|
7
|
+
const DeveloperApiURL = 'https://api.anearapp.com/developer/'
|
|
7
8
|
|
|
8
9
|
class ApiService {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
this.api_base_url = DeveloperApiURL
|
|
10
|
+
constructor(apiKey, apiVersion) {
|
|
11
|
+
this.api_base_url = DeveloperApiURL + apiVersion
|
|
12
12
|
this.defaultHeaderObject = {
|
|
13
13
|
'Accept': 'application/json',
|
|
14
14
|
'Content-Type': 'application/json',
|
|
15
|
-
'X-Api-Key':
|
|
15
|
+
'X-Api-Key': apiKey
|
|
16
16
|
}
|
|
17
17
|
this.default_headers = new fetch.Headers(this.defaultHeaderObject)
|
|
18
18
|
}
|
|
@@ -39,12 +39,12 @@ class ApiService {
|
|
|
39
39
|
)
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
get(resource, params={}) {
|
|
43
43
|
const request = this.prepareGetRequest(resource, params)
|
|
44
|
-
return
|
|
44
|
+
return this.issueRequest(request)
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
post(resource, attributes, relationships={}) {
|
|
48
48
|
const payload = this.formatPayload(resource, attributes, relationships)
|
|
49
49
|
const request = new fetch.Request(
|
|
50
50
|
`${this.api_base_url}/${resource}`, {
|
|
@@ -53,10 +53,10 @@ class ApiService {
|
|
|
53
53
|
body: JSON.stringify(payload)
|
|
54
54
|
}
|
|
55
55
|
)
|
|
56
|
-
return
|
|
56
|
+
return this.issueRequest(request)
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
put(resource, id, attributes, relationships={}) {
|
|
60
60
|
const payload = this.formatPayload(resource, attributes, relationships)
|
|
61
61
|
const urlString = `${this.api_base_url}/${resource}/${id}`
|
|
62
62
|
const request = new fetch.Request(
|
|
@@ -66,10 +66,10 @@ class ApiService {
|
|
|
66
66
|
body: JSON.stringify(payload)
|
|
67
67
|
}
|
|
68
68
|
)
|
|
69
|
-
return
|
|
69
|
+
return this.issueRequest(request)
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
|
|
72
|
+
httpDelete(resource, id=null) {
|
|
73
73
|
const idStr = (id ? `/${id}` : '')
|
|
74
74
|
const urlString = `${this.api_base_url}/${resource}${idStr}`
|
|
75
75
|
const request = new fetch.Request(
|
|
@@ -78,12 +78,12 @@ class ApiService {
|
|
|
78
78
|
headers: this.default_headers
|
|
79
79
|
}
|
|
80
80
|
)
|
|
81
|
-
return
|
|
81
|
+
return this.issueRequest(request)
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
async issueRequest(request) {
|
|
85
85
|
const resp = await fetch(request)
|
|
86
|
-
return
|
|
86
|
+
return this.checkStatus(resp)
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
formatPayload(resource, attributes, relationships) {
|
|
@@ -19,12 +19,17 @@ const ALREADY_PRESENT = 'present'
|
|
|
19
19
|
const ChannelParams = {params: {rewind: "5s"}}
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
// 0 - no logging, 4 - verbose logging
|
|
23
|
+
const AblyLogLevel = process.env.ANEARAPP_ABLY_LOG_LEVEL || 0
|
|
24
|
+
|
|
23
25
|
const AnearCreateEventChannelName = `anear:${AppId}:e`
|
|
24
26
|
|
|
25
27
|
class AnearMessaging {
|
|
26
28
|
constructor(AnearEventClass, AnearParticipantClass) {
|
|
27
|
-
this.api = new AnearApi(
|
|
29
|
+
this.api = new AnearApi(
|
|
30
|
+
process.env.ANEARAPP_API_KEY,
|
|
31
|
+
process.env.ANEARAPP_API_VERSION
|
|
32
|
+
)
|
|
28
33
|
this.AnearEventClass = AnearEventClass
|
|
29
34
|
this.AnearParticipantClass = AnearParticipantClass
|
|
30
35
|
this.anearEvents = {}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "anear-js-api",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.6",
|
|
4
4
|
"description": "Javascript Developer API for Anear Apps",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
},
|
|
18
18
|
"homepage": "https://github.com/machvee/anear-js-api#readme",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"ably": "^1.2.
|
|
20
|
+
"ably": "^1.2.34",
|
|
21
21
|
"async-mutex": "^0.3.2",
|
|
22
22
|
"async-redis": "^2.0.0",
|
|
23
23
|
"cross-fetch": "^3.1.5",
|