currentrms-jsdeprecated

An easy to use NPM HTTP client for the Current RMS API.

Usage no npm install needed!

<script type="module">
  import currentrmsJs from 'https://cdn.skypack.dev/currentrms-js';
</script>

README

Current RMS JS

An easy to use NPM HTTP client for the Current RMS API.

GitHub license npm (scoped)

Installation

npm install --save currentrms-js
const currentApi = require('currentrms-js')
const client = new currentApi.Client('apiKey', 'subdomain')
const helper = new currentApi.Helper()

Usage

See the Current RMS API documentation for a full list of endpoints: http://api.current-rms.com/doc

Every request returns a Promise from Axios.

apiClient.getProductRevenue(productId, productRevenueId)
  .then((response) => {
    console.log(response.data) // Data from the server
    console.log(response.status) // HTTP status code from the server response
    console.log(response.statusText) // HTTP status message from the server response
    console.log(response.headers) // Headers that the server responded with
    console.log(response.config) // Config that was provided to `axios` for the request
  })
  .catch((error) => {
    console.error(error)
  })

GET

For any GET requests that accept query parameters, the 'queries' parameter is always last.

The queryParameters() and includeAssociations() helper functions return QueryStrings in the correct format for Current RMS.

Query Parameters

let queries = helper.queryParameters({
  filtermode: ['live'],
  per_page: 1,
  q: {
    state_eq: 3
  }
})

// returns string: filtermode=live&per_page=1&q[state_eq]=3

Include Associations

let include = helper.includeAssociations('member', 'opportunity_items')

// returns string: include[]=member&include[]=opportunity_items

You can then pass these variables as an Array to a function that accepts query parameters.

apiClient.getOpportunities([queries, include])

// path will be: /opportunities?filtermode=live&per_page=1&q[state_eq]=3&include[]=member&include[]=opportunity_items

String Query Parameters

If for some reason the helper functions queryParameters() and includeAssociations() do not fit your use-case, you can pass the query parameters as a string.

apiClient.getOpportunities('filtermode=live&per_page=1&q[state_eq]=3&include[]=member&include[]=opportunity_items')

// path will be: /opportunities?filtermode=live&per_page=1&q[state_eq]=3&include[]=member&include[]=opportunity_items

PUT and POST

For all PUT and POST requests, the 'body' parameter is always last. You do not need to use JSON.parse() or JSON.stringify().

For example:

apiClient.postDiscussion(discussionId, body)

Standard JavaScript

License

MIT License

Copyright (c) 2018 Sam Caplat

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.