Class: TextRazor::Response
- Inherits:
-
Object
- Object
- TextRazor::Response
- Defined in:
- lib/textrazor/response.rb
Constant Summary collapse
- BadRequest =
Class.new(StandardError)
Class.new(StandardError)
- RequestEntityTooLong =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#raw_response ⇒ Object
readonly
Returns the value of attribute raw_response.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Instance Method Summary collapse
- #categories ⇒ Object
- #cleaned_text ⇒ Object
- #coarse_topics ⇒ Object
-
#custom_annotation_output ⇒ Object
def message end.
- #entailments ⇒ Object
- #entities ⇒ Object
-
#initialize(http_response) ⇒ Response
constructor
A new instance of Response.
- #language ⇒ Object
- #language_is_reliable? ⇒ Boolean
- #ok? ⇒ Boolean
- #phrases ⇒ Object
- #properties ⇒ Object
- #raw_text ⇒ Object
- #relations ⇒ Object
- #sentences ⇒ Object
- #topics ⇒ Object
- #words ⇒ Object
Constructor Details
#initialize(http_response) ⇒ Response
Returns a new instance of Response.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/textrazor/response.rb', line 13 def initialize(http_response) code = http_response.code body = http_response.body raise BadRequest.new(body) if bad_request?(code) raise Unauthorised.new(body) if (code) raise RequestEntityTooLong.new(body) if request_entity_too_long?(code) json_body = ::JSON::parse(body, symbolize_names: true) @time = json_body[:time].to_f @ok = json_body[:ok] @raw_response = json_body[:response] end |
Instance Attribute Details
#raw_response ⇒ Object (readonly)
Returns the value of attribute raw_response.
11 12 13 |
# File 'lib/textrazor/response.rb', line 11 def raw_response @raw_response end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
11 12 13 |
# File 'lib/textrazor/response.rb', line 11 def time @time end |
Instance Method Details
#categories ⇒ Object
87 88 89 |
# File 'lib/textrazor/response.rb', line 87 def categories @categories ||= parse_categories end |
#cleaned_text ⇒ Object
43 44 45 |
# File 'lib/textrazor/response.rb', line 43 def cleaned_text @cleaned_text ||= raw_response[:cleanedText] end |
#coarse_topics ⇒ Object
59 60 61 |
# File 'lib/textrazor/response.rb', line 59 def coarse_topics @coarse_topics ||= parse_coarse_topics end |
#custom_annotation_output ⇒ Object
def message end
39 40 41 |
# File 'lib/textrazor/response.rb', line 39 def custom_annotation_output @custom_annotation_output ||= raw_response[:customAnnotationOutput] end |
#entailments ⇒ Object
51 52 53 |
# File 'lib/textrazor/response.rb', line 51 def entailments @entailments ||= parse_entailments end |
#entities ⇒ Object
55 56 57 |
# File 'lib/textrazor/response.rb', line 55 def entities @entities ||= parse_entities end |
#language ⇒ Object
91 92 93 |
# File 'lib/textrazor/response.rb', line 91 def language raw_response[:language] end |
#language_is_reliable? ⇒ Boolean
95 96 97 |
# File 'lib/textrazor/response.rb', line 95 def language_is_reliable? raw_response[:languageIsReliable] end |
#ok? ⇒ Boolean
28 29 30 |
# File 'lib/textrazor/response.rb', line 28 def ok? @ok end |
#phrases ⇒ Object
67 68 69 |
# File 'lib/textrazor/response.rb', line 67 def phrases @phrases ||= parse_phrases end |
#properties ⇒ Object
75 76 77 |
# File 'lib/textrazor/response.rb', line 75 def properties @properties ||= parse_properties end |
#raw_text ⇒ Object
47 48 49 |
# File 'lib/textrazor/response.rb', line 47 def raw_text @raw_text||= raw_response[:rawText] end |
#relations ⇒ Object
79 80 81 |
# File 'lib/textrazor/response.rb', line 79 def relations @relations ||= parse_relations end |
#sentences ⇒ Object
83 84 85 |
# File 'lib/textrazor/response.rb', line 83 def sentences @sentences ||= parse_sentences end |
#topics ⇒ Object
63 64 65 |
# File 'lib/textrazor/response.rb', line 63 def topics @topics ||= parse_topics end |
#words ⇒ Object
71 72 73 |
# File 'lib/textrazor/response.rb', line 71 def words @words ||= parse_words end |