trypaper 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4d438a45fbade41f11342e31a4716450747d6d94
4
+ data.tar.gz: 1addf7667cfcc8e1771fcbf6a6824faad7cd53f8
5
+ SHA512:
6
+ metadata.gz: 53f0eacd1cce52af1c3639d949ae935e81af81395e517000c789433ee0d08295dc58342b81871221e76da6adc1181de82994ce5a0a59e14eda803ad2918129db
7
+ data.tar.gz: 29fb0793ae46cab7a2637140ef138bfbd8ea4da3de8f5a4e50e0db7fbb0ed80a49be6331c483e479e1bcd77c1302f5b02eac4adf82b979bc5aac241f51d16201
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.gem
14
+ *.a
15
+ *.DS_Store
16
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in TryPaper.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Patrick Jones
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,76 @@
1
+ # TryPaperAPI
2
+ ---
3
+
4
+ A gem for TryPaper API. Use when you need to print and mail letters via USPS.
5
+
6
+ Gem requires API keys from [TryPaper.com](http://trypaper.com)
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'TryPaper'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install TryPaper
23
+
24
+ ## Usage
25
+
26
+ Instantiate the client with API and return address ID(both created in the TryPaper dashboard):
27
+
28
+ ```ruby
29
+ return_address_id = "main_street_headquarters"
30
+ api_key = "AAABBDDCCDDSS"
31
+ client = TryPaper::Mailer.new(api_key, return_address_id)
32
+ ```
33
+
34
+ Add optional printing tags array if desired. See [available tags here.](http://docs.trypaper.com/article/36-mailing-tags)
35
+
36
+ ```ruby
37
+ return_address_id = "main_street_headquarters"
38
+ api_key = "AAABBDDCCDDSS"
39
+ client = TryPaper::Mailer.new(api_key, return_address_id, ["force_bw", "duplicate_contents"])
40
+ ```
41
+
42
+ Set the recipient value(leave address2 blank if needed):
43
+
44
+ ```ruby
45
+ client.recipient.configure do |r|
46
+ r.name = "Patrick Jones"
47
+ r.address1 = "555 Main Street"
48
+ r.address2 = "Apartment #3"
49
+ r.city = "Denver"
50
+ r.state = "CO"
51
+ r.zipcode = "55555"
52
+ end
53
+ ```
54
+
55
+ Read PDF document into variable and load into client:
56
+
57
+ ```ruby
58
+ file = File.read('./documents/business_report.pdf')
59
+ doc = TryPaper::Document.new(file)
60
+ client.document = doc
61
+ ```
62
+
63
+ Submit document to TryPaperAPI
64
+ ```ruby
65
+ client.submit
66
+ ```
67
+
68
+ Check [TryPaper API logs](https://www.trypaper.com/Printroom/APIHistory) to see printing status (document recieved, printing, printed, mailed, etc).
69
+
70
+ ## Contributing
71
+
72
+ 1. Fork it ( https://github.com/pmichaeljones/TryPaperAPI/fork )
73
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
74
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
75
+ 4. Push to the branch (`git push origin my-new-feature`)
76
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/TryPaper.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'TryPaper/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "trypaper"
8
+ spec.version = TryPaper::VERSION
9
+ spec.authors = ["Patrick Jones"]
10
+ spec.email = ["pmichaeljones@gmail.com"]
11
+ spec.summary = %q{This gem is used to access the TryPaper postal mailing API.}
12
+ spec.description = %q{Using this gem allows you to upload Base64 encoded documents and send them to the TryPaper API endoints. Manage your mailing from your TryPaper dashboard.}
13
+ spec.homepage = "http://github.com/pmichaeljones/trypaperapi"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", '~> 0'
24
+ spec.add_development_dependency "vcr", '~> 0'
25
+
26
+ end
data/lib/TryPaper.rb ADDED
@@ -0,0 +1,5 @@
1
+ require_relative "TryPaper/version"
2
+ require_relative "TryPaper/configuration"
3
+ require_relative "TryPaper/document"
4
+ require_relative "TryPaper/recipient"
5
+ require_relative "TryPaper/mailer"
@@ -0,0 +1,29 @@
1
+ # Enable setting and getting of configuration options.
2
+ #
3
+ # Example:
4
+ #
5
+ # This can now be used under config/initializers/trypaperapi.rb
6
+ # TryPaper.configure do |config|
7
+ # config.api_key = 'dfskljkf'
8
+ # end
9
+
10
+ module TryPaper
11
+
12
+ class Configuration
13
+
14
+ attr_accessor :api_key, :return_address
15
+
16
+ def initialize
17
+ end
18
+
19
+ end
20
+
21
+ def self.configuration
22
+ @configuration ||= Configuration.new
23
+ end
24
+
25
+ def self.configure
26
+ yield configuration
27
+ end
28
+
29
+ end
@@ -0,0 +1,20 @@
1
+ require 'Base64'
2
+
3
+ module TryPaper
4
+
5
+ # this is a base64 encoded document that will get sent to the mailer class
6
+ class Document
7
+
8
+ attr_reader :base64format, :file
9
+
10
+ def initialize(file)
11
+ @file = file
12
+ end
13
+
14
+ def base64format
15
+ Base64.encode64(file)
16
+ end
17
+
18
+ end
19
+
20
+ end
@@ -0,0 +1,49 @@
1
+ require 'json'
2
+ require 'net/http'
3
+
4
+ module TryPaper
5
+ class InvalidRecipientError < StandardError; end
6
+ class InvalidAPIKeyError < StandardError; end
7
+
8
+ #the Mailer class takes an instance of the document class and sends it to the TryPaper API
9
+ class Mailer
10
+ API_URL = "https://api.trypaper.com/Mailing"
11
+
12
+ attr_accessor :document, :recipient
13
+ attr_reader :api_key, :return_address_id, :tags
14
+
15
+ # instantiate client and then add document and recipient
16
+ def initialize(api_key, return_address_id, tags = [])
17
+ @recipient = TryPaper::Recipient.new
18
+ @document = nil
19
+ @api_key = api_key
20
+ @return_address_id = return_address_id
21
+ @tags = tags
22
+ end
23
+
24
+ def send_data
25
+ {
26
+ "ReturnAddressId" => return_address_id,
27
+ "Tags" => tags,
28
+ "Content" => document.base64format,
29
+ "Recipient" => recipient.formatted_address
30
+ }
31
+ end
32
+
33
+ def submit
34
+ uri = URI.parse(API_URL)
35
+ http = Net::HTTP.new(uri.host, uri.port)
36
+ http.use_ssl = true
37
+ request = Net::HTTP::Post.new(uri.request_uri)
38
+
39
+ #headers
40
+ request['Authorization'] = api_key
41
+ request['Content-Type'] = "application/json"
42
+
43
+ request.body = send_data.to_json
44
+ response = http.request(request)
45
+ end
46
+
47
+ end
48
+
49
+ end
@@ -0,0 +1,57 @@
1
+ module TryPaper
2
+
3
+ # address object for recipient address
4
+ class Recipient
5
+
6
+ class InvalidDataError < StandardError; end
7
+
8
+ attr_accessor :name, :address1, :address2, :city, :state, :zipcode
9
+ attr_reader :formatted_address
10
+
11
+ def initialize(name = "", address1 = "", address2 = "", city = "", state = "", zip = "")
12
+ @name = name
13
+ @address1 = address1
14
+ @address2 = address2
15
+ @city = city
16
+ @state = state
17
+ @zipcode = zip
18
+ end
19
+
20
+ def formatted_address
21
+ check_attributes
22
+ {
23
+ "Name" => name,
24
+ "AddressLineOne" => address1,
25
+ "AddressLineTwo" => address2,
26
+ "City" => city,
27
+ "Province" => state,
28
+ "PostalCode" => zipcode
29
+ }
30
+ end
31
+
32
+ # set up recipient configuration prior to submission
33
+ def configure
34
+ yield self
35
+ end
36
+
37
+ private
38
+
39
+ def check_attributes
40
+ [name, address1, address2, city, state, zipcode].each do |field|
41
+ raise InvalidDataError, "Recipient attributes must strings" if field.class != String
42
+ end
43
+ end
44
+
45
+ end
46
+
47
+ end
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+
56
+
57
+
@@ -0,0 +1,3 @@
1
+ module TryPaper
2
+ VERSION = "1.1.0"
3
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe TryPaper::Document do
4
+
5
+ it 'should exist' do
6
+ file = File.read('../../Documents/mac.pdf')
7
+ doc = TryPaper::Document.new(file)
8
+ expect(doc).to be_a(TryPaper::Document)
9
+ end
10
+
11
+ it 'should accept a file when initialized' do
12
+ file = File.read('../../Documents/mac.pdf')
13
+ doc = TryPaper::Document.new(file)
14
+ expect(doc.file).to eq(file)
15
+ end
16
+
17
+ it 'should Base64 encode the file' do
18
+ file = File.read('../../Documents/mac.pdf')
19
+ doc = TryPaper::Document.new(file)
20
+ expect(doc.base64format).to be_a(String)
21
+ end
22
+
23
+ end
@@ -0,0 +1 @@
1
+ TryPaper API only accepts PDFs and HTML files. This document will raise an error when used.
@@ -0,0 +1,52 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.trypaper.com/Mailing
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"ReturnAddressId":"555_Main_Street_Fake_City","Tags":[],"Content":"VHJ5UGB1c2Vk\nLgo=\n","Recipient":{"Name":"Patrick Jones","AddressLineOne":"555 Main Street","AddressLineTwo":"Apt 1","City":"Denver","Province":"CO","PostalCode":"54345"}}'
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ Authorization:
17
+ - TPTESTCF24A7D8095EDF88E3EFD6103C
18
+ Content-Type:
19
+ - application/json
20
+ response:
21
+ status:
22
+ code: 400
23
+ message: Bad Request
24
+ headers:
25
+ Cache-Control:
26
+ - no-cache
27
+ Pragma:
28
+ - no-cache
29
+ Content-Length:
30
+ - '42'
31
+ Content-Type:
32
+ - application/json; charset=utf-8
33
+ Expires:
34
+ - "-1"
35
+ Server:
36
+ - Microsoft-IIS/8.0
37
+ Strict-Transport-Security:
38
+ - max-age=31536000
39
+ X-Requestid:
40
+ - a5091fd8-7834-4171-aeed-7219297d549a
41
+ X-Apiversion:
42
+ - 2.0.1
43
+ Set-Cookie:
44
+ - ARRAffinity=0fb861b9c6efe57eefc5a6471990344a9dafe3dcc9dc120612c4578f5eaef35e;Path=/;Domain=api.trypaper.com
45
+ Date:
46
+ - Mon, 12 Jan 2015 19:09:40 GMT
47
+ body:
48
+ encoding: UTF-8
49
+ string: '"Mailing Content was an unsupported type."'
50
+ http_version:
51
+ recorded_at: Mon, 12 Jan 2015 19:09:40 GMT
52
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,55 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.trypaper.com/Mailing
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"ReturnAddressId":"555_Main_Street_Fake_City","Tags":["force_bw","triplicate_contents"],"Content":"JVBERi0xLjUNCiW1t", "Recipient":{"Name":"Patrick Jones","AddressLineOne":"555 Main Street","AddressLineTwo":"Apt 1","City":"Denver","Province":"CO","PostalCode":"54345"}}'
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ Authorization:
17
+ - TPTESTCF24A7D8095EDF88E3EFD6103C
18
+ Content-Type:
19
+ - application/json
20
+ response:
21
+ status:
22
+ code: 201
23
+ message: Created
24
+ headers:
25
+ Cache-Control:
26
+ - no-cache
27
+ Pragma:
28
+ - no-cache
29
+ Content-Length:
30
+ - '135'
31
+ Content-Type:
32
+ - application/json; charset=utf-8
33
+ Expires:
34
+ - "-1"
35
+ Location:
36
+ - https://api.trypaper.com/Mailing
37
+ Server:
38
+ - Microsoft-IIS/8.0
39
+ Strict-Transport-Security:
40
+ - max-age=31536000
41
+ X-Requestid:
42
+ - 1d268b46-0ed3-44d8-82bb-ff927776a28c
43
+ X-Apiversion:
44
+ - 2.0.1
45
+ Set-Cookie:
46
+ - ARRAffinity=0fb861b9c6efe57eefc5a6471990344a9dafe3dcc9dc120612c4578f5eaef35e;Path=/;Domain=api.trypaper.com
47
+ Date:
48
+ - Mon, 12 Jan 2015 19:04:52 GMT
49
+ body:
50
+ encoding: UTF-8
51
+ string: '{"Id":"Patrick Jones 54345 CO - 0A8971D0AA89","BatchId":"Test 1/12/2015
52
+ 6:45 PM - Auto","CreateDateUtc":"2015-01-12T19:04:52.3260059Z"}'
53
+ http_version:
54
+ recorded_at: Mon, 12 Jan 2015 19:04:52 GMT
55
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,55 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.trypaper.com/Mailing
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"ReturnAddressId":"555_Main_Street_Fake_City","Tags":[],"Content":"JVBERi0xLjUNCiW1t","Recipient":{"Name":"Patrick Jones","AddressLineOne":"555 Main Street","AddressLineTwo":"Apt 1","City":"Denver","Province":"CO","PostalCode":"54345"}}'
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ Authorization:
17
+ - TPTESTCF24A7D8095EDF88E3EFD6103C
18
+ Content-Type:
19
+ - application/json
20
+ response:
21
+ status:
22
+ code: 201
23
+ message: Created
24
+ headers:
25
+ Cache-Control:
26
+ - no-cache
27
+ Pragma:
28
+ - no-cache
29
+ Content-Length:
30
+ - '135'
31
+ Content-Type:
32
+ - application/json; charset=utf-8
33
+ Expires:
34
+ - "-1"
35
+ Location:
36
+ - https://api.trypaper.com/Mailing
37
+ Server:
38
+ - Microsoft-IIS/8.0
39
+ Strict-Transport-Security:
40
+ - max-age=31536000
41
+ X-Requestid:
42
+ - f983a885-b138-42a7-bd89-93ce492e791c
43
+ X-Apiversion:
44
+ - 2.0.1
45
+ Set-Cookie:
46
+ - ARRAffinity=0fb861b9c6efe57eefc5a6471990344a9dafe3dcc9dc120612c4578f5eaef35e;Path=/;Domain=api.trypaper.com
47
+ Date:
48
+ - Mon, 12 Jan 2015 19:04:50 GMT
49
+ body:
50
+ encoding: UTF-8
51
+ string: '{"Id":"Patrick Jones 54345 CO - CC28758F6F5F","BatchId":"Test 1/12/2015
52
+ 6:45 PM - Auto","CreateDateUtc":"2015-01-12T19:04:50.0357126Z"}'
53
+ http_version:
54
+ recorded_at: Mon, 12 Jan 2015 19:04:49 GMT
55
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,95 @@
1
+ require 'spec_helper'
2
+ require 'pry'
3
+
4
+ # Testing the class here
5
+ describe TryPaper::Mailer do
6
+
7
+ it 'should exist' do
8
+ mailing = TryPaper::Mailer.new(TEST_API_KEY, RETURN_ADDRESS_ID)
9
+ expect(mailing).to be_kind_of(TryPaper::Mailer)
10
+ end
11
+
12
+ it 'should have a recipient setter method' do
13
+ file = File.read('../../Documents/mac.pdf')
14
+ doc = TryPaper::Document.new(file)
15
+ recipient = TryPaper::Recipient.new("Patrick Jones", "555 Main Street", "Apt 1", "Denver", "CO", "54323")
16
+ mailing = TryPaper::Mailer.new(TEST_API_KEY, RETURN_ADDRESS_ID)
17
+ mailing.recipient = recipient
18
+ expect(mailing.recipient).to eq(recipient)
19
+ end
20
+
21
+ it 'should have a document setter method' do
22
+ file = File.read('../../Documents/mac.pdf')
23
+ doc = TryPaper::Document.new(file)
24
+ mailing = TryPaper::Mailer.new(TEST_API_KEY, RETURN_ADDRESS_ID)
25
+ mailing.document = doc
26
+ expect(mailing.document).to eq(doc)
27
+ end
28
+
29
+ it 'should accept an optional array as the last argument' do
30
+ mailing = TryPaper::Mailer.new(TEST_API_KEY, RETURN_ADDRESS_ID, ["triplicate", "duplicate"])
31
+ expect(mailing.tags).to eq(["triplicate", "duplicate"])
32
+ end
33
+
34
+ end
35
+
36
+ # Testing the API calls here
37
+ describe TryPaper::Mailer do
38
+
39
+ context 'with a correct(pdf) document type' do
40
+ file = File.read('../../Documents/mac.pdf')
41
+ doc = TryPaper::Document.new(file)
42
+ recipient = TryPaper::Recipient.new("Patrick Jones", "555 Main Street", "Apt 1", "Denver", "CO", "54345")
43
+
44
+ subject { TryPaper::Mailer.new(TEST_API_KEY, RETURN_ADDRESS_ID) }
45
+
46
+ it 'should receive a 201 response with successful send' do
47
+ VCR.use_cassette('pdf_document') do
48
+ subject.document = doc
49
+ subject.recipient = recipient
50
+ response = subject.submit
51
+ expect(response.code).to eq("201")
52
+ end
53
+ end
54
+
55
+ end
56
+
57
+ end
58
+
59
+ describe TryPaper::Mailer do
60
+ context 'with wrong document type' do
61
+ file = File.read('./spec/documents/input_document.txt')
62
+ doc = TryPaper::Document.new(file)
63
+ recipient = TryPaper::Recipient.new("Patrick Jones", "555 Main Street", "Apt 1", "Denver", "CO", "54345")
64
+
65
+ subject { TryPaper::Mailer.new(TEST_API_KEY, RETURN_ADDRESS_ID) }
66
+
67
+ it 'should receive a 404 error on bad document' do
68
+ VCR.use_cassette('bad_document') do
69
+ subject.document = doc
70
+ subject.recipient = recipient
71
+ response = subject.submit
72
+ expect(response.code).to eq("400")
73
+ end
74
+ end
75
+ end
76
+
77
+ context 'with correct optional tags added' do
78
+ file = File.read('../../Documents/mac.pdf')
79
+ doc = TryPaper::Document.new(file)
80
+ recipient = TryPaper::Recipient.new("Patrick Jones", "555 Main Street", "Apt 1", "Denver", "CO", "54345")
81
+
82
+ subject { TryPaper::Mailer.new(TEST_API_KEY, RETURN_ADDRESS_ID, ["force_bw", "triplicate_contents"]) }
83
+
84
+ it 'should receive a 201 response with successful send' do
85
+ VCR.use_cassette('good_document_with_tags') do
86
+ subject.document = doc
87
+ subject.recipient = recipient
88
+ response = subject.submit
89
+ expect(response.code).to eq("201")
90
+ end
91
+ end
92
+ end
93
+
94
+ end
95
+
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ describe TryPaper::Recipient do
4
+
5
+ it 'should exist' do
6
+ receiver = TryPaper::Recipient.new
7
+ expect(receiver).to be_kind_of(TryPaper::Recipient)
8
+ end
9
+
10
+ it 'should have a name setter method' do
11
+ receiver = TryPaper::Recipient.new
12
+ receiver.name = "Patrick"
13
+ expect(receiver.name).to eq("Patrick")
14
+ end
15
+
16
+ it 'should have a address1 setter method' do
17
+ receiver = TryPaper::Recipient.new
18
+ receiver.address1 = "555 Main Street"
19
+ expect(receiver.address1).to eq("555 Main Street")
20
+ end
21
+
22
+ it 'should have a address2 setter method' do
23
+ receiver = TryPaper::Recipient.new
24
+ receiver.address2 = "Apt 2"
25
+ expect(receiver.address2).to eq("Apt 2")
26
+ end
27
+
28
+ it 'should have a city setter method' do
29
+ receiver = TryPaper::Recipient.new
30
+ receiver.city = "Denver"
31
+ expect(receiver.city).to eq("Denver")
32
+ end
33
+
34
+ it 'should have a state setter method' do
35
+ receiver = TryPaper::Recipient.new
36
+ receiver.state = "Wisconsin"
37
+ expect(receiver.state).to eq("Wisconsin")
38
+ end
39
+
40
+ it 'should have a zipcode setter method' do
41
+ receiver = TryPaper::Recipient.new
42
+ receiver.zipcode = 342353
43
+ expect(receiver.zipcode).to eq(342353)
44
+ end
45
+
46
+ it 'should raise error on non-string attribute field' do
47
+ receiver = TryPaper::Recipient.new("Patrick", "555 Main Street", "Apt 1", "Denver", "CO", 55555)
48
+ expect{receiver.formatted_address}.to raise_error
49
+ end
50
+
51
+ describe "#formatted_address" do
52
+
53
+ it "should return an address hash" do
54
+ receiver = TryPaper::Recipient.new
55
+ expect(receiver.formatted_address).to be_kind_of(Hash)
56
+ end
57
+
58
+ end
59
+ end
@@ -0,0 +1,16 @@
1
+ require 'trypaper'
2
+ require 'vcr'
3
+ require 'webmock/rspec'
4
+
5
+ TEST_API_KEY = "TPTESTCF24A7D8095EDF88E3EFD6103C"
6
+ RETURN_ADDRESS_ID = "555_Main_Street_Fake_City"
7
+
8
+ RSpec.configure do |config|
9
+ # some (optional) config here
10
+ end
11
+
12
+ VCR.configure do |c|
13
+ c.cassette_library_dir = "spec/fixtures/cassettes"
14
+ c.hook_into :webmock
15
+ c.default_cassette_options = { :record => :once }
16
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trypaper
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Patrick Jones
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: vcr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Using this gem allows you to upload Base64 encoded documents and send
70
+ them to the TryPaper API endoints. Manage your mailing from your TryPaper dashboard.
71
+ email:
72
+ - pmichaeljones@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - TryPaper.gemspec
83
+ - lib/TryPaper.rb
84
+ - lib/TryPaper/configuration.rb
85
+ - lib/TryPaper/document.rb
86
+ - lib/TryPaper/mailer.rb
87
+ - lib/TryPaper/recipient.rb
88
+ - lib/TryPaper/version.rb
89
+ - spec/document_spec.rb
90
+ - spec/documents/input_document.txt
91
+ - spec/fixtures/cassettes/bad_document.yml
92
+ - spec/fixtures/cassettes/good_document_with_tags.yml
93
+ - spec/fixtures/cassettes/pdf_document.yml
94
+ - spec/mailer_spec.rb
95
+ - spec/recipient_spec.rb
96
+ - spec/spec_helper.rb
97
+ homepage: http://github.com/pmichaeljones/trypaperapi
98
+ licenses:
99
+ - MIT
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.2.2
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: This gem is used to access the TryPaper postal mailing API.
121
+ test_files:
122
+ - spec/document_spec.rb
123
+ - spec/documents/input_document.txt
124
+ - spec/fixtures/cassettes/bad_document.yml
125
+ - spec/fixtures/cassettes/good_document_with_tags.yml
126
+ - spec/fixtures/cassettes/pdf_document.yml
127
+ - spec/mailer_spec.rb
128
+ - spec/recipient_spec.rb
129
+ - spec/spec_helper.rb