Sha256: c3a17f3c80c19cc3f312e368233635976bc7f1dbfe6437ff8dbc8ad8b69db874

Contents?: true

Size: 1.43 KB

Versions: 1

Compression:

Stored size: 1.43 KB

Contents

require 'net/http'
require 'net/https'
require 'digest'
require 'logger'

require 'json'

require 'postageapp/utils'
require 'postageapp/version'
require 'postageapp/configuration'
require 'postageapp/logger'
require 'postageapp/request'
require 'postageapp/failed_request'
require 'postageapp/response'

module PostageApp
  
  class Error < StandardError ; end
  
  class << self
    
    # Accessor for the PostageApp::Configuration object
    attr_accessor :configuration
    
    # Call this method to modify your configuration
    # 
    # Example:
    #   PostageApp.configure do |config|
    #     config.api_key             = '1234567890abcdef'
    #     config.recipient_override  = 'test@test.test' if Rails.env.staging?
    #   end
    def configure
      self.configuration ||= Configuration.new
      yield self.configuration
    end
    
    # Logger for the plugin
    def logger
      raise Error, 'Need configuration to be set before logger can be used' if !configuration
      @logger ||= begin
        configuration.logger || PostageApp::Logger.new(
          if configuration.project_root
            FileUtils.mkdir_p(File.join(File.expand_path(configuration.project_root), 'log'))
            File.join(configuration.project_root, "log/postageapp_#{configuration.environment}.log")
          else
            STDOUT
          end
        )
      end
    end
    
  end
end

# Loading Rails hook
require 'postageapp/rails' if defined?(Rails)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
postageapp-1.0.0 lib/postageapp.rb