3.0.1 • Published 5 years ago

seniorvu-sdk v3.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

Build Status Coverage Status Dependency Status XO code style

Table of Contents generated with DocToc

seniorvu-sdk

JavaScript wrapper for the SeniorVu web API

srvu.communities()
  .get()
  .then(communities => {
    console.log(communities);
  });

Install

npm install --save seniorvu-sdk

In your code:

import SeniorVu from 'seniorvu-sdk';

// or

const SeniorVu = require('seniorvu-sdk');

Usage

Create a new instance of the SDK:

const srvu = new SeniorVu();

Configuration

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'
});

Other Options

  • baseUrl: Set baseUrl for the api
  • token: Set bearer token manually

Authentication

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'
});

Fetching Data

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();

Parameters

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.

Common Parameters

Many endpoints allow paging using limit and offset parameters:

// Get the second 20 communities
srvu.communities().get({ limit: 20, offset: 20 });

Writing data

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();

List of Valid Paths

[
  "/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",
]

Development

Committing changes

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.

Testing

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.

Coverage

# Run sirv in another terminal window
npx sirv ./coverage

# Build and run tests+coverage on changes
npm run cover:watch

Linting

Run npm run lint to run linter with XO.

Releasing

@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.

TODO

  • Re-authenticate when token expires.
3.0.1

5 years ago

3.0.0

5 years ago

2.3.0

5 years ago

2.2.0

6 years ago

2.1.0

6 years ago

2.0.4

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.0.0

7 years ago