ups_pickup 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +60 -0
- data/Rakefile +2 -0
- data/lib/schema/Error1.1.xsd +47 -0
- data/lib/schema/Pickup.wsdl +162 -0
- data/lib/schema/PickupWebServiceSchema.xsd +1 -0
- data/lib/schema/UPSSecurity.xsd +23 -0
- data/lib/schema/common.xsd +48 -0
- data/lib/ups_pickup.rb +18 -0
- data/lib/ups_pickup/address.rb +63 -0
- data/lib/ups_pickup/error_response.rb +18 -0
- data/lib/ups_pickup/fault_response.rb +12 -0
- data/lib/ups_pickup/pickup_cancel.rb +51 -0
- data/lib/ups_pickup/pickup_cancel_success.rb +13 -0
- data/lib/ups_pickup/pickup_creation.rb +141 -0
- data/lib/ups_pickup/pickup_creation_success.rb +13 -0
- data/lib/ups_pickup/pickup_piece.rb +20 -0
- data/lib/ups_pickup/pickup_request.rb +69 -0
- data/lib/ups_pickup/shipper.rb +57 -0
- data/lib/ups_pickup/util.rb +41 -0
- data/lib/ups_pickup/version.rb +3 -0
- data/ups_pickup.gemspec +20 -0
- metadata +118 -0
@@ -0,0 +1,57 @@
|
|
1
|
+
module UpsPickup
|
2
|
+
class Shipper
|
3
|
+
attr_accessor :account_number,:account_country_code,:card_hoder_name,:card_type,:card_number
|
4
|
+
attr_accessor :expiration_date,:security_code,:card_address,:payment_method
|
5
|
+
# options=>{:card_address=>{:state=>,:city=>,...}}
|
6
|
+
# Valid Card Type values are :
|
7
|
+
# 01 = American Express
|
8
|
+
# 03 = Discover
|
9
|
+
# 04 = Mastercard
|
10
|
+
# 06 = VISA
|
11
|
+
def initialize(options={})
|
12
|
+
@account_number = options[:account_number]
|
13
|
+
@account_country_code = options[:account_country_code] || "US"
|
14
|
+
@card_hoder_name = options[:card_hoder_name]
|
15
|
+
# TODO Validate card type 01 = American Express 03 = Discover 04 = Mastercard 06 = VISA
|
16
|
+
# if country code is US and payment method is 3
|
17
|
+
@card_type = options[:card_type]
|
18
|
+
@card_number = options[:card_number]
|
19
|
+
@expiration_date = options[:expiration_date]
|
20
|
+
@security_code = options[:security_code]
|
21
|
+
@card_address = UpsPickup::Address.new(options[:card_address])
|
22
|
+
#TODO raise an exception for payment method
|
23
|
+
@payment_method = options[:payment_method] if !options[:payment_method].nil? && [0,1,2,3,4,5].include?(options[:payment_method].to_i)
|
24
|
+
@payment_method ||="00"
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_ups_hash
|
28
|
+
|
29
|
+
if @payment_method.to_i == 3
|
30
|
+
{
|
31
|
+
"ns2:Account"=>{
|
32
|
+
"AccountNumber"=>@account_number,
|
33
|
+
"AccountCountryCode"=>@account_country_code
|
34
|
+
},
|
35
|
+
"ns2:ChargeCard"=>{
|
36
|
+
"ns2:CardType"=>@card_type,
|
37
|
+
"ns2:CardNumber"=>@card_number,
|
38
|
+
"ns2:ExpirationDate"=>@expiration_date,
|
39
|
+
"ns2:SecurityCode"=>@security_code,
|
40
|
+
"ns2:CardAddress"=>{
|
41
|
+
"ns2:AddressLine"=>@card_address.to_ups_hash
|
42
|
+
}
|
43
|
+
}
|
44
|
+
}
|
45
|
+
else
|
46
|
+
{
|
47
|
+
"ns2:Account"=>{
|
48
|
+
"ns2:AccountNumber"=>@account_number,
|
49
|
+
"ns2:AccountCountryCode"=>@account_country_code
|
50
|
+
}
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module UpsPickup
|
2
|
+
module Util
|
3
|
+
def set_yes_or_no_option(value)
|
4
|
+
if value.nil? || value == 0 || value == false || value == "n" || value == "N"
|
5
|
+
"N"
|
6
|
+
elsif value == 1 || value == true || value == "y" || value == "Y"
|
7
|
+
"Y"
|
8
|
+
else
|
9
|
+
raise "Option can be [Y,N]"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
#Finding nested hash keys value
|
13
|
+
def deep_find(obj,key)
|
14
|
+
if obj.respond_to?(:key?) && obj.key?(key)
|
15
|
+
obj[key]
|
16
|
+
elsif obj.respond_to?(:each)
|
17
|
+
r = nil
|
18
|
+
obj.find{ |*a| r=deep_find(a.last,key) }
|
19
|
+
r
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
class Hash
|
26
|
+
def deep_fetch(key, default = nil)
|
27
|
+
default = yield if block_given?
|
28
|
+
(deep_find(key) or default) or nil
|
29
|
+
end
|
30
|
+
|
31
|
+
def deep_find(key)
|
32
|
+
if key?(key)
|
33
|
+
self[key]
|
34
|
+
else
|
35
|
+
self.values.inject(nil) do |memo, v|
|
36
|
+
memo = v.deep_find(key) if v.respond_to?(:deep_find)
|
37
|
+
memo unless memo.nil?
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/ups_pickup.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/ups_pickup/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["amardaxini"]
|
6
|
+
gem.email = ["amardaxini@gmail.com"]
|
7
|
+
gem.description = %q{UPS Pickup Request API}
|
8
|
+
gem.summary = %q{UPS Pickup Request API}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "ups_pickup"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = UpsPickup::VERSION
|
17
|
+
gem.add_dependency('httparty')
|
18
|
+
gem.add_dependency('savon', '>= 1.1.0')
|
19
|
+
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ups_pickup
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- amardaxini
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-08-31 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: httparty
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: savon
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 19
|
43
|
+
segments:
|
44
|
+
- 1
|
45
|
+
- 1
|
46
|
+
- 0
|
47
|
+
version: 1.1.0
|
48
|
+
type: :runtime
|
49
|
+
version_requirements: *id002
|
50
|
+
description: UPS Pickup Request API
|
51
|
+
email:
|
52
|
+
- amardaxini@gmail.com
|
53
|
+
executables: []
|
54
|
+
|
55
|
+
extensions: []
|
56
|
+
|
57
|
+
extra_rdoc_files: []
|
58
|
+
|
59
|
+
files:
|
60
|
+
- .gitignore
|
61
|
+
- Gemfile
|
62
|
+
- LICENSE
|
63
|
+
- README.md
|
64
|
+
- Rakefile
|
65
|
+
- lib/schema/Error1.1.xsd
|
66
|
+
- lib/schema/Pickup.wsdl
|
67
|
+
- lib/schema/PickupWebServiceSchema.xsd
|
68
|
+
- lib/schema/UPSSecurity.xsd
|
69
|
+
- lib/schema/common.xsd
|
70
|
+
- lib/ups_pickup.rb
|
71
|
+
- lib/ups_pickup/address.rb
|
72
|
+
- lib/ups_pickup/error_response.rb
|
73
|
+
- lib/ups_pickup/fault_response.rb
|
74
|
+
- lib/ups_pickup/pickup_cancel.rb
|
75
|
+
- lib/ups_pickup/pickup_cancel_success.rb
|
76
|
+
- lib/ups_pickup/pickup_creation.rb
|
77
|
+
- lib/ups_pickup/pickup_creation_success.rb
|
78
|
+
- lib/ups_pickup/pickup_piece.rb
|
79
|
+
- lib/ups_pickup/pickup_request.rb
|
80
|
+
- lib/ups_pickup/shipper.rb
|
81
|
+
- lib/ups_pickup/util.rb
|
82
|
+
- lib/ups_pickup/version.rb
|
83
|
+
- ups_pickup.gemspec
|
84
|
+
homepage: ""
|
85
|
+
licenses: []
|
86
|
+
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
hash: 3
|
98
|
+
segments:
|
99
|
+
- 0
|
100
|
+
version: "0"
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
hash: 3
|
107
|
+
segments:
|
108
|
+
- 0
|
109
|
+
version: "0"
|
110
|
+
requirements: []
|
111
|
+
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 1.8.24
|
114
|
+
signing_key:
|
115
|
+
specification_version: 3
|
116
|
+
summary: UPS Pickup Request API
|
117
|
+
test_files: []
|
118
|
+
|