Class: Logan::Project

Inherits:
Object
  • Object
show all
Includes:
HashConstructed, ResponseHandler
Defined in:
lib/logan/project.rb

Instance Attribute Summary collapse

Attributes included from HashConstructed

#attributes, #json_raw

Instance Method Summary collapse

Methods included from ResponseHandler

#handle_error, #handle_response, #success?

Methods included from HashConstructed

#initialize

Instance Attribute Details

#app_urlObject

Returns the value of attribute app_url.



15
16
17
# File 'lib/logan/project.rb', line 15

def app_url
  @app_url
end

#archivedObject

Returns the value of attribute archived.



17
18
19
# File 'lib/logan/project.rb', line 17

def archived
  @archived
end

#colorObject

Returns the value of attribute color.



22
23
24
# File 'lib/logan/project.rb', line 22

def color
  @color
end

#descriptionObject

Returns the value of attribute description.



12
13
14
# File 'lib/logan/project.rb', line 12

def description
  @description
end

#draftObject

Returns the value of attribute draft.



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

def draft
  @draft
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#is_client_projectObject

Returns the value of attribute is_client_project.



21
22
23
# File 'lib/logan/project.rb', line 21

def is_client_project
  @is_client_project
end

#nameObject

Returns the value of attribute name.



11
12
13
# File 'lib/logan/project.rb', line 11

def name
  @name
end

#starredObject

Returns the value of attribute starred.



18
19
20
# File 'lib/logan/project.rb', line 18

def starred
  @starred
end

#templateObject

Returns the value of attribute template.



16
17
18
# File 'lib/logan/project.rb', line 16

def template
  @template
end

#trashedObject

Returns the value of attribute trashed.



19
20
21
# File 'lib/logan/project.rb', line 19

def trashed
  @trashed
end

#updated_atObject

Returns the value of attribute updated_at.



13
14
15
# File 'lib/logan/project.rb', line 13

def updated_at
  @updated_at
end

#urlObject

Returns the value of attribute url.



14
15
16
# File 'lib/logan/project.rb', line 14

def url
  @url
end

Instance Method Details

#accessesObject



86
87
88
89
# File 'lib/logan/project.rb', line 86

def accesses
  response = Logan::Client.get "/projects/#{@id}/accesses.json"
  response.parsed_response.map { |h| p = Logan::Person.new(h) }
end

#add_client_by_email(email) ⇒ Object



118
119
120
121
122
123
124
125
# File 'lib/logan/project.rb', line 118

def add_client_by_email(email)
  post_params = {
    :body => { email_addresses: [email] }.to_json,
    :headers => Logan::Client.headers.merge({'Content-Type' => 'application/json'})
  }

  response = Logan::Client.post "/projects/#{@id}/client_accesses.json", post_params
end

#add_client_by_id(id) ⇒ Object



100
101
102
103
104
105
106
107
# File 'lib/logan/project.rb', line 100

def add_client_by_id(id)
  post_params = {
    :body => { ids: [id] }.to_json,
    :headers => Logan::Client.headers.merge({'Content-Type' => 'application/json'})
  }

  response = Logan::Client.post "/projects/#{@id}/client_accesses.json", post_params
end

#add_user_by_email(email) ⇒ Object



109
110
111
112
113
114
115
116
# File 'lib/logan/project.rb', line 109

def add_user_by_email(email)
  post_params = {
    :body => { email_addresses: [email] }.to_json,
    :headers => Logan::Client.headers.merge({'Content-Type' => 'application/json'})
  }

  response = Logan::Client.post "/projects/#{@id}/accesses.json", post_params
end

#add_user_by_id(id) ⇒ Object



91
92
93
94
95
96
97
98
# File 'lib/logan/project.rb', line 91

def add_user_by_id(id)
  post_params = {
    :body => { ids: [id] }.to_json,
    :headers => Logan::Client.headers.merge({'Content-Type' => 'application/json'})
  }

  response = Logan::Client.post "/projects/#{@id}/accesses.json", post_params
end

#all_todolistsArray<Logan::TodoList>

get both active and completed todo lists for this project from Basecamp API

Returns:

  • (Array<Logan::TodoList>)

    array of active and completed todo lists for this project



59
60
61
# File 'lib/logan/project.rb', line 59

def all_todolists
  todolists + completed_todolists
end

#completed_todolistsArray<Logan::TodoList>

get completed todo lists for this project from Basecamp API

Returns:

  • (Array<Logan::TodoList>)

    array of completed todo lists for this project



49
50
51
52
53
54
# File 'lib/logan/project.rb', line 49

def completed_todolists
  completed_response = Logan::Client.get "/projects/#{@id}/todolists/completed.json"
  lists_array = completed_response.parsed_response.map do |h|
    Logan::TodoList.new h.merge({ :project_id => @id })
  end
end

#completed_todosArray<Logan::Todo>

returns the array of completed todos - potentially synchronously downloaded from API

Returns:

  • (Array<Logan::Todo>)

    Array of completed todos for this todo list



176
177
178
179
# File 'lib/logan/project.rb', line 176

def completed_todos
  return @completed_todos if @completed_todos
  completed_todos!
end

#completed_todos!Object



181
182
183
184
185
# File 'lib/logan/project.rb', line 181

def completed_todos!
  response = Logan::Client.get "/projects/#{@id}/todos/completed.json"

  @completed_todos = handle_response(response, Proc.new {|h| Logan::Todo.new(h.merge({ :project_id => @id })) })
end

#create_message(subject, content, subscribers, private) ⇒ Logan::Message

create a message via Basecamp API

Parameters:

  • subject (String)

    subject for the new message

  • content (String)

    content for the new message

  • subscribers (Array)

    array of subscriber ids for the new message

  • private (Bool)

    should the private flag be set for the new message

Returns:



134
135
136
137
138
139
140
141
142
# File 'lib/logan/project.rb', line 134

def create_message(subject, content, subscribers, private)
  post_params = {
    :body => {subject: subject, content: content, subscribers: subscribers, private: private}.to_json,
    :headers => Logan::Client.headers.merge({'Content-Type' => 'application/json'})
  }

  response = Logan::Client.post "/projects/#{@id}/messages.json", post_params
  Logan::Project.new response
end

#create_todolist(todo_list) ⇒ Logan::TodoList

create a todo list in this project via Basecamp API

Parameters:

Returns:



76
77
78
79
80
81
82
83
84
# File 'lib/logan/project.rb', line 76

def create_todolist(todo_list)
  post_params = {
    :body => todo_list.post_json,
    :headers => Logan::Client.headers.merge({'Content-Type' => 'application/json'})
  }

  response = Logan::Client.post "/projects/#{@id}/todolists.json", post_params
  Logan::TodoList.new response.merge({ :project_id => @id })
end

#publishLogan::Project

publish this project from Basecamp API

Returns:



37
38
39
40
41
42
43
44
# File 'lib/logan/project.rb', line 37

def publish
  post_params = {
    :body => {}.to_json,
    :headers => Logan::Client.headers.merge({'Content-Type' => 'application/json'})
  }

  response = Logan::Client.post "/projects/#{@id}/publish.json", post_params
end

#remaining_todos(&block) ⇒ Array<Logan::Todo>

returns the array of remaining todos - potentially synchronously downloaded from API

Returns:

  • (Array<Logan::Todo>)

    Array of remaining todos for this todo list



148
149
150
151
# File 'lib/logan/project.rb', line 148

def remaining_todos &block
  return @remaining_todos if @remaining_todos
  remaining_todos! &block
end

#remaining_todos!(&block) ⇒ Object



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/logan/project.rb', line 153

def remaining_todos! &block
  @remaining_todos = []
  if block_given?
    page = 1
    while true

      response = Logan::Client.get "/projects/#{@id}/todos/remaining.json?page=#{page}"
      list = handle_response(response, Proc.new {|h| Logan::Todo.new(h.merge({ :project_id => @id })) })
      @remaining_todos << list
      page += 1
      break if list.size < 50
    end
    @remaining_todos = @remaining_todos.flatten
  else
    response = Logan::Client.get "/projects/#{@id}/todos/remaining.json"
    @remaining_todos = handle_response(response, Proc.new {|h| Logan::Todo.new(h.merge({ :project_id => @id })) })
  end
  @remaining_todos
end

#todolist(list_id) ⇒ Logan::TodoList

get an individual todo list for this project from Basecamp API

Parameters:

  • list_id (String)

    id for the todo list

Returns:



67
68
69
70
# File 'lib/logan/project.rb', line 67

def todolist(list_id)
  response = Logan::Client.get "/projects/#{@id}/todolists/#{list_id}.json"
  Logan::TodoList.new response.parsed_response.merge({ :project_id => @id })
end

#todolistsArray<Logan::TodoList>

get active todo lists for this project from Basecamp API

Returns:



27
28
29
30
31
32
# File 'lib/logan/project.rb', line 27

def todolists
  active_response = Logan::Client.get "/projects/#{@id}/todolists.json"
  lists_array = active_response.parsed_response.map do |h|
    Logan::TodoList.new h.merge({ :project_id => @id })
  end
end

#todosArray<Logan::Todo>

returns the array of todos - potentially synchronously downloaded from API

Returns:

  • (Array<Logan::Todo>)

    Array of todos for this todo list



204
205
206
207
# File 'lib/logan/project.rb', line 204

def todos
  return @todos if @todos
  todos!
end

#todos!Object



209
210
211
212
213
# File 'lib/logan/project.rb', line 209

def todos!
  response = Logan::Client.get "/projects/#{@id}/todos.json"

  @todos = handle_response(response, Proc.new {|h| Logan::Todo.new(h.merge({ :project_id => @id })) })
end

#trashed_todosArray<Logan::Todo>

returns the array of trashed todos - potentially synchronously downloaded from API

Returns:

  • (Array<Logan::Todo>)

    Array of trashed todos for this todo list



190
191
192
193
# File 'lib/logan/project.rb', line 190

def trashed_todos
  return @trashed_todos if @trashed_todos
  trashed_todos!
end

#trashed_todos!Object



195
196
197
198
199
# File 'lib/logan/project.rb', line 195

def trashed_todos!
  response = Logan::Client.get "/projects/#{@id}/todos/trashed.json"

  @trashed_todos = handle_response(response, Proc.new {|h| Logan::Todo.new(h.merge({ :project_id => @id })) })
end