Class: FoldingAtHomeClient::Project

Inherits:
Object
  • Object
show all
Includes:
Request
Defined in:
lib/folding_at_home_client/project.rb

Constant Summary

Constants included from Request

Request::API_URL, Request::HEADERS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Request

#connection, #format_response, #request, #request_and_instantiate_objects, #request_unencoded

Constructor Details

#initialize(id:, description: nil, manager: nil, cause: nil, modified: nil) ⇒ Project

Returns a new instance of Project.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/folding_at_home_client/project.rb', line 17

def initialize(
  id:,
  description: nil,
  manager: nil,
  cause: nil,
  modified: nil
)
  @id = id

  @description_id = description if description
  @manager = Manager.new(name: manager) if manager
  @cause = cause if cause
  @updated_at = modified if modified
end

Instance Attribute Details

#causeObject (readonly)

Returns the value of attribute cause.



7
8
9
# File 'lib/folding_at_home_client/project.rb', line 7

def cause
  @cause
end

#description_idObject (readonly)

Returns the value of attribute description_id.



7
8
9
# File 'lib/folding_at_home_client/project.rb', line 7

def description_id
  @description_id
end

#errorObject (readonly)

Returns the value of attribute error.



7
8
9
# File 'lib/folding_at_home_client/project.rb', line 7

def error
  @error
end

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'lib/folding_at_home_client/project.rb', line 7

def id
  @id
end

#institutionObject (readonly)

Returns the value of attribute institution.



7
8
9
# File 'lib/folding_at_home_client/project.rb', line 7

def institution
  @institution
end

#managerObject (readonly)

Returns the value of attribute manager.



7
8
9
# File 'lib/folding_at_home_client/project.rb', line 7

def manager
  @manager
end

#thumbObject (readonly)

Returns the value of attribute thumb.



7
8
9
# File 'lib/folding_at_home_client/project.rb', line 7

def thumb
  @thumb
end

#updated_atObject (readonly)

Returns the value of attribute updated_at.



7
8
9
# File 'lib/folding_at_home_client/project.rb', line 7

def updated_at
  @updated_at
end

#urlObject (readonly)

Returns the value of attribute url.



7
8
9
# File 'lib/folding_at_home_client/project.rb', line 7

def url
  @url
end

Instance Method Details

#contributorsObject



55
56
57
58
59
60
61
62
# File 'lib/folding_at_home_client/project.rb', line 55

def contributors
  endpoint = '/project/contributors'
  params = { projects: @id }

  request(endpoint:, params:).map do |name|
    User.new(name:)
  end
end

#descriptionObject



64
65
66
# File 'lib/folding_at_home_client/project.rb', line 64

def description
  Description.new(id: @description_id).lookup
end

#lookupObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/folding_at_home_client/project.rb', line 32

def lookup
  endpoint = "/project/#{@id}"
  project_hash = request(endpoint:).first

  error = project_hash[:error]

  if error
    @error = error
    return self
  end

  @body = project_hash[:description]
  @manager = Manager.new(
    name: project_hash[:manager],
    thumb: project_hash[:mthumb],
    description: project_hash[:mdescription]
  )
  @cause = project_hash[:cause]
  @updated_at = project_hash[:modified]

  self
end