Class: CommandFeedback::Service
- Inherits:
-
Object
- Object
- CommandFeedback::Service
show all
- Defined in:
- lib/command_feedback/feedback.rb
Defined Under Namespace
Classes: ErrorFeedback, SuccessfulFeedback
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(title, choices, description) ⇒ Service
Returns a new instance of Service.
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/command_feedback/feedback.rb', line 11
def initialize title, choices, description
body = {
"multiplechoice" => {
"title" => title,
"description" => description,
"choices" => Service.build_choices_hash(choices)
}
}
options = { :headers => { 'ContentType' => 'application/json' } }
hostname = "get-feedback.at"
@response = HTTParty.post "http://#{ hostname }/questions.json", :body => body, :options => options
end
|
Class Method Details
.build_choices_hash(choices) ⇒ Object
25
26
27
28
29
30
31
|
# File 'lib/command_feedback/feedback.rb', line 25
def self.build_choices_hash(choices)
choices_hash = {}
choices.each_with_index { |choice, index|
choices_hash["choice_#{index + 1}"] = choice
}
choices_hash
end
|
.get_feedback(title, choices, description = "") ⇒ Object
6
7
8
9
|
# File 'lib/command_feedback/feedback.rb', line 6
def self.get_feedback title, choices, description = ""
service = Service.new title, choices, description
service.process
end
|
Instance Method Details
#process ⇒ Object
33
34
35
36
37
38
39
|
# File 'lib/command_feedback/feedback.rb', line 33
def process
if was_successful?
SuccessfulFeedback.new(@response["question"])
else
ErrorFeedback.new(@response["errors"])
end
end
|
#was_successful? ⇒ Boolean
41
42
43
44
45
|
# File 'lib/command_feedback/feedback.rb', line 41
def was_successful?
@response.include? "question" and
@response["question"].include? "admin_link" and
@response["question"].include? "feedback_link"
end
|