Sha256: 3034596a28909d93595b61c1aefe7f7ebaa5acc052540ac0a1340a25fac4ea5c
Contents?: true
Size: 723 Bytes
Versions: 2
Compression:
Stored size: 723 Bytes
Contents
require "myfinance/exception" module Myfinance RequestTimeout = Class.new(Exception) RequestError = Class.new(Exception) class Response < SimpleDelegator def resolve!(&block) if success? block_given? ? yield(self) : self elsif timed_out? timeout! else error! end end def parsed_body(key=nil) return MultiJson.load(self.body)[key] unless key.nil? MultiJson.load(self.body) rescue MultiJson::ParseError {} end private def timeout! raise RequestTimeout end def error! raise RequestError.new( code: code, message: status_message, body: body ) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
myfinance-0.2.0 | lib/myfinance/response.rb |
myfinance-0.1.0 | lib/myfinance/response.rb |