Class: Kanbanery::Client

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

Constant Summary collapse

BASE_URL =
'https://%s.kanbanery.com/api/v1'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(workspace, key) ⇒ Client

Returns a new instance of Client.



14
15
16
17
# File 'lib/ranbanery.rb', line 14

def initialize(workspace, key)
  self.workspace = workspace
  self.key       = key
end

Instance Attribute Details

#keyObject

Returns the value of attribute key.



10
11
12
# File 'lib/ranbanery.rb', line 10

def key
  @key
end

#workspaceObject

Returns the value of attribute workspace.



10
11
12
# File 'lib/ranbanery.rb', line 10

def workspace
  @workspace
end

Instance Method Details

#columns(project_id = nil) ⇒ Object



35
36
37
# File 'lib/ranbanery.rb', line 35

def columns(project_id=nil)
  resource(:column, prefix: project_id ? "/projects/#{project_id}" : nil)
end

#projectsObject



31
32
33
# File 'lib/ranbanery.rb', line 31

def projects
  resource(:project)
end

#resource(name, options = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ranbanery.rb', line 19

def resource(name, options={})
  the_workspace = self.workspace
  the_key       = self.key
  klass      = "Kanbanery::#{name.to_s.classify}".constantize
  Class.new(klass) do |c|
    def self.name; superclass.name; end
    c.element_name                    = name.to_s
    c.site                            = "#{BASE_URL % the_workspace}#{options[:prefix]}"
    c.headers['X-Kanbanery-ApiToken'] = the_key
  end
end

#subtasks(task_id = nil) ⇒ Object



43
44
45
# File 'lib/ranbanery.rb', line 43

def subtasks(task_id=nil)
  resource(:subtask, prefix: task_id ? "/tasks/#{task_id}" : nil)
end

#tasks(project_id = nil) ⇒ Object



39
40
41
# File 'lib/ranbanery.rb', line 39

def tasks(project_id=nil)
  resource(:task, prefix: project_id ? "/projects/#{project_id}" : nil)
end