module Trello

Ruby wrapper around the Trello API

First, set up your key information. You can get this information by clicking here.

You can get the key by going to this url in your browser: trello.com/1/authorize?key=TRELLO_CONSUMER_KEY_FROM_ABOVE&name=MyApp&response_type=token&scope=read,write,account&expiration=never Only request the permissions you need; i.e., scope=read if you only need read, or scope=write if you only need write. Comma separate scopes you need. If you want your token to expire after 30 days, drop the &expiration=never. Then run the following code, where KEY denotes the key returned from the url above:

Trello.configure do |config|

config.consumer_key = TRELLO_CONSUMER_KEY
config.consumer_secret = TRELLO_CONSUMER_SECRET
config.oauth_token = TRELLO_OAUTH_TOKEN
config.oauth_token_secret = TRELLO_OAUTH_TOKEN_SECRET

end

All the calls this library make to Trello require authentication using these keys. Be sure to protect them.

So lets say you want to get information about the user bobtester. We can do something like this:

bob = Member.find("bobtester")
# Print out his name
puts bob.full_name # "Bob Tester"
# Print his bio
puts bob.bio # A wonderfully delightful test user
# How about a list of his boards?
bob.boards

And so much more. Consult the rest of the documentation for more information.

Feel free to peruse and participate in our Trello board. It's completely open to the public.

Constants

API_VERSION

Version of the Trello API that we use by default.

ConfigurationError

This error is thrown when your client has not been configured

Error

Raise this when we hit a Trello error.

InvalidAccessToken

This specific error is thrown when your access token is invalid. You should get a new one.

Request
Response

Public Class Methods

auth_policy() click to toggle source
# File lib/trello.rb, line 108
def self.auth_policy; client.auth_policy; end
authorize_url(options = {}) click to toggle source

Url to token for making authorized requests to the Trello API

@param [String, read] contents the contents to reverse @param options [Hash] Repository information to update @option options [String] :name Name of the application @option options [String] :key Application key @option options [String] :response_type 'token' @option options [String] :callback_method 'postMessage' or 'fragment' @option options [String] :return_url URL the token should be returned to @option options [String] :scope Comma-separated list of one or more of 'read', 'write', 'account' @option options [String] :expiration '1hour', '1day', '30days', 'never' @see developers.trello.com/authorize

# File lib/trello.rb, line 128
def self.authorize_url(options = {})
  params = options.dup
  params[:key] ||= configuration.developer_public_key or
    raise ArgumentError, 'Please configure your Trello public key'
  params[:name] ||= 'Ruby Trello'
  params[:scope] ||= 'read,write,account'
  params[:expiration] ||= 'never'
  params[:response_type] ||= 'token'
  uri = Addressable::URI.parse 'https://trello.com/1/authorize'
  uri.query_values = params
  uri
end
client() click to toggle source
# File lib/trello.rb, line 95
def self.client
  @client ||= Client.new
end
configuration() click to toggle source
# File lib/trello.rb, line 109
def self.configuration; client.configuration; end
configure(&block) click to toggle source
# File lib/trello.rb, line 99
def self.configure(&block)
  reset!
  client.configure(&block)
end
logger() click to toggle source
# File lib/trello.rb, line 87
def self.logger
  @logger ||= Logger.new(STDOUT)
end
logger=(logger) click to toggle source
# File lib/trello.rb, line 91
def self.logger=(logger)
  @logger = logger
end
open_authorization_url(options = {}) click to toggle source

Visit the Trello authorized token page

@see developers.trello.com/authorize

# File lib/trello.rb, line 151
def self.open_authorization_url(options = {})
  open_url authorize_url(options)
end
open_public_key_url() click to toggle source

Visit the Trello API public key page

@see trello.com/app-key

# File lib/trello.rb, line 144
def self.open_public_key_url
  open_url public_key_url
end
open_url(url) click to toggle source

@private

# File lib/trello.rb, line 156
def self.open_url(url)
  require 'launchy'
  Launchy.open(url.to_s)
rescue LoadError
  warn 'Please install the launchy gem to open the url automatically.'
  url
end
public_key_url() click to toggle source

Url to Trello API public key page

# File lib/trello.rb, line 112
def self.public_key_url
  'https://trello.com/app-key'
end
reset!() click to toggle source
# File lib/trello.rb, line 104
def self.reset!
  @client = nil
end