twurlrc
Parse .twurlrc files.
twurl stores Twitter credentials in ~/.twurlrc (in YAML format).
This package will parse a .twurlrc file and return credentials suitable for use with oauth-1.0a
.
Install
npm install twurlrc
Quick Start
The got
package provides an excellent example of how to send a signed OAuth request with oauth-1.0a
.
A modified version of that example is included below to illustrate how to incorporate twurlrc:
const got = ;const crypto = ;const OAuth = ;const consumer access_token = ; const oauth = ; const url = 'https://api.twitter.com/1.1/statuses/home_timeline.json'; ;
The Twurlrc
class is used to get credentials from parsed data.
Call Twurlrc.fromFile
or Twurlrc.fromFileSync
to create a Twurlrc
object
and load the contents of the specified file path.
If no path is specified ~/.twurlrc is loaded by default.
Call Twurlrc.fromYAMLSync
to create a Twurlrc
object from a YAML string.
API
Table of Contents
Twurlrc
Get credentials from parsed data.
Parameters
data
Object object returned by YAML parser
data
object returned by YAML parser
Type: Object
credentials
Get credentials for the specified profile.
Returns grouped key/secret pairs by default. Disable grouping by passing true
for the raw
parameter value.
If the consumer_key
parameter is omitted or falsy, the "first" consumer_key defined for provided screen_name
is used. This fallback is provided for convenience when parsing profiles with a single consumer_key defined.
To load credentials from profiles with multiple consumer_keys defined, specifying which consumer_key to load is
strongly recommended (as opposed to relying on definition order).
Parameters
screen_name
string Twitter user screen_nameconsumer_key
string Twitter app consumer_keyraw
boolean return unmodified credentials object instead of grouping key/secret pairs (optional, defaultfalse
)
Examples
// get credentials with grouped key/secret pairsconst consumer access_token screen_name = twurlrc;// consumer === {key: consumer_key, secret: consumer_secret}// access_token === {key: token, secret: secret}// screen_name === 'my_screen_name'
// disable groupingconst consumer_key consumer_secret token secret username = twurlrc;
Returns Object
defaultCredentials
Get credentials for the default profile.
Returns grouped key/secret pairs by default. Disable grouping by passing true
for the raw
parameter value.
Parameters
raw
boolean return unmodified credentials object instead of grouping key/secret pairs (optional, defaultfalse
)
Examples
// get default credentials with grouped key/secret pairsconst consumer access_token screen_name = twurlrc;// consumer === {key: consumer_key, secret: consumer_secret}// access_token === {key: token, secret: secret}// screen_name === 'my_screen_name'
// disable groupingconst consumer_key consumer_secret token secret username = twurlrc;
Returns Object
fromYAMLSync
Create a Twurlrc object from a YAML string.
Parameters
yaml
string YAML string
Examples
try const twurlrc = ; // use twurlrc catcherror console;
Returns Twurlrc
fromFileSync
Create a Twurlrc object from a file path.
Parameters
filePath
string path to .twurlrc file
Examples
try const twurlrc = ; // use twurlrc catcherror console;
Returns Twurlrc
fromFile
Asynchronously create a Twurlrc object from a file path.
Parameters
filePath
string path to .twurlrc file
Examples
const Twurlrc = ;Twurlrc ;
Returns Promise
Development
Clone the repository and cd
into the resulting directory.
Install Dependencies
npm install
Run Tests
npm test
Note: Tests expect a ~/.twurlrc file to exist. The easiest way to create one is with twurl.
Built With
Contributing
Fork the repo and submit a pull request.
Versioning
SemVer is used for versioning. For the versions available, see the tags on this repository.
Author
License
This project is licensed under the MIT License. See the LICENSE.txt file for details.