ruby-trello-czuger 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +182 -0
  3. data/lib/trello.rb +163 -0
  4. data/lib/trello/action.rb +68 -0
  5. data/lib/trello/association.rb +14 -0
  6. data/lib/trello/association_proxy.rb +42 -0
  7. data/lib/trello/attachment.rb +40 -0
  8. data/lib/trello/authorization.rb +187 -0
  9. data/lib/trello/basic_data.rb +132 -0
  10. data/lib/trello/board.rb +211 -0
  11. data/lib/trello/card.rb +467 -0
  12. data/lib/trello/checklist.rb +143 -0
  13. data/lib/trello/client.rb +120 -0
  14. data/lib/trello/comment.rb +62 -0
  15. data/lib/trello/configuration.rb +68 -0
  16. data/lib/trello/core_ext/array.rb +6 -0
  17. data/lib/trello/core_ext/hash.rb +6 -0
  18. data/lib/trello/core_ext/string.rb +6 -0
  19. data/lib/trello/cover_image.rb +8 -0
  20. data/lib/trello/has_actions.rb +9 -0
  21. data/lib/trello/item.rb +37 -0
  22. data/lib/trello/item_state.rb +30 -0
  23. data/lib/trello/json_utils.rb +64 -0
  24. data/lib/trello/label.rb +108 -0
  25. data/lib/trello/label_name.rb +31 -0
  26. data/lib/trello/list.rb +114 -0
  27. data/lib/trello/member.rb +112 -0
  28. data/lib/trello/multi_association.rb +12 -0
  29. data/lib/trello/net.rb +39 -0
  30. data/lib/trello/notification.rb +61 -0
  31. data/lib/trello/organization.rb +68 -0
  32. data/lib/trello/plugin_datum.rb +34 -0
  33. data/lib/trello/token.rb +37 -0
  34. data/lib/trello/webhook.rb +103 -0
  35. data/spec/action_spec.rb +149 -0
  36. data/spec/array_spec.rb +13 -0
  37. data/spec/association_spec.rb +26 -0
  38. data/spec/basic_auth_policy_spec.rb +51 -0
  39. data/spec/board_spec.rb +442 -0
  40. data/spec/card_spec.rb +822 -0
  41. data/spec/checklist_spec.rb +296 -0
  42. data/spec/client_spec.rb +257 -0
  43. data/spec/configuration_spec.rb +95 -0
  44. data/spec/hash_spec.rb +15 -0
  45. data/spec/integration/how_to_authorize_spec.rb +53 -0
  46. data/spec/integration/how_to_use_boards_spec.rb +48 -0
  47. data/spec/integration/integration_test.rb +40 -0
  48. data/spec/item_spec.rb +75 -0
  49. data/spec/json_utils_spec.rb +73 -0
  50. data/spec/label_spec.rb +205 -0
  51. data/spec/list_spec.rb +253 -0
  52. data/spec/member_spec.rb +159 -0
  53. data/spec/notification_spec.rb +143 -0
  54. data/spec/oauth_policy_spec.rb +160 -0
  55. data/spec/organization_spec.rb +71 -0
  56. data/spec/spec_helper.rb +435 -0
  57. data/spec/string_spec.rb +55 -0
  58. data/spec/token_spec.rb +89 -0
  59. data/spec/trello_spec.rb +134 -0
  60. data/spec/webhook_spec.rb +130 -0
  61. metadata +200 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 90cf20663bfabaa746c5dd9bf073d1a4e43cf108
4
+ data.tar.gz: d77c1e852013936738f64840fd46ad4f5cd5efc4
5
+ SHA512:
6
+ metadata.gz: 204f92e6c4540e905c94c4842b0142441c33ca62d0629aa16defdf21f9f150db7ed1e2010ea6816ee94847ab34e5044cbecf664afccc8f2c1a160ea85ee62a18
7
+ data.tar.gz: 165ce19bc465b5c6b844665f93838c4716e846e1e83e48dacb9c34de4ad7fb99d4f7130e79e9975830c7156ce587dd23e3282d498ec1c5615b59476f089fd56a
data/README.md ADDED
@@ -0,0 +1,182 @@
1
+ # Ruby Trello API
2
+
3
+ [![Stories in Ready](http://badge.waffle.io/jeremytregunna/ruby-trello.png)](http://waffle.io/jeremytregunna/ruby-trello)
4
+ [![Build Status](https://secure.travis-ci.org/jeremytregunna/ruby-trello.png)](http://travis-ci.org/jeremytregunna/ruby-trello) [![Dependency Status](https://gemnasium.com/jeremytregunna/ruby-trello.png)](https://gemnasium.com/jeremytregunna/ruby-trello)
5
+ [![Code Climate](https://codeclimate.com/github/jeremytregunna/ruby-trello/badges/gpa.svg)](https://codeclimate.com/github/jeremytregunna/ruby-trello)
6
+
7
+ This library implements the [Trello](http://www.trello.com/) [API](https://developers.trello.com/).
8
+
9
+ Trello is an awesome tool for organization. Not just aimed at developers, but everybody.
10
+ Seriously, [check it out](http://www.trello.com/).
11
+
12
+ [Full API documentation](http://www.rubydoc.info/gems/ruby-trello).
13
+
14
+ ## Installation
15
+
16
+ ```
17
+ # gem install ruby-trello
18
+ ```
19
+
20
+ Full Disclosure: This library is mostly complete, if you do find anything missing or not functioning as you expect it
21
+ to, please [let us know](https://trello.com/card/spot-a-bug-report-it/4f092b2ee23cb6fe6d1aaabd/17).
22
+
23
+ Supports Ruby 2.1.0 or newer.
24
+
25
+ Use version 1.3.0 or earlier for Ruby 1.9.3 support.
26
+ Use version 1.4.x or earlier for Ruby 2.0.0 support.
27
+
28
+ ## Configuration
29
+
30
+ #### Basic authorization:
31
+
32
+ 1. Get your API public key from Trello via the irb console:
33
+
34
+ ```
35
+ $ gem install ruby-trello
36
+ $ irb -rubygems
37
+ irb> require 'trello'
38
+ irb> Trello.open_public_key_url # copy your public key
39
+ irb> Trello.open_authorization_url key: 'yourpublickey' # copy your member token
40
+ ```
41
+
42
+ 2. You can now use the public key and member token in your app code:
43
+
44
+ ```ruby
45
+ require 'trello'
46
+
47
+ Trello.configure do |config|
48
+ config.developer_public_key = TRELLO_DEVELOPER_PUBLIC_KEY # The "key" from step 1
49
+ config.member_token = TRELLO_MEMBER_TOKEN # The token from step 2.
50
+ end
51
+ ```
52
+
53
+ #### 2-legged OAuth authorization
54
+
55
+ ```ruby
56
+ Trello.configure do |config|
57
+ config.consumer_key = TRELLO_CONSUMER_KEY
58
+ config.consumer_secret = TRELLO_CONSUMER_SECRET
59
+ config.oauth_token = TRELLO_OAUTH_TOKEN
60
+ config.oauth_token_secret = TRELLO_OAUTH_TOKEN_SECRET
61
+ end
62
+ ```
63
+
64
+ #### 3-legged OAuth authorization
65
+
66
+ ```ruby
67
+ Trello.configure do |config|
68
+ config.consumer_key = TRELLO_CONSUMER_KEY
69
+ config.consumer_secret = TRELLO_CONSUMER_SECRET
70
+ config.return_url = "http://your.site.com/path/to/receive/post"
71
+ config.callback = lambda { |request_token| DB.save(request_token.key, request_token.secret) }
72
+ end
73
+ ```
74
+
75
+ All the calls this library makes to Trello require authentication using these keys. Be sure to protect them.
76
+
77
+ #### Usage
78
+
79
+ So let's say you want to get information about the user *bobtester*. We can do something like this:
80
+
81
+ ```ruby
82
+ bob = Trello::Member.find("bobtester")
83
+
84
+ # Print out his name
85
+ puts bob.full_name # "Bob Tester"
86
+
87
+ # Print his bio
88
+ puts bob.bio # A wonderfully delightful test user
89
+
90
+ # How about a list of his boards?
91
+ bob.boards
92
+
93
+ # And then to read the lists of the first board do :
94
+ bob.boards.first.lists
95
+ ```
96
+
97
+ ##### Accessing specific items
98
+
99
+ There is no find by name method in the trello API, to access a specific item, you have to know it's ID.
100
+ The best way is to pretty print the elements and then find the id of the element you are looking for.
101
+
102
+ ```ruby
103
+ # With bob
104
+ pp bob.boards # Will pretty print all boards, allowing us to find our board id
105
+
106
+ # We can now access it's lists
107
+ pp Trello::Board.find( board_id ).lists # will pretty print all lists. Let's get the list id
108
+
109
+ # We can now access the cards of the list
110
+ pp Trello::List.find( list_id ).cards
111
+
112
+ # We can now access the checklists of the card
113
+ pp Trello::Card.find( card_id ).checklists
114
+
115
+ # and so on ...
116
+ ```
117
+
118
+ ##### Changing a checkbox state
119
+ ```ruby
120
+ # First get your checklist id
121
+ checklist = Trello::Checklist.find( checklist_id )
122
+
123
+ # At this point, there is no more ids. To get your checklist item,
124
+ # you have to know it's position (same as in the trello interface).
125
+ # Let's take the first
126
+ checklist_item = checklist.items.first
127
+
128
+ # Then we can read the status
129
+ checklist_item.state # return 'complete' or 'incomplete'
130
+
131
+ # We can update it (note we call update_item_state from checklist, not from checklist_item)
132
+ checklist.update_item_state( checklist_item.id, 'complete' ) # or 'incomplete'
133
+
134
+ # You can also use true or false instead of 'complete' or 'incomplete'
135
+ checklist.update_item_state( checklist_item.id, true ) # or false
136
+ ```
137
+
138
+ #### Multiple Users
139
+
140
+ 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`:
141
+
142
+ ```ruby
143
+ @client_bob = Trello::Client.new(
144
+ :consumer_key => YOUR_CONSUMER_KEY,
145
+ :consumer_secret => YOUR_CONSUMER_SECRET,
146
+ :oauth_token => "Bob's access token",
147
+ :oauth_token_secret => "Bob's access secret"
148
+ )
149
+
150
+ @client_alice = Trello::Client.new(
151
+ :consumer_key => YOUR_CONSUMER_KEY,
152
+ :consumer_secret => YOUR_CONSUMER_SECRET,
153
+ :oauth_token => "Alice's access token",
154
+ :oauth_token_secret => "Alice's access secret"
155
+ )
156
+ ```
157
+
158
+ You can now make threadsafe requests as the authenticated user:
159
+
160
+ ```ruby
161
+ Thread.new do
162
+ @client_bob.find(:members, "bobtester")
163
+ @client_bob.find(:boards, "bobs_board_id")
164
+ end
165
+ Thread.new do
166
+ @client_alice.find(:members, "alicetester")
167
+ @client_alice.find(:boards, "alices_board_id")
168
+ end
169
+ ```
170
+
171
+ ## Special thanks
172
+
173
+ A special thanks goes out to [Ben Biddington](https://github.com/ben-biddington) who has contributed a significant amount
174
+ of refactoring and functionality to be deserving of a beer and this special thanks.
175
+
176
+ ## Contributing
177
+
178
+ Several ways you can contribute. Documentation, code, tests, feature requests, bug reports.
179
+
180
+ If you submit a pull request that's accepted, you'll be given commit access to this repository.
181
+
182
+ Please see the `CONTRIBUTING.md` file for more information.
data/lib/trello.rb ADDED
@@ -0,0 +1,163 @@
1
+ require 'oauth'
2
+ require 'json'
3
+ require 'logger'
4
+ require 'active_model'
5
+ require 'addressable/uri'
6
+
7
+ # Ruby wrapper around the Trello[http://trello.com] API
8
+ #
9
+ # First, set up your key information. You can get this information by {clicking here}[https://trello.com/1/appKey/generate].
10
+ #
11
+ # You can get the key by going to this url in your browser:
12
+ # https://trello.com/1/authorize?key=TRELLO_CONSUMER_KEY_FROM_ABOVE&name=MyApp&response_type=token&scope=read,write,account&expiration=never
13
+ # 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.
14
+ # 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
15
+ # url above:
16
+ #
17
+ # Trello.configure do |config|
18
+ # config.consumer_key = TRELLO_CONSUMER_KEY
19
+ # config.consumer_secret = TRELLO_CONSUMER_SECRET
20
+ # config.oauth_token = TRELLO_OAUTH_TOKEN
21
+ # config.oauth_token_secret = TRELLO_OAUTH_TOKEN_SECRET
22
+ # end
23
+ #
24
+ # All the calls this library make to Trello require authentication using these keys. Be sure to protect them.
25
+ #
26
+ # So lets say you want to get information about the user *bobtester*. We can do something like this:
27
+ #
28
+ # bob = Member.find("bobtester")
29
+ # # Print out his name
30
+ # puts bob.full_name # "Bob Tester"
31
+ # # Print his bio
32
+ # puts bob.bio # A wonderfully delightful test user
33
+ # # How about a list of his boards?
34
+ # bob.boards
35
+ #
36
+ # And so much more. Consult the rest of the documentation for more information.
37
+ #
38
+ # Feel free to {peruse and participate in our Trello board}[https://trello.com/board/ruby-trello/4f092b2ee23cb6fe6d1aaabd]. It's completely open to the public.
39
+ module Trello
40
+ autoload :Action, 'trello/action'
41
+ autoload :Comment, 'trello/comment'
42
+ autoload :Association, 'trello/association'
43
+ autoload :AssociationProxy, 'trello/association_proxy'
44
+ autoload :Attachment, 'trello/attachment'
45
+ autoload :CoverImage, 'trello/cover_image'
46
+ autoload :BasicData, 'trello/basic_data'
47
+ autoload :Board, 'trello/board'
48
+ autoload :Card, 'trello/card'
49
+ autoload :Checklist, 'trello/checklist'
50
+ autoload :Client, 'trello/client'
51
+ autoload :Configuration, 'trello/configuration'
52
+ autoload :HasActions, 'trello/has_actions'
53
+ autoload :Item, 'trello/item'
54
+ autoload :CheckItemState, 'trello/item_state'
55
+ autoload :Label, 'trello/label'
56
+ autoload :LabelName, 'trello/label_name'
57
+ autoload :List, 'trello/list'
58
+ autoload :Member, 'trello/member'
59
+ autoload :MultiAssociation, 'trello/multi_association'
60
+ autoload :Notification, 'trello/notification'
61
+ autoload :Organization, 'trello/organization'
62
+ autoload :PluginDatum, 'trello/plugin_datum'
63
+ autoload :Request, 'trello/net'
64
+ autoload :TInternet, 'trello/net'
65
+ autoload :Token, 'trello/token'
66
+ autoload :Webhook, 'trello/webhook'
67
+ autoload :JsonUtils, 'trello/json_utils'
68
+
69
+ module Authorization
70
+ autoload :AuthPolicy, 'trello/authorization'
71
+ autoload :BasicAuthPolicy, 'trello/authorization'
72
+ autoload :OAuthPolicy, 'trello/authorization'
73
+ end
74
+
75
+ # Version of the Trello API that we use by default.
76
+ API_VERSION = 1
77
+
78
+ # Raise this when we hit a Trello error.
79
+ Error = Class.new(StandardError)
80
+
81
+ # This specific error is thrown when your access token is invalid. You should get a new one.
82
+ InvalidAccessToken = Class.new(Error)
83
+
84
+ # This error is thrown when your client has not been configured
85
+ ConfigurationError = Class.new(Error)
86
+
87
+ def self.logger
88
+ @logger ||= Logger.new(STDOUT)
89
+ end
90
+
91
+ def self.logger=(logger)
92
+ @logger = logger
93
+ end
94
+
95
+ def self.client
96
+ @client ||= Client.new
97
+ end
98
+
99
+ def self.configure(&block)
100
+ reset!
101
+ client.configure(&block)
102
+ end
103
+
104
+ def self.reset!
105
+ @client = nil
106
+ end
107
+
108
+ def self.auth_policy; client.auth_policy; end
109
+ def self.configuration; client.configuration; end
110
+
111
+ # Url to Trello API public key page
112
+ def self.public_key_url
113
+ 'https://trello.com/app-key'
114
+ end
115
+
116
+ # Url to token for making authorized requests to the Trello API
117
+ #
118
+ # @param [String, #read] contents the contents to reverse
119
+ # @param options [Hash] Repository information to update
120
+ # @option options [String] :name Name of the application
121
+ # @option options [String] :key Application key
122
+ # @option options [String] :response_type 'token'
123
+ # @option options [String] :callback_method 'postMessage' or 'fragment'
124
+ # @option options [String] :return_url URL the token should be returned to
125
+ # @option options [String] :scope Comma-separated list of one or more of 'read', 'write', 'account'
126
+ # @option options [String] :expiration '1hour', '1day', '30days', 'never'
127
+ # @see https://developers.trello.com/authorize
128
+ def self.authorize_url(options = {})
129
+ params = options.dup
130
+ params[:key] ||= configuration.developer_public_key or
131
+ raise ArgumentError, 'Please configure your Trello public key'
132
+ params[:name] ||= 'Ruby Trello'
133
+ params[:scope] ||= 'read,write,account'
134
+ params[:expiration] ||= 'never'
135
+ params[:response_type] ||= 'token'
136
+ uri = Addressable::URI.parse 'https://trello.com/1/authorize'
137
+ uri.query_values = params
138
+ uri
139
+ end
140
+
141
+ # Visit the Trello API public key page
142
+ #
143
+ # @see https://trello.com/app-key
144
+ def self.open_public_key_url
145
+ open_url public_key_url
146
+ end
147
+
148
+ # Visit the Trello authorized token page
149
+ #
150
+ # @see https://developers.trello.com/authorize
151
+ def self.open_authorization_url(options = {})
152
+ open_url authorize_url(options)
153
+ end
154
+
155
+ # @private
156
+ def self.open_url(url)
157
+ require 'launchy'
158
+ Launchy.open(url.to_s)
159
+ rescue LoadError
160
+ warn 'Please install the launchy gem to open the url automatically.'
161
+ url
162
+ end
163
+ end
@@ -0,0 +1,68 @@
1
+ module Trello
2
+ # Action represents some event that occurred. For instance, when a card is created.
3
+ #
4
+ # @!attribute [r] id
5
+ # @return [String]
6
+ # @!attribute [r] type
7
+ # @return [String]
8
+ # @!attribute [r] data
9
+ # @return [Hash]
10
+ # @!attribute [r] date
11
+ # @return [Datetime]
12
+ # @!attribute [r] member_creator_id
13
+ # @return [String]
14
+ # @!attribute [r] member_participant
15
+ # @return [Object]
16
+ class Action < BasicData
17
+ register_attributes :id, :type, :data, :date, :member_creator_id, :member_participant,
18
+ readonly: [ :id, :type, :data, :date, :member_creator_id, :member_participant ]
19
+ validates_presence_of :id, :type, :date, :member_creator_id
20
+
21
+ class << self
22
+ # Locate a specific action and return a new Action object.
23
+ def find(id, params = {})
24
+ client.find(:action, id, params)
25
+ end
26
+
27
+ def search(query, opts = {})
28
+ response = client.get("/search/", { query: query }.merge(opts))
29
+ parse_json(response).except("options").each_with_object({}) do |(key, data), result|
30
+ klass = "Trello::#{key.singularize.capitalize}".constantize
31
+ result[key] = klass.from_json(data)
32
+ end
33
+ end
34
+ end
35
+
36
+ # Update the attributes of an action
37
+ #
38
+ # Supply a hash of string keyed data retrieved from the Trello API representing
39
+ # an Action.
40
+ def update_fields(fields)
41
+ attributes[:id] = fields['id'] || attributes[:id]
42
+ attributes[:type] = fields['type'] || attributes[:type]
43
+ attributes[:data] = fields['data'] || attributes[:data]
44
+ attributes[:date] = Time.iso8601(fields['date']) rescue nil if fields.has_key?('date')
45
+ attributes[:member_creator_id] = fields['idMemberCreator'] || attributes[:member_creator_id]
46
+ attributes[:member_participant] = fields['member'] || attributes[:member_participant]
47
+ self
48
+ end
49
+
50
+ # Returns the board this action occurred on.
51
+ def board
52
+ Board.from_response client.get("/actions/#{id}/board")
53
+ end
54
+
55
+ # Returns the card the action occurred on.
56
+ def card
57
+ Card.from_response client.get("/actions/#{id}/card")
58
+ end
59
+
60
+ # Returns the list the action occurred on.
61
+ def list
62
+ List.from_response client.get("/actions/#{id}/list")
63
+ end
64
+
65
+ # Returns the member who created the action.
66
+ one :member_creator, via: Member, path: :members, using: :member_creator_id
67
+ end
68
+ end
@@ -0,0 +1,14 @@
1
+ module Trello
2
+ class Association
3
+ attr_reader :owner, :target, :options, :proxy
4
+
5
+ def initialize(owner, target)
6
+ @owner = owner
7
+ @target = target
8
+ @options = {}
9
+ if target.is_a?(Array)
10
+ target.each { |array_element| array_element.client = owner.client }
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,42 @@
1
+ require 'active_support/core_ext'
2
+
3
+ module Trello
4
+ class AssociationProxy
5
+ extend Forwardable
6
+ alias :proxy_extend :extend
7
+
8
+ instance_methods.each { |m| undef_method m unless m.to_s =~ /^(?:nil\?|send|object_id|to_a)$|^__|^respond_to|proxy_/ }
9
+
10
+ def_delegators :@association, :owner, :target, :count
11
+
12
+ def initialize(association)
13
+ @association = association
14
+ Array(association.options[:extend]).each { |ext| proxy_extend(ext) }
15
+ end
16
+
17
+ def proxy_assocation
18
+ @association
19
+ end
20
+
21
+ def method_missing(method, *args, &block)
22
+ if target.respond_to? method
23
+ target.send(method, *args, &block)
24
+ else
25
+ super
26
+ end
27
+ end
28
+
29
+ def ===(other)
30
+ other === target
31
+ end
32
+
33
+ def to_ary
34
+ proxy_assocation.dup
35
+ end
36
+ alias_method :to_a, :to_ary
37
+
38
+ def <<(*records)
39
+ proxy_assocation.concat(records) && self
40
+ end
41
+ end
42
+ end