g4s_client 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,16 @@
1
+ require 'soap/header/simplehandler'
2
+
3
+ class CommodityListHeader < CustomHeader
4
+
5
+ NAMESPACE = 'http://WS.G4SI.COM/'
6
+
7
+ def initialize(commodity_list)
8
+ @commodity_list = commodity_list
9
+ super(XSD::QName.new(NAMESPACE, 'CommodityList'))
10
+ end
11
+
12
+ def on_simple_outbound
13
+ to_hash(@commodity_list)
14
+ end
15
+
16
+ end
@@ -2,7 +2,7 @@ require 'soap/header/simplehandler'
2
2
 
3
3
  class CustomHeader < SOAP::Header::SimpleHandler
4
4
 
5
- NAMESPACE = 'http://tempuri.org'
5
+ NAMESPACE = 'http://WS.G4SI.COM/'
6
6
 
7
7
  # def initialize(shipment_request)
8
8
  # @shipment_request = shipment_request
@@ -16,16 +16,20 @@ class CustomHeader < SOAP::Header::SimpleHandler
16
16
 
17
17
  protected
18
18
 
19
+ def primitive_types
20
+ [ NilClass, TrueClass, FalseClass, Numeric, Time, Date, DateTime, String, Symbol ]
21
+ end
22
+
19
23
  # Transform a object into a hash of its instance variables
20
24
  def to_hash(object)
21
25
  return {} unless object
22
26
  result = {}
27
+ #puts "to_hash #{object.class}:#{object}"
28
+ #puts "#{y object.instance_variables.sort}"
23
29
  object.instance_variables.each do |var|
24
30
  value = object.instance_variable_get(var)
25
- var.gsub!('@','')
26
- var = capitalize_first_letter(var)
27
- result[var] = value
28
- #TODO: NESTING: some things like Address will need to result[var] = to_hash(object.instance_variable_get(var))
31
+ result[instance_var_name_to_tag(var)] = format_value(value)
32
+ #TODO: NESTING
29
33
  end
30
34
  result
31
35
  end
@@ -35,5 +39,23 @@ class CustomHeader < SOAP::Header::SimpleHandler
35
39
  string[0].chr.capitalize + string[1, string.size]
36
40
  end
37
41
 
42
+ def instance_var_name_to_tag(var)
43
+ var.gsub!('@','')
44
+ var = capitalize_first_letter(var)
45
+ var
46
+ end
47
+
48
+ def format_value(value)
49
+ if primitive_types.any?{|type| value.is_a?(type)}
50
+ if value.is_a?(Time)
51
+ return value.strftime("%Y-%m-%dT%H:%M:%S") # YYYY-MM-DDTHH:MM:SS
52
+ end
53
+ return value
54
+ else
55
+ #puts "non primitive value found: #{value.class}:#{value}"
56
+ return to_hash(value) # recurse for non-"primitive" types such as Address.
57
+ end
58
+ end
59
+
38
60
 
39
61
  end
@@ -2,7 +2,7 @@ require 'soap/header/simplehandler'
2
2
 
3
3
  class ShipmentRequestHeader < CustomHeader
4
4
 
5
- NAMESPACE = 'http://tempuri.org'
5
+ NAMESPACE = 'http://WS.G4SI.COM/'
6
6
 
7
7
  def initialize(shipment_request)
8
8
  @shipment_request = shipment_request
@@ -9,8 +9,13 @@ class InsuredShip
9
9
  reset_service_instance
10
10
  @service.headerhandler << ShipmentRequestHeader.new(shipment_request) # add new headers.
11
11
  @service.calculateEstimatedPrice(CalculateEstimatedPrice.new())
12
+ end
12
13
 
13
- puts ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #{@service.filterchain }"
14
+ def createShipment(shipment_request = ShipmentRequest.new, commodity_list = CommodityList.new)
15
+ reset_service_instance
16
+ @service.headerhandler << ShipmentRequestHeader.new(shipment_request) # add new headers.
17
+ @service.headerhandler << CommodityListHeader.new(commodity_list) # add new headers.
18
+ @service.createShipment(CreateShipment.new())
14
19
  end
15
20
 
16
21
  protected
@@ -20,7 +25,6 @@ class InsuredShip
20
25
  @service.wiredump_dev=STDERR
21
26
  @service.options['protocol.http.ssl_config.verify_mode'] = OpenSSL::SSL::VERIFY_NONE
22
27
  @service.filterchain << G4sNamespaceFilter.new
23
- puts "gogogo"
24
28
  end
25
29
 
26
30
  end
@@ -0,0 +1,23 @@
1
+
2
+
3
+ class InsuredUtilities
4
+
5
+ def initialize
6
+ end
7
+
8
+ def getPackageTypes()
9
+ reset_service_instance
10
+ #@service.headerhandler << ShipmentRequestHeader.new(shipment_request) # add new headers.
11
+ @service.getPackageTypes(GetPackageTypes.new())
12
+ end
13
+
14
+ protected
15
+
16
+ def reset_service_instance
17
+ @service = G4s.instance.utilities.service # must make a new instance each time.
18
+ @service.wiredump_dev=STDERR
19
+ @service.options['protocol.http.ssl_config.verify_mode'] = OpenSSL::SSL::VERIFY_NONE
20
+ @service.filterchain << G4sNamespaceFilter.new
21
+ end
22
+
23
+ end
data/lib/g4s_client.rb CHANGED
@@ -14,10 +14,12 @@
14
14
  "g4s/utilities/defaultMappingRegistry",
15
15
  "g4s/g4s",
16
16
  "g4s/insured_ship",
17
+ "g4s/insured_utilities",
17
18
  "g4s/headers/custom_header",
18
19
  "g4s/headers/g4si_auth_header",
19
20
  "g4s/headers/shipment_request_header",
20
21
  "g4s/headers/g4s_namespace_filter",
22
+ "g4s/headers/commodity_list_header",
21
23
  "version"].each{|f| require f}
22
24
 
23
25
  module G4sClient
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  #puts "REQUIRING: #{Dir[__FILE__]}"
2
2
 
3
3
  module G4sClient
4
- VERSION = '0.1.6'
4
+ VERSION = '0.1.7'
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: g4s_client
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 6
10
- version: 0.1.6
9
+ - 7
10
+ version: 0.1.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Rob Tierney
@@ -35,11 +35,13 @@ files:
35
35
  - Rakefile
36
36
  - g4s_client.gemspec
37
37
  - lib/g4s/g4s.rb
38
+ - lib/g4s/headers/commodity_list_header.rb
38
39
  - lib/g4s/headers/custom_header.rb
39
40
  - lib/g4s/headers/g4s_namespace_filter.rb
40
41
  - lib/g4s/headers/g4si_auth_header.rb
41
42
  - lib/g4s/headers/shipment_request_header.rb
42
43
  - lib/g4s/insured_ship.rb
44
+ - lib/g4s/insured_utilities.rb
43
45
  - lib/g4s/shipping/IPSShippingClient.rb
44
46
  - lib/g4s/shipping/default.rb
45
47
  - lib/g4s/shipping/defaultDriver.rb