ship_me 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,47 @@
1
+ # module ShipMe #:nodoc:
2
+ # module PostsData #:nodoc:
3
+ #
4
+ # def self.included(base)
5
+ # base.superclass_delegating_accessor :ssl_strict
6
+ # base.ssl_strict = true
7
+ #
8
+ # base.class_inheritable_accessor :retry_safe
9
+ # base.retry_safe = false
10
+ #
11
+ # base.superclass_delegating_accessor :open_timeout
12
+ # base.open_timeout = 60
13
+ #
14
+ # base.superclass_delegating_accessor :read_timeout
15
+ # base.read_timeout = 60
16
+ #
17
+ # base.superclass_delegating_accessor :logger
18
+ # base.superclass_delegating_accessor :wiredump_device
19
+ # end
20
+ #
21
+ # def ssl_get(endpoint, headers={})
22
+ # ssl_request(:get, endpoint, nil, headers)
23
+ # end
24
+ #
25
+ # def ssl_post(endpoint, data, headers = {})
26
+ # ssl_request(:post, endpoint, data, headers)
27
+ # end
28
+ #
29
+ # private
30
+ # def ssl_request(method, endpoint, data, headers = {})
31
+ # connection = ActiveMerchant::Connection.new(endpoint)
32
+ # connection.open_timeout = open_timeout
33
+ # connection.read_timeout = read_timeout
34
+ # connection.retry_safe = retry_safe
35
+ # connection.verify_peer = ssl_strict
36
+ # connection.logger = logger
37
+ # connection.tag = self.class.name
38
+ # connection.wiredump_device = wiredump_device
39
+ #
40
+ # connection.pem = @options[:pem] if @options
41
+ # connection.pem_password = @options[:pem_password] if @options
42
+ #
43
+ # connection.request(method, data, headers)
44
+ # end
45
+ #
46
+ # end
47
+ # end
@@ -0,0 +1,55 @@
1
+ module RestrictedEnumeration
2
+ def self.included base
3
+ base.class_eval do
4
+ unless roxml_attrs.find { |r| r.attr_name == "value" && r.name == "." }
5
+ xml_accessor :value, :from => :content
6
+ end
7
+ end
8
+ base.extend ClassMethods
9
+ end
10
+
11
+ module ClassMethods
12
+ attr_reader :enums
13
+
14
+ def enum(*args, &blk)
15
+ @enums ||= []
16
+ args.each do |enum_name_or_hash|
17
+
18
+ case enum_name_or_hash
19
+ when Hash
20
+ enum_name_or_hash.each do |name, value|
21
+ setup_enum(name, value, &blk)
22
+ end
23
+ else
24
+ setup_enum(enum_name_or_hash, &blk)
25
+ end
26
+ end
27
+ end
28
+
29
+ def xml_enum(*args)
30
+ enum(*args) do |e, name, value|
31
+ e.value = value || name.to_s
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ def setup_enum(enum_name, *args)
38
+ mod = self.const_set(enum_name, self.new)
39
+ mod = yield(mod, enum_name, *args) if block_given?
40
+ @enums << mod
41
+ end
42
+ end
43
+
44
+ def initialize(enum=nil)
45
+ self.value = enum.value if enum
46
+ end
47
+
48
+ def ==(other)
49
+ self.value == other.value
50
+ end
51
+
52
+ def eql?(other)
53
+ self == other && self.class == other.class
54
+ end
55
+ end
@@ -0,0 +1,21 @@
1
+ module ShipMe
2
+ class Template
3
+ attr_reader :klass
4
+ attr_accessor :options_block
5
+
6
+ def initialize(klass)
7
+ @klass = klass
8
+ end
9
+
10
+ def make(attributes = {})
11
+ proxy = Module.new
12
+ attributes.each do |method, value|
13
+ (class << proxy; self; end).send(:define_method, method) do
14
+ value
15
+ end
16
+ end
17
+ opts = proxy.instance_eval(&options_block)
18
+ @klass.new(opts)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,95 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{ship_me}
8
+ s.version = "0.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Henry Hsu"]
12
+ s.date = %q{2010-09-17}
13
+ s.description = %q{Just ship me. No fuss FedEx integration for Ruby}
14
+ s.email = %q{henry@qlane.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".autotest",
21
+ ".document",
22
+ ".gitignore",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "lib/roxml/attribute_initializable.rb",
30
+ "lib/ship_me.rb",
31
+ "lib/ship_me/carriers/fed_ex.rb",
32
+ "lib/ship_me/carriers/fed_ex/element.rb",
33
+ "lib/ship_me/carriers/fed_ex/types.rb",
34
+ "lib/ship_me/posts_data.rb",
35
+ "lib/ship_me/restricted_enumeration.rb",
36
+ "lib/ship_me/template.rb",
37
+ "ship_me.gemspec",
38
+ "spec/carriers/fed_ex_spec.rb",
39
+ "spec/cases/delete_shipment.rb",
40
+ "spec/cases/pending_shipment.rb",
41
+ "spec/cases/process_shipment.rb",
42
+ "spec/cases/process_shipment_template.rb",
43
+ "spec/fixtures/fed_ex/delete_request.xml",
44
+ "spec/fixtures/fed_ex/delete_response.xml",
45
+ "spec/fixtures/fed_ex/deleted_response.xml",
46
+ "spec/fixtures/fed_ex/pending_request.xml",
47
+ "spec/fixtures/fed_ex/pending_response.xml",
48
+ "spec/fixtures/fed_ex/process_request.xml",
49
+ "spec/fixtures/fed_ex/process_response.xml",
50
+ "spec/restricted_enumeration_spec.rb",
51
+ "spec/roxml/attribute_initializable_spec.rb",
52
+ "spec/ship_me_spec.rb",
53
+ "spec/spec.opts",
54
+ "spec/spec_helper.rb"
55
+ ]
56
+ s.homepage = %q{http://github.com/hsume2/ship_me}
57
+ s.rdoc_options = ["--charset=UTF-8"]
58
+ s.require_paths = ["lib"]
59
+ s.rubygems_version = %q{1.3.7}
60
+ s.summary = %q{Just ship me. No fuss.}
61
+ s.test_files = [
62
+ "spec/carriers/fed_ex_spec.rb",
63
+ "spec/cases/delete_shipment.rb",
64
+ "spec/cases/pending_shipment.rb",
65
+ "spec/cases/process_shipment.rb",
66
+ "spec/cases/process_shipment_template.rb",
67
+ "spec/restricted_enumeration_spec.rb",
68
+ "spec/roxml/attribute_initializable_spec.rb",
69
+ "spec/ship_me_spec.rb",
70
+ "spec/spec_helper.rb"
71
+ ]
72
+
73
+ if s.respond_to? :specification_version then
74
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
75
+ s.specification_version = 3
76
+
77
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
78
+ s.add_runtime_dependency(%q<roxml>, ["= 3.1.5"])
79
+ s.add_runtime_dependency(%q<activesupport>, ["= 2.3.8"])
80
+ s.add_runtime_dependency(%q<active_merchant>, [">= 0"])
81
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
82
+ else
83
+ s.add_dependency(%q<roxml>, ["= 3.1.5"])
84
+ s.add_dependency(%q<activesupport>, ["= 2.3.8"])
85
+ s.add_dependency(%q<active_merchant>, [">= 0"])
86
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
87
+ end
88
+ else
89
+ s.add_dependency(%q<roxml>, ["= 3.1.5"])
90
+ s.add_dependency(%q<activesupport>, ["= 2.3.8"])
91
+ s.add_dependency(%q<active_merchant>, [">= 0"])
92
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
93
+ end
94
+ end
95
+
@@ -0,0 +1,240 @@
1
+ require 'spec_helper'
2
+
3
+ module ShipMe
4
+
5
+ describe FedEx do
6
+ %w(ProcessShipmentRequest WebAuthenticationDetail ClientDetail TransactionDetail VersionId RequestedShipment).each do |type|
7
+ it "should have #{type}" do
8
+ "ShipMe::FedEx::#{type}".constantize.should_not be_nil
9
+ end
10
+ end
11
+
12
+ it "should create process shipment request" do
13
+ request = FedEx::ProcessShipmentRequest.new
14
+ request.key = "1111"
15
+ request.password = "2222"
16
+ request.account_number = "3333"
17
+ request.meter_number = "4444"
18
+ request.requested_shipment = FedEx::RequestedShipment.new
19
+ request.requested_shipment.ship_timestamp = "2010-08-03T14:46:01-07:00"
20
+ request.requested_shipment.dropoff_type = FedEx::DropoffType::REGULAR_PICKUP
21
+ request.requested_shipment.service_type = FedEx::ServiceType::FEDEX_GROUND
22
+ request.requested_shipment.packaging_type = FedEx::PackagingType::YOUR_PACKAGING
23
+ request.requested_shipment.shipper = FedEx::Party.new(
24
+ :contact => FedEx::Contact.new(
25
+ :person_name => 'Henry Hsu',
26
+ :company_name => 'Photo USA Corporation',
27
+ :phone_number => '4087359900'
28
+ ),
29
+ :address => FedEx::Address.new(
30
+ :street_line => '1133 Sonora Ct.',
31
+ :city => 'Sunnyvale',
32
+ :state_or_province_code => 'CA',
33
+ :postal_code => '94086',
34
+ :country_code => 'US'
35
+ )
36
+ )
37
+ request.requested_shipment.recipient = FedEx::Party.new(
38
+ :contact => FedEx::Contact.new(
39
+ :person_name => 'Henry Hsu',
40
+ :company_name => 'Photo USA Corporation',
41
+ :phone_number => '4087359900'
42
+ ),
43
+ :address => FedEx::Address.new(
44
+ :street_line => '1135 Sonora Ct.',
45
+ :street_line_2 => 'Building #2',
46
+ :city => 'Sunnyvale',
47
+ :state_or_province_code => 'CA',
48
+ :postal_code => '94086',
49
+ :country_code => 'US'
50
+ )
51
+ )
52
+ request.requested_shipment.shipping_charges_payment = FedEx::Payment.new(
53
+ :payment_type => FedEx::PaymentType::SENDER,
54
+ :payor => FedEx::Payor.new(
55
+ :account_number => '3333',
56
+ :country_code => 'US'
57
+ )
58
+ )
59
+ request.requested_shipment.label_specification = FedEx::LabelSpecification.new(
60
+ :label_format_type => FedEx::LabelFormatType::COMMON2D,
61
+ :image_type => FedEx::ShippingDocumentImageType::PNG,
62
+ :label_stock_type => FedEx::LabelStockType::PAPER_4X6
63
+ )
64
+ request.requested_shipment.rate_request_types = [FedEx::RateRequestType::LIST]
65
+ request.requested_shipment.package_count = 1
66
+ request.requested_shipment.package_detail = FedEx::RequestedPackageDetailType::INDIVIDUAL_PACKAGES
67
+ request.requested_shipment.requested_package_line_items = [
68
+ FedEx::RequestedPackageLineItem.new(
69
+ :weight => FedEx::Weight.new(
70
+ :units => FedEx::WeightUnits::LB,
71
+ :value => '33'
72
+ ),
73
+ :dimensions => FedEx::Dimensions.new(
74
+ :length => 14,
75
+ :width => 14,
76
+ :height => 14,
77
+ :units => FedEx::LinearUnits::IN
78
+ )
79
+ )
80
+ ]
81
+
82
+ request.to_xml.to_s.should == File.read('spec/fixtures/fed_ex/process_request.xml')
83
+ end
84
+
85
+ it "should parse process shipment reply" do
86
+ response_xml = File.read('spec/fixtures/fed_ex/process_response.xml')
87
+ reply = FedEx::ProcessShipmentReply.from_xml(response_xml)
88
+ reply.completed_shipment_detail.should_not be_nil
89
+ reply.completed_shipment_detail.completed_package_details.should_not be_empty
90
+ end
91
+
92
+ it "should create pending shipment request" do
93
+ request = FedEx::CreatePendingShipmentRequest.new
94
+ request.key = "1111"
95
+ request.password = "2222"
96
+ request.account_number = "3333"
97
+ request.meter_number = "4444"
98
+ request.requested_shipment = FedEx::RequestedShipment.new
99
+ request.requested_shipment.ship_timestamp = "2010-08-03T14:46:01-07:00"
100
+ request.requested_shipment.dropoff_type = FedEx::DropoffType::REGULAR_PICKUP
101
+ request.requested_shipment.service_type = FedEx::ServiceType::FEDEX_GROUND
102
+ request.requested_shipment.packaging_type = FedEx::PackagingType::YOUR_PACKAGING
103
+ request.requested_shipment.shipper = FedEx::Party.new(
104
+ :contact => FedEx::Contact.new(
105
+ :person_name => 'Henry Hsu',
106
+ :company_name => 'Photo USA Corporation',
107
+ :phone_number => '4087359900'
108
+ ),
109
+ :address => FedEx::Address.new(
110
+ :street_line => '1133 Sonora Ct.',
111
+ :city => 'Sunnyvale',
112
+ :state_or_province_code => 'CA',
113
+ :postal_code => '94086',
114
+ :country_code => 'US'
115
+ )
116
+ )
117
+ request.requested_shipment.recipient = FedEx::Party.new(
118
+ :contact => FedEx::Contact.new(
119
+ :person_name => 'Henry Hsu',
120
+ :company_name => 'Photo USA Corporation',
121
+ :phone_number => '4087359900'
122
+ ),
123
+ :address => FedEx::Address.new(
124
+ :street_line => '1135 Sonora Ct.',
125
+ :city => 'Sunnyvale',
126
+ :state_or_province_code => 'CA',
127
+ :postal_code => '94086',
128
+ :country_code => 'US'
129
+ )
130
+ )
131
+ request.requested_shipment.shipping_charges_payment = FedEx::Payment.new(
132
+ :payment_type => FedEx::PaymentType::SENDER,
133
+ :payor => FedEx::Payor.new(
134
+ :account_number => '3333',
135
+ :country_code => 'US'
136
+ )
137
+ )
138
+ request.requested_shipment.special_services_requested = FedEx::ShipmentSpecialServicesRequested.new(
139
+ :special_service_types => [FedEx::ShipmentSpecialServiceType::PENDING_SHIPMENT],
140
+ :pending_shipment_detail => FedEx::PendingShipmentDetail.new(
141
+ :email_label_detail => FedEx::EMailLabelDetail.new(
142
+ :notification_e_mail_address => 'henry@photomugs.com'
143
+ ),
144
+ :expiration_date => "2010-08-07",
145
+ :type => FedEx::PendingShipmentType::EMAIL
146
+ )
147
+ )
148
+ request.requested_shipment.label_specification = FedEx::LabelSpecification.new(
149
+ :label_format_type => FedEx::LabelFormatType::COMMON2D,
150
+ :image_type => FedEx::ShippingDocumentImageType::PNG,
151
+ :label_stock_type => FedEx::LabelStockType::PAPER_4X6
152
+ )
153
+ request.requested_shipment.rate_request_types = [FedEx::RateRequestType::LIST]
154
+ request.requested_shipment.package_count = 1
155
+ request.requested_shipment.package_detail = FedEx::RequestedPackageDetailType::INDIVIDUAL_PACKAGES
156
+ request.requested_shipment.requested_package_line_items = [
157
+ FedEx::RequestedPackageLineItem.new(
158
+ :weight => FedEx::Weight.new(
159
+ :units => FedEx::WeightUnits::LB,
160
+ :value => '33'
161
+ ),
162
+ :dimensions => FedEx::Dimensions.new(
163
+ :length => 14,
164
+ :width => 14,
165
+ :height => 14,
166
+ :units => FedEx::LinearUnits::IN
167
+ ),
168
+ :item_description => "11 oz. Ceramic Mug"
169
+ )
170
+ ]
171
+
172
+ request.to_xml.to_s.should == File.read('spec/fixtures/fed_ex/pending_request.xml')
173
+ end
174
+
175
+ it "should parse pending shipment reply" do
176
+ response_xml = File.read('spec/fixtures/fed_ex/pending_response.xml')
177
+ reply = FedEx::CreatePendingShipmentReply.from_xml(response_xml)
178
+ reply.completed_shipment_detail.should_not be_nil
179
+ reply.completed_shipment_detail.completed_package_details.should_not be_empty
180
+ end
181
+
182
+ it "should create delete shipment request" do
183
+ request = FedEx::DeleteShipmentRequest.new(
184
+ :key => "1111",
185
+ :password => '2222',
186
+ :account_number => '3333',
187
+ :meter_number => '4444',
188
+ :tracking_id => {
189
+ :tracking_id_type => FedEx::TrackingIdType::GROUND,
190
+ :tracking_number => "800025615003088"
191
+ },
192
+ :deletion_control => FedEx::DeletionControlType::DELETE_ALL_PACKAGES
193
+ )
194
+ # request.password = "2222"
195
+ # request.account_number = "3333"
196
+ # request.meter_number = "4444"
197
+ # request.tracking_id = FedEx::TrackingId.new
198
+ # request.tracking_id.tracking_id_type = FedEx::TrackingIdType::GROUND
199
+ # request.tracking_id.tracking_number = "800025615003088"
200
+ # request.deletion_control = FedEx::DeletionControlType::DELETE_ALL_PACKAGES
201
+
202
+ request.to_xml.to_s.should == File.read('spec/fixtures/fed_ex/delete_request.xml')
203
+ end
204
+
205
+ context "with request" do
206
+ before do
207
+ @request = FedEx::DeleteShipmentRequest.new(
208
+ :key => "1111",
209
+ :password => '2222',
210
+ :account_number => '3333',
211
+ :meter_number => '4444',
212
+ :tracking_id => {
213
+ :tracking_id_type => FedEx::TrackingIdType::GROUND,
214
+ :tracking_number => "800025615003088"
215
+ },
216
+ :deletion_control => FedEx::DeletionControlType::DELETE_ALL_PACKAGES
217
+ )
218
+ end
219
+
220
+ it "should commit request" do
221
+ response = File.read('spec/fixtures/fed_ex/delete_request.xml')
222
+ FakeWeb.register_uri(:post, 'https://gatewaybeta.fedex.com/xml', :body => response)
223
+ @request.commit(true).should == response
224
+ end
225
+
226
+ it "should commit request to test url" do
227
+ @request.expects(:ssl_post).with('https://gatewaybeta.fedex.com:443/xml', @request.to_xml.to_s.gsub("\n",''))
228
+
229
+ @request.commit(true)
230
+ end
231
+
232
+ it "should commit request to live url" do
233
+ @request.expects(:ssl_post).with('https://gateway.fedex.com:443/xml', @request.to_xml.to_s.gsub("\n",''))
234
+
235
+ @request.commit
236
+ end
237
+ end
238
+ end
239
+
240
+ end