Class: HttpParser
- Inherits:
-
Object
- Object
- HttpParser
- Defined in:
- lib/http-parser.rb,
lib/http-parser/version.rb
Constant Summary collapse
- VERSION =
'1.0.1'
Instance Attribute Summary collapse
-
#response ⇒ Object
Returns the value of attribute response.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(response) ⇒ HttpParser
constructor
A new instance of HttpParser.
- #parse ⇒ Object
Constructor Details
#initialize(response) ⇒ HttpParser
Returns a new instance of HttpParser.
8 9 10 11 12 |
# File 'lib/http-parser.rb', line 8 def initialize(response) @response = response check_valid_response?(response) end |
Instance Attribute Details
#response ⇒ Object
Returns the value of attribute response.
6 7 8 |
# File 'lib/http-parser.rb', line 6 def response @response end |
Class Method Details
.parse(response) ⇒ Object
15 16 17 18 |
# File 'lib/http-parser.rb', line 15 def parse(response) response = new(response) response.parse end |
Instance Method Details
#parse ⇒ Object
21 22 23 24 25 26 |
# File 'lib/http-parser.rb', line 21 def parse success = (200..308).to_a.include?(response.code.to_i) ? true : false hash_response = JSON.parse(response.body) Struct.new(:success?, :hash_response).new(success, hash_response) end |