blue-state-digital

0.2.0 • Public • Published

blue-state-digital

Generated with nod NPM version Build Status Coverage Status

A node module for accessing the blue state digital api service

Install

$ npm install --save blue-state-digital

Usage

import BSD from 'blue-state-digital';
 
const blueStateDigital = new BSD(options)

API

BSD

Create a new BSD rest client.

Parameters

  • options object The BSD API Options.
    • options.baseUrl String The base url of your bsd instance. IE: https://XYZ
    • options.apiID String The App ID for your BSD API Secret.
    • options.apiSecret String The API Secret for your BSD API App.
    • options.apiVer Number The API version, default is 2 and 2 is only supported for now.

Examples

The BSD constructor takes a API ID, if specified it will be used as default value for all endpoints that accept a API ID. The default is 2 but is required so you are aware of what version you are using.

const blueStateDigital = new BSD({
  baseUrl: 'legislator.bsd.net',
  apiID: 'MyApiID',
  apiSecret: '43875utihgkfj38563y4uig',
  apiVer: 2,
})

authenticate

Returns string Returns authentication response

request

This is the main method to handle easy authentication with bsd and node js. API Base Documentation https://secure.bluestatedigital.com/page/api/doc

Parameters

  • options object Options Object
    • options.method string |'GET'|'POST'|'PUT'|'DELETE'|
    • options.path string BSD API Path /page/api/ or /page/api/events/search_events
    • options.body any Post Body. {string} XML or {string} JSON
    • options.query object Query Params

Examples

async function doRequest() {
  try {
    const response = await blueStateDigital.request({
      method: '|GET|POST|PUT|DELETE|',
      path: 'path for the call, see BSD documentation for possible calls',
      body: //body parameters as JSON or an XML string
      query: {
       // query string parameters, {event_id:2, ids:'1,3,5' } is valid for example
      },
    })
  } catch(err) {
    // handle error
  }
}
 
 
const response = blueStateDigital.request({
  method: '|GET|POST|PUT|DELETE|',
  path: 'path for the call, see BSD documentation for possible calls',
  body: // //body parameters as JSON or an XML string
  query: {
   // query string parameters, {event_id: 2 ids:'1,3,5' } is valid for example
  },
}).then(resp => {
  // bsd response
})
.catch(err => {
  // be sure to handle errors
})

Returns Promise BSD Response Promise

searchEvents

Searches all the events and returns the future events unless specified by date_start.

REF: https://secure.bluestatedigital.com/page/api/doc#-------------Event-API-Calls---------

Parameters

  • params object The BSD API Options.
    • params.event_id string Search by Event ID
    • params.event_type string Search by Event Type
    • params.host_name string Search by the Host of the Event
    • params.day string Search by the day of the Event
    • params.date_start string Search by the start date of the Event
    • params.date_end string Search by the end date of the Event
    • params.create_day string Search by the created day of the Event
    • params.create_date_start string Search by the created start date of the Event
    • params.create_date_end string Search by the created end date of the Event
    • params.country string Search by events country
    • params.zip string Search by events zipcode
    • params.city string Search by events by city
    • params.state string Search events by state
    • params.zip_radius string Search events in a given zipcode radius
    • params.radius_unit string Search events in a given radius
    • params.attendee_cons_id string Search events by a consituent's ID who is attending
    • params.creator_cons_id string Search events by the consituent that created the Event
    • params.order_field string Search events by order field

Returns Promise BSD JSON Response Promise

sendTriggeredEmail

Searches all the events and returns the future events unless specified by date_start.

REF: https://secure.bluestatedigital.com/page/api/doc (send_triggered_email)

Parameters

  • params object The BSD API Options.
    • params.mailing_id string Obfuscated mailing ID to be sent (found in the BSD cp)
    • params.email string Recipient email address
    • params.email_opt_in string Whether to subscribe newly-created constituents
    • params.trigger_values string Additional data to be made available to the email

Returns Promise BSD JSON Response Promise

listForms

This method lists all signup forms and relevant data about those forms. https://secure.bluestatedigital.com/page/api/doc#---------------------list_forms-----------------0.7883351277818669 No Params

Examples

const forms = await blueStateDigital.listForms()

Returns Promise BSD XML Response

getFormByID

This method gets all properties of the specified signup form. https://secure.bluestatedigital.com/page/api/doc#---------------------get_form-----------------

Parameters

  • params object Params Object
    • params.signup_form_id string BSD Form ID

Examples

const form = await blueStateDigital.getFormByID({ signup_form_id: '105' })

Returns Promise BSD XML Response Promise

listFormFields

Retrieves a list of all form fields associated with a specified signup form.

https://secure.bluestatedigital.com/page/api/doc#---------------------list_form_fields-----------------

Parameters

  • params object Params Object
    • params.signup_form_id string BSD Form ID

Examples

const formFields = await blueStateDigital.listFormFields({ signup_form_id: '105' })

Returns Promise BSD XML Response Promise

License

MIT © Samuel Robertson

Readme

Keywords

Package Sidebar

Install

npm i blue-state-digital

Weekly Downloads

0

Version

0.2.0

License

MIT

Unpacked Size

28.8 kB

Total Files

10

Last publish

Collaborators

  • robertsonsamuel