lib/egp_rates/cib.rb
def raw_exchange_rates
      req = Net::HTTP::Post.new(@uri, 'Content-Type' => 'application/json')
      req.body = { lang: :en }.to_json
      response = Net::HTTP.start(@uri.hostname, @uri.port) do |http|
        http.request(req)
      end
      fail ResponseError, response.code unless response.is_a? Net::HTTPSuccess
      response = JSON.parse(response.body)

      # CIB provide 6 currencies only
      unless response['d'] && response['d'].size >= 6
        fail ResponseError, "Unknown JSON #{response}"
      end

      response
    rescue JSON::ParserError
      raise ResponseError, "Unknown JSON: #{response.body}"
    end
def raw_exchange_rates
      req = Net::HTTP::Post.new(@uri, 'Content-Type' => 'application/json')
      req.body = { lang: :en }.to_json
      response = Net::HTTP.start(@uri.hostname, @uri.port) do |http|
        http.request(req)
      end
      fail ResponseError, response.code unless response.is_a? Net::HTTPSuccess
      response = JSON.parse(response.body)

      # CIB provide 6 currencies only
      unless response['d'] && response['d'].size >= 6
        fail ResponseError, "Unknown JSON #{response}"
      end

      response
    rescue JSON::ParserError
      raise ResponseError, "Unknown JSON: #{response.body}"
    end
def raw_exchange_rates req = Net :: HTTP :: Post . new ( @uri , 'Content-Type' => 'application/json' ) req . body = { lang : :en } . to_json response = Net :: HTTP . start ( @uri . hostname , @uri . port ) do | http | http . request ( req ) end fail ResponseError , response . code unless response . is_a? Net :: HTTPSuccess response = JSON . parse ( response . body ) # CIB provide 6 currencies only unless response [ 'd' ] && response [ 'd' ] . size >= 6 fail ResponseError , "Unknown JSON #{response}" end response rescue JSON :: ParserError raise ResponseError , "Unknown JSON: #{response.body}" end
Send the request to URL and return the JSON response
 @return [Hash] JSON response of the exchange rates
   {
     "d"=> [
       {
         "__type"=>"LINKDev.CIB.CurrenciesFunds.CIBFund.CurrencyObject",
         "CurrencyID"=>"USD",
         "BuyRate"=>15.9,
         "SellRate"=>16.05
       }, {
         "__type"=>"LINKDev.CIB.CurrenciesFunds.CIBFund.CurrencyObject",
         "CurrencyID"=>"EUR",
         "BuyRate"=>17.1904,
         "SellRate"=>17.5234
       }, {
         ...
       }
     ]
   }
Send the request to URL and return the JSON response