lewagon/ruby-trello

Name: ruby-trello

Owner: Le Wagon

Description: Implementation of the Trello API for Ruby

Created: 2018-04-09 12:47:01.0

Updated: 2018-04-09 12:47:47.0

Pushed: 2018-04-09 12:47:46.0

Homepage:

Size: 974

Language: Ruby

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Ruby Trello API

Stories in Ready Build Status Dependency Status Code Climate

This library implements the Trello API.

Trello is an awesome tool for organization. Not just aimed at developers, but everybody. Seriously, check it out.

Full API documentation.

Installation
m install ruby-trello

Full Disclosure: This library is mostly complete, if you do find anything missing or not functioning as you expect it to, please let us know.

Supports Ruby 2.1.0 or newer.

Use version 1.3.0 or earlier for Ruby 1.9.3 support. Use version 1.4.x or earlier for Ruby 2.0.0 support.

Configuration
Basic authorization:
  1. Get your API public key from Trello via the irb console:
m install ruby-trello
b -rubygems
 require 'trello'
 Trello.open_public_key_url                         # copy your public key
 Trello.open_authorization_url key: 'yourpublickey' # copy your member token
  1. You can now use the public key and member token in your app code:
ire 'trello'

lo.configure do |config|
nfig.developer_public_key = TRELLO_DEVELOPER_PUBLIC_KEY # The "key" from step 1
nfig.member_token = TRELLO_MEMBER_TOKEN # The token from step 2.

2-legged OAuth authorization
lo.configure do |config|
nfig.consumer_key = TRELLO_CONSUMER_KEY
nfig.consumer_secret = TRELLO_CONSUMER_SECRET
nfig.oauth_token = TRELLO_OAUTH_TOKEN
nfig.oauth_token_secret = TRELLO_OAUTH_TOKEN_SECRET

3-legged OAuth authorization
lo.configure do |config|
nfig.consumer_key    = TRELLO_CONSUMER_KEY
nfig.consumer_secret = TRELLO_CONSUMER_SECRET
nfig.return_url      = "http://your.site.com/path/to/receive/post"
nfig.callback        = lambda { |request_token| DB.save(request_token.key, request_token.secret) }

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

Usage

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

= Trello::Member.find("bobtester")

int out his name
 bob.full_name # "Bob Tester"

int his bio
 bob.bio # A wonderfully delightful test user

w about a list of his boards?
boards

d then to read the lists of the first board do : 
boards.first.lists
Accessing specific items

There is no find by name method in the trello API, to access a specific item, you have to know it's ID. The best way is to pretty print the elements and then find the id of the element you are looking for.

th bob
ob.boards # Will pretty print all boards, allowing us to find our board id

 can now access it's lists
rello::Board.find( board_id ).lists # will pretty print all lists. Let's get the list id

 can now access the cards of the list
rello::List.find( list_id ).cards

 can now access the checklists of the card
rello::Card.find( card_id ).checklists

d so on ...
Changing a checkbox state
rst get your checklist id 
klist = Trello::Checklist.find( checklist_id )

 this point, there is no more ids. To get your checklist item, 
u have to know it's position (same as in the trello interface).
t's take the first
klist_item = checklist.items.first

en we can read the status
klist_item.state # return 'complete' or 'incomplete'

 can update it (note we call update_item_state from checklist, not from checklist_item)
klist.update_item_state( checklist_item.id, 'complete' ) # or 'incomplete'

u can also use true or false instead of 'complete' or 'incomplete'
klist.update_item_state( checklist_item.id, true ) # or false
Multiple Users

Applications that make requests on behalf of multiple Trello users have an alternative to global configuration. For each user's access token/secret pair, instantiate a Trello::Client:

ent_bob = Trello::Client.new(
onsumer_key => YOUR_CONSUMER_KEY,
onsumer_secret => YOUR_CONSUMER_SECRET,
auth_token => "Bob's access token",
auth_token_secret => "Bob's access secret"


ent_alice = Trello::Client.new(
onsumer_key => YOUR_CONSUMER_KEY,
onsumer_secret => YOUR_CONSUMER_SECRET,
auth_token => "Alice's access token",
auth_token_secret => "Alice's access secret"

You can now make threadsafe requests as the authenticated user:

ad.new do
lient_bob.find(:members, "bobtester")
lient_bob.find(:boards, "bobs_board_id")

ad.new do
lient_alice.find(:members, "alicetester")
lient_alice.find(:boards, "alices_board_id")

Special thanks

A special thanks goes out to Ben Biddington who has contributed a significant amount of refactoring and functionality to be deserving of a beer and this special thanks.

Contributing

Several ways you can contribute. Documentation, code, tests, feature requests, bug reports.

If you submit a pull request that's accepted, you'll be given commit access to this repository.

Please see the CONTRIBUTING.md file for more information.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.