Created
January 8, 2013 03:37
-
-
Save rossta/4480968 to your computer and use it in GitHub Desktop.
Ruby-trello and Threads:
Making requests on behalf of multiple clients is not currently thread-safe, as demonstrated in the gist below (with placeholders for sensitive data).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
include Trello | |
include Trello::Authorization | |
Trello::Authorization.const_set :AuthPolicy, OAuthPolicy | |
OAuthPolicy.consumer_credential = OAuthCredential.new('user_key', 'user_secret') | |
threads = [] | |
tokens = %w[ not_rosstas_token rosstas_token ] | |
tokens.each_with_index do |token, i| | |
threads << Thread.new(token) do |access_token| | |
OAuthPolicy.token = OAuthCredential.new(access_token) | |
sleep 1 | |
member = Trello::Member.find('rossta') | |
puts "Thread #{i + 1}: #{member.inspect}" | |
puts "Thread #{i + 1}: #{member.boards.map(&:name).inspect}" | |
end | |
end | |
threads.each { |thread| thread.join } | |
# The oauth token for the first thread can be overwritten by the second thread, leading to unexpected results |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment