usps 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,55 +1,16 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
- begin
5
- require 'jeweler'
6
-
7
- Jeweler::Tasks.new do |gem|
8
- gem.name = "usps"
9
- gem.summary = "USPS Webtools API for Ruby"
10
- gem.description = "USPS Webtools API for Ruby."
11
- gem.email = "gaffneyc@gmail.com"
12
- gem.homepage = "http://github.com/gaffneyc/usps"
13
- gem.authors = ["Chris Gaffney"]
14
-
15
- gem.add_dependency 'builder', '>= 2.1.2'
16
- gem.add_dependency 'nokogiri', '>= 1.4.1'
17
- gem.add_dependency 'typhoeus', '>= 0.1.18'
18
-
19
- gem.add_development_dependency "mocha", ">= 0.9.8"
20
- gem.add_development_dependency "rspec", ">= 1.3.0"
21
- end
22
- Jeweler::GemcutterTasks.new
23
- rescue LoadError
24
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
25
- end
1
+ require 'bundler/setup'
2
+ Bundler::GemHelper.install_tasks
26
3
 
4
+ require 'rake'
27
5
  require 'spec/rake/spectask'
6
+
28
7
  Spec::Rake::SpecTask.new(:spec) do |spec|
29
8
  spec.libs << 'lib' << 'spec'
30
9
  spec.spec_files = FileList['spec/**/*_spec.rb']
31
10
  end
32
11
 
33
- Spec::Rake::SpecTask.new(:rcov) do |spec|
34
- spec.libs << 'lib' << 'spec'
35
- spec.pattern = 'spec/**/*_spec.rb'
36
- spec.rcov = true
37
- end
38
-
39
- task :spec => :check_dependencies
40
-
41
12
  task :default => :spec
42
13
 
43
- require 'rake/rdoctask'
44
- Rake::RDocTask.new do |rdoc|
45
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
-
47
- rdoc.rdoc_dir = 'rdoc'
48
- rdoc.title = "usps #{version}"
49
- rdoc.rdoc_files.include('README*')
50
- rdoc.rdoc_files.include('lib/**/*.rb')
51
- end
52
-
53
14
  desc "Run the certification tests against USPS's API. Requires ENV['USPS_USER'] to be set or passed in."
54
15
  task :certify do
55
16
  ruby "-rubygems -Ilib -rusps lib/usps/test.rb"
@@ -8,6 +8,7 @@ module USPS
8
8
  autoload :Client, 'usps/client'
9
9
  autoload :Address, 'usps/address'
10
10
  autoload :Request, 'usps/request'
11
+ autoload :VERSION, 'usps/version'
11
12
  autoload :Response, 'usps/response'
12
13
 
13
14
  class << self
@@ -5,11 +5,9 @@ module USPS
5
5
  def request(request, &block)
6
6
  server = server(request)
7
7
 
8
- # The USPS documentation shows all requests as being GET requests, but
9
- # the servers also appear to support POST. We're using POST here so we
10
- # don't need to escape the request and to keep from running into any
11
- # concerns with data length.
12
- response = Typhoeus::Request.post(server, {
8
+ # Make the API request to the USPS servers. Used to support POST, now it's
9
+ # just GET request *grumble*.
10
+ response = Typhoeus::Request.get(server, {
13
11
  :timeout => USPS.config.timeout,
14
12
  :params => {
15
13
  "API" => request.api,
@@ -0,0 +1,44 @@
1
+ module USPS::Request
2
+ class SignatureConfirmation < Base
3
+ config(
4
+ :api => 'DeliveryConfirmationV3',
5
+ :tag => 'DeliveryConfirmationV3.0Request',
6
+ :secure => true,
7
+ :response => USPS::Response::DeliveryConfirmation
8
+ )
9
+
10
+ attr_reader :to, :from, :weight, :service
11
+
12
+ def initialize(to, from, weight, service = 'Priority')
13
+ @to = to
14
+ @from = from
15
+ @weight = weight
16
+ @service = service
17
+ end
18
+
19
+ def build
20
+ super do |builder|
21
+ builder.tag!('Option', '1')
22
+ builder.tag!('ImageParameters')
23
+
24
+ [
25
+ [self.from, 'From'],
26
+ [self.to, 'To']
27
+ ].each do |address, prefix|
28
+ builder.tag!("#{prefix}Name", address.name)
29
+ builder.tag!("#{prefix}Firm", address.company)
30
+ builder.tag!("#{prefix}Address1", address.extra_address)
31
+ builder.tag!("#{prefix}Address2", address.address)
32
+ builder.tag!("#{prefix}City", address.city)
33
+ builder.tag!("#{prefix}State", address.state)
34
+ builder.tag!("#{prefix}Zip5", address.zip5)
35
+ builder.tag!("#{prefix}Zip4", address.zip4)
36
+ end
37
+
38
+ builder.tag!('WeightInOunces', self.weight)
39
+ builder.tag!('ServiceType', self.service)
40
+ builder.tag!('ImageType', 'TIF')
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,3 @@
1
+ module USPS
2
+ VERSION = '0.1.1'
3
+ end
@@ -48,7 +48,7 @@ describe USPS::Address do
48
48
  :zip => 20006
49
49
  )
50
50
 
51
- USPS.client.expects(:request).returns(
51
+ USPS.client.should_receive(:request).and_return(
52
52
  USPS::Response::AddressStandardization.new(
53
53
  addy, load_xml('address_standardization_1.xml')
54
54
  )
@@ -58,7 +58,7 @@ describe USPS::Address do
58
58
 
59
59
  error = USPS::Error.new('error', '1234', 'source')
60
60
  # Failure
61
- USPS.client.expects(:request).raises(error)
61
+ USPS.client.should_receive(:request).and_raise(error)
62
62
  addy.valid?.should be_false
63
63
  addy.error.should be(error)
64
64
  end
@@ -1,23 +1,11 @@
1
- $:.unshift(File.dirname(__FILE__))
2
- $:.unshift(File.join(File.dirname(__FILE__), %w(.. lib)))
3
-
4
- require 'rubygems'
1
+ require 'bundler/setup'
2
+ Bundler.require(:default, :development)
5
3
 
6
4
  require 'usps'
7
- require 'spec'
8
- require 'spec/autorun'
9
-
10
- require 'builder'
11
- require 'nokogiri'
12
-
13
- Spec::Runner.configure do |config|
14
- config.mock_with :mocha
15
- end
16
-
17
5
  USPS.username = 'TESTING'
18
6
 
19
7
  def load_data(path)
20
- (@_file_cache ||= {})[path] ||= File.read(File.expand_path(File.join(File.dirname(__FILE__), 'data', path)))
8
+ (@_file_cache ||= {})[path] ||= File.read(File.expand_path("../data/#{path}", __FILE__))
21
9
  end
22
10
 
23
11
  def load_xml(path)
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: usps
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ hash: 25
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
5
11
  platform: ruby
6
12
  authors:
7
13
  - Chris Gaffney
@@ -9,100 +15,94 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2010-02-05 00:00:00 -05:00
18
+ date: 2011-02-18 00:00:00 -05:00
13
19
  default_executable:
14
20
  dependencies:
15
21
  - !ruby/object:Gem::Dependency
16
- name: builder
22
+ prerelease: false
17
23
  type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
24
+ name: builder
25
+ version_requirements: &id001 !ruby/object:Gem::Requirement
26
+ none: false
20
27
  requirements:
21
28
  - - ">="
22
29
  - !ruby/object:Gem::Version
30
+ hash: 15
31
+ segments:
32
+ - 2
33
+ - 1
34
+ - 2
23
35
  version: 2.1.2
24
- version:
36
+ requirement: *id001
25
37
  - !ruby/object:Gem::Dependency
26
- name: nokogiri
38
+ prerelease: false
27
39
  type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
40
+ name: nokogiri
41
+ version_requirements: &id002 !ruby/object:Gem::Requirement
42
+ none: false
30
43
  requirements:
31
44
  - - ">="
32
45
  - !ruby/object:Gem::Version
46
+ hash: 5
47
+ segments:
48
+ - 1
49
+ - 4
50
+ - 1
33
51
  version: 1.4.1
34
- version:
52
+ requirement: *id002
35
53
  - !ruby/object:Gem::Dependency
36
- name: typhoeus
54
+ prerelease: false
37
55
  type: :runtime
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
56
+ name: typhoeus
57
+ version_requirements: &id003 !ruby/object:Gem::Requirement
58
+ none: false
40
59
  requirements:
41
60
  - - ">="
42
61
  - !ruby/object:Gem::Version
62
+ hash: 63
63
+ segments:
64
+ - 0
65
+ - 1
66
+ - 18
43
67
  version: 0.1.18
44
- version:
45
- - !ruby/object:Gem::Dependency
46
- name: mocha
47
- type: :development
48
- version_requirement:
49
- version_requirements: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - ">="
52
- - !ruby/object:Gem::Version
53
- version: 0.9.8
54
- version:
55
- - !ruby/object:Gem::Dependency
56
- name: rspec
57
- type: :development
58
- version_requirement:
59
- version_requirements: !ruby/object:Gem::Requirement
60
- requirements:
61
- - - ">="
62
- - !ruby/object:Gem::Version
63
- version: 1.3.0
64
- version:
65
- description: USPS Webtools API for Ruby.
66
- email: gaffneyc@gmail.com
68
+ requirement: *id003
69
+ description:
70
+ email:
71
+ - gaffneyc@gmail.com
67
72
  executables: []
68
73
 
69
74
  extensions: []
70
75
 
71
- extra_rdoc_files:
72
- - LICENSE
73
- - README.rdoc
76
+ extra_rdoc_files: []
77
+
74
78
  files:
75
- - .document
76
- - .gitignore
77
- - LICENSE
78
- - README.rdoc
79
- - Rakefile
80
- - VERSION
81
- - lib/usps.rb
82
79
  - lib/usps/address.rb
83
80
  - lib/usps/client.rb
84
81
  - lib/usps/configuration.rb
85
82
  - lib/usps/errors.rb
86
- - lib/usps/request.rb
87
83
  - lib/usps/request/address_standardization.rb
88
84
  - lib/usps/request/base.rb
89
85
  - lib/usps/request/city_and_state_lookup.rb
90
86
  - lib/usps/request/delivery_confirmation.rb
91
87
  - lib/usps/request/delivery_confirmation_certify.rb
88
+ - lib/usps/request/signature_confirmation.rb
92
89
  - lib/usps/request/tracking_lookup.rb
93
90
  - lib/usps/request/zip_code_lookup.rb
94
- - lib/usps/response.rb
91
+ - lib/usps/request.rb
95
92
  - lib/usps/response/address_standardization.rb
96
93
  - lib/usps/response/base.rb
97
94
  - lib/usps/response/city_and_state_lookup.rb
98
95
  - lib/usps/response/delivery_confirmation.rb
99
96
  - lib/usps/response/tracking_lookup.rb
100
- - lib/usps/test.rb
97
+ - lib/usps/response.rb
101
98
  - lib/usps/test/address_verification.rb
102
99
  - lib/usps/test/city_and_state_lookup.rb
103
100
  - lib/usps/test/delivery_confirmation.rb
104
101
  - lib/usps/test/tracking_lookup.rb
105
102
  - lib/usps/test/zip_code_lookup.rb
103
+ - lib/usps/test.rb
104
+ - lib/usps/version.rb
105
+ - lib/usps.rb
106
106
  - spec/address_spec.rb
107
107
  - spec/configuration_spec.rb
108
108
  - spec/data/address_standardization_1.xml
@@ -118,61 +118,54 @@ files:
118
118
  - spec/request/city_and_state_lookup_spec.rb
119
119
  - spec/request/delivery_confirmation_certify_spec.rb
120
120
  - spec/request/delivery_confirmation_spec.rb
121
+ - spec/request/signature_confirmation_spec.rb
121
122
  - spec/request/tracking_spec.rb
122
123
  - spec/request/zip_code_lookup_spec.rb
123
124
  - spec/response/address_standardization_spec.rb
124
125
  - spec/response/base_spec.rb
125
126
  - spec/response/city_and_state_lookup_spec.rb
126
127
  - spec/response/delivery_confirmation_spec.rb
128
+ - spec/response/signature_confirmation_spec.rb
127
129
  - spec/response/tracking_lookup_spec.rb
128
130
  - spec/spec.opts
129
131
  - spec/spec_helper.rb
130
132
  - spec/usps_spec.rb
131
- - usps.gemspec
133
+ - Rakefile
134
+ - LICENSE
135
+ - README.rdoc
132
136
  has_rdoc: true
133
137
  homepage: http://github.com/gaffneyc/usps
134
138
  licenses: []
135
139
 
136
140
  post_install_message:
137
- rdoc_options:
138
- - --charset=UTF-8
141
+ rdoc_options: []
142
+
139
143
  require_paths:
140
144
  - lib
141
145
  required_ruby_version: !ruby/object:Gem::Requirement
146
+ none: false
142
147
  requirements:
143
148
  - - ">="
144
149
  - !ruby/object:Gem::Version
150
+ hash: 3
151
+ segments:
152
+ - 0
145
153
  version: "0"
146
- version:
147
154
  required_rubygems_version: !ruby/object:Gem::Requirement
155
+ none: false
148
156
  requirements:
149
157
  - - ">="
150
158
  - !ruby/object:Gem::Version
159
+ hash: 3
160
+ segments:
161
+ - 0
151
162
  version: "0"
152
- version:
153
163
  requirements: []
154
164
 
155
165
  rubyforge_project:
156
- rubygems_version: 1.3.5
166
+ rubygems_version: 1.5.2
157
167
  signing_key:
158
168
  specification_version: 3
159
169
  summary: USPS Webtools API for Ruby
160
- test_files:
161
- - spec/address_spec.rb
162
- - spec/configuration_spec.rb
163
- - spec/request/address_standardization_spec.rb
164
- - spec/request/base_spec.rb
165
- - spec/request/city_and_state_lookup_spec.rb
166
- - spec/request/delivery_confirmation_certify_spec.rb
167
- - spec/request/delivery_confirmation_spec.rb
168
- - spec/request/signature_confirmation_spec.rb
169
- - spec/request/tracking_spec.rb
170
- - spec/request/zip_code_lookup_spec.rb
171
- - spec/response/address_standardization_spec.rb
172
- - spec/response/base_spec.rb
173
- - spec/response/city_and_state_lookup_spec.rb
174
- - spec/response/delivery_confirmation_spec.rb
175
- - spec/response/signature_confirmation_spec.rb
176
- - spec/response/tracking_lookup_spec.rb
177
- - spec/spec_helper.rb
178
- - spec/usps_spec.rb
170
+ test_files: []
171
+
data/.document DELETED
@@ -1,5 +0,0 @@
1
- README.rdoc
2
- lib/**/*.rb
3
- bin/*
4
- features/**/*.feature
5
- LICENSE
data/.gitignore DELETED
@@ -1,21 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.1.0
@@ -1,129 +0,0 @@
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{usps}
8
- s.version = "0.1.0"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Chris Gaffney"]
12
- s.date = %q{2010-02-05}
13
- s.description = %q{USPS Webtools API for Ruby.}
14
- s.email = %q{gaffneyc@gmail.com}
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- ".document",
21
- ".gitignore",
22
- "LICENSE",
23
- "README.rdoc",
24
- "Rakefile",
25
- "VERSION",
26
- "lib/usps.rb",
27
- "lib/usps/address.rb",
28
- "lib/usps/client.rb",
29
- "lib/usps/configuration.rb",
30
- "lib/usps/errors.rb",
31
- "lib/usps/request.rb",
32
- "lib/usps/request/address_standardization.rb",
33
- "lib/usps/request/base.rb",
34
- "lib/usps/request/city_and_state_lookup.rb",
35
- "lib/usps/request/delivery_confirmation.rb",
36
- "lib/usps/request/delivery_confirmation_certify.rb",
37
- "lib/usps/request/tracking_lookup.rb",
38
- "lib/usps/request/zip_code_lookup.rb",
39
- "lib/usps/response.rb",
40
- "lib/usps/response/address_standardization.rb",
41
- "lib/usps/response/base.rb",
42
- "lib/usps/response/city_and_state_lookup.rb",
43
- "lib/usps/response/delivery_confirmation.rb",
44
- "lib/usps/response/tracking_lookup.rb",
45
- "lib/usps/test.rb",
46
- "lib/usps/test/address_verification.rb",
47
- "lib/usps/test/city_and_state_lookup.rb",
48
- "lib/usps/test/delivery_confirmation.rb",
49
- "lib/usps/test/tracking_lookup.rb",
50
- "lib/usps/test/zip_code_lookup.rb",
51
- "spec/address_spec.rb",
52
- "spec/configuration_spec.rb",
53
- "spec/data/address_standardization_1.xml",
54
- "spec/data/address_standardization_2.xml",
55
- "spec/data/city_and_state_lookup_1.xml",
56
- "spec/data/city_and_state_lookup_2.xml",
57
- "spec/data/delivery_confirmation_1.xml",
58
- "spec/data/delivery_confirmation_2.xml",
59
- "spec/data/tracking_lookup_1.xml",
60
- "spec/data/tracking_lookup_2.xml",
61
- "spec/request/address_standardization_spec.rb",
62
- "spec/request/base_spec.rb",
63
- "spec/request/city_and_state_lookup_spec.rb",
64
- "spec/request/delivery_confirmation_certify_spec.rb",
65
- "spec/request/delivery_confirmation_spec.rb",
66
- "spec/request/tracking_spec.rb",
67
- "spec/request/zip_code_lookup_spec.rb",
68
- "spec/response/address_standardization_spec.rb",
69
- "spec/response/base_spec.rb",
70
- "spec/response/city_and_state_lookup_spec.rb",
71
- "spec/response/delivery_confirmation_spec.rb",
72
- "spec/response/tracking_lookup_spec.rb",
73
- "spec/spec.opts",
74
- "spec/spec_helper.rb",
75
- "spec/usps_spec.rb",
76
- "usps.gemspec"
77
- ]
78
- s.homepage = %q{http://github.com/gaffneyc/usps}
79
- s.rdoc_options = ["--charset=UTF-8"]
80
- s.require_paths = ["lib"]
81
- s.rubygems_version = %q{1.3.5}
82
- s.summary = %q{USPS Webtools API for Ruby}
83
- s.test_files = [
84
- "spec/address_spec.rb",
85
- "spec/configuration_spec.rb",
86
- "spec/request/address_standardization_spec.rb",
87
- "spec/request/base_spec.rb",
88
- "spec/request/city_and_state_lookup_spec.rb",
89
- "spec/request/delivery_confirmation_certify_spec.rb",
90
- "spec/request/delivery_confirmation_spec.rb",
91
- "spec/request/signature_confirmation_spec.rb",
92
- "spec/request/tracking_spec.rb",
93
- "spec/request/zip_code_lookup_spec.rb",
94
- "spec/response/address_standardization_spec.rb",
95
- "spec/response/base_spec.rb",
96
- "spec/response/city_and_state_lookup_spec.rb",
97
- "spec/response/delivery_confirmation_spec.rb",
98
- "spec/response/signature_confirmation_spec.rb",
99
- "spec/response/tracking_lookup_spec.rb",
100
- "spec/spec_helper.rb",
101
- "spec/usps_spec.rb"
102
- ]
103
-
104
- if s.respond_to? :specification_version then
105
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
106
- s.specification_version = 3
107
-
108
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
109
- s.add_runtime_dependency(%q<builder>, [">= 2.1.2"])
110
- s.add_runtime_dependency(%q<nokogiri>, [">= 1.4.1"])
111
- s.add_runtime_dependency(%q<typhoeus>, [">= 0.1.18"])
112
- s.add_development_dependency(%q<mocha>, [">= 0.9.8"])
113
- s.add_development_dependency(%q<rspec>, [">= 1.3.0"])
114
- else
115
- s.add_dependency(%q<builder>, [">= 2.1.2"])
116
- s.add_dependency(%q<nokogiri>, [">= 1.4.1"])
117
- s.add_dependency(%q<typhoeus>, [">= 0.1.18"])
118
- s.add_dependency(%q<mocha>, [">= 0.9.8"])
119
- s.add_dependency(%q<rspec>, [">= 1.3.0"])
120
- end
121
- else
122
- s.add_dependency(%q<builder>, [">= 2.1.2"])
123
- s.add_dependency(%q<nokogiri>, [">= 1.4.1"])
124
- s.add_dependency(%q<typhoeus>, [">= 0.1.18"])
125
- s.add_dependency(%q<mocha>, [">= 0.9.8"])
126
- s.add_dependency(%q<rspec>, [">= 1.3.0"])
127
- end
128
- end
129
-