Class: NS1::Transport::NetHttp

Inherits:
Object
  • Object
show all
Defined in:
lib/record_store/provider/ns1/patch_api_header.rb

Instance Method Summary collapse

Instance Method Details

#process_response(response) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/record_store/provider/ns1/patch_api_header.rb', line 6

def process_response(response)
  sleep(response.to_hash["x-ratelimit-period"].first.to_i /
    [1, response.to_hash["x-ratelimit-remaining"].first.to_i].max.to_f)

  body = JSON.parse(response.body)
  case response
  when Net::HTTPOK
    NS1::Response::Success.new(body, response.code.to_i)
  else
    NS1::Response::Error.new(body, response.code.to_i)
  end
rescue JSON::ParserError
  raise NS1::Transport::ResponseParseError
end