Class: Dobedobedo::Project

Inherits:
Object
  • Object
show all
Includes:
ObjToJson
Defined in:
lib/dobedobedo/project.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ObjToJson

#objToJson, #obj_to_json, #obj_to_json2

Constructor Details

#initialize(token, workspace_id, h = {}) ⇒ Project

Returns a new instance of Project.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/dobedobedo/project.rb', line 7

def initialize(token, workspace_id, h={})
  @token = token
  @workspace_id = workspace_id
  if h.nil? #if we're creating a new project object without a hash of data, hit the post resource to create an empty obj
    h = token.post("/workspaces/#{workspace_id}/projects").parsed
  end
  h.each do |k,v|
    Project.send(:attr_accessor, k.to_sym)
    self.send("#{k}=".to_sym, v)
  end

end

Instance Attribute Details

#tokenObject (readonly)

Returns the value of attribute token.



5
6
7
# File 'lib/dobedobedo/project.rb', line 5

def token
  @token
end

Class Method Details

.create(token, workspace_id, create_data) ⇒ Object



24
25
26
# File 'lib/dobedobedo/project.rb', line 24

def self.create(token, workspace_id, create_data)
  Project.new(token, workspace_id, token.post("/workspaces/#{workspace_id}/projects", :body => create_data.to_json ).parsed)
end

.get(token, workspace_id, project_id) ⇒ Object



20
21
22
# File 'lib/dobedobedo/project.rb', line 20

def self.get(token, workspace_id, project_id)
  Project.new(token, workspace_id, token.get("/workspaces/#{workspace_id}/projects/#{project_id}").parsed)
end

Instance Method Details

#deleteObject



36
37
38
# File 'lib/dobedobedo/project.rb', line 36

def delete()
  @token.delete("/workspaces/#{@workspace_id}/projects/#{@id}")
end

#tasksObject



28
29
30
# File 'lib/dobedobedo/project.rb', line 28

def tasks
  @token.get("/workspaces/#{@workspace_id}/projects/#{@id}/tasks").parsed.map {|t| Dobedobedo::Task.new(@token, @id, nil, t)}
end

#updateObject



32
33
34
# File 'lib/dobedobedo/project.rb', line 32

def update()
  @token.put("/workspaces/#{@workspace_id}/projects/#{@id}", :body => self.objToJson)
end