Sha256: 563e35d82db52a2459f5ad3ba15dd5b9a071a412544f6e426fe1d0daf04a2b07

Contents?: true

Size: 1.47 KB

Versions: 2

Compression:

Stored size: 1.47 KB

Contents

require 'active_support'
require 'active_support/dependencies'
require 'active_support/core_ext'

require 'oauth'

require 'organizai/consumer'
require 'organizai/provider'
require 'organizai/response'
require 'organizai/api'

require 'organizai/user'
require 'organizai/coupon'

module Organizai
  
  # Consumers for each environment
  mattr_accessor :consumers
  @@consumers = ActiveSupport::OrderedHash.new
  
  # Api calls format
  mattr_accessor :format
  @@format = :json
  
  # Protocol
  mattr_accessor :protocol
  @@protocol = :http
  
  # Whether Organizai.config was called or not
  @@configured = false;
  
  # API hosts
  HOST = {
    :production => "api.organizai.com.br",
    :sandbox    => "sandbox.organizai.com.br"
  }
  
  # Setup
  def self.config
    yield self
    @@configured = true
    raise "Missing consumer config for Organizaí" if @@consumers.empty?
  end
  
  def self.configured?
    @@configured
  end
  
  # Used by #config to add consumers configuration
  def self.consumer env, &block
    consumer = Organizai::Consumer.new
    consumer.instance_eval(&block)
    @@consumers[env] = consumer
  end
  
  # App env
  def self.env
    defined?(::Rails) ? ::Rails.env.to_sym : :development
  end
  
  # Current api env
  def self.api_env
    current_consumer.kind
  end 
  
  # Current consumer by app env
  def self.current_consumer
    consumer = @@consumers[env]
    raise "Missing consumer config for '#{env}' environment." if consumer.nil?
    consumer
  end
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
organizai-0.1.1 lib/organizai.rb
organizai-0.1.0 lib/organizai.rb