Sha256: 0b2efc9a431ea821fbfaaf2aeebd514e7bd46c37cb6320e07e853f94e159d532

Contents?: true

Size: 973 Bytes

Versions: 27

Compression:

Stored size: 973 Bytes

Contents

require 'rack/request'

class RollbarAPI
  def call(env)
    request = Rack::Request.new(env)
    json = JSON.parse(request.body.read)

    return bad_request(json) unless access_token?(json)

    success(json)
  end

  private

  def response_headers
    {
      'Content-Type' => 'application/json'
    }
  end

  def access_token?(json)

    !!json['access_token']
  end

  def bad_request(json)
    # We don't have for now any test doing bad requests
    # so raise here in order to detect that scenario
    raise


    [400, response_headers, [bad_request_body]]
  end

  def success(json)
    [200, response_headers, [success_body(json)]]
  end

  def bad_request_body
    result(1, nil, 'bad request')
  end

  def success_body(json)
    result(0, {
      :id => rand(1_000_000),
      :uuid => json['data']['uuid']
    }, nil)
  end

  def result(err, body, message)
    {
      :err => err,
      :result => body,
      :message => message
    }.to_json
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
rollbar-2.18.2 spec/support/rollbar_api.rb
rollbar-2.18.0 spec/support/rollbar_api.rb
rollbar-2.17.0 spec/support/rollbar_api.rb
rollbar-2.16.4 spec/support/rollbar_api.rb
rollbar-2.16.3 spec/support/rollbar_api.rb
rollbar-2.16.2 spec/support/rollbar_api.rb
rollbar-2.16.0 spec/support/rollbar_api.rb
rollbar-2.15.6 spec/support/rollbar_api.rb
rollbar-2.15.5 spec/support/rollbar_api.rb
rollbar-2.15.4 spec/support/rollbar_api.rb
rollbar-2.15.3 spec/support/rollbar_api.rb
rollbar-2.15.2 spec/support/rollbar_api.rb
rollbar-2.15.1 spec/support/rollbar_api.rb
rollbar-2.15.0 spec/support/rollbar_api.rb
rollbar-2.14.1 spec/support/rollbar_api.rb
rollbar-2.14.0 spec/support/rollbar_api.rb
rollbar-2.13.3 spec/support/rollbar_api.rb
rollbar-2.13.2 spec/support/rollbar_api.rb
rollbar-2.13.1 spec/support/rollbar_api.rb
rollbar-2.13.0 spec/support/rollbar_api.rb