Class: Trello::Board
- Inherits:
-
Object
- Object
- Trello::Board
- Defined in:
- lib/trello-lite/board.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#id ⇒ Object
Returns the value of attribute id.
-
#lists ⇒ Object
Returns the value of attribute lists.
Instance Method Summary collapse
- #check_created_cards_since(days_ago) ⇒ Object
- #create_work_units_field ⇒ Object
- #credentials ⇒ Object
- #custom_fields ⇒ Object
- #desc ⇒ Object
- #enable_custom_fields ⇒ Object
- #find(id) ⇒ Object
- #find_list(name) ⇒ Object
- #find_member(name) ⇒ Object
- #has_custom_fields? ⇒ Boolean
-
#initialize(id, attrs = {}) ⇒ Board
constructor
A new instance of Board.
- #name ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(id, attrs = {}) ⇒ Board
Returns a new instance of Board.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/trello-lite/board.rb', line 7 def initialize(id, attrs = {}) @id = id @lists = [] @attributes = attrs @board_url = "https://api.trello.com/1/boards/#{id}?fields=all&members=all&customFields=true" @board_list_url = "https://api.trello.com/1/boards/#{id}/lists?cards=open&card_fields=name&filter=open&fields=all" @members = [] @custom_fields = [] find(id) end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
5 6 7 |
# File 'lib/trello-lite/board.rb', line 5 def attributes @attributes end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/trello-lite/board.rb', line 5 def id @id end |
#lists ⇒ Object
Returns the value of attribute lists.
5 6 7 |
# File 'lib/trello-lite/board.rb', line 5 def lists @lists end |
Instance Method Details
#check_created_cards_since(days_ago) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/trello-lite/board.rb', line 62 def check_created_cards_since(days_ago) url = "https://api.trello.com/1/boards/#{id}/actions?#{credentials}" activities = Trello.parse(url) created_cards = [] activities.each do |activity| if activity[:type] == "createCard" && Time.parse(activity[:date]) > days_ago created_cards << Activity.new(activity) end end created_cards end |
#create_work_units_field ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/trello-lite/board.rb', line 108 def create_work_units_field url = "https://api.trello.com/1/customFields?" + Trello.credentials wu_body = { idModel: "#{id}", modelType: "board", name: "Work Units", pos: "top", type: "number", display_cardFront: true } wu_headers = { 'Content-Type': 'application/json' } response = HTTParty.post(url, body: wu_body, format: :plain) JSON.parse(response, symbolize_names: true) end |
#credentials ⇒ Object
18 19 20 |
# File 'lib/trello-lite/board.rb', line 18 def credentials Trello.credentials end |
#custom_fields ⇒ Object
96 97 98 |
# File 'lib/trello-lite/board.rb', line 96 def custom_fields @custom_fields end |
#desc ⇒ Object
82 83 84 |
# File 'lib/trello-lite/board.rb', line 82 def desc attributes[:desc] end |
#enable_custom_fields ⇒ Object
100 101 102 103 104 105 106 |
# File 'lib/trello-lite/board.rb', line 100 def enable_custom_fields cf_id = "56d5e249a98895a9797bebb9" url = "https://api.trello.com/1/boards/#{id}/boardPlugins?idPlugin=#{cf_id}&" + Trello.credentials response = HTTParty.post(url, format: :plain) JSON.parse(response, symbolize_names: true) end |
#find(id) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/trello-lite/board.rb', line 22 def find(id) # puts "creating board #{id}" @attributes = Trello.parse(@board_url + "&#{credentials}") attributes[:members].each do |member| member_obj = Member.new(member) @members << member_obj end attributes[:customFields].each do |custom_field| @custom_fields << CustomField.new(custom_field) end Trello.parse(@board_list_url + "&#{credentials}").each do |list_json| list = List.new(list_json) @lists << list end self end |
#find_list(name) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/trello-lite/board.rb', line 39 def find_list(name) list_obj = nil lists.each do |list| list_obj = list if list.name == name end if list_obj.nil? puts "List doesn't exist. Here are some list names." lists.each do |list| puts list.name end else list_obj end end |
#find_member(name) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/trello-lite/board.rb', line 54 def find_member(name) @members.each do |member| if name == member.full_name || name == member.username return member end end end |
#has_custom_fields? ⇒ Boolean
90 91 92 93 94 |
# File 'lib/trello-lite/board.rb', line 90 def has_custom_fields? url = "https://api.trello.com/1/boards/#{id}/plugins?filter=enabled&" + Trello.credentials plugin_list = Trello.parse(url) !plugin_list.select { |plugin| plugin[:name] == "Custom Fields"}.empty? end |
#name ⇒ Object
78 79 80 |
# File 'lib/trello-lite/board.rb', line 78 def name attributes[:name] end |
#url ⇒ Object
86 87 88 |
# File 'lib/trello-lite/board.rb', line 86 def url attributes[:url] end |