Class: Quandora::Question

Inherits:
Request
  • Object
show all
Defined in:
lib/quandora/question.rb

Overview

show

Instance Attribute Summary

Attributes inherited from Request

#api, #params

Instance Method Summary collapse

Methods inherited from Request

#index, #initialize, #show

Constructor Details

This class inherits a constructor from Quandora::Request

Instance Method Details

#answer(question_id, args) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/quandora/question.rb', line 19

def answer(question_id, args)
  args = args.stringify_keys

  body = {
    "type": "post-answer",
    "data": {
      "content": args["content"],
      "contentType": args["content_type"] || "markdown"
    }
  }
  resp = @conn.post("q/#{question_id}/answer") do |req|
    req.body = body.to_json
    req.headers['Content-Type'] = 'application/json'
  end
end

#comment(question_id) ⇒ Object



49
50
51
# File 'lib/quandora/question.rb', line 49

def comment(question_id)
  Quandora::Comment.new(@conn, "q", question_id)
end

#detail(question_id) ⇒ Object



4
5
6
7
# File 'lib/quandora/question.rb', line 4

def detail(question_id)
  @api = "q/"
  show("#{question_id}")
end

#mlt(question_id, args = {}) ⇒ Object



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

def mlt(question_id, args = {})
  @api = "q/"
  show("#{question_id}/mlt")
end

#tag(answer_id) ⇒ Object



53
54
55
# File 'lib/quandora/question.rb', line 53

def tag(answer_id)
  Quandora::Tag.new(@conn, "q", answer_id)
end

#view(question_id, args = {}) ⇒ Object



9
10
11
12
# File 'lib/quandora/question.rb', line 9

def view(question_id, args = {})
  @api = "q/"
  show("#{question_id}/view")
end

#vote(question_id, args) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/quandora/question.rb', line 35

def vote(question_id, args)
  args = args.stringify_keys

  body = {
    "type": "boolean",
    "data": args["vote"]
  }

  resp = @conn.post("q/#{question_id}/vote") do |req|
    req.body = body.to_json
    req.headers['Content-Type'] = 'application/json'
  end
end