Module: Trello

Defined in:
lib/trello.rb,
lib/trello/net.rb,
lib/trello/card.rb,
lib/trello/item.rb,
lib/trello/list.rb,
lib/trello/board.rb,
lib/trello/error.rb,
lib/trello/label.rb,
lib/trello/token.rb,
lib/trello/action.rb,
lib/trello/client.rb,
lib/trello/member.rb,
lib/trello/schema.rb,
lib/trello/comment.rb,
lib/trello/webhook.rb,
lib/trello/checklist.rb,
lib/trello/attachment.rb,
lib/trello/basic_data.rb,
lib/trello/item_state.rb,
lib/trello/json_utils.rb,
lib/trello/label_name.rb,
lib/trello/association.rb,
lib/trello/cover_image.rb,
lib/trello/has_actions.rb,
lib/trello/net/faraday.rb,
lib/trello/custom_field.rb,
lib/trello/notification.rb,
lib/trello/organization.rb,
lib/trello/plugin_datum.rb,
lib/trello/authorization.rb,
lib/trello/configuration.rb,
lib/trello/net/rest_client.rb,
lib/trello/association_proxy.rb,
lib/trello/custom_field_item.rb,
lib/trello/multi_association.rb,
lib/trello/custom_field_option.rb,
lib/trello/schema/attribute/base.rb,
lib/trello/association_infer_tool.rb,
lib/trello/schema/serializer/time.rb,
lib/trello/schema/attribute/default.rb,
lib/trello/schema/attribute_builder.rb,
lib/trello/schema/serializer/labels.rb,
lib/trello/schema/serializer/default.rb,
lib/trello/schema/serializer/webhooks.rb,
lib/trello/association_builder/has_one.rb,
lib/trello/association_fetcher/has_one.rb,
lib/trello/schema/attribute/board_pref.rb,
lib/trello/association_builder/has_many.rb,
lib/trello/association_fetcher/has_many.rb,
lib/trello/schema/attribute_registration.rb,
lib/trello/association_fetcher/has_one/fetch.rb,
lib/trello/association_fetcher/has_many/fetch.rb,
lib/trello/association_fetcher/has_one/params.rb,
lib/trello/association_fetcher/has_many/params.rb,
lib/trello/schema/attribute/custom_field_display.rb

Overview

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.

[trello]: trello.com [trello-app-key]: trello.com/app-key [ruby-trello-board]: trello.com/board/ruby-trello/4f092b2ee23cb6fe6d1aaabd

Defined Under Namespace

Modules: AssociationBuilder, AssociationFetcher, Authorization, HasActions, JsonUtils, TFaraday, TRestClient Classes: Action, Association, AssociationInferTool, AssociationProxy, Attachment, BasicData, Board, Card, CheckItemState, Checklist, Client, Comment, Configuration, CoverImage, CustomField, CustomFieldItem, CustomFieldOption, Error, Item, Label, LabelName, List, Member, MultiAssociation, Notification, Organization, PluginDatum, Request, Response, Schema, TInternet, Token, Webhook

Constant Summary collapse

API_VERSION =

Version of the Trello API that we use by default.

1
InvalidAccessToken =

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

Class.new(Error)
ConfigurationError =

This error is thrown when your client has not been configured

Class.new(Error)
HTTP_CLIENT_PRIORITY =

The order in which we will try the http clients

%w(faraday rest-client)
HTTP_CLIENTS =
{
  'faraday' => Trello::TFaraday::TInternet,
  'rest-client' => Trello::TRestClient::TInternet
}

Class Method Summary collapse

Class Method Details

.auth_policyObject



177
# File 'lib/trello.rb', line 177

def self.auth_policy; client.auth_policy; end

.authorize_url(options = {}) ⇒ Object

Url to token for making authorized requests to the Trello API

Parameters:

  • options (Hash) (defaults to: {})

    Repository information to update

Options Hash (options):

  • :name (String)

    Name of the application

  • :key (String)

    Application key

  • :response_type (String)

    ‘token’

  • :callback_method (String)

    ‘postMessage’ or ‘fragment’

  • :return_url (String)

    URL the token should be returned to

  • :scope (String)

    Comma-separated list of one or more of ‘read’, ‘write’, ‘account’

  • :expiration (String)

    ‘1hour’, ‘1day’, ‘30days’, ‘never’

See Also:



196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/trello.rb', line 196

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

.clientObject



163
164
165
# File 'lib/trello.rb', line 163

def self.client
  @client ||= Client.new
end

.configurationObject



178
# File 'lib/trello.rb', line 178

def self.configuration; client.configuration; end

.configure(&block) ⇒ Object



167
168
169
170
# File 'lib/trello.rb', line 167

def self.configure(&block)
  reset!
  client.configure(&block)
end

.http_clientObject



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/trello.rb', line 131

def self.http_client
  @http_client ||= begin
    # No client has been set explicitly. Try to load each supported client.
    # The first one that loads successfully will be used.
    client = HTTP_CLIENT_PRIORITY.each do |key|
      begin
        require key
        break HTTP_CLIENTS[key]
      rescue LoadError
        next
      end
    end

    raise ConfigurationError, 'Trello requires either faraday or rest-client installed' unless client

    client
  end
end

.http_client=(http_client) ⇒ Object



150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/trello.rb', line 150

def self.http_client=(http_client)
  if HTTP_CLIENTS.include?(http_client)
    begin
      require http_client
      @http_client = HTTP_CLIENTS[http_client]
    rescue LoadError
      raise ConfigurationError, "Trello tried to use #{http_client}, but that gem is not installed"
    end
  else
    raise ArgumentError, "Unsupported HTTP client: #{http_client}"
  end
end

.loggerObject



116
117
118
# File 'lib/trello.rb', line 116

def self.logger
  @logger ||= Logger.new(STDOUT)
end

.logger=(logger) ⇒ Object



120
121
122
# File 'lib/trello.rb', line 120

def self.logger=(logger)
  @logger = logger
end

.open_authorization_url(options = {}) ⇒ Object

Visit the Trello authorized token page



219
220
221
# File 'lib/trello.rb', line 219

def self.open_authorization_url(options = {})
  open_url authorize_url(options)
end

.open_public_key_urlObject

Visit the Trello API public key page



212
213
214
# File 'lib/trello.rb', line 212

def self.open_public_key_url
  open_url public_key_url
end

.open_url(url) ⇒ Object



224
225
226
227
228
229
230
# File 'lib/trello.rb', line 224

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_urlObject

Url to Trello API public key page



181
182
183
# File 'lib/trello.rb', line 181

def self.public_key_url
  'https://trello.com/app-key'
end

.reset!Object



172
173
174
175
# File 'lib/trello.rb', line 172

def self.reset!
  @client = nil
  @http_client = nil
end