Gem Version Build Status Dependency Status Code Climate Coverage Status

bwapi

A Ruby interface to the Brandwatch API.

Documentation

http://rubydoc.info/gems/bwapi/

Getting Started

All Brandwatch API calls at present require you to be authenticated, therefore you'll need to create an instance of a bwapi client and call the login method immediately:

bw = BWAPI::Client.new(username: '[email protected]', password: 'pa$$w0rd')
bw.

The API returns the oauth/token response with your authentication details.

Examples

Once authenticated, you are then able to make additional requests. The bwapi gem will automatically add your access token to subsequent request headers.

Please see an example projects response below:

bw.projects
{
  "resultsTotal"=>-1,
  "resultsPage"=>-1,
  "resultsPageSize"=>-1,
  "results"=>[
    { "id"=>1856280126,
      "name"=>"Demo Project",
      "description"=>nil,
      "clientId"=>1856278873,
      "defaultLangCodes"=>["en"],
      "defaultIndustry"=>"general-(recommended)",
      "creatorUserId"=>158304410,
      "creationDate"=>"2013-07-24T17:56:31.074+0000",
      "links"=> {
        "queries"=>"http://newapi.brandwatch.com//projects/1856280126/queries.json?access_token=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
      },
      "clientName"=>"JC BWAPI Demo"
    }
  ]
}

Debug Mode

In order to see additional logging and performance information you can enable debug mode by passing this in as an option when creating your client instance:

bw = BWAPI::Client.new(username: '[email protected]', password: 'pa$$w0rd', debug: true)

Logging

Any log output will be written to STDOUT unless you define a logger:

bw = BWAPI::Client.new(username: '[email protected]', password: 'pa$$w0rd', debug: true, logger: Logger.new('main.log'))

Performance

When debug mode is running the response performance is stored on each request, to view the stats call the performance method on the client instance:

bw.performance
{
  "post_oauth_token"=>[0.125019],
  "get_me"=> [0.048003, 0.034587, 0.038165, 0.10304]
}

Please note that only successful responses are recorded. Any request which raises an error is ignored.

Contributing

If you would like to contribute to this project please see the contributing guidelines.

Tests

There are a number of unit tests which are included as part of this project, please run:

rspec spec

Please note that a number of tests still need to be added so I don't currently have complete coverage, subject to workload these will be slowly added over the next few months.

Feedback

I would be more than happy to recieve feedback, please email me at: [email protected] or [email protected]