Sha256: 84a21d0431120d8a714828377bda150bb5b0822fc6271c26fa7cb262cbc050b8

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

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 ENV['G4S_TEST_MODE']==false
      ::G4s::LIVE
    elsif ENV['G4S_TEST_MODE']==true
      ::G4s::TEST
    elsif defined?(Rails) && (Rails.env.development? || Rails.env == "staging")
      ::G4s::TEST
    else
      ::G4s::LIVE
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
g4s_client-0.2.0 lib/g4s/g4s.rb