Class: Ahub::Question

Inherits:
Object
  • Object
show all
Extended by:
APIHelpers
Includes:
ClassHelpers
Defined in:
lib/ahub/question.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from APIHelpers

admin_headers, base_url, find, find_all, headers, object_id_from_response

Methods included from ClassHelpers

#destroy, included, #update

Constructor Details

#initialize(attrs) ⇒ Question

Returns a new instance of Question.



20
21
22
23
24
25
26
27
28
# File 'lib/ahub/question.rb', line 20

def initialize(attrs)
  @answer_ids = attrs[:answers]
  @answerCount = attrs[:answerCount]
  @body = attrs[:body]
  @body_as_html = attrs[:bodyAsHTML]
  @space_id = attrs[:primaryContainerId]
  @title = attrs[:title]
  @topics = attrs[:topics]
end

Instance Attribute Details

#answerCountObject (readonly)

Returns the value of attribute answerCount.



18
19
20
# File 'lib/ahub/question.rb', line 18

def answerCount
  @answerCount
end

#authorObject

Returns the value of attribute author.



17
18
19
# File 'lib/ahub/question.rb', line 17

def author
  @author
end

#bodyObject

Returns the value of attribute body.



17
18
19
# File 'lib/ahub/question.rb', line 17

def body
  @body
end

#body_as_htmlObject

Returns the value of attribute body_as_html.



17
18
19
# File 'lib/ahub/question.rb', line 17

def body_as_html
  @body_as_html
end

#space_idObject (readonly)

Returns the value of attribute space_id.



18
19
20
# File 'lib/ahub/question.rb', line 18

def space_id
  @space_id
end

#titleObject

Returns the value of attribute title.



17
18
19
# File 'lib/ahub/question.rb', line 17

def title
  @title
end

Class Method Details

.create(title:, body:, topics:, space_id: nil, username:, password:) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/ahub/question.rb', line 6

def self.create(title:, body:, topics:, space_id: nil, username:, password:)
  url = "#{base_url}.json"

  payload = {title: title, body: body, topics: topics}
  payload[:spaceId] = space_id if space_id

  user_headers = headers(username:username, password:password)

  make_post_call(url: url, payload: payload, headers: user_headers)
end

Instance Method Details

#move(space_id:) ⇒ Object



30
31
32
33
34
35
# File 'lib/ahub/question.rb', line 30

def move(space_id:)
  raise Exception("No Question Id") unless id

  move_url = "#{self.class.base_url}/#{id}/move.json?space=#{space_id}"
  RestClient.put("#{url}", self.class.admin_headers)
end

#to_sObject



41
42
43
# File 'lib/ahub/question.rb', line 41

def to_s
  url
end

#urlObject



37
38
39
# File 'lib/ahub/question.rb', line 37

def url
  "#{self.class.base_url}/#{id}.json" if id
end