Class: Tredo::Todo
- Inherits:
-
Object
- Object
- Tredo::Todo
- Defined in:
- lib/tredo/todo.rb
Constant Summary collapse
- BOARD_ID =
"61af9e0503811b04f6771d00".freeze
- LIST_ID =
"61af9e0503811b04f6771d01".freeze
- BASE_URL =
"https://api.trello.com/1".freeze
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #cards(list_id) ⇒ Object
- #create_card(name) ⇒ Object
-
#initialize(restclient, token = nil, key = nil) ⇒ Todo
constructor
A new instance of Todo.
- #lists ⇒ Object
Constructor Details
#initialize(restclient, token = nil, key = nil) ⇒ Todo
Returns a new instance of Todo.
13 14 15 16 17 |
# File 'lib/tredo/todo.rb', line 13 def initialize(restclient, token = nil, key = nil) @restprovider = restclient @token = token ||= ENV["PROVIDER_TOKEN"] @key = key ||= ENV["PROVIDER_KEY"] end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
11 12 13 |
# File 'lib/tredo/todo.rb', line 11 def key @key end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
11 12 13 |
# File 'lib/tredo/todo.rb', line 11 def token @token end |
Instance Method Details
#cards(list_id) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/tredo/todo.rb', line 48 def cards(list_id) return error(message: "Missing Token or Key") if invalid_auth? return error("List Id cannot be nil or empty") if list_id.nil? || list_id.empty? url = "#{BASE_URL}/lists/#{list_id}/cards?token=#{@token}&key=#{@key}" response = @restprovider.get url return error("Failed to retrieve cards for list.") if response.code != 200 Jsender::Json.success(data: { "result" => response.body }) rescue RestClient::Unauthorized error("Unauthorized access.") rescue RestClient::BadRequest error("Bad request") end |
#create_card(name) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/tredo/todo.rb', line 19 def create_card(name) return error("Missing Token or Key") if invalid_auth? return error("Card name is empty") if name.nil? || name.empty? url = "#{BASE_URL}/cards" response = @restprovider.post url, idList: LIST_ID, token: @token, key: @key, name: name return error("Failed to create todo.") if response.code != 200 Jsender::Json.success(data: { "result" => response.body }) rescue RestClient::Unauthorized error("Unauthorized access. No todo created") rescue RestClient::BadRequest error("Bad request. No todo created") end |
#lists ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/tredo/todo.rb', line 34 def lists return error(message: "Missing Token or Key") if invalid_auth? url = "#{BASE_URL}/boards/#{BOARD_ID}/lists?token=#{@token}&key=#{@key}" response = @restprovider.get url return error("Failed to retrieve lists.") if response.code != 200 Jsender::Json.success(data: { "result" => response.body }) rescue RestClient::Unauthorized error("Unauthorized access.") rescue RestClient::BadRequest error("Bad request") end |