Class: HttpParser

Inherits:
Object
  • Object
show all
Defined in:
lib/http-parser.rb,
lib/http-parser/version.rb

Constant Summary collapse

VERSION =
'1.0.1'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#responseObject

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

#parseObject



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