Class: Client

Inherits:
Object
  • Object
show all
Defined in:
lib/trellist/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(board_id:, key:, token:) ⇒ Client

Returns a new instance of Client.



30
31
32
33
34
35
36
37
38
39
# File 'lib/trellist/client.rb', line 30

def initialize(board_id:, key:, token:)
  @board = board_id
  @key = key
  @token = token

  Trello.configure do |config|
    config.developer_public_key = key
    config.member_token = token
  end
end

Instance Attribute Details

#boardObject

Returns the value of attribute board.



28
29
30
# File 'lib/trellist/client.rb', line 28

def board
  @board
end

#cardsObject

Returns the value of attribute cards.



28
29
30
# File 'lib/trellist/client.rb', line 28

def cards
  @cards
end

#labelsObject

Returns the value of attribute labels.



28
29
30
# File 'lib/trellist/client.rb', line 28

def labels
  @labels
end

#listsObject

Returns the value of attribute lists.



28
29
30
# File 'lib/trellist/client.rb', line 28

def lists
  @lists
end

Instance Method Details

#board_labelsObject



45
46
47
# File 'lib/trellist/client.rb', line 45

def board_labels
  @labels = Trello::Board.find(@board).labels
end


54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/trellist/client.rb', line 54

def generate_links(format: 'markdown', prefix: '', suffix: '')
  case format
  when 'markdown'
    @cards.map { |card| card.as_markdown(prefix: prefix, suffix: suffix) }
  when 'plain'
    @cards.map(&:short_url)
  when 'html'
    @cards.map { |card| card.as_html(prefix: prefix, suffix: suffix) }
  when 'titles-only'
    @cards.map { |card| card.as_plain_title(prefix: prefix, suffix: suffix) }
  else
    @cards.map(&:inspect)
  end
end

#get_board_listsObject



41
42
43
# File 'lib/trellist/client.rb', line 41

def get_board_lists
  @lists = Trello::Board.find(@board).lists
end

#list_cards(list_id, label: nil) ⇒ Object



49
50
51
52
# File 'lib/trellist/client.rb', line 49

def list_cards(list_id, label: nil)
  @cards = Trello::List.find(list_id).cards
  @cards.select! { |card| card.labels.map(&:name).include?(label) } if label
end