Sha256: b131928dddd44cec1b6fb43937e5485b01c8abaa6655d4b07860740ceea75e2f

Contents?: true

Size: 1.03 KB

Versions: 6

Compression:

Stored size: 1.03 KB

Contents

require_relative "base_client"

module PortalConnectors
  module TestsHelper
    # FROM http://stackoverflow.com/questions/25815741/set-header-in-rspec-3-request#answer-25847940
    def get_with_signature(path, params={}, headers={})
      prepare_headers(params, headers)
      get path, params, headers
    end

    def post_with_signature(path, params={}, headers={})
      prepare_headers(params, headers)
      post path, params, headers
    end

    def patch_with_signature(path, params={}, headers={})
      prepare_headers(params, headers)
      patch path, params, headers
    end

    def prepare_headers(params, headers)
      headers[:Authorization] = sign(params)
      headers[:Appname] ||= 'remitano'
    end

    def sign(params)
      SignatureSigner.new("remitano").sign(params)
    end

    def next_nonce
      PortalConnectors.redis.incr("nonce").to_i
    end

    def json_body
      @json_body ||= json_body!
    end

    def json_body!
      body = response.body.sub(/^\)\]\}'\,\n/, '')
      JSON.parse(body)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
portal-connectors-0.58.39xc lib/portal-connectors/test_helpers.rb
portal-connectors-0.58.39xb lib/portal-connectors/test_helpers.rb
portal-connectors-0.58.39xa lib/portal-connectors/test_helpers.rb
portal-connectors-0.58.39fj lib/portal-connectors/test_helpers.rb
portal-connectors-0.58.39fg lib/portal-connectors/test_helpers.rb
portal-connectors-0.58.38xn lib/portal-connectors/test_helpers.rb