Class: Trello::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(key:, token:) ⇒ Client

Returns a new instance of Client.



7
8
9
10
11
# File 'lib/trello/client.rb', line 7

def initialize(key:, token:)
  @key = key
  @token = token
  @base_url = 'https://api.trello.com/1'
end

Instance Method Details

#add_card!(list_id:, title:, description: nil, labels: nil) ⇒ Object



37
38
39
40
41
# File 'lib/trello/client.rb', line 37

def add_card!(list_id:, title:, description: nil, labels: nil)
  options = { query: { key: key, token: token, idList: list_id, name: title, desc: description, idLabels: labels } }

  request('cards') { |url| HTTParty.post(url, options) }
end

#add_card_by_name!(board_name:, list_name:, label_name:, title:, description: nil) ⇒ Object



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

def add_card_by_name!(board_name:, list_name:, label_name:, title:, description: nil)
  board_id = get_board_by_name(name: board_name)['id']
  list_id = get_list(board_id: board_id, list_name: list_name)['id']
  label_id = get_label(board_id: board_id, label_name: label_name)['id']

  add_card!(
    list_id: list_id,
    title: title,
    description: description,
    labels: label_id
  )
end

#boardsObject



56
57
58
59
60
# File 'lib/trello/client.rb', line 56

def boards
  options = { query: { key: key, token: token } }

  request('members/me/boards') { |url| HTTParty.get(url, options) }
end

#get_board_by_name(name:) ⇒ Object



13
14
15
# File 'lib/trello/client.rb', line 13

def get_board_by_name(name:)
  boards.select { |value| value['name'] == name }.first
end

#get_label(board_id:, label_name:) ⇒ Object



33
34
35
# File 'lib/trello/client.rb', line 33

def get_label(board_id:, label_name:)
  get_labels_for_board(board_id: board_id).select { |value| value['name'] == label_name }.first
end

#get_labels_for_board(board_id:) ⇒ Object



27
28
29
30
31
# File 'lib/trello/client.rb', line 27

def get_labels_for_board(board_id:)
  options = { query: { key: key, token: token } }

  request("boards/#{board_id}/labels") { |url| HTTParty.get(url, options) }
end

#get_list(board_id:, list_name:) ⇒ Object



23
24
25
# File 'lib/trello/client.rb', line 23

def get_list(board_id:, list_name:)
  get_lists_for_board(board_id: board_id).select { |value| value['name'] == list_name }.first
end

#get_lists_for_board(board_id:) ⇒ Object



17
18
19
20
21
# File 'lib/trello/client.rb', line 17

def get_lists_for_board(board_id:)
  options = { query: { key: key, token: token } }

  request("boards/#{board_id}/lists") { |url| HTTParty.get(url, options) }
end