项目作者: centre-for-effective-altruism

项目描述 :
Lightweight API wrapper for making requests to GoCardless
高级语言: JavaScript
项目地址: git://github.com/centre-for-effective-altruism/node-gocardless.git


Lightweight API wrapper for making requests to GoCardless.

See the GoCardless docs for a list of valid resources.

Installation

  1. npm install --save gocardless-api

Usage

Constructor

new GoCardless() => GoCardlessClient

Creates a new client instance using your GoCardless access token

  1. const gocardless = new GoCardless(YOUR_ACCESS_TOKEN)

Client Methods

.request(options) => Promise(GoCardlessResource)

Makes an API request, then returns the resulting resource.

  1. const GoCardless = require('gocardless-api')
  2. const gocardless = new GoCardless(YOUR_ACCESS_TOKEN)
  3. gocardless.request({
  4. method: 'GET',
  5. resource: 'customers'
  6. query: {
  7. limit: 10,
  8. after: 'CU123'
  9. }
  10. })
  11. .then(customers => {
  12. // customers => {
  13. // "meta": {
  14. // "cursors": {
  15. // "before": "CU000",
  16. // "after": "CU456",
  17. // },
  18. // "limit": 10
  19. // },
  20. // "customers": [{
  21. // "id": "CU123",
  22. // "created_at": "2014-05-08T17:01:06.000Z",
  23. // "email": "user@example.com",
  24. // "given_name": "Frank",
  25. // "family_name": "Osborne",
  26. // "address_line1": "27 Acer Road",
  27. // "address_line2": "Apt 2",
  28. // "address_line3": null,
  29. // "city": "London",
  30. // "region": null,
  31. // "postal_code": "E8 3GX",
  32. // "country_code": "GB",
  33. // "language": "en",
  34. // "metadata": {
  35. // "salesforce_id": "ABCD1234"
  36. // }
  37. // }, {
  38. // ...
  39. // }]
  40. // }
  41. })

The request will automatically add the following headers:

  • Authorization: Bearer <YOUR_ACCESS_TOKEN>
  • GoCardless-Version: 2015-07-06

You can override these headers using options.headers (see below)

request options Object:

  • method (String): HTTP request method. One of GET, PUT, PATCH or DELETE
  • resource (String): Path to the requested resource (e.g. customers, mandates/123)
  • data (Object): Data to accompany PUT or PATCH requests
  • query (Object): Query string as key=>value pairs (e.g. { limit: 10, after: ID789 } becomes ?limit=10&after=ID789)
  • options (Object): Additional request options. Passed directly to needle.