Class: KanbanTool::Client
- Inherits:
-
Object
- Object
- KanbanTool::Client
- Includes:
- HTTParty
- Defined in:
- lib/kanbantool/client.rb
Instance Attribute Summary collapse
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #activity(board_id) ⇒ Object
- #api_url ⇒ Object
- #board(board_id) ⇒ Object
- #boards ⇒ Object
- #get(path) ⇒ Object
- #headers ⇒ Object
-
#initialize(domain, token) ⇒ Client
constructor
A new instance of Client.
- #params ⇒ Object
- #tasks(board_id) ⇒ Object
- #unwrap(data) ⇒ Object
- #url_for(path) ⇒ Object
- #users(board_id) ⇒ Object
Constructor Details
#initialize(domain, token) ⇒ Client
Returns a new instance of Client.
10 11 12 13 |
# File 'lib/kanbantool/client.rb', line 10 def initialize(domain, token) @domain = domain @token = token end |
Instance Attribute Details
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
8 9 10 |
# File 'lib/kanbantool/client.rb', line 8 def domain @domain end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
8 9 10 |
# File 'lib/kanbantool/client.rb', line 8 def token @token end |
Instance Method Details
#activity(board_id) ⇒ Object
35 36 37 |
# File 'lib/kanbantool/client.rb', line 35 def activity(board_id) get("boards/#{board_id}/changelog") end |
#api_url ⇒ Object
39 40 41 |
# File 'lib/kanbantool/client.rb', line 39 def api_url "https://#{domain}.#{KanbanTool::API_DOMAIN}#{KanbanTool::API_PATH}" end |
#board(board_id) ⇒ Object
21 22 23 |
# File 'lib/kanbantool/client.rb', line 21 def board(board_id) Board.create_from_hash get("boards/#{board_id}") end |
#boards ⇒ Object
15 16 17 18 19 |
# File 'lib/kanbantool/client.rb', line 15 def boards get("boards").collect do |board| Board.create_from_hash board end end |
#get(path) ⇒ Object
55 56 57 58 59 |
# File 'lib/kanbantool/client.rb', line 55 def get(path) r = HTTParty.get url_for(path), params raise "Error: #{url_for(path)} => #{r.inspect}" if r.code != 200 unwrap JSON.parse(r.body) end |
#headers ⇒ Object
47 48 49 |
# File 'lib/kanbantool/client.rb', line 47 def headers { "X-KanbanToolToken" => token } end |
#params ⇒ Object
51 52 53 |
# File 'lib/kanbantool/client.rb', line 51 def params { :headers => headers } end |
#tasks(board_id) ⇒ Object
29 30 31 32 33 |
# File 'lib/kanbantool/client.rb', line 29 def tasks(board_id) get("boards/#{board_id}/tasks").collect do |task| Task.create_from_hash task end end |
#unwrap(data) ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/kanbantool/client.rb', line 61 def unwrap(data) if data.is_a? Array data.collect { |item| unwrap item } else keys = %w{ board task shared_item_user } key = keys.find { |key| !data[key].nil? } data.include?(key) ? data[key] : data end end |
#url_for(path) ⇒ Object
43 44 45 |
# File 'lib/kanbantool/client.rb', line 43 def url_for(path) "#{api_url}#{path}.json" end |
#users(board_id) ⇒ Object
25 26 27 |
# File 'lib/kanbantool/client.rb', line 25 def users(board_id) get("boards/#{board_id}/users") end |