Class: KiTrello::Session
- Inherits:
-
Object
- Object
- KiTrello::Session
- Defined in:
- lib/ki_trello/session.rb
Constant Summary collapse
- API_URL =
"https://api.trello.com"
Instance Method Summary collapse
- #auth_params ⇒ Object
- #boards ⇒ Object
- #card(card_id) ⇒ Object
- #card_on_board(board_id, card_id) ⇒ Object
-
#initialize(config) ⇒ Session
constructor
A new instance of Session.
- #lists(board_id) ⇒ Object
- #new_card(list_id, data) ⇒ Object
Constructor Details
#initialize(config) ⇒ Session
Returns a new instance of Session.
9 10 11 12 13 14 15 |
# File 'lib/ki_trello/session.rb', line 9 def initialize(config) @config = config @config.ensure_present('username', 'developer_api_key', 'member_token') @username = config.read('username') @key = config.read('developer_api_key') @token = config.read('member_token') end |
Instance Method Details
#auth_params ⇒ Object
17 18 19 20 21 22 |
# File 'lib/ki_trello/session.rb', line 17 def auth_params { :key => @key, :token => @token } end |
#boards ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/ki_trello/session.rb', line 69 def boards response = connection.get("/1/members/#{@username}/boards", auth_params) case response.status when 200 response.body else raise SessionError, "Unhandled status code #{response.status}" end end |
#card(card_id) ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/ki_trello/session.rb', line 44 def card(card_id) response = connection.get("/1/cards/#{card_id}", auth_params.merge(:checklists => 'all')) case response.status when 200 response.body.merge('ki_type' => 'trello_card') else raise SessionError, "Unhandled status code #{response.status}: #{response.body}" end end |
#card_on_board(board_id, card_id) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/ki_trello/session.rb', line 34 def card_on_board(board_id, card_id) response = connection.get("/1/boards/#{board_id}/cards/#{card_id}", auth_params.merge(:checklists => 'all')) case response.status when 200 response.body.merge('ki_type' => 'trello_card') else raise SessionError, "Unhandled status code #{response.status}: #{response.body}" end end |
#lists(board_id) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/ki_trello/session.rb', line 24 def lists(board_id) response = connection.get("/1/boards/#{board_id}/lists", auth_params) case response.status when 200 response.body else raise SessionError, "Unhandled status code #{response.status}: #{response.body}" end end |
#new_card(list_id, data) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/ki_trello/session.rb', line 55 def new_card(list_id, data) params = data.merge(auth_params).merge('idList' => list_id) response = connection.post("/1/cards", params) case response.status when 200 response.body when 400 raise SessionError, "Bad parameters. Check the JSON.\n#{response.body}" else raise SessionError, "Unhandled status code #{response.status}" end end |