Class: TrelloTool::TrelloClient

Inherits:
SimpleDelegator
  • Object
show all
Includes:
Util
Defined in:
lib/trello_tool/trello_client.rb

Overview

Wrapped client for trello adapting it to things we need it to do

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ TrelloClient

Returns a new instance of TrelloClient.

Parameters:



13
14
15
16
17
18
19
20
# File 'lib/trello_tool/trello_client.rb', line 13

def initialize(configuration)
  @configuration = configuration
  @client = Trello::Client.new(
    developer_public_key: ENV["TRELLO_DEVELOPER_PUBLIC_KEY"],
    member_token: ENV["TRELLO_MEMBER_TOKEN"]
  )
  super(@client)
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



10
11
12
# File 'lib/trello_tool/trello_client.rb', line 10

def client
  @client
end

#configurationObject (readonly)

Returns the value of attribute configuration.



10
11
12
# File 'lib/trello_tool/trello_client.rb', line 10

def configuration
  @configuration
end

Instance Method Details

#archive_boardObject



38
39
40
# File 'lib/trello_tool/trello_client.rb', line 38

def archive_board
  @archive_board ||= client.find(:boards, extract_id_from_url(configuration.archive_board_url))
end

#archiveable_list_names_with_indexArray

Returns of list names with left index, ordered from right.

Returns:

  • (Array)

    of list names with left index, ordered from right



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/trello_tool/trello_client.rb', line 43

def archiveable_list_names_with_index
  @archiveable_list_names_with_index ||= [].tap do |lists|
    all_lists = main_board.lists
    all_lists.reverse.each_with_index do |list, right_index|
      if (divider_list?(list) && right_index.zero?) || version_list?(list) # rubocop:disable Style/GuardClause
        left_index = all_lists.length - right_index - 1
        lists << [list.name, left_index]
      else
        break
      end
    end
  end
end

#authorized(&block) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/trello_tool/trello_client.rb', line 22

def authorized(&block)
  Trello.configure do |config|
    config.developer_public_key = ENV["TRELLO_DEVELOPER_PUBLIC_KEY"]
    config.member_token = ENV["TRELLO_MEMBER_TOKEN"]
  end
  block.call
  Trello.configure do |config|
    config.developer_public_key = nil
    config.member_token = nil
  end
end

#main_boardObject



34
35
36
# File 'lib/trello_tool/trello_client.rb', line 34

def main_board
  @main_board ||= client.find(:boards, extract_id_from_url(configuration.main_board_url))
end

#next_version_listObject



57
58
59
# File 'lib/trello_tool/trello_client.rb', line 57

def next_version_list
  @next_version_list ||= find_list_by_list_name(main_board, configuration.next_version_list_name)
end