Sha256: 5d0036401e5a63b5154e1d91a204726752f4f38e07cbe884c34f902c29005148

Contents?: true

Size: 1.94 KB

Versions: 1

Compression:

Stored size: 1.94 KB

Contents

require 'flowcommerce'
require 'flowcommerce-activemerchant'
require 'active_merchant/billing/bogus_flow_gateway'
require 'active_merchant/billing/flow_gateway'
require 'net/sftp'

require 'workarea'
require 'workarea/storefront'
require 'workarea/admin'
require 'workarea/freedom_patches/flow_io'
require 'workarea/flow_io/controller_log_subscriber'

require 'workarea/flow_io/engine'
require 'workarea/flow_io/version'
require 'workarea/flow_io/http_handler'
require 'workarea/flow_io/bogus_client'

module Workarea
  module FlowIo
    FTP_HOST = 'ftp.flow.io'

    def self.credentials
      (Rails.application.secrets.flow_io || config.to_h).deep_symbolize_keys
    end

    def self.config
      Workarea.config.flow_io
    end

    def self.api_token
      credentials[:api_token]
    end

    def self.organization_id
      credentials[:organization_id]
    end

    def self.image_sizes
      config.image_sizes
    end

    def self.client(timeout: nil, open_timeout: nil, read_timeout: nil, logger: nil, **options)
      timeout ||= config.default_timeout
      read_timeout ||= timeout
      open_timeout ||= timeout

      if api_token.present?
        FlowCommerce.instance(
          token: Workarea::FlowIo.api_token,
          http_handler: Workarea::FlowIo::HttpHandler.new(open_timeout: open_timeout, read_timeout: read_timeout, logger: logger, **options)
        )
      else
        FlowIo::BogusClient.new
      end
    end

    def self.webhook_shared_secret
      Workarea::FlowIo::Webhook::SharedSecret.first.try(:token)
    end

    # Conditionally use the real gateway when secrets are present.
    # Otherwise, use the bogus gateway.
    #
    # @return [ActiveMerchant::Billing::Gateway]
    def self.gateway
      if credentials.present?
        ActiveMerchant::Billing::FlowGateway.new(api_key: Workarea::FlowIo.api_token, organization: Workarea::FlowIo.organization_id)
      else
        ActiveMerchant::Billing::BogusGateway.new
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
workarea-flow_io-1.2.1 lib/workarea/flow_io.rb