Repository is archived
No commit activity in last 3 years
No release in over 3 years
A simple wrapper around Brightcove's CMS API
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.15

Runtime

~> 2.2.2
 Project Readme

Brightcove::Cmsapi

Build Status

This gem wraps Brightcove's CMS API.

Installation

Add this line to your application's Gemfile:

gem 'brightcove-cmsapi'

And then execute:

$ bundle

Or install it yourself as:

$ gem install brightcove-cmsapi

Setup

To use this library you will require a client ID and secret, as well as your brightcove account's ID. You can find instructions of obtaining these credentials in the Brightcove docs.

** Setup a basic client **

  @client = Brightcove::Cmsapi.new(
    account_id: "my_account_id",
    client_id: "my_client_id",
    client_secret: "my_client_secret")

One alternative to this setup that can save you time and boilerplate code would be to call the .default_api method. This assumes you have your credentials and account ID set as environment variables BRIGHTCOVE_ACCOUNT_ID BRIGHTCOVE_CLIENT_ID BRIGHTCOVE_CLIENT_SECRET.

** Alternatively: don't setup the client each time (RECOMMENDED USAGE) **

Brightcove::Cmsapi.default_api.get('videos')

Usage examples

** Get the available videos in account (by default the first 20) **

@client.get('videos')

# or use the default_api setup:
Brightcove::Cmsapi.default_api.get('videos')

Calling .get uses the default API settings and simply appends the argument to the API call like this:

https://cms.api.brightcove.com/v1/accounts/:account_id/videos

The result will be a HTTP::Response object (the gem uses the http.rb gem). To parse the JSON in this response into a Ruby hash call .parse.

The API defaults are described in Brightcove's documentation. To get more than the default 20 results you could call .get('videos?limit=100'), however there is a hard limit at 100 results that you can not exceed. To get around this limit you can use the .get_all method as displayed below, this will paginate through the results and return a parsed set of all a particular resource.

** Get all available videos **

Brightcove::Cmsapi.default_api.get_all('video')

** Get all available videos in a folder **

Brightcove::Cmsapi.default_api.get_all('folder/:folder_id', 'video')

** Get all available videos in a folder as an array of ruby hashes **

Brightcove::Cmsapi.default_api.get_all('folder/:folder_id', 'video').parse

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

License

The gem is available as open source under the terms of the MIT License.