Sha256: c03ed9a13be487e0485c89a9abf38fe17304d76b498d044bcbdb13f695aee7c0

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

Contents

require 'airborne_report/version'
require 'airborne_report/message'
require 'airborne_report/storage/tests'

module AirborneReport
end

module Airborne
  module RestClientRequester
    alias origin_make_request make_request

    def make_request(*args)
      response = origin_make_request(*args)
      save!(args, response)
      response
    rescue SocketError => error
      wasted_save(args, response)
      raise error
    end

    private

    def save!(args, response)
      if response.is_a?(RestClient::Response)
        full_save(response)
      else
        wasted_save(args, response)
      end
    end

    def full_save(response)
      request = response.request
      AirborneReport::Storage::Tests.find_or_create(location)
        .push(AirborneReport::Message.full(request, response).to_hash)
    end

    def wasted_save(args, response)
      url = get_url(args[1])
      AirborneReport::Storage::Tests.find_or_create(location)
        .push(AirborneReport::Message.wasted(args, response, url).to_hash)
    end

    def location
      inspect.to_s.split('(').last.split(')').first
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
airborne_report-0.2.0 lib/airborne_report.rb