ruby-trello 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,26 @@
1
+ # Ruby Trello API
2
+
3
+ [![Build Status](https://secure.travis-ci.org/jeremytregunna/ruby-trello.png)](http://travis-ci.org/jeremytregunna/ruby-trello)
4
+
5
+ This library implements the [Trello](http://www.trello.com/) [API](http://trello.com/api).
6
+
7
+ Trello is an awesome tool for organization. Not just aimed at developers, but everybody.
8
+ Seriously, [check it out](http://www.trello.com/).
9
+
10
+ ## Installation
11
+
12
+ Full disclosure: It doesn't presently work. I'm in the process of implementing
13
+ the specs and the functionality. But if you want to check it out, clone the
14
+ repo for now. I will produce a gem when it's at least minimally usable. When
15
+ that is the case, I'll post that information here.
16
+
17
+ ## Contributing
18
+
19
+ Pick up an editor, fix a test! (If you want to, of course.) Send a pull
20
+ request, and I'll look at it. I only ask a few things:
21
+
22
+ 1. Feature branches please!
23
+ 2. Adding or refactoring existing features, ensure there are tests.
24
+
25
+ Also, don't be afraid to send a pull request if your changes aren't done. Just
26
+ let me know.
data/lib/trello.rb ADDED
@@ -0,0 +1,14 @@
1
+ # Ruby wrapper around the Trello API
2
+ # Copyright (c) 2012, Jeremy Tregunna
3
+ # Use and distribution terms may be found in the file LICENSE included in this distribution.
4
+
5
+ require 'oauth'
6
+ require 'yajl'
7
+
8
+ module Trello
9
+ autoload :Board, 'trello/board'
10
+ autoload :Card, 'trello/card'
11
+ autoload :Client, 'trello/client'
12
+ autoload :Member, 'trello/member'
13
+ autoload :Organization, 'trello/organization'
14
+ end
@@ -0,0 +1,54 @@
1
+ # Ruby wrapper around the Trello API
2
+ # Copyright (c) 2012, Jeremy Tregunna
3
+ # Use and distribution terms may be found in the file LICENSE included in this distribution.
4
+
5
+ module Trello
6
+ class Board
7
+ class << self
8
+ def find(id)
9
+ response = Client.query("/1/boards/#{id}")
10
+ new(Yajl::Parser.parse(response.read_body))
11
+ end
12
+ end
13
+
14
+ def initialize(fields = {})
15
+ @fields = fields
16
+ end
17
+
18
+ # Fields
19
+
20
+ def id
21
+ @fields['id']
22
+ end
23
+
24
+ def name
25
+ @fields['name']
26
+ end
27
+
28
+ def description
29
+ @fields['desc']
30
+ end
31
+
32
+ def closed
33
+ @fields['closed']
34
+ end
35
+
36
+ def url
37
+ @fields['url']
38
+ end
39
+
40
+ # Links to other data structures
41
+
42
+ def cards
43
+ response = Client.query("/1/boards/#{id}/cards/all")
44
+ all_cards = Yajl::Parser.parse(response.read_body)
45
+ all_cards.map do |card_fields|
46
+ Card.new(card_fields)
47
+ end
48
+ end
49
+
50
+ def organization
51
+ Organization.find(@fields['idOrganization'])
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,53 @@
1
+ # Ruby wrapper around the Trello API
2
+ # Copyright (c) 2012, Jeremy Tregunna
3
+ # Use and distribution terms may be found in the file LICENSE included in this distribution.
4
+
5
+ module Trello
6
+ class Card
7
+ class << self
8
+ def find(id)
9
+ response = Client.query("/1/cards/#{id}")
10
+ new(Yajl::Parser.parse(response.read_body))
11
+ end
12
+ end
13
+
14
+ def initialize(fields = {})
15
+ @fields = fields
16
+ end
17
+
18
+ # Fields
19
+
20
+ def id
21
+ @fields['id']
22
+ end
23
+
24
+ def name
25
+ @fields['name']
26
+ end
27
+
28
+ def description
29
+ @fields['desc']
30
+ end
31
+
32
+ def closed
33
+ @fields['closed']
34
+ end
35
+
36
+ def url
37
+ @fields['url']
38
+ end
39
+
40
+ # Links to other data structures
41
+
42
+ def board
43
+ Board.find(@fields['idBoard'])
44
+ end
45
+
46
+ def members
47
+ @fields['idMembers'].map do |member_id|
48
+ response = Client.query("/1/members/#{member_id}")
49
+ Member.new(Yajl::Parser.parse(response.read_body))
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,42 @@
1
+ # Ruby wrapper around the Trello API
2
+ # Copyright (c) 2012, Jeremy Tregunna
3
+ # Use and distribution terms may be found in the file LICENSE included in this distribution.
4
+
5
+ require 'addressable/uri'
6
+
7
+ module Trello
8
+ class Client
9
+ class EnterYourPublicKey < StandardError; end
10
+ class EnterYourSecret < StandardError; end
11
+
12
+ class << self
13
+ attr_writer :public_key, :secret, :app_name
14
+
15
+ def query(path, options = { :method => :get, :params => {} })
16
+ uri = Addressable::URI.parse("https://api.trello.com#{path}")
17
+ uri.query_values = options[:params]
18
+
19
+ access_token.send(options[:method], uri.to_s)
20
+ end
21
+
22
+ protected
23
+
24
+ def consumer
25
+ raise EnterYourPublicKey if @public_key.to_s.empty?
26
+ raise EnterYourSecret if @secret.to_s.empty?
27
+
28
+ OAuth::Consumer.new(@public_key, @secret, :site => 'https://trello.com',
29
+ :request_token_path => '/1/OAuthGetRequestToken',
30
+ :authorize_path => '/1/OAuthAuthorizeToken',
31
+ :access_token_path => '/1/OAuthGetAccessToken',
32
+ :http_method => :get)
33
+ end
34
+
35
+ def access_token
36
+ return @access_token if @access_token
37
+
38
+ @access_token = OAuth::AccessToken.new(consumer)
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,62 @@
1
+ # Ruby wrapper around the Trello API
2
+ # Copyright (c) 2012, Jeremy Tregunna
3
+ # Use and distribution terms may be found in the file LICENSE included in this distribution.
4
+
5
+ module Trello
6
+ class Member
7
+ class << self
8
+ def find(id_or_username)
9
+ response = Client.query("/1/members/#{id_or_username}")
10
+ new(Yajl::Parser.parse(response.read_body))
11
+ end
12
+ end
13
+
14
+ def initialize(fields = {})
15
+ @fields = fields
16
+ end
17
+
18
+ # Fields of a user
19
+
20
+ def id
21
+ @fields['id']
22
+ end
23
+
24
+ def full_name
25
+ @fields['fullName']
26
+ end
27
+
28
+ def username
29
+ @fields['username']
30
+ end
31
+
32
+ def gravatar_id
33
+ @fields['gravatar']
34
+ end
35
+
36
+ def bio
37
+ @fields['bio']
38
+ end
39
+
40
+ def url
41
+ @fields['url']
42
+ end
43
+
44
+ # Links to other data structures
45
+
46
+ def boards
47
+ response = Client.query("/1/members/#{username}/boards/all")
48
+ all_boards = Yajl::Parser.parse(response.read_body)
49
+ all_boards.map do |board_fields|
50
+ Board.new(board_fields)
51
+ end
52
+ end
53
+
54
+ def organizations
55
+ response = Client.query("/1/members/#{username}/organizations/all")
56
+ all_orgs = Yajl::Parser.parse(response.read_body)
57
+ all_orgs.map do |org_fields|
58
+ Organization.new(org_fields)
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,40 @@
1
+ # Ruby wrapper around the Trello API
2
+ # Copyright (c) 2012, Jeremy Tregunna
3
+ # Use and distribution terms may be found in the file LICENSE included in this distribution.
4
+
5
+ module Trello
6
+ class Organization
7
+ class << self
8
+ def find(id)
9
+ response = Client.query("/1/organizations/#{id}")
10
+ new(Yajl::Parser.parse(response.read_body))
11
+ end
12
+ end
13
+
14
+ def initialize(fields = {})
15
+ @fields = fields
16
+ end
17
+
18
+ # Fields
19
+
20
+ def id
21
+ @fields['id']
22
+ end
23
+
24
+ def name
25
+ @fields['name']
26
+ end
27
+
28
+ def display_name
29
+ @fields['display_name']
30
+ end
31
+
32
+ def description
33
+ @fields['desc']
34
+ end
35
+
36
+ def url
37
+ @fields['url']
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ module Trello
4
+ describe Board do
5
+ include Helpers
6
+
7
+ before(:all) do
8
+ Client.public_key = 'dummy'
9
+ Client.secret = 'dummy'
10
+ end
11
+
12
+ before(:each) do
13
+ stub_request(:get, "https://api.trello.com/1/boards/abcdef123456789123456789?").
14
+ with(:headers => {'Accept'=>'*/*', 'Authorization'=>/.*/, 'User-Agent' => /.*/}).
15
+ to_return(:status => 200, :headers => {}, :body => Yajl::Encoder.encode(boards_details.first))
16
+
17
+ @board = Board.find('abcdef123456789123456789')
18
+ end
19
+
20
+ context "fields" do
21
+ it "gets an id" do
22
+ @board.id.should_not be_nil
23
+ end
24
+
25
+ it "gets a name" do
26
+ @board.name.should_not be_nil
27
+ end
28
+
29
+ it "gets the description" do
30
+ @board.description.should_not be_nil
31
+ end
32
+
33
+ it "knows if it is closed or open" do
34
+ @board.closed.should_not be_nil
35
+ end
36
+
37
+ it "gets its url" do
38
+ @board.url.should_not be_nil
39
+ end
40
+ end
41
+
42
+ context "cards" do
43
+ it "gets its list of cards" do
44
+ stub_request(:get, "https://api.trello.com/1/boards/abcdef123456789123456789/cards/all?").
45
+ with(:headers => {'Accept'=>'*/*', 'Authorization'=>/.*/, 'User-Agent' => /.*/}).
46
+ to_return(:status => 200, :headers => {}, :body => cards_payload)
47
+
48
+ @board.cards.count.should be > 0
49
+ end
50
+ end
51
+ end
52
+ end
data/spec/card_spec.rb ADDED
@@ -0,0 +1,66 @@
1
+ require 'spec_helper'
2
+
3
+ module Trello
4
+ describe Card do
5
+ include Helpers
6
+
7
+ before(:all) do
8
+ Client.public_key = 'dummy'
9
+ Client.secret = 'dummy'
10
+ end
11
+
12
+ before(:each) do
13
+ stub_request(:get, "https://api.trello.com/1/cards/abcdef123456789123456789?").
14
+ with(:headers => {'Accept'=>'*/*', 'Authorization'=>/.*/, 'User-Agent' => /.*/}).
15
+ to_return(:status => 200, :headers => {}, :body => Yajl::Encoder.encode(cards_details.first))
16
+
17
+ @card = Card.find('abcdef123456789123456789')
18
+ end
19
+
20
+ context "fields" do
21
+ it "gets its id" do
22
+ @card.id.should_not be_nil
23
+ end
24
+
25
+ it "gets its name" do
26
+ @card.name.should_not be_nil
27
+ end
28
+
29
+ it "gets its description" do
30
+ @card.description.should_not be_nil
31
+ end
32
+
33
+ it "knows if it is open or closed" do
34
+ @card.closed.should_not be_nil
35
+ end
36
+
37
+ it "gets its url" do
38
+ @card.url.should_not be_nil
39
+ end
40
+ end
41
+
42
+ context "boards" do
43
+ it "has a board" do
44
+ stub_request(:get, "https://api.trello.com/1/boards/abcdef123456789123456789?").
45
+ with(:headers => {'Accept'=>'*/*', 'Authorization'=>/.*/, 'User-Agent' => /.*/}).
46
+ to_return(:status => 200, :headers => {}, :body => Yajl::Encoder.encode(boards_details.first))
47
+
48
+ @card.board.should_not be_nil
49
+ end
50
+ end
51
+
52
+ context "members" do
53
+ it "has a list of members" do
54
+ stub_request(:get, "https://api.trello.com/1/boards/abcdef123456789123456789?").
55
+ with(:headers => {'Accept'=>'*/*', 'Authorization'=>/.*/, 'User-Agent' => /.*/}).
56
+ to_return(:status => 200, :headers => {}, :body => Yajl::Encoder.encode(boards_details.first))
57
+ stub_request(:get, "https://api.trello.com/1/members/abcdef123456789123456789?").
58
+ with(:headers => {'Accept'=>'*/*', 'Authorization'=>/.*/, 'User-Agent' => /.*/}).
59
+ to_return(:status => 200, :headers => {}, :body => user_payload)
60
+
61
+ @card.board.should_not be_nil
62
+ @card.members.should_not be_nil
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ module Trello
4
+ describe Client do
5
+ before(:all) do
6
+ Client.public_key = 'dummy'
7
+ Client.secret = 'dummy'
8
+ end
9
+
10
+ context 'keys' do
11
+ after do
12
+ Client.public_key = 'dummy'
13
+ end
14
+
15
+ it 'throws an error if the public key is ommitted' do
16
+ Client.public_key = ''
17
+ lambda { Client.send(:consumer) }.should raise_error(Client::EnterYourPublicKey)
18
+ end
19
+
20
+ after do
21
+ Client.secret = 'dummy'
22
+ end
23
+
24
+ it 'throws an error if the secret is ommitted' do
25
+ Client.secret = ''
26
+ lambda { Client.send(:consumer) }.should raise_error(Client::EnterYourSecret)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,68 @@
1
+ # Specs covering the members namespace in the Trello API
2
+
3
+ require 'spec_helper'
4
+
5
+ module Trello
6
+ describe Member do
7
+ include Helpers
8
+
9
+ before(:all) do
10
+ Client.public_key = 'dummy'
11
+ Client.secret = 'dummy'
12
+ end
13
+
14
+ before(:each) do
15
+ stub_oauth!
16
+ @member = Member.find('me')
17
+ end
18
+
19
+ context "actions" do
20
+ # This spec needs a better name
21
+ it "retrieves a list of actions"
22
+ end
23
+
24
+ context "boards" do
25
+ it "has a list of boards" do
26
+ stub_request(:get, "https://api.trello.com/1/members/me/boards/all?").
27
+ with(:headers => {'Accept'=>'*/*', 'Authorization'=>/.*/, 'User-Agent' => /.*/}).
28
+ to_return(:status => 200, :headers => {}, :body => boards_payload)
29
+
30
+ boards = @member.boards
31
+ boards.count.should be > 0
32
+ end
33
+ end
34
+
35
+ context "organizations" do
36
+ it "has a list of organizations" do
37
+ stub_request(:get, "https://api.trello.com/1/members/me/organizations/all?").
38
+ with(:headers => {'Accept'=>'*/*', 'Authorization'=>/.*/, 'User-Agent' => /.*/}).
39
+ to_return(:status => 200, :headers => {}, :body => orgs_payload)
40
+
41
+ orgs = @member.organizations
42
+ orgs.count.should be > 0
43
+ end
44
+ end
45
+
46
+ context "personal" do
47
+ it "gets the members bio" do
48
+ @member.bio.should_not be_nil
49
+ end
50
+
51
+ it "gets the full name" do
52
+ @member.full_name.should_not be_nil
53
+ end
54
+
55
+ it "gets the gravatar id" do
56
+ @member.gravatar_id.should_not be_nil
57
+ end
58
+
59
+ it "gets the url" do
60
+ @member.url.should_not be_nil
61
+ end
62
+
63
+ it "gets the username" do
64
+ @member.username.should_not be_nil
65
+ end
66
+ end
67
+ end
68
+ end
File without changes
@@ -0,0 +1,86 @@
1
+ require 'rubygems'
2
+
3
+ # Set up gems listed in the Gemfile.
4
+ begin
5
+ ENV['BUNDLE_GEMFILE'] = File.expand_path('../Gemfile', File.dirname(__FILE__))
6
+ require 'bundler'
7
+ Bundler.setup
8
+ rescue Bundler::GemNotFound => e
9
+ STDERR.puts e.message
10
+ STDERR.puts "Try running `bundle install`."
11
+ exit!
12
+ end
13
+
14
+ Bundler.require(:spec)
15
+
16
+ require 'trello'
17
+ require 'webmock/rspec'
18
+
19
+ module Helpers
20
+ def user_details
21
+ {
22
+ "id" => "abcdef123456789012345678",
23
+ "fullName" => "Test User",
24
+ "username" => "me",
25
+ "gravatar" => "abcdef1234567890abcdef1234567890",
26
+ "bio" => "a rather dumb user",
27
+ "url" => "https://trello.com/me"
28
+ }
29
+ end
30
+
31
+ def user_payload
32
+ Yajl::Encoder.encode(user_details)
33
+ end
34
+
35
+ def boards_details
36
+ [{
37
+ "id" => "abcdef123456789123456789",
38
+ "name" => "Test",
39
+ "desc" => "This is a test board",
40
+ "closed" => false,
41
+ "idOrganization" => "abcdef123456789123456789",
42
+ "url" => "https://trello.com/board/test/abcdef123456789123456789"
43
+ }]
44
+ end
45
+
46
+ def boards_payload
47
+ Yajl::Encoder.encode(boards_details)
48
+ end
49
+
50
+ def cards_details
51
+ [{
52
+ "id" => "abcdef123456789123456789",
53
+ "name" => "Do something awesome",
54
+ "desc" => "Awesome things are awesome.",
55
+ "closed" => false,
56
+ "idList" => "abcdef123456789123456789",
57
+ "idBoard" => "abcdef123456789123456789",
58
+ "idMembers" => ["abcdef123456789123456789"],
59
+ "url" => "https://trello.com/card/board/specify-the-type-and-scope-of-the-jit-in-a-lightweight-spec/abcdef123456789123456789/abcdef123456789123456789"
60
+ }]
61
+ end
62
+
63
+ def cards_payload
64
+ Yajl::Encoder.encode(cards_details)
65
+ end
66
+
67
+ def orgs_details
68
+ [{
69
+ "id" => "abcdef123456789123456789",
70
+ "name" => "test",
71
+ "displayName" => "Test Organization",
72
+ "desc" => "This is a test organization",
73
+ "url" => "https://trello.com/test"
74
+ }]
75
+ end
76
+
77
+ def orgs_payload
78
+ Yajl::Encoder.encode(orgs_details)
79
+ end
80
+
81
+ def stub_oauth!
82
+ stub_request(:get, "https://api.trello.com/1/members/me?").
83
+ with(:headers => {'Accept'=>'*/*', 'Authorization'=>/.*/, 'User-Agent' => /.*/}).
84
+ to_return(:status => 200, :headers => {}, :body => user_payload)
85
+ end
86
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-trello
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jeremy Tregunna
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-07 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: yajl-ruby
16
+ requirement: &70132949849940 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.1.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70132949849940
25
+ - !ruby/object:Gem::Dependency
26
+ name: oauth
27
+ requirement: &70132949849480 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 0.4.5
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70132949849480
36
+ - !ruby/object:Gem::Dependency
37
+ name: addressable
38
+ requirement: &70132949849020 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 2.2.6
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70132949849020
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: &70132949874400 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.0
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70132949874400
58
+ description: A wrapper around the trello.com API.
59
+ email: jeremy@tregunna.ca
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files:
63
+ - README.md
64
+ files:
65
+ - lib/trello/board.rb
66
+ - lib/trello/card.rb
67
+ - lib/trello/client.rb
68
+ - lib/trello/member.rb
69
+ - lib/trello/organization.rb
70
+ - lib/trello.rb
71
+ - README.md
72
+ - spec/board_spec.rb
73
+ - spec/card_spec.rb
74
+ - spec/client_spec.rb
75
+ - spec/member_spec.rb
76
+ - spec/organization_spec.rb
77
+ - spec/spec_helper.rb
78
+ homepage: https://github.com/jeremytregunna/ruby-trello
79
+ licenses: []
80
+ post_install_message:
81
+ rdoc_options:
82
+ - --charset=UTF-8
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: 1.3.6
97
+ requirements: []
98
+ rubyforge_project: ruby-trello
99
+ rubygems_version: 1.8.10
100
+ signing_key:
101
+ specification_version: 3
102
+ summary: A wrapper around the trello.com API.
103
+ test_files:
104
+ - spec/board_spec.rb
105
+ - spec/card_spec.rb
106
+ - spec/client_spec.rb
107
+ - spec/member_spec.rb
108
+ - spec/organization_spec.rb
109
+ - spec/spec_helper.rb