postalmethods 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.txt CHANGED
@@ -16,7 +16,7 @@ API wrapper library for the postal methods api.
16
16
 
17
17
  require 'postalmethods'
18
18
 
19
- @doc = open(File.dirname(__FILE__) + '/../doc/sample.pdf')
19
+ @doc = open(File.dirname(__FILE__) + '/../spec/doc/sample.pdf')
20
20
  @client = PostalMethods::Client.new(:user => "user", :password => "password")
21
21
  rv = @client.send_letter(@doc, "description of doc")
22
22
  puts rv
data/lib/postalmethods.rb CHANGED
@@ -31,7 +31,7 @@ module PostalMethods
31
31
  end
32
32
 
33
33
  ## declare here so we can override in tests, etc.
34
- self.api_uri = "http://api.postalmethods.com/PostalWS.asmx?WSDL"
34
+ self.api_uri = "https://api.postalmethods.com/PostalWS.asmx?WSDL"
35
35
 
36
36
  self.username = opts[:username]
37
37
  self.password = opts[:password]
@@ -12,13 +12,13 @@ module PostalMethods
12
12
  status_code = rv.sendLetterResult.to_i
13
13
 
14
14
  if status_code > 0
15
- return rv
15
+ return status_code
16
16
  elsif API_STATUS_CODES.has_key?(status_code)
17
17
  instance_eval("raise APIStatusCode#{status_code.to_s.gsub(/( |\-)/,'')}Exception")
18
18
  end
19
19
  end
20
20
 
21
- def send_letter_and_address(doc, description, address)
21
+ def send_letter_with_address(doc, description, address)
22
22
  raise PostalMethods::NoPreparationException unless self.prepared
23
23
  raise PostalMethods::AddressNotHashException unless (address.class == Hash)
24
24
 
@@ -35,7 +35,7 @@ module PostalMethods
35
35
  status_code = rv.sendLetterAndAddressResult.to_i
36
36
 
37
37
  if status_code > 0
38
- return rv
38
+ return status_code
39
39
  elsif API_STATUS_CODES.has_key?(status_code)
40
40
  instance_eval("raise APIStatusCode#{status_code.to_s.gsub(/( |\-)/,'')}Exception")
41
41
  end
@@ -2,7 +2,7 @@ module Postalmethods
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 1
4
4
  MINOR = 0
5
- TINY = 0
5
+ TINY = 1
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -7,17 +7,17 @@ describe "Document Processing" do
7
7
  end
8
8
 
9
9
  it "should open a valid pre-opened document" do
10
- @client.document = open(File.dirname(__FILE__) + '/../doc/sample.pdf')
10
+ @client.document = open(File.dirname(__FILE__) + '/../spec/doc/sample.pdf')
11
11
  @client.document.class.should == Hash
12
12
  end
13
13
 
14
14
  it "should open a valid document path" do
15
- @client.document = File.dirname(__FILE__) + '/../doc/sample.pdf'
15
+ @client.document = File.dirname(__FILE__) + '/../spec/doc/sample.pdf'
16
16
  @client.document.class.should == Hash
17
17
  end
18
18
 
19
19
  it "should create a hash with the right elements" do
20
- @client.document = File.dirname(__FILE__) + '/../doc/sample.pdf'
20
+ @client.document = File.dirname(__FILE__) + '/../spec/doc/sample.pdf'
21
21
  @client.document[:extension].should == "pdf"
22
22
  @client.document[:bytes].length.should == 213312
23
23
  @client.document[:name].should == "sample.pdf"
@@ -25,12 +25,12 @@ describe "Document Processing" do
25
25
  end
26
26
 
27
27
  it "should return true on a valid document path" do
28
- @client.document = File.dirname(__FILE__) + '/../doc/sample.pdf'
28
+ @client.document = File.dirname(__FILE__) + '/../spec/doc/sample.pdf'
29
29
  @client.document?.should == true
30
30
  end
31
31
 
32
32
  it "should throw an exception on a false path" do
33
- @doc = File.dirname(__FILE__) + '/../doc/does_not_exist.pdf'
33
+ @doc = File.dirname(__FILE__) + '/../spec/doc/does_not_exist.pdf'
34
34
  lambda {@client.document = @doc}.should raise_error(Errno::ENOENT)
35
35
  end
36
36
 
@@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/spec_helper.rb'
3
3
  describe "Get Letter Status" do
4
4
 
5
5
  before :each do
6
- @doc = open(File.dirname(__FILE__) + '/../doc/sample.pdf')
6
+ @doc = open(File.dirname(__FILE__) + '/../spec/doc/sample.pdf')
7
7
  @client = PostalMethods::Client.new(PM_OPTS)
8
8
  @client.prepare!
9
9
  sleep(10)
@@ -24,11 +24,11 @@ describe "Get Letter Status" do
24
24
  it "should send multiple letters and get their status" do
25
25
  letters = []
26
26
  1.upto(3) do
27
- @doc = open(File.dirname(__FILE__) + '/../doc/sample.pdf')
27
+ @doc = open(File.dirname(__FILE__) + '/../spec/doc/sample.pdf')
28
28
  @client = PostalMethods::Client.new(PM_OPTS)
29
29
  @client.prepare!
30
- rv = @client.send_letter(@doc, "the long goodbye").sendLetterResult
31
- rv.to_i.should > 0
30
+ rv = @client.send_letter(@doc, "the long goodbye")
31
+ rv.should > 0
32
32
  letters << rv
33
33
  #sleep(10) # api needs some time
34
34
  end
@@ -37,7 +37,7 @@ describe "Get Letter Status" do
37
37
  ret.should be_an_instance_of(Array)
38
38
 
39
39
  # the return is an array [results, status]
40
- recv_letters = ret.collect { |r| r.iD }
40
+ recv_letters = ret.collect { |r| r.iD.to_i }
41
41
 
42
42
  recv_letters.should == letters
43
43
  end
@@ -49,11 +49,11 @@ describe "Get Letter Status" do
49
49
  it "should request a range of letters and get their status" do
50
50
  letters = []
51
51
  1.upto(3) do
52
- @doc = open(File.dirname(__FILE__) + '/../doc/sample.pdf')
52
+ @doc = open(File.dirname(__FILE__) + '/../spec/doc/sample.pdf')
53
53
  @client = PostalMethods::Client.new(PM_OPTS)
54
54
  @client.prepare!
55
- rv = @client.send_letter(@doc, "the long goodbye").sendLetterResult
56
- rv.to_i.should > 0
55
+ rv = @client.send_letter(@doc, "the long goodbye")
56
+ rv.should > 0
57
57
  letters << rv
58
58
  #sleep(10) # api needs some time
59
59
  end
@@ -62,7 +62,7 @@ describe "Get Letter Status" do
62
62
  ret.should be_an_instance_of(Array)
63
63
 
64
64
  # the return is an array [results, status]
65
- recv_letters = ret.collect { |r| r.iD }
65
+ recv_letters = ret.collect { |r| r.iD.to_i }
66
66
 
67
67
  recv_letters.should == letters
68
68
  end
@@ -3,14 +3,13 @@ require File.dirname(__FILE__) + '/spec_helper.rb'
3
3
  describe "Send Letter" do
4
4
 
5
5
  before :each do
6
- @doc = open(File.dirname(__FILE__) + '/../doc/sample.pdf')
6
+ @doc = open(File.dirname(__FILE__) + '/../spec/doc/sample.pdf')
7
7
  @client = PostalMethods::Client.new(PM_OPTS)
8
8
  end
9
9
 
10
10
  it "should instantiate and send a letter" do
11
11
  @client.prepare!
12
- rv = @client.send_letter(@doc, "the long goodbye")
13
- rv.sendLetterResult.to_i.should > 0
12
+ rv = @client.send_letter(@doc, "the long goodbye").should > 0
14
13
  end
15
14
 
16
15
  it "should refuse to send letter before prepare" do
@@ -38,7 +37,7 @@ end
38
37
  describe "Send Letter With Address" do
39
38
 
40
39
  before :each do
41
- @doc = open(File.dirname(__FILE__) + '/../doc/sample.pdf')
40
+ @doc = open(File.dirname(__FILE__) + '/../spec/doc/sample.pdf')
42
41
  @addr = {:AttentionLine1 => "The Fonz", :Address1 => "Happy Days", :City => "Baja", :State => "CA",
43
42
  :PostalCode => "90210", :Country => "USA"}
44
43
  @client = PostalMethods::Client.new(PM_OPTS)
@@ -46,29 +45,28 @@ describe "Send Letter With Address" do
46
45
 
47
46
  it "should instantiate and send a letter with address" do
48
47
  @client.prepare!
49
- rv = @client.send_letter_and_address(@doc, "Shark Jumping Notes", @addr)
50
- rv.sendLetterAndAddressResult.to_i.should > 0
48
+ rv = @client.send_letter_with_address(@doc, "Shark Jumping Notes", @addr).should > 0
51
49
  end
52
50
 
53
51
  it "should raise the proper exception when trying to send letter without valid attention line" do
54
52
  @client.prepare!
55
53
  addr = @addr.except(:AttentionLine1)
56
- lambda {@client.send_letter_and_address(@doc, "the long goodbye", addr)}.should raise_error(PostalMethods::APIStatusCode4008Exception)
54
+ lambda {@client.send_letter_with_address(@doc, "the long goodbye", addr)}.should raise_error(PostalMethods::APIStatusCode4008Exception)
57
55
  end
58
56
 
59
57
  it "should refuse to send letter before prepare" do
60
- lambda {@client.send_letter_and_address(@doc, "the long goodbye", @addr)}.should raise_error(PostalMethods::NoPreparationException)
58
+ lambda {@client.send_letter_with_address(@doc, "the long goodbye", @addr)}.should raise_error(PostalMethods::NoPreparationException)
61
59
  end
62
60
 
63
61
  it "should raise the proper exception when trying to send textfile" do
64
62
  @doc = open(File.dirname(__FILE__) + '/../README.txt')
65
63
  @client.prepare!
66
- lambda {@client.send_letter_and_address(@doc, "the long goodbye", @addr)}.should raise_error(PostalMethods::APIStatusCode3004Exception)
64
+ lambda {@client.send_letter_with_address(@doc, "the long goodbye", @addr)}.should raise_error(PostalMethods::APIStatusCode3004Exception)
67
65
  end
68
66
 
69
67
  it "should raise the proper exception when trying to send an empty string" do
70
68
  @client.prepare!
71
- lambda {@client.send_letter_and_address("", "the long goodbye", @addr)}.should raise_error(Errno::ENOENT)
69
+ lambda {@client.send_letter_with_address("", "the long goodbye", @addr)}.should raise_error(Errno::ENOENT)
72
70
  end
73
71
 
74
72
 
data/spec/utility_spec.rb CHANGED
@@ -4,7 +4,7 @@ require 'base64'
4
4
  describe "Utility Methods" do
5
5
 
6
6
  before :each do
7
- @doc = open(File.dirname(__FILE__) + '/../doc/sample.pdf')
7
+ @doc = open(File.dirname(__FILE__) + '/../spec/doc/sample.pdf')
8
8
  @client = PostalMethods::Client.new(PM_OPTS)
9
9
  @client.prepare!
10
10
  end
@@ -20,16 +20,13 @@ describe "Utility Methods" do
20
20
  end
21
21
 
22
22
  it "should check for error for when there is no file yet" do
23
- res = @client.send_letter(@doc, "the long goodbye")
24
- id = res.sendLetterResult.to_i
25
-
23
+ id = @client.send_letter(@doc, "the long goodbye")
26
24
  id.should > 0
27
- #
28
25
  lambda {@client.get_pdf(id)}.should raise_error(PostalMethods::APIStatusCode3020Exception)
29
26
  end
30
27
 
31
28
  it "should get the details of a letter" do
32
- id = @client.send_letter(@doc, "the long goodbye").sendLetterResult.to_i
29
+ id = @client.send_letter(@doc, "the long goodbye").to_i
33
30
  sleep(10) # because it's a tired little clients
34
31
  details = @client.get_letter_details(id)
35
32
 
@@ -49,7 +46,7 @@ describe "Utility Methods" do
49
46
  end
50
47
 
51
48
  it "should cancel delivery of a letter" do
52
- id = @client.send_letter(@doc, "the long goodbye").sendLetterResult.to_i
49
+ id = @client.send_letter(@doc, "the long goodbye")
53
50
  rv = @client.cancel_delivery(id)
54
51
  rv.should be_true
55
52
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postalmethods
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Cox
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-09-22 00:00:00 +01:00
12
+ date: 2008-10-06 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency