Skip to content

Instantly share code, notes, and snippets.

@nicolaslopezj
Last active March 27, 2018 22:03
Show Gist options
  • Save nicolaslopezj/48905ccb5ec2b738f83f1f6034b44269 to your computer and use it in GitHub Desktop.
Save nicolaslopezj/48905ccb5ec2b738f83f1f6034b44269 to your computer and use it in GitHub Desktop.
Llamar a Orionx desde Node
import JSSHA from 'jssha'
import rp from 'request-promise'
export default async function(query, variables, apiKey, apiSecretKey) {
// New actual Time-Stamp
const timestamp = new Date().getTime() / 1000
const body = JSON.stringify({query, variables})
const shaObj = new JSSHA('SHA-512', 'TEXT')
shaObj.setHMACKey(apiSecretKey, 'TEXT')
shaObj.update(timestamp + body)
const signature = shaObj.getHMAC('HEX')
// Sending request
const uri = 'https://api2.orionx.io/graphql'
try {
const response = await rp({
uri: uri,
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-ORIONX-TIMESTAMP': timestamp,
'X-ORIONX-APIKEY': apiKey,
'X-ORIONX-SIGNATURE': signature
},
body // Cuerpo del Mensaje (query)
})
const {data, errors} = JSON.parse(response)
if (errors) {
const error = errors[0]
throw new Error(error.message)
}
return data
} catch (e) {
throw e
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment