fedex-web-services 1.0.42 → 1.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/lib/fedex.rb CHANGED
@@ -1,6 +1,2 @@
1
1
  require "fedex/version"
2
2
  require "fedex/web_services"
3
-
4
- module Fedex
5
- require 'fedex/railtie' if defined?(Rails)
6
- end
data/lib/fedex/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Fedex
2
- VERSION = "1.0.42"
2
+ VERSION = "1.1.6"
3
3
  end
@@ -33,7 +33,7 @@ module Fedex::WebServices
33
33
  def version
34
34
  VersionId.new.tap do |o|
35
35
  o.serviceId = @service.service_id
36
- o.major = 10
36
+ o.major = @service.service_version
37
37
  o.intermediate = 0
38
38
  o.minor = 0
39
39
  end
@@ -2,13 +2,13 @@ module Fedex::WebServices
2
2
  module Request
3
3
  class GetRates < Base
4
4
 
5
- def initialize(service, service_type, rate_request_type, shipper, recipient, weight)
5
+ def initialize(service, service_type, rate_request_type, from_address, to_address, weight)
6
6
 
7
7
  super(service)
8
8
 
9
9
  @service_type = service_type
10
- @shipper = shipper
11
- @recipient = recipient
10
+ @from_address = from_address
11
+ @to_address = to_address
12
12
  @rate_request_type = rate_request_type
13
13
  @requested_package_line_items = [
14
14
  RequestedPackageLineItem.new.tap do |o|
@@ -31,16 +31,23 @@ module Fedex::WebServices
31
31
 
32
32
  o.requestedShipment = RequestedShipment.new.tap do |o|
33
33
  o.shipTimestamp = Time.now.iso8601
34
- o.serviceType = @service_type
34
+ o.serviceType = @service_type
35
35
  o.packagingType = PackagingType::YOUR_PACKAGING
36
36
 
37
- o.shipper = @shipper
38
- o.recipient = @recipient
37
+ o.shipper = Party.new.tap do |o|
38
+ o.address = @from_address
39
+ end
40
+
41
+ o.recipient = Party.new.tap do |o|
42
+ o.address = @to_address
43
+ end
39
44
 
40
45
  o.shippingChargesPayment = Payment.new.tap do |o|
41
46
  o.paymentType = PaymentType::SENDER
42
47
  o.payor = Payor.new.tap do |o|
43
- o.accountNumber = @service.credentials.account_number
48
+ o.responsibleParty = Party.new.tap do |o|
49
+ o.accountNumber = @service.credentials.account_number
50
+ end
44
51
  end
45
52
  end
46
53
 
@@ -58,7 +58,9 @@ module Fedex::WebServices
58
58
  o.shippingChargesPayment = Payment.new.tap do |o|
59
59
  o.paymentType = PaymentType::SENDER
60
60
  o.payor = Payor.new.tap do |o|
61
- o.accountNumber = @service.credentials.account_number
61
+ o.responsibleParty = @shipper.clone.tap do |o|
62
+ o.accountNumber = @service.credentials.account_number
63
+ end
62
64
  end
63
65
  end
64
66
 
@@ -10,7 +10,7 @@ module Fedex::WebServices
10
10
  include Fedex::WebServices::Definitions
11
11
  include Fedex::WebServices::Request
12
12
 
13
- Credentials = Struct.new("Credentials",
13
+ Credentials = Struct.new(
14
14
  :account_number, :meter_number, :key, :password, :environment
15
15
  )
16
16
 
@@ -25,6 +25,16 @@ module Fedex::WebServices
25
25
  raise "service_id must be implemented by subclasses of Service"
26
26
  end
27
27
 
28
+ def service_version
29
+ raise "service_version must be implemented by subclasses of Service"
30
+ end
31
+
32
+ def service_url
33
+ (@credentials.environment.to_sym == :production) ?
34
+ 'https://ws.fedex.com:443/web-services' :
35
+ 'https://wsbeta.fedex.com:443/web-services'
36
+ end
37
+
28
38
  protected
29
39
  def port
30
40
  raise "port must be implemented by subclasses of Service"
@@ -4,12 +4,12 @@ module Fedex::WebServices
4
4
  module Service
5
5
  class Rate < Base
6
6
 
7
- def get_rates(service_type, rate_request_type, shipper, recipient, weight, &process_contents)
7
+ def get_rates(service_type, rate_request_type, from, to, weight, &process_contents)
8
8
  request = GetRates.new(self,
9
9
  service_type,
10
10
  rate_request_type,
11
- shipper,
12
- recipient,
11
+ from,
12
+ to,
13
13
  weight
14
14
  )
15
15
 
@@ -21,6 +21,10 @@ module Fedex::WebServices
21
21
  :crs
22
22
  end
23
23
 
24
+ def service_version
25
+ 13
26
+ end
27
+
24
28
  def self.rate_for(response, rate_request_type)
25
29
  details = response.rateReplyDetails.first.ratedShipmentDetails.select do |detail|
26
30
  detail.shipmentRateDetail.rateType == "PAYOR_#{rate_request_type}_PACKAGE"
@@ -33,7 +37,7 @@ module Fedex::WebServices
33
37
 
34
38
  protected
35
39
  def port
36
- RatePortType.new('https://wsbeta.fedex.com:443/web-services')
40
+ RatePortType.new(service_url)
37
41
  end
38
42
  end
39
43
  end
@@ -9,6 +9,10 @@ module Fedex::WebServices
9
9
  :ship
10
10
  end
11
11
 
12
+ def service_version
13
+ 12
14
+ end
15
+
12
16
  def process_shipment(service_type, shipper, recipient,
13
17
  label_specification, package_weights, &process_contents)
14
18
 
@@ -72,11 +76,13 @@ module Fedex::WebServices
72
76
  acc + BigDecimal.new(rate.netCharge.amount) :
73
77
  acc
74
78
  end
79
+ rescue
80
+ raise "Unable to extract rate information from response"
75
81
  end
76
82
 
77
83
  protected
78
84
  def port
79
- ShipPortType.new('https://wsbeta.fedex.com:443/web-services')
85
+ ShipPortType.new(service_url)
80
86
  end
81
87
  end
82
88
  end
@@ -0,0 +1,38 @@
1
+ module Fedex
2
+ module Generators
3
+ class GenerateDefinitionsGenerator < ::Rails::Generators::Base
4
+ FEDEX_INITIALIZER_FILE = File.join(Rails.root, 'config', 'initializers', 'fedex.rb')
5
+
6
+ class_option :wsdl_dir,
7
+ default: File.join(%w(lib fedex web_services wsdl)),
8
+ type: :string,
9
+ desc: "directory where the fedex wsld files are stored"
10
+
11
+
12
+ class_option :skip_initializer,
13
+ default: false,
14
+ type: :boolean,
15
+ desc: "install a rails initializer to load the wsdl definitions"
16
+
17
+ desc "Generate the FedEx WebServices class definitions and create an initializer to load them"
18
+
19
+ def install
20
+ wsdl_dir = options[:wsdl_dir]
21
+ wsdl_files = Dir.glob(File.join(wsdl_dir, '*.wsdl'))
22
+ target_lib_dir = File.join(Rails.root, 'lib')
23
+
24
+ if (wsdl_files.empty?)
25
+ say("Could not find any wsdl files in #{wsdl_dir}", :red)
26
+ else
27
+ Fedex::WebServices::Definitions.generate_definitions(target_lib_dir, *wsdl_files)
28
+ say("Added #{File.join(target_lib_dir, Fedex::WebServices::Definitions::MODULE_PATH)}", :green)
29
+
30
+ unless (options[:skip_initializer])
31
+ create_file(FEDEX_INITIALIZER_FILE,
32
+ "Fedex::WebServices::Definitions.load_definitions('lib')")
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fedex-web-services
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.42
4
+ version: 1.1.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-18 00:00:00.000000000Z
13
- dependencies: []
12
+ date: 2012-11-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: soap4r-ruby19
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
14
30
  description: Interfaces with the FedEx web services API to look up shipping rates,
15
31
  generate labels, and cancel shipments
16
32
  email:
@@ -19,8 +35,6 @@ executables: []
19
35
  extensions: []
20
36
  extra_rdoc_files: []
21
37
  files:
22
- - lib/fedex/railtie.rb
23
- - lib/fedex/tasks/fedex.rake
24
38
  - lib/fedex/version.rb
25
39
  - lib/fedex/web_services/definitions.rb
26
40
  - lib/fedex/web_services/request/base.rb
@@ -32,8 +46,10 @@ files:
32
46
  - lib/fedex/web_services/service/ship.rb
33
47
  - lib/fedex/web_services.rb
34
48
  - lib/fedex.rb
49
+ - lib/generators/fedex/generate_definitions_generator.rb
35
50
  homepage: https://github.com/brewski/fedex-web-services
36
- licenses: []
51
+ licenses:
52
+ - MIT
37
53
  post_install_message:
38
54
  rdoc_options: []
39
55
  require_paths:
@@ -43,7 +59,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
43
59
  requirements:
44
60
  - - ! '>='
45
61
  - !ruby/object:Gem::Version
46
- version: '0'
62
+ version: 1.9.0
47
63
  required_rubygems_version: !ruby/object:Gem::Requirement
48
64
  none: false
49
65
  requirements:
@@ -52,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
52
68
  version: '0'
53
69
  requirements: []
54
70
  rubyforge_project: fedex-web-services
55
- rubygems_version: 1.8.10
71
+ rubygems_version: 1.8.23
56
72
  signing_key:
57
73
  specification_version: 3
58
74
  summary: Provies an interface to the FedEx web services API (version 10)
data/lib/fedex/railtie.rb DELETED
@@ -1,9 +0,0 @@
1
- module Fedex
2
- class Railtie < Rails::Railtie
3
- railtie_name :fedex
4
-
5
- rake_tasks do
6
- load "fedex/tasks/fedex.rake"
7
- end
8
- end
9
- end
@@ -1,21 +0,0 @@
1
- namespace :fedex do
2
- desc "Generate the ruby definition files from the FedEx wsdl files"
3
- task :generate_definitions do
4
- wsdl_dir = ENV['WSDL_DIR']
5
- if (!Dir.exist?(wsdl_dir || ""))
6
- puts "Set the WSDL_DIR environment variable to location of the Fedex wsdl files"
7
- else
8
- Fedex::WebServices::Definitions.generate_definitions(
9
- File.join(Rails.root, 'lib'),
10
- *Dir.glob(File.join(ENV['WSDL_DIR'], '*.wsdl'))
11
- )
12
-
13
- File.open(File.join(Rails.root, 'config', 'initializers', 'fedex.rb'), "w") do |file|
14
- file.puts "Fedex::WebServices::Definitions.load_definitions('lib')"
15
- end
16
-
17
- puts "Added lib/fedex/web_services/definitions/"
18
- puts "Added config/initializers/fedex.rb"
19
- end
20
- end
21
- end