Sha256: 1d72d361fbd1a02a9912f6a69e794fd222b743e8fc09331ad7d961363deeac13

Contents?: true

Size: 1.4 KB

Versions: 1

Compression:

Stored size: 1.4 KB

Contents

module Workarea
  module Forter
    class Gateway

      attr_reader :options

      def initialize(options = {})
        @options = options
      end

      def create_decision(order_id, order_details)
        body = order_details.to_json

        connection.post do |req|
          req.url "v2/orders/#{order_id}", {}
          req.body = body
        end
      end

      def update_order_status(order_id, order_details)
        body = order_details.to_json

        connection.put do |req|
          req.url "v2/status/#{order_id}", {}
          req.body = body
        end
      end

      private

        def rest_endpoint
          "https://api.forter-secure.com"
        end

        def connection
          headers = {
            "Content-Type" => "application/json",
            "x-forter-siteid" => site_id,
            "api-version" => api_version
          }

          request_timeouts = {
            timeout: Workarea.config.forter[:api_timeout],
            open_timeout: Workarea.config.forter[:open_timeout]
          }

          conn = Faraday.new(url: rest_endpoint, headers: headers, request: request_timeouts)
          conn.basic_auth(secret_key, nil)

          conn
        end

        def api_version
          options[:api_version] || "2.2"
        end

        def secret_key
          options[:secret_key]
        end

        def site_id
          options[:site_id]
        end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
workarea-forter-1.2.2 lib/workarea/forter/gateway.rb