Class: Trello2WR
- Inherits:
-
Object
- Object
- Trello2WR
- Includes:
- Trello, Trello::Authorization
- Defined in:
- lib/trello2wr.rb
Constant Summary collapse
- @@debug =
true
Instance Attribute Summary collapse
-
#board ⇒ Object
readonly
Returns the value of attribute board.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
-
#week ⇒ Object
readonly
Returns the value of attribute week.
-
#year ⇒ Object
readonly
Returns the value of attribute year.
Instance Method Summary collapse
-
#body ⇒ Object
Prepare mail body.
- #cards(board, list_name) ⇒ Object
- #construct_mail_to_url(recipient, subject, body) ⇒ Object
- #escape(string) ⇒ Object
- #export ⇒ Object
-
#initialize ⇒ Trello2WR
constructor
A new instance of Trello2WR.
- #log(message) ⇒ Object
-
#subject ⇒ Object
Prepare mail header.
Constructor Details
#initialize ⇒ Trello2WR
Returns a new instance of Trello2WR.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/trello2wr.rb', line 18 def initialize Trello::Authorization.const_set :AuthPolicy, OAuthPolicy # Read keys from ~/trello2wr/config.yml key = CONFIG['trello']['developer_public_key'] secret = CONFIG['trello']['developer_secret'] token = CONFIG['trello']['member_token'] OAuthPolicy.consumer_credential = OAuthCredential.new key, secret OAuthPolicy.token = OAuthCredential.new token, nil self.log("*** Searching for user '#{CONFIG['trello']['username']}'") begin @user = Member.find(CONFIG['trello']['username']) rescue Trello::Error raise "ERROR: user '#{CONFIG['trello']['username']}' not found!}" end @year = Date.today.year @week = Date.today.cweek # FIXME: Allow more than one board # self.log("*** Getting lists for '#{CONFIG['trello']['boards'].first}' board") @board = @user.boards.find{|b| b.name == CONFIG['trello']['boards'].first} end |
Instance Attribute Details
#board ⇒ Object (readonly)
Returns the value of attribute board.
15 16 17 |
# File 'lib/trello2wr.rb', line 15 def board @board end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
15 16 17 |
# File 'lib/trello2wr.rb', line 15 def user @user end |
#week ⇒ Object (readonly)
Returns the value of attribute week.
15 16 17 |
# File 'lib/trello2wr.rb', line 15 def week @week end |
#year ⇒ Object (readonly)
Returns the value of attribute year.
15 16 17 |
# File 'lib/trello2wr.rb', line 15 def year @year end |
Instance Method Details
#body ⇒ Object
Prepare mail body
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/trello2wr.rb', line 69 def body body = '' ['Done', 'In review', 'To Do', 'Doing'].each do |list_name| if list_name.downcase.include? 'done' body += "Accomplishments:\n" elsif list_name.downcase.include? 'review' body += "\nIn review:\n" elsif list_name.downcase.include? 'to do' body += "\nObjectives:\n" if list_name.downcase.include? 'to do' end self.cards(self.board, list_name).each do |card| if list_name.downcase.include? 'doing' body += "- #{card.name} (##{card.short_id}) [WIP]\n" else body += "- #{card.name} (##{card.short_id})\n" end end end body += "\n\nNOTE: (#<number>) are Trello board card IDs" self.escape(body) end |
#cards(board, list_name) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/trello2wr.rb', line 45 def cards(board, list_name) self.log("*** Getting cards for '#{list_name}' list") if board if list_name == 'Done' list = board.lists.select{|l| l.name.include?('Done') && l.name.include?((self.week-1).to_s) }.first else list = board.lists.find{|l| l.name == list_name} end cards = list.cards.select{|c| c.member_ids.include? self.user.id} return cards else raise "ERROR: Board '#{list_name}' not found!" end end |
#construct_mail_to_url(recipient, subject, body) ⇒ Object
93 94 95 96 97 98 99 |
# File 'lib/trello2wr.rb', line 93 def construct_mail_to_url(recipient, subject, body) if CONFIG['email'].has_key?('cc') && CONFIG['email']['cc'].present? URI::MailTo.build({:to => recipient, :headers => {"cc" => CONFIG['email']['cc'], "subject" => subject, "body" => body}}).to_s.inspect else URI::MailTo.build({:to => recipient, :headers => {"subject" => subject, "body" => body}}).to_s.inspect end end |
#escape(string) ⇒ Object
101 102 103 |
# File 'lib/trello2wr.rb', line 101 def escape(string) URI.escape(string, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")) end |
#export ⇒ Object
105 106 107 108 109 110 111 112 |
# File 'lib/trello2wr.rb', line 105 def export mailto = self.construct_mail_to_url(CONFIG['email']['recipient'], self.subject, self.body) self.log("*** Preparing email, please wait ...") system("#{CONFIG['email']['client']} #{mailto}") self.log("*** DONE") end |
#log(message) ⇒ Object
114 115 116 |
# File 'lib/trello2wr.rb', line 114 def log() puts if @@debug end |
#subject ⇒ Object
Prepare mail header
64 65 66 |
# File 'lib/trello2wr.rb', line 64 def subject self.escape("A&O Week ##{self.week} #{self.user.username}") end |