Table of Contents generated with DocToc
JavaScript wrapper for the SeniorVu web API
srvu.communities()
.get()
.then(communities => {
console.log(communities);
});
npm install --save seniorvu-sdk
In your code:
import SeniorVu from 'seniorvu-sdk';
// or
const SeniorVu = require('seniorvu-sdk');
Create a new instance of the SDK:
const srvu = new SeniorVu();
Configuration options can either be passed to the constructor or to the config()
method:
const srvu = new SeniorVu({
apiKey: 'foobar'
});
srvu.config({
apiKey: 'new-api-key'
});
- baseUrl: Set baseUrl for the api
- token: Set bearer token manually
In order to access private information, you must supply an apiKey, username/password, or single-use token to the authenticate()
method.
By default, authenticate()
will use options already passed in the constructor or to config()
. You can override these by passing an object to the method.
authenticate()
returns a promise the token result. A bearer token is stored in the instance for further requests.
// Use already-configured options
srvu.authenticate();
// API key
srvu.authenticate({
apiKey: 'api-key-here'
});
// Email and password
srvu.authenticate({
email: 'you@bar.baz',
password: 'secret'
});
// One-time token
srvu.authenticate({
oneTimeToken: 'one-time-token-here'
});
This SDK works by chaining method calls in order to build the URL to call at the API. Then a final "verb" method is called to execute the request.
The verb method returns a promise with the results of the call;
For example, to fetch back a list of communities you would call:
srvu.communities().get()
.then(communities => {
// communities available here
})
.catch(err => {
// Any error that hapens
});
Parameters passed to methods are used as identifiers, so this will fetch the community with id 123
:
srvu.communities(123).get();
// And this will fetch one of its purchased leads
srvu.communities(123).purchasedLeads(456).get();
Query parameters can be passed as an object to the final method call, or to the action call if it is a get:
srvu.communities(123).purchasedLeads({ sortBy: 'lastName' }).get();
srvu.communities(123).purchasedLeads().get({ sortBy: 'lastName' });
All possible parameters are listed in the SeniorVu API docs.
Many endpoints allow paging using limit
and offset
parameters:
// Get the second 20 communities
srvu.communities().get({ limit: 20, offset: 20 });
The verb methods that write data are .put()
, .post()
, and .delete()
, as you might expect. Pass the new data to the verb method.
To update a community:
srvu.communities(123).put({
name: 'Some Fancy New Name'
});
To create a new lead
srvu.leads().post({
firstName: 'Some',
lastName: 'Guy',
dob: '1955-5-5',
});
To delete a community room
srvu.communities(123).rooms(456).delete();
[
"/claimRequests",
"/communities",
"/communities/predict",
"/communities/proximity",
"/communities/{communityId}",
"/communities/{communityId}/address",
"/communities/{communityId}/amenities",
"/communities/{communityId}/appointments",
"/communities/{communityId}/archivedLeads",
"/communities/{communityId}/archivedLeads/{archivedLeadId}",
"/communities/{communityId}/assets",
"/communities/{communityId}/assets/awsSettings",
"/communities/{communityId}/assets/image",
"/communities/{communityId}/assets/video",
"/communities/{communityId}/assets/{assetId}",
"/communities/{communityId}/cartItems",
"/communities/{communityId}/cartItems/{cartItemId}",
"/communities/{communityId}/hours",
"/communities/{communityId}/hours/{hourId}",
"/communities/{communityId}/leads",
"/communities/{communityId}/neighborhoods",
"/communities/{communityId}/payment",
"/communities/{communityId}/purchasedLeads",
"/communities/{communityId}/purchasedLeads/{purchasedLeadId}",
"/communities/{communityId}/purchasedLeads/{purchasedLeadId}/carers",
"/communities/{communityId}/purchasedLeads/{purchasedLeadId}/carers/{carerId}",
"/communities/{communityId}/purchasedLeads/{purchasedLeadId}/events",
"/communities/{communityId}/purchasedLeads/{purchasedLeadId}/events/{eventId}",
"/communities/{communityId}/reviews",
"/communities/{communityId}/reviews/{reviewId}",
"/communities/{communityId}/rooms",
"/communities/{communityId}/rooms/{roomId}",
"/communities/{communityId}/rooms/{roomId}/image",
"/communities/{communityId}/rooms/{roomId}/upload",
"/leads",
"/leads/batchCreate",
"/leads/deleteCreated",
"/leads/upload",
"/users",
"/users/forgotPassword",
"/users/me",
"/users/reset/{token}",
"/users/{userId}",
"/users/{userId}/password",
"/auth/login",
"/auth/registration",
]
Run npm (run) start
to check that linting with XO and tests with ava pass.
Also, make sure you run npm run build
and npm run toc
before committing changes. A pre-commit hook helps.
NOTE: the tests run against the transpiled version, so if you use ava manually be sure that your changes are transpiled.
Run npm (run) test
to run tests with ava.
# Run sirv in another terminal window
npx sirv ./coverage
# Build and run tests+coverage on changes
npm run cover:watch
Run npm run lint
to run linter with XO.
@sindresorhus's np
package is great for doing releases. Just install it globally and run np
in your directory. Choose the option you want; voila, you're done.
- Re-authenticate when token expires.