g4s_client 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
1
  pkg
2
+ nbproject
data/g4s_client.gemspec CHANGED
@@ -1,10 +1,10 @@
1
1
  $:.push File.expand_path("../lib", __FILE__)
2
- require "g4s/version"
2
+ require "version" # path WITHIN the s.require_paths below
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = %q{g4s_client}
6
- s.version = G4SClient::VERSION
7
- s.platform = Gem::Platform::RUBY
6
+ s.version = G4sClient::VERSION
7
+ #s.platform = Gem::Platform::RUBY
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
9
  s.authors = ["Rob Tierney"]
10
10
  s.date = %q{2011-01-05}
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
21
21
 
22
22
  s.homepage = %q{http://github.com/robtierney/g4s_client}
23
23
  s.rdoc_options = ["--charset=UTF-8"]
24
- s.require_paths = ["lib"]
24
+ s.require_paths = ["lib"] + ["lib/g4s"] + ['lib/g4s/shipping'] + ['lib/g4s/tracking'] + ['lib/g4s/utilities']
25
25
  s.summary = %q{G4S SOAP Client}
26
26
 
27
27
  if s.respond_to? :specification_version then
data/lib/g4s/g4s.rb CHANGED
@@ -1,29 +1,39 @@
1
1
 
2
- module G4S
2
+ class G4s
3
+
4
+ CONFIG = YAML.load( ENV['G4S_CONFIG'] || File.read(Rails.root + 'config' + 'g4s.yml') )
3
5
 
4
- #TODO: add method_missing to forward calls to the service.
5
- class Shipping
6
- attr_reader :service
7
- def initialize(endpoint=nil)
8
- @endpoint = endpoint || ENV['G4S_SHIPPING_ENDPOINT_URL']
9
- @service = IPSShippingSoap.new(@endpoint)
10
- end
6
+ class TEST; end
7
+ class LIVE; end
8
+
9
+ def self.instance
10
+ @@instance ||= self.new
11
11
  end
12
-
13
- class Tracking
14
- attr_reader :service
15
- def initialize(endpoint=nil)
16
- @endpoint = endpoint || ENV['G4S_TRACKING_ENDPOINT_URL']
17
- @service = IPSTrackingSoap.new(@endpoint)
12
+
13
+ def initialize
14
+ if g4s_env == ::G4s::TEST
15
+ @shipping_client = G4sClient::ShippingTest.new
16
+ @utilities_client = G4sClient::UtilitiesTest.new
17
+ @tracking_client = G4sClient::TrackingTest.new
18
+ else
19
+ @shipping_client = G4sClient::ShippingLive.new
20
+ @utilities_client = G4sClient::UtilitiesLive.new
21
+ @tracking_client = G4sClient::TrackingLive.new
18
22
  end
19
23
  end
20
24
 
21
- class Utilities
22
- attr_reader :service
23
- def initialize(endpoint=nil)
24
- @endpoint = endpoint || ENV['G4S_UTILITIES_ENDPOINT_URL']
25
- @service = IPSUtilitesSoap.new(@endpoint)
25
+ def shipping; @shipping_client; end
26
+ def utilities; @utilities_client; end
27
+ def tracking; @tracking_client; end
28
+
29
+ protected
30
+
31
+ def g4s_env
32
+ if (defined?(Rails) && Rails.env.development?) && !ENV['G4S_TEST_MODE']==false
33
+ G4s::TEST
34
+ else
35
+ G4s::LIVE
26
36
  end
27
37
  end
28
-
38
+
29
39
  end
@@ -0,0 +1,21 @@
1
+
2
+ # Idea taken from: http://blog.willcannings.com/2008/07/06/wsse-authentication-in-ruby-soap4r/
3
+ # See also: http://journal.dedasys.com/2009/05/08/ruby-soap4r-wsse-authentication
4
+
5
+ require 'soap/header/simplehandler'
6
+
7
+ class G4SIAuthHeader < SOAP::Header::SimpleHandler
8
+
9
+ NAMESPACE = 'http://tempuri.org'
10
+
11
+ def initialize(username, password, accessKey)
12
+ @username, @password, @accessKey = username, password, accessKey
13
+ super(XSD::QName.new(NAMESPACE, 'G4SIAuthentication'))
14
+ end
15
+
16
+ def on_simple_outbound
17
+ {"Username" => @username, "Password" => @password, "AccessKey"=>@accessKey}
18
+ end
19
+
20
+
21
+ end
@@ -1,3 +1,6 @@
1
+ #puts "REQUIRING: #{Dir[__FILE__]}"
2
+
3
+
1
4
  #!/usr/bin/env ruby
2
5
  require 'defaultDriver.rb'
3
6