tomtaylor-viapost 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ == 0.0.2 2009-01-18
2
+
3
+ * 0.0.1 was a bad build (forgot to update Manifest).
4
+
5
+ == 0.0.1 2009-01-17
6
+
7
+ * First release
@@ -0,0 +1,17 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.rdoc
4
+ Rakefile
5
+ documentation/ViaPostCustomer API v1.1.pdf
6
+ lib/viapost.rb
7
+ lib/viapost/interface.rb
8
+ lib/viapost/letter.rb
9
+ script/console
10
+ script/destroy
11
+ script/generate
12
+ spec/spec.opts
13
+ spec/spec_helper.rb
14
+ spec/viapost/interface_spec.rb
15
+ spec/viapost_spec.rb
16
+ tasks/rspec.rake
17
+ viapost.gemspec
@@ -0,0 +1,61 @@
1
+ = viapost
2
+
3
+ * http://tomtaylor.co.uk/projects/viapost
4
+ * http://www.viapost.com/
5
+
6
+ == DESCRIPTION:
7
+
8
+ A Ruby library that wraps the Viapost SOAP API, providing an easy way of sending post (you know, real letter box post) from your applications.
9
+
10
+ The author, Tom Taylor, has no affiliation with Viapost other than thinking it's a useful service.
11
+
12
+ == FEATURES/PROBLEMS:
13
+
14
+ Supports:
15
+
16
+ * Supports PDF upload
17
+ * Fetching account balance
18
+ * Sending of post
19
+
20
+ Problems/missing:
21
+
22
+ * Requires very strict address formats (Ensure 1, Road Name, not 1 Road Name, and so on. This is changing with an address cleanser in the upcoming Viapost 1.2 API).
23
+ * No formatting of the PDF you send - you will need to position the address correctly for the address window.
24
+ * No mail merge support.
25
+
26
+ == SYNOPSIS:
27
+
28
+ Coming soon.
29
+
30
+ == REQUIREMENTS:
31
+
32
+ * soap4r >= 1.5.8
33
+
34
+ == INSTALL:
35
+
36
+ * sudo gem install tomtaylor-viapost
37
+
38
+ == LICENSE:
39
+
40
+ (The MIT License)
41
+
42
+ Copyright (c) 2008 Tom Taylor
43
+
44
+ Permission is hereby granted, free of charge, to any person obtaining
45
+ a copy of this software and associated documentation files (the
46
+ 'Software'), to deal in the Software without restriction, including
47
+ without limitation the rights to use, copy, modify, merge, publish,
48
+ distribute, sublicense, and/or sell copies of the Software, and to
49
+ permit persons to whom the Software is furnished to do so, subject to
50
+ the following conditions:
51
+
52
+ The above copyright notice and this permission notice shall be
53
+ included in all copies or substantial portions of the Software.
54
+
55
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
56
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
57
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
58
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
59
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
60
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
61
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,27 @@
1
+ %w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
2
+ require File.dirname(__FILE__) + '/lib/viapost'
3
+
4
+ # Generate all the Rake tasks
5
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
6
+ $hoe = Hoe.new('viapost', Viapost::VERSION) do |p|
7
+ p.developer('Tom Taylor', 'tom@tomtaylor.co.uk')
8
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
9
+ p.rubyforge_name = p.name # TODO this is default value
10
+ p.extra_deps = [
11
+ ['soap4r','>= 1.5.8'],
12
+ ]
13
+ p.extra_dev_deps = [
14
+ ['newgem', ">= #{::Newgem::VERSION}"]
15
+ ]
16
+
17
+ p.clean_globs |= %w[**/.DS_Store tmp *.log]
18
+ path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
19
+ p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
20
+ p.rsync_args = '-av --delete --ignore-errors'
21
+ end
22
+
23
+ require 'newgem/tasks' # load /tasks/*.rake
24
+ Dir['tasks/**/*.rake'].each { |t| load t }
25
+
26
+ # TODO - want other tests/tasks run by default? Add them to the list
27
+ # task :default => [:spec, :features]
@@ -0,0 +1,11 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ gem 'soap4r'
5
+ require 'soap/wsdlDriver'
6
+ require 'viapost/interface'
7
+ require 'viapost/letter'
8
+
9
+ module Viapost
10
+ VERSION = '0.0.2'
11
+ end
@@ -0,0 +1,77 @@
1
+ require 'base64'
2
+
3
+ module Viapost
4
+
5
+ class Interface
6
+
7
+ TEST_WSDL = 'http://apitest.viapost.com/viapostcustomer.asmx?WSDL'
8
+ LIVE_WSDL = 'http://api.viapost.com/Viapostcustomer.asmx?WSDL'
9
+
10
+ class UnknownEnvironment < Exception; end
11
+ class InvalidUserOrPass < Exception; end
12
+
13
+ attr_reader :driver, :login_token
14
+
15
+ def initialize(user, pass, environment = :live)
16
+ @driver = SOAP::WSDLDriverFactory.new(wsdl(environment)).create_rpc_driver
17
+ @user = user
18
+ @pass = pass
19
+ end
20
+
21
+ def balance
22
+ response = @driver.GetBalance(:sLoginToken => login_token)
23
+ response.dBalance.to_f
24
+ end
25
+
26
+ def letters(query = '')
27
+ response = @driver.GetLetters(:sLoginToken => login_token, :sSearchDocumentName => query)
28
+ soap_letters = response.returnLetters.anyType
29
+
30
+ # for some reason their API returns just the letter instead of an array if it only returns one letter
31
+ if soap_letters.is_a?(Array)
32
+ soap_letters.map { |l| Letter.build_from_soap_object(l) }
33
+ else
34
+ [Letter.build_from_soap_object(soap_letters)]
35
+ end
36
+ end
37
+
38
+ def upload_letter(file, title, colour = false, double_sided = false)
39
+ file = File.open(file, 'r') if file.is_a?(String) # allow path instead of file
40
+
41
+ response = @driver.UploadDocument(:sLoginToken => login_token, :sDocumentName => title, :DocumentData => file.read, :Colour => colour, :DoubleSided => double_sided)
42
+ end
43
+
44
+ def send_letter(letter, name, address_1, address_2, address_3, address_4, address_5, postcode)
45
+ response = @driver.SendLetter(:sLoginToken => login_token, :myCustomerAPILetter => letter, :addressName => name, :address1 => address_1, :address2 => address_2, :address3 => address_3, :address4 => address_4, :address5 => address_5, :postcode => postcode)
46
+ end
47
+
48
+ def letter(letter_id)
49
+ @driver.GetLetterByID(:sLoginToken => login_token, :LetterID => letter_id)
50
+ end
51
+
52
+ # private
53
+
54
+ def login_token
55
+ @login_response ||= @driver.SignIn(:sUserName => @user, :sPassword => @pass)
56
+
57
+ if @login_response.signInResult == 'true' # i hate soap.
58
+ return @login_response.sLoginToken
59
+ else
60
+ raise InvalidUserOrPass
61
+ end
62
+ end
63
+
64
+ def wsdl(environment)
65
+ case environment.to_sym
66
+ when :live
67
+ wsdl = LIVE_WSDL
68
+ when :test
69
+ wsdl = TEST_WSDL
70
+ else
71
+ raise UnknownEnvironment
72
+ end
73
+ end
74
+
75
+ end
76
+
77
+ end
@@ -0,0 +1,40 @@
1
+ module Viapost
2
+
3
+ class Letter
4
+
5
+ attr_reader :id, :file_name, :number_of_pages, :uploaded_at
6
+
7
+ def LetterID
8
+ self.id
9
+ end
10
+
11
+ def LetterFileName
12
+ self.file_name
13
+ end
14
+
15
+ def NumberOfPages
16
+ self.number_of_pages
17
+ end
18
+
19
+ def DateUploaded
20
+ self.uploaded_at
21
+ end
22
+
23
+ def initialize(id, file_name, number_of_pages, uploaded_at)
24
+ @id = id
25
+ @file_name = file_name
26
+ @number_of_pages = number_of_pages
27
+ @uploaded_at = uploaded_at
28
+ end
29
+
30
+ def self.build_from_soap_object(soap_object)
31
+ file_name = soap_object.letterFileName
32
+ id = soap_object.letterID.to_i
33
+ number_of_pages = soap_object.numberOfPages.to_i
34
+ uploaded_at = Time.parse(soap_object.dateUploaded)
35
+ return new(id, file_name, number_of_pages, uploaded_at)
36
+ end
37
+
38
+ end
39
+
40
+ end
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/viapost.rb'}"
9
+ puts "Loading viapost gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,10 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ gem 'rspec'
6
+ require 'spec'
7
+ end
8
+
9
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
10
+ require 'viapost'
@@ -0,0 +1,2 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ # Time to add your specs!
4
+ # http://rspec.info/
5
+ describe "Place your specs here" do
6
+
7
+ it "find this spec in spec directory" do
8
+ violated "Be sure to write your specs"
9
+ end
10
+
11
+ end
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ require 'spec'
6
+ end
7
+ begin
8
+ require 'spec/rake/spectask'
9
+ rescue LoadError
10
+ puts <<-EOS
11
+ To use rspec for testing you must install rspec gem:
12
+ gem install rspec
13
+ EOS
14
+ exit(0)
15
+ end
16
+
17
+ desc "Run the specs under spec/models"
18
+ Spec::Rake::SpecTask.new do |t|
19
+ t.spec_opts = ['--options', "spec/spec.opts"]
20
+ t.spec_files = FileList['spec/**/*_spec.rb']
21
+ end
@@ -0,0 +1,38 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = %q{viapost}
3
+ s.version = "0.0.2"
4
+
5
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
6
+ s.authors = ["Tom Taylor"]
7
+ s.date = %q{2009-01-18}
8
+ s.description = %q{A Ruby library that wraps the Viapost SOAP API, providing an easy way of sending post (you know, real letter box post) from your applications. The author, Tom Taylor, has no affiliation with Viapost other than thinking it's a useful service.}
9
+ s.email = ["tom@tomtaylor.co.uk"]
10
+ s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.rdoc"]
11
+ s.files = ["History.txt", "Manifest.txt", "README.rdoc", "Rakefile", "documentation/ViaPostCustomer API v1.1.pdf", "lib/viapost.rb", "lib/viapost/interface.rb", "lib/viapost/letter.rb", "script/console", "script/destroy", "script/generate", "spec/spec.opts", "spec/spec_helper.rb", "spec/viapost/interface_spec.rb", "spec/viapost_spec.rb", "tasks/rspec.rake", "viapost.gemspec"]
12
+ s.has_rdoc = true
13
+ s.homepage = %q{http://tomtaylor.co.uk/projects/viapost}
14
+ s.rdoc_options = ["--main", "README.rdoc"]
15
+ s.require_paths = ["lib"]
16
+ s.rubyforge_project = %q{viapost}
17
+ s.rubygems_version = %q{1.3.1}
18
+ s.summary = %q{A Ruby library that wraps the Viapost SOAP API, providing an easy way of sending post (you know, real letter box post) from your applications}
19
+
20
+ if s.respond_to? :specification_version then
21
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
22
+ s.specification_version = 2
23
+
24
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
25
+ s.add_runtime_dependency(%q<soap4r>, [">= 1.5.8"])
26
+ s.add_development_dependency(%q<newgem>, [">= 1.2.3"])
27
+ s.add_development_dependency(%q<hoe>, [">= 1.8.0"])
28
+ else
29
+ s.add_dependency(%q<soap4r>, [">= 1.5.8"])
30
+ s.add_dependency(%q<newgem>, [">= 1.2.3"])
31
+ s.add_dependency(%q<hoe>, [">= 1.8.0"])
32
+ end
33
+ else
34
+ s.add_dependency(%q<soap4r>, [">= 1.5.8"])
35
+ s.add_dependency(%q<newgem>, [">= 1.2.3"])
36
+ s.add_dependency(%q<hoe>, [">= 1.8.0"])
37
+ end
38
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tomtaylor-viapost
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Tom Taylor
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-01-18 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: soap4r
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.5.8
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: newgem
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: 1.2.3
32
+ version:
33
+ - !ruby/object:Gem::Dependency
34
+ name: hoe
35
+ version_requirement:
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.8.0
41
+ version:
42
+ description: A Ruby library that wraps the Viapost SOAP API, providing an easy way of sending post (you know, real letter box post) from your applications. The author, Tom Taylor, has no affiliation with Viapost other than thinking it's a useful service.
43
+ email:
44
+ - tom@tomtaylor.co.uk
45
+ executables: []
46
+
47
+ extensions: []
48
+
49
+ extra_rdoc_files:
50
+ - History.txt
51
+ - Manifest.txt
52
+ - README.rdoc
53
+ files:
54
+ - History.txt
55
+ - Manifest.txt
56
+ - README.rdoc
57
+ - Rakefile
58
+ - documentation/ViaPostCustomer API v1.1.pdf
59
+ - lib/viapost.rb
60
+ - lib/viapost/interface.rb
61
+ - lib/viapost/letter.rb
62
+ - script/console
63
+ - script/destroy
64
+ - script/generate
65
+ - spec/spec.opts
66
+ - spec/spec_helper.rb
67
+ - spec/viapost/interface_spec.rb
68
+ - spec/viapost_spec.rb
69
+ - tasks/rspec.rake
70
+ - viapost.gemspec
71
+ has_rdoc: true
72
+ homepage: http://tomtaylor.co.uk/projects/viapost
73
+ post_install_message:
74
+ rdoc_options:
75
+ - --main
76
+ - README.rdoc
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: "0"
84
+ version:
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: "0"
90
+ version:
91
+ requirements: []
92
+
93
+ rubyforge_project: viapost
94
+ rubygems_version: 1.2.0
95
+ signing_key:
96
+ specification_version: 2
97
+ summary: A Ruby library that wraps the Viapost SOAP API, providing an easy way of sending post (you know, real letter box post) from your applications
98
+ test_files: []
99
+