tacokit 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +86 -0
  3. data/.travis.yml +6 -0
  4. data/Gemfile +16 -25
  5. data/Guardfile +1 -1
  6. data/README.md +61 -17
  7. data/Rakefile +10 -5
  8. data/lib/tacokit/authorization.rb +14 -13
  9. data/lib/tacokit/client/actions.rb +68 -28
  10. data/lib/tacokit/client/boards.rb +92 -85
  11. data/lib/tacokit/client/cards.rb +285 -92
  12. data/lib/tacokit/client/checklists.rb +48 -28
  13. data/lib/tacokit/client/labels.rb +14 -16
  14. data/lib/tacokit/client/lists.rb +52 -28
  15. data/lib/tacokit/client/members.rb +56 -46
  16. data/lib/tacokit/client/notifications.rb +13 -27
  17. data/lib/tacokit/client/organizations.rb +0 -6
  18. data/lib/tacokit/client/searches.rb +0 -1
  19. data/lib/tacokit/client/tokens.rb +0 -6
  20. data/lib/tacokit/client/types.rb +0 -1
  21. data/lib/tacokit/client/webhooks.rb +3 -8
  22. data/lib/tacokit/client.rb +48 -75
  23. data/lib/tacokit/collection.rb +49 -0
  24. data/lib/tacokit/configuration.rb +4 -6
  25. data/lib/tacokit/error.rb +0 -2
  26. data/lib/tacokit/middleware/boom.rb +6 -7
  27. data/lib/tacokit/middleware.rb +2 -10
  28. data/lib/tacokit/resource.rb +84 -57
  29. data/lib/tacokit/response.rb +3 -3
  30. data/lib/tacokit/transform.rb +35 -13
  31. data/lib/tacokit/utils.rb +40 -8
  32. data/lib/tacokit/version.rb +1 -1
  33. data/lib/tacokit.rb +0 -2
  34. data/spec/cassettes/Tacokit_Client_Actions/_action_board/returns_action_board.json +1 -0
  35. data/spec/cassettes/Tacokit_Client_Actions/_action_card/returns_action_card.json +1 -0
  36. data/spec/cassettes/Tacokit_Client_Actions/_action_entities/returns_action_entities.json +1 -0
  37. data/spec/cassettes/Tacokit_Client_Actions/_action_list/returns_action_list.json +1 -0
  38. data/spec/cassettes/Tacokit_Client_Boards/_add_board_member/adds_invites_member_to_board.json +1 -1
  39. data/spec/cassettes/Tacokit_Client_Boards/_board_actions/returns_board_actions.json +1 -0
  40. data/spec/cassettes/Tacokit_Client_Boards/_board_cards/returns_board_cards.json +1 -0
  41. data/spec/cassettes/Tacokit_Client_Boards/_board_checklists/returns_board_checklists.json +1 -0
  42. data/spec/cassettes/Tacokit_Client_Boards/_board_labels/returns_board_labels.json +1 -0
  43. data/spec/cassettes/Tacokit_Client_Boards/_board_lists/returns_board_lists.json +1 -0
  44. data/spec/cassettes/Tacokit_Client_Boards/_board_members/returns_board_members.json +1 -0
  45. data/spec/cassettes/Tacokit_Client_Boards/_board_organization/returns_board_organization.json +1 -0
  46. data/spec/cassettes/Tacokit_Client_Boards/_board_preferences/returns_preferences_for_a_board.json +1 -0
  47. data/spec/cassettes/Tacokit_Client_Boards/_board_stars/returns_board_stars.json +1 -0
  48. data/spec/cassettes/Tacokit_Client_Boards/_member_board_stars/returns_board_stars.json +1 -0
  49. data/spec/cassettes/Tacokit_Client_Boards/_update_board_member/updates_member.json +1 -0
  50. data/spec/cassettes/Tacokit_Client_Cards/_add_comment/creates_a_comment.json +1 -0
  51. data/spec/cassettes/Tacokit_Client_Cards/_add_label/adds_label_to_card.json +1 -0
  52. data/spec/cassettes/Tacokit_Client_Cards/_add_member_to_card/adds_member_to_card.json +1 -0
  53. data/spec/cassettes/Tacokit_Client_Cards/_archive_card/archives_card.json +1 -0
  54. data/spec/cassettes/Tacokit_Client_Cards/_archive_card/restore_card.json +1 -0
  55. data/spec/cassettes/Tacokit_Client_Cards/_attachments/returns_an_attachment.json +1 -0
  56. data/spec/cassettes/Tacokit_Client_Cards/_attachments/returns_attachment.json +1 -0
  57. data/spec/cassettes/Tacokit_Client_Cards/_attachments/returns_attachments.json +1 -0
  58. data/spec/cassettes/Tacokit_Client_Cards/_card/returns_a_card_by_card_resource.json +1 -0
  59. data/spec/cassettes/Tacokit_Client_Cards/_card/returns_a_card_by_id.json +1 -1
  60. data/spec/cassettes/Tacokit_Client_Cards/_card/returns_a_card_by_short_link.json +1 -1
  61. data/spec/cassettes/Tacokit_Client_Cards/_card_actions/returns_card_actions.json +1 -0
  62. data/spec/cassettes/Tacokit_Client_Cards/_card_board/returns_card_board.json +1 -0
  63. data/spec/cassettes/Tacokit_Client_Cards/_card_field/returns_a_hash.json +1 -1
  64. data/spec/cassettes/Tacokit_Client_Cards/_card_field/returns_a_value.json +1 -1
  65. data/spec/cassettes/Tacokit_Client_Cards/_card_field/returns_an_array.json +1 -1
  66. data/spec/cassettes/Tacokit_Client_Cards/_card_list/returns_a_list.json +1 -0
  67. data/spec/cassettes/Tacokit_Client_Cards/_card_members/returns_members.json +1 -0
  68. data/spec/cassettes/Tacokit_Client_Cards/_card_members/returns_members_voted.json +1 -0
  69. data/spec/cassettes/Tacokit_Client_Cards/_card_resource/returns_card_actions.json +1 -1
  70. data/spec/cassettes/Tacokit_Client_Cards/_card_resource/returns_card_board.json +1 -1
  71. data/spec/cassettes/Tacokit_Client_Cards/_card_resource/returns_card_check_item_states.json +1 -1
  72. data/spec/cassettes/Tacokit_Client_Cards/_card_stickers/returns_.json +1 -0
  73. data/spec/cassettes/Tacokit_Client_Cards/_checklists/returns_check_item_states.json +1 -0
  74. data/spec/cassettes/Tacokit_Client_Cards/_checklists/returns_checklists.json +1 -0
  75. data/spec/cassettes/Tacokit_Client_Cards/_create_card/creates_a_card.json +1 -1
  76. data/spec/cassettes/Tacokit_Client_Cards/_create_card_attachment/attaches_external_url.json +1 -1
  77. data/spec/cassettes/Tacokit_Client_Cards/_create_card_attachment/uploads_local_file.json +1 -1
  78. data/spec/cassettes/Tacokit_Client_Cards/_delete_card/deletes_a_card.json +1 -1
  79. data/spec/cassettes/Tacokit_Client_Cards/_delete_card_resource/deletes_resource.json +1 -1
  80. data/spec/cassettes/Tacokit_Client_Cards/_delete_comment/deletes_comment.json +1 -0
  81. data/spec/cassettes/Tacokit_Client_Cards/_list/returns_list.json +1 -0
  82. data/spec/cassettes/Tacokit_Client_Cards/_move_card/moves_card_to_a_new_position.json +1 -0
  83. data/spec/cassettes/Tacokit_Client_Cards/_move_card/moves_card_to_another_board_list.json +1 -0
  84. data/spec/cassettes/Tacokit_Client_Cards/_move_card/moves_card_to_board.json +1 -0
  85. data/spec/cassettes/Tacokit_Client_Cards/_move_card/moves_card_to_list.json +1 -0
  86. data/spec/cassettes/Tacokit_Client_Cards/_move_card/raises_error_if_missing_options.json +1 -0
  87. data/spec/cassettes/Tacokit_Client_Cards/_start_checklist/adds_a_checklist_item.json +1 -0
  88. data/spec/cassettes/Tacokit_Client_Cards/_start_checklist/adds_new_checklist_by_name.json +1 -0
  89. data/spec/cassettes/Tacokit_Client_Cards/_start_checklist/copies_a_checklist_by_id.json +1 -0
  90. data/spec/cassettes/Tacokit_Client_Cards/_stickers/returns_stickers.json +1 -0
  91. data/spec/cassettes/Tacokit_Client_Cards/_update_card/updates_a_card.json +1 -1
  92. data/spec/cassettes/Tacokit_Client_Cards/_update_checklist_item/updates_checklist_item.json +1 -0
  93. data/spec/cassettes/Tacokit_Client_Cards/_update_comment/updates_a_comment.json +1 -0
  94. data/spec/cassettes/Tacokit_Client_Cards/_vote/adds_a_member_s_vote_to_card.json +1 -0
  95. data/spec/cassettes/Tacokit_Client_Checklists/_check_items/adds_a_checklist_check_item.json +1 -0
  96. data/spec/cassettes/Tacokit_Client_Checklists/_check_items/retrieves_checklist_check_items.json +1 -0
  97. data/spec/cassettes/Tacokit_Client_Lists/_archive_list_cards/should_archive_cards_in_list.json +1 -0
  98. data/spec/cassettes/Tacokit_Client_Lists/_list_actions/returns_list_actions.json +1 -0
  99. data/spec/cassettes/Tacokit_Client_Lists/_list_board/returns_list_board.json +1 -0
  100. data/spec/cassettes/Tacokit_Client_Lists/_list_cards/returns_list_cards.json +1 -0
  101. data/spec/cassettes/Tacokit_Client_Lists/_move_list_cards/should_move_cards_in_list.json +1 -0
  102. data/spec/cassettes/Tacokit_Client_Members/_actions/returns_member_actions.json +1 -0
  103. data/spec/cassettes/Tacokit_Client_Members/_board_stars/returns_member_board_stars.json +1 -0
  104. data/spec/cassettes/Tacokit_Client_Members/_boards/returns_member_boards.json +1 -0
  105. data/spec/cassettes/Tacokit_Client_Members/_cards/returns_member_cards.json +1 -0
  106. data/spec/cassettes/Tacokit_Client_Members/_notifications/returns_member_notifications.json +1 -0
  107. data/spec/cassettes/Tacokit_Client_Members/_organizations/returns_member_organizations.json +1 -0
  108. data/spec/cassettes/Tacokit_Client_Members/_tokens/returns_member_organizations.json +1 -0
  109. data/spec/cassettes/Tacokit_Client_Members/_tokens/returns_member_tokens.json +1 -0
  110. data/spec/spec_helper.rb +39 -29
  111. data/spec/tacokit/authorization_spec.rb +11 -11
  112. data/spec/tacokit/client/actions_spec.rb +56 -19
  113. data/spec/tacokit/client/boards_spec.rb +81 -78
  114. data/spec/tacokit/client/cards_spec.rb +322 -68
  115. data/spec/tacokit/client/checklists_spec.rb +29 -27
  116. data/spec/tacokit/client/labels_spec.rb +8 -16
  117. data/spec/tacokit/client/lists_spec.rb +74 -27
  118. data/spec/tacokit/client/members_spec.rb +55 -41
  119. data/spec/tacokit/client/notifications_spec.rb +3 -31
  120. data/spec/tacokit/client/organizations_spec.rb +6 -27
  121. data/spec/tacokit/client/searches_spec.rb +1 -3
  122. data/spec/tacokit/client/tokens_spec.rb +2 -18
  123. data/spec/tacokit/client/types_spec.rb +2 -3
  124. data/spec/tacokit/client/webhooks_spec.rb +6 -14
  125. data/spec/tacokit/client_spec.rb +3 -3
  126. data/spec/tacokit/configuration_spec.rb +30 -31
  127. data/spec/tacokit/middleware/boom_spec.rb +6 -7
  128. data/spec/tacokit/resource_spec.rb +142 -17
  129. data/spec/tacokit/transform_spec.rb +37 -35
  130. data/spec/tacokit_spec.rb +3 -5
  131. data/tacokit.gemspec +6 -6
  132. metadata +132 -15
  133. data/config.ru +0 -7
  134. data/lib/tacokit/middleware/debug.rb +0 -22
  135. data/spec/cassettes/Tacokit_Client_Boards/_update_board_resource/updates_member.json +0 -1
  136. data/spec/cassettes/Tacokit_Client_Members/_member/raises_error_for_missing_token.json +0 -1
@@ -1,83 +1,87 @@
1
1
  module Tacokit
2
2
  class Client
3
3
  module Boards
4
-
5
- # GET /1/boards/[board_id]
4
+ # Retrieve a board
5
+ #
6
+ # @see https://trello.com/docs/api/board/index.html#get-1-boards-board-id
6
7
  def board(board_id, options = nil)
7
8
  get board_path(board_id), options
8
9
  end
9
10
 
10
- # GET /1/boards/[board_id]/[field]
11
- def board_field(board_id, field, options = nil)
12
- get board_path(board_id, camp(field)), options
13
- end
14
-
15
- # GET /1/boards/[board_id]/[resource]
16
- # actions
17
- # boardStars
18
- # cards
19
- # cards/[filter]
20
- # cards/[idCard]
21
- # checklists
22
- # deltas
23
- # labels
24
- # labels/[idLabel]
25
- # lists
26
- # lists/[filter]
27
- # members
28
- # members/[filter]
29
- # members/[idMember]/cards
30
- # membersInvited
31
- # membersInvited/[field]
32
- # memberships
33
- # memberships/[idMembership]
34
- # myPrefs
35
- # organization
36
- # organization/[field]
37
- def board_resource(board_id, resource, *paths)
38
- paths, options = extract_options(camp(resource), *paths)
39
- get board_path(board_id, *paths), options
11
+ # Retrieve a board's actions
12
+ #
13
+ # @see https://trello.com/docs/api/board/index.html#get-1-boards-board-id-actions
14
+ def board_actions(board_id, options = {})
15
+ paginated_board_resource(board_id, "actions", options)
16
+ end
17
+
18
+ # Retrieve a board's stars
19
+ #
20
+ # @see https://trello.com/docs/api/board/index.html#get-1-boards-board-id-boardstars
21
+ def board_stars(board_id, options = {})
22
+ board_resource(board_id, "board_stars", options)
23
+ end
24
+
25
+ # Retrieve a board's cards
26
+ #
27
+ # @see https://trello.com/docs/api/board/index.html#get-1-boards-board-id-cards
28
+ def board_cards(board_id, options = {})
29
+ paginated_board_resource(board_id, "cards", options)
30
+ end
31
+
32
+ # Retrieve a board's checklists
33
+ #
34
+ # @see https://trello.com/docs/api/board/index.html#get-1-boards-board-id-checklists
35
+ def board_checklists(board_id, options = {})
36
+ board_resource(board_id, "checklists", options)
37
+ end
38
+
39
+ # Retrieve a board's labels
40
+ #
41
+ # @see https://trello.com/docs/api/board/index.html#get-1-boards-board-id-labels
42
+ def board_labels(board_id, options = {})
43
+ board_resource(board_id, "labels", options)
44
+ end
45
+
46
+ # Retrieve a board's lists
47
+ #
48
+ # @see https://trello.com/docs/api/board/index.html#get-1-boards-board-id-lists
49
+ def lists(board_id, options = {})
50
+ board_resource(board_id, "lists", options)
51
+ end
52
+ alias_method :board_lists, :lists
53
+
54
+ # Retrieve a board's members
55
+ #
56
+ # @see https://trello.com/docs/api/board/index.html#get-1-boards-board-id-members
57
+ def board_members(board_id, options = {})
58
+ board_resource(board_id, "members", options)
59
+ end
60
+
61
+ # Retrieve your preferences for a board
62
+ #
63
+ # @see https://trello.com/docs/api/board/index.html#get-1-boards-board-id-myprefs
64
+ def board_preferences(board_id, options = {})
65
+ board_resource(board_id, "my_prefs", options)
66
+ end
67
+
68
+ # Retrieve a board's organization
69
+ #
70
+ # @see https://trello.com/docs/api/board/index.html#get-1-boards-board-id-organization
71
+ def board_organization(board_id, options = {})
72
+ board_resource(board_id, "organization", options)
40
73
  end
41
74
 
42
- # PUT /1/boards/[board_id]
75
+ # Update board attributes
76
+ #
77
+ # @see https://trello.com/docs/api/board/index.html#put-1-boards-board-id
43
78
  def update_board(board_id, options = {})
44
79
  put board_path(board_id), options
45
80
  end
46
81
 
47
- # PUT /1/boards/[board_id]/[field]
48
- # closed
49
- # desc
50
- # idOrganization
51
- # labelNames/blue
52
- # labelNames/green
53
- # labelNames/orange
54
- # labelNames/purple
55
- # labelNames/red
56
- # labelNames/yellow
57
- # myPrefs/emailPosition
58
- # myPrefs/idEmailList
59
- # myPrefs/showListGuide
60
- # myPrefs/showSidebar
61
- # myPrefs/showSidebarActivity
62
- # myPrefs/showSidebarBoardActions
63
- # myPrefs/showSidebarMembers
64
- # name
65
- # prefs/background
66
- # prefs/calendarFeedEnabled
67
- # prefs/cardAging
68
- # prefs/cardCovers
69
- # prefs/comments
70
- # prefs/invitations
71
- # prefs/permissionLevel
72
- # prefs/selfJoin
73
- # prefs/voting
74
- # subscribed
75
- def update_board_field(board_id, *paths)
76
- value = paths.pop
77
- put board_path(board_id, camel_join(*paths)), value: value
78
- end
79
-
80
- # PUT /1/boards/[board_id]/members
82
+ # Add a member to a board
83
+ #
84
+ # @see https://trello.com/docs/api/board/index.html#put-1-boards-board-id-members-idmember
81
85
  def add_board_member(board_id, email, full_name, options = {})
82
86
  options.update \
83
87
  email: email,
@@ -85,11 +89,11 @@ module Tacokit
85
89
  put board_path(board_id, "members"), options
86
90
  end
87
91
 
88
- # PUT /1/boards/[board_id]/[resource]
89
- # members/[idMember]
90
- # memberships/[idMembership]
91
- def update_board_resource(board_id, resource, resource_id, options = {})
92
- put board_path(board_id, camp(resource), resource_id), options
92
+ # Update a board member's type
93
+ #
94
+ # @see https://trello.com/docs/api/board/index.html#put-1-boards-board-id-members-idmember
95
+ def update_board_member(board_id, member_id, type)
96
+ update_board_resource(board_id, "members", member_id, type: type)
93
97
  end
94
98
 
95
99
  # POST /1/boards
@@ -97,28 +101,31 @@ module Tacokit
97
101
  post board_path, options.merge(name: name)
98
102
  end
99
103
 
100
- # POST /1/boards/[board_id]/[resource]
101
- # calendarKey/generate
102
- # checklists
103
- # emailKey/generate
104
- # labels
105
- # lists
106
- # markAsViewed
107
- # powerUps
104
+ private
105
+
108
106
  def create_board_resource(board_id, resource, *paths)
109
107
  paths, options = extract_options(camp(resource), *paths)
110
108
  post board_path(board_id, *paths), options
111
109
  end
112
110
 
113
- # DELETE /1/boards/[board_id]/[resource]/[resource_id]
114
- # members/[idMember]
115
- # powerUps/[powerUp]
116
- #
111
+ def update_board_resource(board_id, resource, *paths)
112
+ paths, options = extract_options(camp(resource), *paths)
113
+ put board_path(board_id, *paths), options
114
+ end
115
+
116
+ def board_resource(board_id, resource, *paths)
117
+ paths, options = extract_options(camp(resource), *paths)
118
+ get board_path(board_id, *paths), options
119
+ end
120
+
121
+ def paginated_board_resource(board_id, resource, *paths)
122
+ paths, options = extract_options(camp(resource), *paths)
123
+ paginated_get board_path(board_id, *paths), options
124
+ end
117
125
 
118
126
  def board_path(*paths)
119
127
  path_join("boards", *paths)
120
128
  end
121
-
122
129
  end
123
130
  end
124
131
  end
@@ -1,96 +1,183 @@
1
1
  module Tacokit
2
2
  class Client
3
+ # Methods for the Cards API
4
+ #
5
+ # @see https://trello.com/docs/api/card/index.html
3
6
  module Cards
4
-
5
- # GET cards/[card id or shortlink]
7
+ # Retrieve a card by id or shortlink
8
+ #
9
+ # @see https://trello.com/docs/api/card/index.html#get-1-cards-card-id-or-shortlink
6
10
  def card(card_id, options = nil)
7
11
  get card_path(card_id), options
8
12
  end
9
13
 
10
- # GET cards/[card id or shortlink]/[field]
11
- # badges
12
- # checkItemStates
13
- # closed
14
- # dateLastActivity
15
- # desc
16
- # descData
17
- # due
18
- # email
19
- # idAttachmentCover
20
- # idBoard
21
- # idChecklists
22
- # idLabels
23
- # idList
24
- # idMembers
25
- # idMembersVoted
26
- # idShort
27
- # labels
28
- # manualCoverAttachment
29
- # name
30
- # pos
31
- # shortLink
32
- # shortUrl
33
- # subscribed
34
- # url
35
- def card_field(card_id, field, options = nil)
36
- get card_path(card_id, camp(field)), options
37
- end
38
-
39
- # GET cards/[card id or shortlink]/[resource]
40
- # actions
41
- # attachments
42
- # attachments/[idAttachment]
43
- # board
44
- # board/[field]
45
- # checkItemStates
46
- # checklists
47
- # list
48
- # list/[field]
49
- # members
50
- # membersVoted
51
- # stickers
52
- # stickers/[idSticker]
53
- def card_resource(card_id, resource, options = {})
54
- get card_path(card_id, camp(resource)), options
14
+ # Retrieve card actions
15
+ #
16
+ # @see https://trello.com/docs/api/card/index.html#get-1-cards-card-id-or-shortlink-actions
17
+ def card_actions(card_id, options = {})
18
+ paginated_card_resource(card_id, "actions", options)
19
+ end
20
+
21
+ # Retrieve card attachments
22
+ #
23
+ # @see https://trello.com/docs/api/card/index.html#get-1-cards-card-id-or-shortlink-attachments
24
+ def attachments(card_id, options = {})
25
+ card_resource(card_id, "attachments", options)
26
+ end
27
+ alias_method :card_attachments, :attachments
28
+
29
+ # Retrieve a card attachment
30
+ #
31
+ # @see https://trello.com/docs/api/card/index.html#get-1-cards-card-id-or-shortlink-attachments-idattachment
32
+ def attachment(card_id, attachment_id, options = {})
33
+ card_resource(card_id, "attachments/#{attachment_id}", options)
34
+ end
35
+
36
+ # Retrieve a card board
37
+ #
38
+ # @see https://trello.com/docs/api/card/index.html#get-1-cards-card-id-or-shortlink-board
39
+ def card_board(card_id, options = {})
40
+ card_resource(card_id, "board", options)
41
+ end
42
+
43
+ # Retrieve card checklist item states
44
+ #
45
+ # @see https://trello.com/docs/api/card/index.html#get-1-cards-card-id-or-shortlink-board
46
+ def check_item_states(card_id, options = {})
47
+ card_resource(card_id, "check_item_states", options)
48
+ end
49
+
50
+ # Retrieve card checklists
51
+ #
52
+ # @see https://trello.com/docs/api/card/index.html#get-1-cards-card-id-or-shortlink-board
53
+ def checklists(card_id, options = {})
54
+ card_resource(card_id, "checklists", options)
55
+ end
56
+
57
+ # Retrive a card list
58
+ #
59
+ # @see https://trello.com/docs/api/card/index.html#get-1-cards-card-id-or-shortlink-list
60
+ def card_list(card_id, options = {})
61
+ card_resource(card_id, "list", options)
55
62
  end
56
63
 
57
- # PUT cards/[card id or shortlink]
64
+ # Retrieve card members
65
+ #
66
+ # @see https://trello.com/docs/api/card/index.html#get-1-cards-card-id-or-shortlink-members
67
+ def card_members(card_id, options = {})
68
+ card_resource(card_id, "members", options)
69
+ end
70
+
71
+ # Retrieve members who voted on a card
72
+ #
73
+ # @see https://trello.com/docs/api/card/index.html#get-1-cards-card-id-or-shortlink-membersvoted
74
+ def card_members_voted(card_id, options = {})
75
+ card_resource(card_id, "members_voted", options)
76
+ end
77
+
78
+ # Retrieve card stickers
79
+ #
80
+ # @see https://trello.com/docs/api/card/index.html#get-1-cards-card-id-or-shortlink-stickers
81
+ def stickers(card_id, options = {})
82
+ card_resource(card_id, "stickers", options)
83
+ end
84
+
85
+ # Update card attributes
86
+ #
87
+ # @see https://trello.com/docs/api/card/index.html#put-1-cards-card-id-or-shortlink
58
88
  def update_card(card_id, options = {})
59
89
  put card_path(card_id), options
60
90
  end
61
91
 
62
- # PUT cards/[card id or shortlink]/[resource]
63
- # actions/[idAction]/comments
64
- # checklist/[idChecklist]/checkItem/[idCheckItem]/name
65
- # checklist/[idChecklist]/checkItem/[idCheckItem]/pos
66
- # checklist/[idChecklist]/checkItem/[idCheckItem]/state
67
- # checklist/[idChecklistCurrent]/checkItem/[idCheckItem]
68
- # closed
69
- # desc
70
- # due
71
- # idAttachmentCover
72
- # idBoard
73
- # idList
74
- # idMembers
75
- # labels
76
- # name
77
- # pos
78
- # stickers/[idSticker]
79
- # subscribed
80
-
81
- # POST cards
92
+ # Update comment text
93
+ #
94
+ # @see https://trello.com/docs/api/card/index.html#put-1-cards-card-id-or-shortlink-actions-idaction-comments
95
+ def update_comment(card_id, comment_id, text, options = {})
96
+ update_card_resource(card_id, "actions", comment_id, "comments", options.merge(text: text))
97
+ end
98
+ alias_method :edit_comment, :update_comment
99
+
100
+ # Update checklist item text, position or state
101
+ #
102
+ # @see https://trello.com/docs/api/card/index.html#put-1-cards-card-id-or-shortlink-checklist-idchecklistcurrent-checkitem-idcheckitem
103
+ def update_check_item(card_id, checklist_id, check_item_id, options = {})
104
+ update_card_resource(card_id, "checklist", checklist_id, "checkItem", check_item_id, options)
105
+ end
106
+
107
+ # Archive a card
108
+ #
109
+ # @see https://trello.com/docs/api/card/index.html#put-1-cards-card-id-or-shortlink-closed
110
+ def archive_card(card_id)
111
+ update_card(card_id, closed: true)
112
+ end
113
+
114
+ # Restore an archived card
115
+ #
116
+ # @see https://trello.com/docs/api/card/index.html#put-1-cards-card-id-or-shortlink-closed
117
+ def restore_card(card_id)
118
+ update_card(card_id, closed: false)
119
+ end
120
+
121
+ # Move card to another position, board and/or list
122
+ #
123
+ # @see https://trello.com/docs/api/card/index.html#put-1-cards-card-id-or-shortlink-idboard
124
+ # @see https://trello.com/docs/api/card/index.html#put-1-cards-card-id-or-shortlink-idlist
125
+ def move_card(card_id, options)
126
+ unless options.is_a?(Hash) && ([:board_id, :list_id, :pos].any? { |key| options.key? key })
127
+ raise ArgumentError, "Required option: :pos, :board_id and/or :list_id"
128
+ end
129
+ update_card(card_id, options)
130
+ end
131
+
132
+ # Update card name
133
+ #
134
+ # @see https://trello.com/docs/api/card/index.html#put-1-cards-card-id-or-shortlink-name
135
+ def update_card_name(card_id, name)
136
+ put card_path(card_id, "name"), value: name
137
+ end
138
+
139
+ # Subscribe to card
140
+ #
141
+ # @see https://trello.com/docs/api/card/index.html#put-1-cards-card-id-or-shortlink-subscribed
142
+ def subscribe_to_card(card_id)
143
+ put card_path(card_id, "subscribed"), value: true
144
+ end
145
+
146
+ # Unubscribe from card
147
+ #
148
+ # @see https://trello.com/docs/api/card/index.html#put-1-cards-card-id-or-shortlink-subscribed
149
+ def unsubscribe_from_card(card_id)
150
+ put card_path(card_id, "subscribed"), value: false
151
+ end
152
+
153
+ # Update any card resource
154
+ def update_card_resource(card_id, resource, *paths)
155
+ paths, options = extract_options(camp(resource), *paths)
156
+ put card_path(card_id, *paths), options
157
+ end
158
+
159
+ # Create a card
160
+ #
161
+ # @see https://trello.com/docs/api/card/index.html#post-1-cards
82
162
  def create_card(list_id, name = nil, options = {})
83
163
  post card_path, options.merge(name: name, list_id: list_id)
84
164
  end
85
165
 
86
- # POST cards/[card id or shortlink]/actions/comments
87
- def create_card_comment(card_id, text, options = {})
166
+ # Add a comment to a card
167
+ #
168
+ # @see https://trello.com/docs/api/card/index.html#post-1-cards-card-id-or-shortlink-actions-comments
169
+ def add_comment(card_id, text, options = {})
88
170
  options.update text: text
89
171
  create_card_resource card_id, "actions", "comments", options
90
172
  end
173
+ alias_method :create_card_comment, :add_comment
174
+
175
+ # Attach a file to a card
176
+ #
177
+ # @see https://trello.com/docs/api/card/index.html#post-1-cards-card-id-or-shortlink-attachments
178
+ def attach_file(card_id, url, mime_type = nil, options = {})
179
+ options = mime_type if mime_type.is_a?(Hash)
91
180
 
92
- # POST cards/[card id or shortlink]/attachments
93
- def create_card_attachment(card_id, url, mime_type = nil, options = {})
94
181
  uri = Addressable::URI.parse(url)
95
182
 
96
183
  if uri.scheme =~ %r{https?}
@@ -100,43 +187,149 @@ module Tacokit
100
187
  options.update file: file, mime_type: file.content_type
101
188
  end
102
189
 
103
- create_card_resource card_id, 'attachments', options
190
+ create_card_resource card_id, "attachments", options
191
+ end
192
+ alias_method :create_card_attachment, :attach_file
193
+
194
+ # Convert a checklist item to a card
195
+ #
196
+ # @see https://trello.com/docs/api/card/index.html#post-1-cards-card-id-or-shortlink-checklist-idchecklist-checkitem-idcheckitem-converttocard
197
+ def convert_to_card(card_id, checklist_id, check_item_id)
198
+ create_card_resource(card_id, "checklist", checklist_id, "checkItem", check_item_id, "convertToCard")
104
199
  end
105
200
 
106
- # POST cards/[card id or shortlink]/[resource]
107
- # checklist/[idChecklist]/checkItem
108
- # checklist/[idChecklist]/checkItem/[idCheckItem]/convertToCard
109
- # checklists
110
- # idMembers
111
- # labels
112
- # markAssociatedNotificationsRead
113
- # membersVoted
114
- # stickers
201
+ # Start a new checklist on card
202
+ #
203
+ # @see https://trello.com/docs/api/card/index.html#post-1-cards-card-id-or-shortlink-checklists
204
+ def add_checklist(card_id, name)
205
+ create_card_resource(card_id, "checklists", name: name)
206
+ end
207
+ alias_method :start_checklist, :add_checklist
208
+
209
+ # Copy another checklist to card
210
+ #
211
+ # @see https://trello.com/docs/api/card/index.html#post-1-cards-card-id-or-shortlink-checklists
212
+ def copy_checklist(card_id, checklist_id)
213
+ create_card_resource(card_id, "checklists", checklist_source_id: checklist_id)
214
+ end
215
+
216
+ # Add a member to a card
217
+ #
218
+ # @see https://trello.com/docs/api/card/index.html#post-1-cards-card-id-or-shortlink-idmembers
219
+ def add_member_to_card(card_id, member_id)
220
+ create_card_resource(card_id, "idMembers", value: member_id)
221
+ end
222
+
223
+ # Add label to card
224
+ #
225
+ # @see https://trello.com/docs/api/card/index.html#post-1-cards-card-id-or-shortlink-labels
226
+ def add_label(card_id, color, options = {})
227
+ create_card_resource(card_id, "labels", options.merge(color: color))
228
+ end
229
+
230
+ # Cast vote for card
231
+ #
232
+ # @see https://trello.com/docs/api/card/index.html#post-1-cards-card-id-or-shortlink-membersvoted
233
+ def vote(card_id, member_id)
234
+ create_card_resource(card_id, "membersVoted", value: member_id)
235
+ end
236
+ alias_method :create_vote, :vote
237
+
238
+ # Add sticker to card
239
+ #
240
+ # @see https://trello.com/docs/api/card/index.html#post-1-cards-card-id-or-shortlink-stickers
241
+ def add_sticker(card_id, image_name, options = {})
242
+ defaults = { top: 0, left: 0, z_index: 1 }
243
+ create_card_resource(card_id, "stickers", defaults.merge(options.merge(image: image_name)))
244
+ end
245
+ alias_method :create_sticker, :add_sticker
246
+
247
+ # Create a card resource
248
+ #
115
249
  def create_card_resource(card_id, resource, *paths)
116
250
  paths, options = extract_options(camp(resource), *paths)
117
251
  post card_path(card_id, *paths), options
118
252
  end
119
253
 
120
254
  # DELETE cards/[card id or shortlink]
255
+ #
256
+ # @see https://trello.com/docs/api/card/index.html#delete-1-cards-card-id-or-shortlink
121
257
  def delete_card(card_id)
122
258
  delete card_path(card_id)
123
259
  end
124
260
 
125
- # DELETE cards/[card id or shortlink]/[resource]
126
- # actions/[idAction]/comments
127
- # attachments/[idAttachment]
128
- # checklist/[idChecklist]/checkItem/[idCheckItem]
129
- # checklists/[idChecklist]
130
- # idMembers/[idMember]
131
- # labels/[color]
132
- # membersVoted/[idMember]
133
- # stickers/[idSticker]
261
+ # Remove a comment
262
+ #
263
+ # @see https://trello.com/docs/api/card/index.html#post-1-cards-card-id-or-shortlink-labels
264
+ def remove_comment(card_id, comment_id)
265
+ delete_card_resource card_id, "actions", comment_id, "comments"
266
+ end
267
+ alias_method :delete_comment, :remove_comment
268
+
269
+ # Remove an attachment
270
+ #
271
+ # @see https://trello.com/docs/api/card/index.html#delete-1-cards-card-id-or-shortlink-attachments-idattachment
272
+ def remove_attachment(card_id, attachment_id)
273
+ delete_card_resource card_id, "attachments", attachment_id
274
+ end
275
+ alias_method :delete_attachement, :remove_attachment
276
+
277
+ # Remove checklist
278
+ #
279
+ # @see https://trello.com/docs/api/card/index.html#delete-1-cards-card-id-or-shortlink-checklists-idchecklist
280
+ def remove_checklist(card_id, checklist_id)
281
+ delete_card_resource card_id, "checklists", checklist_id
282
+ end
283
+ alias_method :delete_checklist, :remove_checklist
284
+
285
+ # Remove a member from a card
286
+ #
287
+ # @see https://trello.com/docs/api/card/index.html#delete-1-cards-card-id-or-shortlink-idmembers-idmember
288
+ def remove_card_member(card_id, member_id)
289
+ delete_card_resource card_id, "idMembers", member_id
290
+ end
291
+ alias_method :delete_card_member, :remove_card_member
292
+
293
+ # Remove label from card
294
+ #
295
+ # @see https://trello.com/docs/api/card/index.html#delete-1-cards-card-id-or-shortlink-labels-color
296
+ def remove_label(card_id, color)
297
+ delete_card_resource card_id, "labels", color
298
+ end
299
+ alias_method :delete_label, :remove_label
300
+
301
+ # Remove a vote from a card
302
+ #
303
+ # @see https://trello.com/docs/api/card/index.html#delete-1-cards-card-id-or-shortlink-membersvoted-idmember
304
+ def remove_vote(card_id, member_id)
305
+ delete_card_resource card_id, "membersVoted", member_id
306
+ end
307
+ alias_method :delete_vote, :remove_vote
308
+
309
+ # Remove a sticker from a card
310
+ #
311
+ # @see https://trello.com/docs/api/card/index.html#delete-1-cards-card-id-or-shortlink-membersvoted-idmember
312
+ def remove_sticker(card_id, sticker_id)
313
+ delete_card_resource card_id, "stickers", sticker_id
314
+ end
315
+ alias_method :delete_sticker, :remove_sticker
316
+
317
+ private
318
+
319
+ def card_resource(card_id, resource, options = {})
320
+ get card_path(card_id, camp(resource)), options
321
+ end
322
+
323
+ def paginated_card_resource(card_id, resource, options = {})
324
+ paginated_get card_path(card_id, camp(resource)), options
325
+ end
326
+
134
327
  def delete_card_resource(card_id, resource, *paths)
135
328
  delete card_path(card_id, camp(resource), *paths)
136
329
  end
137
330
 
138
331
  def card_path(*paths)
139
- path_join "cards", *paths
332
+ base_path "cards", *paths
140
333
  end
141
334
  end
142
335
  end