Sha256: d180dc543172c20dd88a9c8cbaa0cd75e3245446ce41871fd5f992eebafae679

Contents?: true

Size: 980 Bytes

Versions: 2

Compression:

Stored size: 980 Bytes

Contents

require "g4s_client"

class G4s

  CONFIG = YAML.load( ENV['G4S_CONFIG'] || File.read(Rails.root + 'config' + 'g4s.yml') )
  
  class TEST; end
  class LIVE; end

  def self.instance
    @@instance ||= self.new
  end

  def initialize
    if g4s_env == ::G4s::TEST
      @shipping_class  = ::G4sClient::ShippingTest
      @utilities_class = ::G4sClient::UtilitiesTest
      @tracking_class  = ::G4sClient::TrackingTest
    else
      @shipping_class  = ::G4sClient::ShippingLive
      @utilities_class = ::G4sClient::UtilitiesLive
      @tracking_class  = ::G4sClient::TrackingLive
    end
  end
  
  def shipping
    @shipping_class.new  # do not cache these between requests!  need to clear-out headers!
  end
  def utilities
    @utilities_class.new
  end
  def tracking
    @tracking_class.new
  end

  protected

  def g4s_env
    if (defined?(Rails) && Rails.env.development?) && !(ENV['G4S_TEST_MODE']==false)
      ::G4s::TEST
    else
      ::G4s::LIVE
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
g4s_client-0.1.7 lib/g4s/g4s.rb
g4s_client-0.1.6 lib/g4s/g4s.rb