seeuletter 1.0.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 1408fe288ce4a9b2f41d176873e32c47a2717dcf
4
- data.tar.gz: a958dad52b535b938c0d60183969cf99cf6bf148
2
+ SHA256:
3
+ metadata.gz: 4ae03460189501286ccadd04b8fed5ec5cbaf1fc457b550f0ca559fc655450f0
4
+ data.tar.gz: e8b36e0d48592e84e60456c9870956a84f85dabd618a8654e6de491925460f97
5
5
  SHA512:
6
- metadata.gz: 678d19d0e7976d2b154d15f5ff6487d57d8b2da53ec308e91ad8ac9ea904a91e388bb695936d4ce01621f130a0c37937f8ca185616e073427e07457a445b369c
7
- data.tar.gz: a5dcf091b2165b1cac85fa2a0742c81e69ffde43bce15862826c4df69ad77a22e3f4ebf7e4437f6dfc5195368bf4af6d18187b0265eb58a6d22b7d54e59c827f
6
+ metadata.gz: 0ab2e688c5ca19522f28cc73a601d2772290f8be0ae9e1777a1fd833b45a65c0335ef94723324ee78db793a3f2de4e4b2503036a162372d6c28907127d99e535
7
+ data.tar.gz: 5b9c39c72c7cd3bdf39f30d445ecd6eb2a15fd898f5ca05bd838b0aed6b8f4ee1560f92d07b1170fb10488dccb84fed59a6f1f92e054241c99ad8facd9935eb0
data/.gitignore CHANGED
@@ -1,14 +1,14 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- .DS_Store
7
- Gemfile.lock
8
- InstalledFiles
9
- _yardoc
10
- coverage
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- tmp
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .DS_Store
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ tmp
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in seeuletter.gemspec
4
- gemspec
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in seeuletter.gemspec
4
+ gemspec
data/LICENSE.txt CHANGED
@@ -1,22 +1,22 @@
1
- Copyright (c) 2017 Seeuletter.com
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.
1
+ Copyright (c) 2017 Seeuletter.com
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 CHANGED
@@ -1,82 +1,232 @@
1
- # seeuletter-ruby
2
-
3
- Ruby wrapper for the [Seeuletter.com](https://www.seeuletter.com) API. See the full Seeuletter.com [API Documentation](https://docs.seeuletter.com/?ruby#). For best results, be sure that you're using the latest version of the Seeuletter API and the latest version of the ruby wrapper. This gem gives you an ActiveRecord-style syntax to use the Seeuletter.com API.
4
-
5
- Supports Ruby 2.0.0 and greater.
6
-
7
- ## Table of Contents
8
-
9
- - [Getting Started](#getting-started)
10
- - [Registration](#registration)
11
- - [Installation](#installation)
12
- - [Usage](#usage)
13
- - [Examples](#examples)
14
-
15
- ## Getting Started
16
-
17
- Here's a general overview of the Seeuletter services available, click through to read more.
18
-
19
- Please read through the official [API Documentation](#api-documentation) to get a complete sense of what to expect from each endpoint.
20
-
21
- ### Registration
22
-
23
- First, you will need to first create an account at [Seeuletter.com](https://www.seeuletter.com/signup) and obtain your Test and Live API Keys.
24
-
25
- Once you have created an account, you can access your API Keys from the [Settings Panel](https://www.seeuletter.com/app/dashboard/keys).
26
-
27
- ### Installation
28
-
29
- Add this line to your application's `Gemfile`:
30
-
31
- gem 'seeuletter'
32
-
33
- And then execute:
34
-
35
- $ bundle
36
-
37
- Or manually install it yourself:
38
-
39
- $ gem install seeuletter
40
-
41
- ### Usage
42
-
43
- The library uses an ActiveRecord-style interface. You'll feel right at home.
44
-
45
- For optional parameters and other details, refer to the docs [here](https://docs.seeuletter.com/?ruby#).
46
-
47
- #### Initialization and Configuration
48
-
49
- ```ruby
50
- # To initialize a Seeuletter object
51
- seeuletter = Seeuletter::Client.new(api_key: "your-api-key")
52
- ```
53
-
54
- #### Caution: Pass zero-prefixed postal codes as strings
55
-
56
- When using postal codes with zero-prefixes, always quote them. For example when specifying `02125`, pass it as a string `"02125"`, instead of an integer.
57
-
58
- The Ruby interpreter assumes it's not of base-10 and tries to convert it to base-10 number. So that might result in an entirely different postal code than intended.
59
-
60
- #### Accessing Response Headers
61
-
62
- You can access response headers via a hidden `headers` method on the response hash.
63
-
64
- ```ruby
65
- addresses = seeuletter.addresses.list
66
-
67
- addresses._response.headers[:content_type]
68
- # => "application/json; charset=utf-8"
69
- ```
70
-
71
-
72
- ## Examples
73
-
74
- We've provided various examples for you to try out [here](https://github.com/seeuletter/seeuletter-ruby/tree/master/examples).
75
-
76
- There are simple scripts to demonstrate how to create all letters with the Seeuletter API Ruby wrapper.
77
-
78
- =======================
79
-
80
- Copyright © 2017 Seeuletter.com
81
-
82
- Released under the MIT License, which can be found in the repository in `LICENSE.txt`.
1
+ # seeuletter-ruby
2
+
3
+
4
+ [![Gem Version](https://badge.fury.io/rb/seeuletter.svg)](https://badge.fury.io/rb/seeuletter)
5
+ [![Dependency Status](https://gemnasium.com/badges/github.com/seeuletter/seeuletter-ruby.svg)](https://gemnasium.com/github.com/seeuletter/seeuletter-ruby)
6
+
7
+
8
+ Ruby wrapper for the [Seeuletter.com](https://www.seeuletter.com) API. See the full Seeuletter.com [API Documentation](https://docs.seeuletter.com/?ruby#). For best results, be sure that you're using the latest version of the Seeuletter API and the latest version of the ruby wrapper. This gem gives you an ActiveRecord-style syntax to use the Seeuletter.com API.
9
+
10
+ Supports Ruby 2.0.0 and greater.
11
+
12
+ ## Table of Contents
13
+
14
+ - [Getting Started](#getting-started)
15
+ - [Registration](#registration)
16
+ - [Installation](#installation)
17
+ - [Usage](#usage)
18
+ - [Letters](#letters)
19
+ - [Accounts](#accounts)
20
+ - [Invoices](#invoices)
21
+ - [Examples](#examples)
22
+
23
+ ## Getting Started
24
+
25
+ Here's a general overview of the Seeuletter services available, click through to read more.
26
+
27
+ Please read through the official [API Documentation](https://docs.seeuletter.com/?ruby#) to get a complete sense of what to expect from each endpoint.
28
+
29
+ ### Registration
30
+
31
+ First, you will need to first create an account at [Seeuletter.com](https://www.seeuletter.com/signup) and obtain your Test and Live API Keys.
32
+
33
+ Once you have created an account, you can access your API Keys from the [API Keys Panel](https://www.seeuletter.com/app/dashboard/keys).
34
+
35
+ ### Installation
36
+
37
+ Add this line to your application's `Gemfile`:
38
+
39
+ gem 'seeuletter'
40
+
41
+ And then execute:
42
+
43
+ $ bundle
44
+
45
+ Or manually install it yourself:
46
+
47
+ $ gem install seeuletter
48
+
49
+ ### Usage
50
+
51
+ The library uses an ActiveRecord-style interface.
52
+
53
+ For optional parameters and other details, refer to the docs [here](https://docs.seeuletter.com/?ruby#).
54
+
55
+ #### Initialization and Configuration
56
+
57
+ ```ruby
58
+ # To initialize a Seeuletter object
59
+ seeuletter = Seeuletter::Client.new(api_key: "your-api-key")
60
+ ```
61
+
62
+ ### Letters
63
+
64
+ #### Create a new letter
65
+
66
+ ```ruby
67
+ # send the letter
68
+ require 'seeuletter'
69
+
70
+ # initialize Seeuletter object
71
+ seeuletter = Seeuletter::Client.new(api_key: '<PUT_YOU_API_KEY_HERE>')
72
+
73
+ puts seeuletter.letters.create(
74
+ description: "Test letter from the Ruby Wrapper",
75
+ to: {
76
+ name: 'Erlich',
77
+ address_line1: '30 rue de rivoli',
78
+ address_line2: '',
79
+ address_city: 'Paris',
80
+ address_country: 'France',
81
+ address_postalcode: '75004'
82
+ },
83
+ source_file: '<html>Hello {{name}}</html>',
84
+ source_file_type: 'html',
85
+ postage_type: 'prioritaire',
86
+ variables: { name: 'Erlich'},
87
+ color: 'color'
88
+ )
89
+ ```
90
+
91
+ #### Create a new electronic letter
92
+
93
+ ```ruby
94
+ # send the letter
95
+ require 'seeuletter'
96
+
97
+ # initialize Seeuletter object
98
+ seeuletter = Seeuletter::Client.new(api_key: '<PUT_YOU_API_KEY_HERE>')
99
+
100
+ puts seeuletter.letters.createElectronic(
101
+ description: "Test electronic letter from the Ruby Wrapper",
102
+ to: {
103
+ email: 'erlich.dumas@example.com',
104
+ first_name: 'Erlich',
105
+ last_name: 'Dumas',
106
+ status: 'individual'
107
+ },
108
+ source_file: '<html>Hello {{name}}</html>',
109
+ source_file_type: 'html',
110
+ postage_type: 'lre',
111
+ variables: {
112
+ name: 'Erlich'
113
+ }
114
+ )
115
+ ```
116
+
117
+ #### List all letters
118
+
119
+ ```ruby
120
+ require 'seeuletter'
121
+
122
+ seeuletter = Seeuletter::Client.new(api_key: 'test_12345678901234567890')
123
+
124
+ puts seeuletter.letters.list()
125
+ ```
126
+
127
+ #### Get a specific letter
128
+
129
+ ```ruby
130
+ require 'seeuletter'
131
+
132
+ seeuletter = Seeuletter::Client.new(api_key: 'test_12345678901234567890')
133
+
134
+ puts seeuletter.letters.find('LETTER_ID')
135
+ ```
136
+ #### Get the price of a letter
137
+
138
+ ```ruby
139
+ require 'seeuletter'
140
+
141
+ seeuletter = Seeuletter::Client.new(api_key: 'test_12345678901234567890')
142
+
143
+ puts seeuletter.letter_price.get(color: 'bw', postage_type: 'prioritaire', postage_speed: 'D1', page_count: 1)
144
+ ```
145
+
146
+ ### Accounts
147
+
148
+ #### Create a new account for the company
149
+
150
+ ```ruby
151
+ require 'seeuletter'
152
+
153
+ # initialize Seeuletter object
154
+ seeuletter = Seeuletter::Client.new(api_key: 'test_12345678901234567890')
155
+
156
+ puts seeuletter.accounts.create(
157
+ email: "msb.partner@example.com",
158
+ name: "Erlich Bachman",
159
+ phone: "+33104050607",
160
+ company_name: "MSB Partner from Ruby Wrapper",
161
+ address_line1: '30 rue de rivoli',
162
+ address_line2: '',
163
+ address_city: 'Paris',
164
+ address_country: 'France',
165
+ address_postalcode: '75004'
166
+ )
167
+ ```
168
+
169
+ ### Update the account company email
170
+
171
+ ```ruby
172
+ require 'seeuletter'
173
+
174
+ # initialize Seeuletter object
175
+ seeuletter = Seeuletter::Client.new(api_key: 'test_12345678901234567890')
176
+
177
+ seeuletter.accounts.updateEmail('ACCOUNT_COMPANY_ID', "msb.partner.new@example.com")
178
+ ```
179
+
180
+
181
+
182
+ ### Invoices
183
+
184
+ #### List all invoices for a company
185
+
186
+ ```ruby
187
+ require 'seeuletter'
188
+
189
+ seeuletter = Seeuletter::Client.new(api_key: 'test_12345678901234567890')
190
+
191
+ puts seeuletter.invoices.list()
192
+ ```
193
+
194
+ #### Get a specific invoice
195
+
196
+ ```ruby
197
+ require 'seeuletter'
198
+
199
+ seeuletter = Seeuletter::Client.new(api_key: 'test_12345678901234567890')
200
+
201
+ puts seeuletter.invoices.find('INVOICE_ID')
202
+ ```
203
+
204
+ #### Caution: Pass zero-prefixed postal codes as strings
205
+
206
+ When using postal codes with zero-prefixes, always quote them. For example when specifying `02125`, pass it as a string `"02125"`, instead of an integer.
207
+
208
+ The Ruby interpreter assumes it's not of base-10 and tries to convert it to base-10 number. So that might result in an entirely different postal code than intended.
209
+
210
+ #### Accessing Response Headers
211
+
212
+ You can access response headers via a hidden `headers` method on the response hash.
213
+
214
+ ```ruby
215
+ addresses = seeuletter.addresses.list
216
+
217
+ addresses._response.headers[:content_type]
218
+ # => "application/json"
219
+ ```
220
+
221
+
222
+ ## Examples
223
+
224
+ We've provided various examples for you to try out [here](https://github.com/seeuletter/seeuletter-ruby/tree/master/examples).
225
+
226
+ There are simple scripts to demonstrate how to create all letters with the Seeuletter API Ruby wrapper.
227
+
228
+ =======================
229
+
230
+ Copyright &copy; 2017 Seeuletter.com
231
+
232
+ Released under the MIT License, which can be found in the repository in `LICENSE.txt`.
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
3
-
4
- Rake::TestTask.new do |t|
5
- t.libs.push "lib"
6
- t.verbose = true
7
- end
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs.push "lib"
6
+ t.verbose = true
7
+ end
data/examples/README.md CHANGED
@@ -1,17 +1,31 @@
1
- # Ruby Examples
2
-
3
- Here you can find some examples to help you get started with the Ruby wrapper.
4
-
5
- ## Getting started
6
- Before running these examples make sure you are in the `examples/` directory.
7
- ```
8
- cd examples/
9
- ```
10
-
11
- ## Examples
12
-
13
-
14
- ### Create a letter
15
- ```
16
- ruby letters.rb
17
- ```
1
+ # Ruby Examples
2
+
3
+ Here you can find some examples to help you get started with the Ruby wrapper.
4
+
5
+ ## Getting started
6
+ Before running these examples make sure you are in the `examples/` directory.
7
+ ```
8
+ cd examples/
9
+ ```
10
+
11
+ ## Examples
12
+
13
+ ### Create a letter
14
+ ```
15
+ ruby letters.rb
16
+ ```
17
+
18
+ ### Create an electronic letter
19
+ ```
20
+ ruby letters_electronic.rb
21
+ ```
22
+
23
+ ### Create and update account
24
+ ```
25
+ ruby accounts.rb
26
+ ```
27
+
28
+ ### Get invoices
29
+ ```
30
+ ruby invoices.rb
31
+ ```
@@ -0,0 +1,27 @@
1
+ $:.unshift File.expand_path("../lib", File.dirname(__FILE__))
2
+ require 'seeuletter'
3
+
4
+ # initialize Seeuletter object
5
+ seeuletter = Seeuletter::Client.new(api_key: '<PUT_YOU_API_KEY_HERE>')
6
+
7
+ begin
8
+ # create a new company account
9
+ create_response = seeuletter.accounts.create(
10
+ email: "msb.partner@example.com",
11
+ name: "Erlich Bachman",
12
+ phone: "+33104050607",
13
+ company_name: "MSB Partner from Ruby Wrapper",
14
+ address_line1: '30 rue de rivoli',
15
+ address_line2: '',
16
+ address_city: 'Paris',
17
+ address_country: 'France',
18
+ address_postalcode: '75004'
19
+ )
20
+ puts "The Seeuletter API Account responded : #{create_response}"
21
+
22
+ # update email of a company account
23
+ seeuletter.accounts.updateEmail(create_response['company']['_id'], "msb.partner.new@example.com")
24
+
25
+ rescue Seeuletter::SeeuletterError => ex
26
+ puts "Error from API : #{ex}"
27
+ end
@@ -0,0 +1,21 @@
1
+ $:.unshift File.expand_path("../lib", File.dirname(__FILE__))
2
+ require 'seeuletter'
3
+
4
+ # initialize Seeuletter object
5
+ seeuletter = Seeuletter::Client.new(api_key: '<PUT_YOU_API_KEY_HERE>')
6
+
7
+ begin
8
+ # get list of invoices
9
+ list_response = seeuletter.invoices.list(
10
+ status: "paid",
11
+ date_start: "2020-01-01"
12
+ )
13
+ puts "The Seeuletter API Invoices responded : #{list_response}"
14
+
15
+ # get single invoice by API
16
+ find_response = seeuletter.invoices.find(list_response['invoices'][0]['_id'])
17
+ puts "The Seeuletter API Invoice responded : #{find_response}"
18
+
19
+ rescue Seeuletter::SeeuletterError => ex
20
+ puts "Error from API : #{ex}"
21
+ end
@@ -0,0 +1,6 @@
1
+ $:.unshift File.expand_path("../lib", File.dirname(__FILE__))
2
+ require 'seeuletter'
3
+
4
+ seeuletter = Seeuletter::Client.new(api_key: '<PUT_YOU_API_KEY_HERE>')
5
+
6
+ puts seeuletter.letter_price.get(color: 'bw', postage_type: 'prioritaire', postage_speed: 'D1', page_count: 1)
data/examples/letters.rb CHANGED
@@ -1,49 +1,49 @@
1
- $:.unshift File.expand_path("../lib", File.dirname(__FILE__))
2
- require 'seeuletter'
3
-
4
- # initialize Seeuletter object
5
- seeuletter = Seeuletter::Client.new(api_key: '<PUT_YOU_API_KEY_HERE>')
6
-
7
- html = %{
8
- <html>
9
- <head>
10
- <style>
11
- *, *:before, *:after {
12
- -webkit-box-sizing: border-box;
13
- -moz-box-sizing: border-box;
14
- box-sizing: border-box;
15
- }
16
- .text {
17
- margin-left: 50px;
18
- padding-top: 450px;
19
- font-size: 50px;
20
- font-weight: 700;
21
- }
22
- </style>
23
- </head>
24
-
25
- <body>
26
- <p class="text">Hello {{name}}!</p>
27
- </body>
28
-
29
- </html>
30
- }
31
-
32
-
33
- # send the letter
34
- puts seeuletter.letters.create(
35
- description: "Test letter from the Ruby Wrapper",
36
- to: {
37
- name: 'Erlich',
38
- address_line1: '30 rue de rivoli',
39
- address_line2: '',
40
- address_city: 'Paris',
41
- address_country: 'France',
42
- address_postalcode: '75004'
43
- },
44
- source_file: html,
45
- source_file_type: 'html',
46
- postage_type: 'prioritaire',
47
- variables: { name: 'Erlich'},
48
- color: 'color'
49
- )
1
+ $:.unshift File.expand_path("../lib", File.dirname(__FILE__))
2
+ require 'seeuletter'
3
+
4
+ # initialize Seeuletter object
5
+ seeuletter = Seeuletter::Client.new(api_key: '<PUT_YOU_API_KEY_HERE>')
6
+
7
+ html = %{
8
+ <html>
9
+ <head>
10
+ <style>
11
+ *, *:before, *:after {
12
+ -webkit-box-sizing: border-box;
13
+ -moz-box-sizing: border-box;
14
+ box-sizing: border-box;
15
+ }
16
+ .text {
17
+ margin-left: 50px;
18
+ padding-top: 450px;
19
+ font-size: 50px;
20
+ font-weight: 700;
21
+ }
22
+ </style>
23
+ </head>
24
+
25
+ <body>
26
+ <p class="text">Hello {{name}}!</p>
27
+ </body>
28
+
29
+ </html>
30
+ }
31
+
32
+
33
+ # send the letter
34
+ puts seeuletter.letters.create(
35
+ description: "Test letter from the Ruby Wrapper",
36
+ to: {
37
+ name: 'Erlich',
38
+ address_line1: '30 rue de rivoli',
39
+ address_line2: '',
40
+ address_city: 'Paris',
41
+ address_country: 'France',
42
+ address_postalcode: '75004'
43
+ },
44
+ source_file: html,
45
+ source_file_type: 'html',
46
+ postage_type: 'prioritaire',
47
+ variables: { name: 'Erlich'},
48
+ color: 'color'
49
+ )
@@ -0,0 +1,48 @@
1
+ $:.unshift File.expand_path("../lib", File.dirname(__FILE__))
2
+ require 'seeuletter'
3
+
4
+ # initialize Seeuletter object
5
+ seeuletter = Seeuletter::Client.new(api_key: '<PUT_YOU_API_KEY_HERE>')
6
+
7
+ html = %{
8
+ <html>
9
+ <head>
10
+ <style>
11
+ *, *:before, *:after {
12
+ -webkit-box-sizing: border-box;
13
+ -moz-box-sizing: border-box;
14
+ box-sizing: border-box;
15
+ }
16
+ .text {
17
+ margin-left: 50px;
18
+ padding-top: 450px;
19
+ font-size: 50px;
20
+ font-weight: 700;
21
+ }
22
+ </style>
23
+ </head>
24
+
25
+ <body>
26
+ <p class="text">Hello {{name}}!</p>
27
+ </body>
28
+
29
+ </html>
30
+ }
31
+
32
+
33
+ # send the letter
34
+ puts seeuletter.letters.createElectronic(
35
+ description: "Test electronic letter from the Ruby Wrapper",
36
+ to: {
37
+ email: 'erlich.dumas@example.com',
38
+ first_name: 'Erlich',
39
+ last_name: 'Dumas',
40
+ status: 'individual'
41
+ },
42
+ source_file: '<html>Hello {{name}}</html>',
43
+ source_file_type: 'html',
44
+ postage_type: 'lre',
45
+ variables: {
46
+ name: 'Erlich'
47
+ }
48
+ )
data/examples/users.rb ADDED
@@ -0,0 +1,6 @@
1
+ $:.unshift File.expand_path("../lib", File.dirname(__FILE__))
2
+ require 'seeuletter'
3
+
4
+ seeuletter = Seeuletter::Client.new(api_key: '<PUT_YOU_API_KEY_HERE>')
5
+
6
+ puts seeuletter.users.create_from_api(email: 'email@example.com', name: 'Example')
@@ -1,21 +1,40 @@
1
- require "seeuletter/resources/letter"
2
-
3
- module Seeuletter
4
- class Client
5
-
6
- attr_reader :config
7
-
8
- def initialize(config = nil)
9
- if config.nil? || config[:api_key].nil?
10
- raise ArgumentError.new(":api_key is a required argument to initialize Seeuletter")
11
- end
12
-
13
- @config = config
14
- end
15
-
16
- def letters
17
- Seeuletter::Resources::Letter.new(config)
18
- end
19
-
20
- end
21
- end
1
+ require "seeuletter/resources/letter"
2
+ require 'seeuletter/resources/letter_price'
3
+ require "seeuletter/resources/user"
4
+ require "seeuletter/resources/account"
5
+ require "seeuletter/resources/invoice"
6
+
7
+ module Seeuletter
8
+ class Client
9
+
10
+ attr_reader :config
11
+
12
+ def initialize(config = nil)
13
+ if config.nil? || config[:api_key].nil?
14
+ raise ArgumentError.new(":api_key is a required argument to initialize Seeuletter")
15
+ end
16
+
17
+ @config = config
18
+ end
19
+
20
+ def letters
21
+ Seeuletter::Resources::Letter.new(config)
22
+ end
23
+
24
+ def letter_price
25
+ Seeuletter::Resources::LetterPrice.new(config)
26
+ end
27
+
28
+ def users
29
+ Seeuletter::Resources::User.new(config)
30
+ end
31
+
32
+ def accounts
33
+ Seeuletter::Resources::Account.new(config)
34
+ end
35
+
36
+ def invoices
37
+ Seeuletter::Resources::Invoice.new(config)
38
+ end
39
+ end
40
+ end
@@ -1,4 +1,4 @@
1
- module Seeuletter
2
- class InvalidRequestError < SeeuletterError
3
- end
4
- end
1
+ module Seeuletter
2
+ class InvalidRequestError < SeeuletterError
3
+ end
4
+ end
@@ -1,20 +1,20 @@
1
- module Seeuletter
2
-
3
- class SeeuletterError < StandardError
4
- attr_reader :http_status, :http_body, :json_body
5
-
6
- def initialize(message, http_status=nil, http_body=nil, json_body=nil)
7
- @http_status = http_status
8
- @http_body = http_body
9
- @json_body = json_body
10
- status_string = @http_status.nil? ? "" : "(Status #{@http_status}) "
11
- super("#{status_string}#{message} \n #{@http_body}")
12
- end
13
-
14
- def _response
15
- @json_body
16
- end
17
-
18
- end
19
-
20
- end
1
+ module Seeuletter
2
+
3
+ class SeeuletterError < StandardError
4
+ attr_reader :http_status, :http_body, :json_body
5
+
6
+ def initialize(message, http_status=nil, http_body=nil, json_body=nil)
7
+ @http_status = http_status
8
+ @http_body = http_body
9
+ @json_body = json_body
10
+ status_string = @http_status.nil? ? "" : "(Status #{@http_status}) "
11
+ super("#{status_string}#{message} \n #{@http_body}")
12
+ end
13
+
14
+ def _response
15
+ @json_body
16
+ end
17
+
18
+ end
19
+
20
+ end
@@ -0,0 +1,30 @@
1
+ require "seeuletter/resources/resource_base"
2
+
3
+ module Seeuletter
4
+ module Resources
5
+ class Account < Seeuletter::Resources::ResourceBase
6
+
7
+ def initialize(config)
8
+ super(config)
9
+ @endpoint = "accounts"
10
+ end
11
+
12
+ def updateEmail(resource_id, email, headers={})
13
+ submit :put, resource_url(resource_id), {"email" => email}, headers
14
+ end
15
+
16
+ def list(options={})
17
+ raise SeeuletterError.new("Invalid REST operation : GET /accounts", "404", nil)
18
+ end
19
+
20
+ def find(resource_id)
21
+ raise SeeuletterError.new("Invalid REST operation : GET /accounts/:account_id", "404", nil)
22
+ end
23
+
24
+ def destroy(resource_id)
25
+ raise SeeuletterError.new("Invalid REST operation : DELETE /accounts/:account_id", "404", nil)
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,22 @@
1
+ require "seeuletter/resources/resource_base"
2
+
3
+ module Seeuletter
4
+ module Resources
5
+ class Invoice < Seeuletter::Resources::ResourceBase
6
+
7
+ def initialize(config)
8
+ super(config)
9
+ @endpoint = "invoices"
10
+ end
11
+
12
+ def create(options={}, headers={})
13
+ raise SeeuletterError.new("Invalid REST operation : POST /invoices", "404", nil)
14
+ end
15
+
16
+ def destroy(resource_id)
17
+ raise SeeuletterError.new("Invalid REST operation : DELETE /accounts/:invoice_id", "404", nil)
18
+ end
19
+
20
+ end
21
+ end
22
+ end
@@ -1,14 +1,17 @@
1
- require "seeuletter/resources/resource_base"
2
-
3
- module Seeuletter
4
- module Resources
5
- class Letter < Seeuletter::Resources::ResourceBase
6
-
7
- def initialize(config)
8
- super(config)
9
- @endpoint = "letters"
10
- end
11
-
12
- end
13
- end
14
- end
1
+ require "seeuletter/resources/resource_base"
2
+
3
+ module Seeuletter
4
+ module Resources
5
+ class Letter < Seeuletter::Resources::ResourceBase
6
+
7
+ def initialize(config)
8
+ super(config)
9
+ @endpoint = "letters"
10
+ end
11
+
12
+ def createElectronic(options={}, headers={})
13
+ submit :post, resource_url("electronic"), options, headers
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,14 @@
1
+ require "seeuletter/resources/resource_base"
2
+
3
+ module Seeuletter
4
+ module Resources
5
+ class LetterPrice < Seeuletter::Resources::ResourceBase
6
+ def initialize(config)
7
+ super(config)
8
+ @endpoint = "price/letter"
9
+ end
10
+
11
+ alias get list
12
+ end
13
+ end
14
+ end
@@ -1,109 +1,109 @@
1
- require "rest-client"
2
- require "json"
3
- require "uri"
4
-
5
- module Seeuletter
6
- module Resources
7
- class ResourceBase
8
-
9
- attr_reader :config, :endpoint
10
-
11
- def initialize(config)
12
- @config = config
13
- end
14
-
15
- def list(options={})
16
- submit :get, endpoint_url, options
17
- end
18
-
19
- def find(resource_id)
20
- submit :get, resource_url(resource_id)
21
- end
22
-
23
- def create(options={}, headers={})
24
- submit :post, endpoint_url, options, headers
25
- end
26
-
27
- def destroy(resource_id)
28
- submit :delete, resource_url(resource_id)
29
- end
30
-
31
- private
32
-
33
- def submit(method, url, parameters={}, headers={})
34
- clientVersion = Seeuletter::VERSION
35
-
36
- begin
37
- if method == :get || method == :delete
38
- # Hack to URL encode nested objects like metadata.
39
- url = "#{url}?#{build_nested_query(parameters)}"
40
- response = RestClient.send(method, url, {
41
- user_agent: 'Seeuletter/v1 RubyBindings/' + clientVersion,
42
- "Seeuletter-Version" => config[:api_version]
43
- })
44
- else
45
- headers = headers.merge({
46
- user_agent: 'Seeuletter/v1 RubyBindings/' + clientVersion,
47
- "Seeuletter-Version" => config[:api_version]
48
- })
49
- response = RestClient.send(method, url, parameters, headers)
50
- end
51
-
52
- body = JSON.parse(response)
53
-
54
- body.define_singleton_method(:_response) do
55
- response
56
- end
57
-
58
- return body
59
-
60
- rescue RestClient::ExceptionWithResponse => e
61
- handle_api_error(e)
62
- end
63
- end
64
-
65
- private
66
-
67
- def handle_api_error(error)
68
- begin
69
- response = JSON.parse(error.http_body.to_s)
70
- message = response.fetch("error").fetch("message")
71
- raise InvalidRequestError.new(message, error.http_code, error.http_body, error.response)
72
- rescue JSON::ParserError, KeyError
73
- # :nocov:
74
- raise SeeuletterError.new("Invalid response object:", error.http_code, error.http_body)
75
- # :nocov:
76
- end
77
- end
78
-
79
- def build_nested_query(value, prefix = nil)
80
- case value
81
- when Array
82
- value.map { |v|
83
- build_nested_query(v, "#{prefix}[]")
84
- }.join("&")
85
- when Hash
86
- value.map { |k, v|
87
- build_nested_query(v, prefix ? "#{prefix}[#{URI.encode_www_form_component(k)}]" : URI.encode_www_form_component(k))
88
- }.reject(&:empty?).join('&')
89
- else
90
- raise ArgumentError, "value must be an Array or Hash" if prefix.nil?
91
- "#{prefix}=#{URI.encode_www_form_component(value)}"
92
- end
93
- end
94
-
95
- def base_url
96
- "https://#{config[:api_key]}:@api.seeuletter.com"
97
- end
98
-
99
- def endpoint_url
100
- "#{base_url}/#{endpoint}"
101
- end
102
-
103
- def resource_url(resource_id)
104
- "#{endpoint_url}/#{resource_id}"
105
- end
106
-
107
- end
108
- end
109
- end
1
+ require "rest-client"
2
+ require "json"
3
+ require "uri"
4
+
5
+ module Seeuletter
6
+ module Resources
7
+ class ResourceBase
8
+
9
+ attr_reader :config, :endpoint
10
+
11
+ def initialize(config)
12
+ @config = config
13
+ end
14
+
15
+ def list(options={})
16
+ submit :get, endpoint_url, options
17
+ end
18
+
19
+ def find(resource_id)
20
+ submit :get, resource_url(resource_id)
21
+ end
22
+
23
+ def create(options={}, headers={})
24
+ submit :post, endpoint_url, options, headers
25
+ end
26
+
27
+ def destroy(resource_id)
28
+ submit :delete, resource_url(resource_id)
29
+ end
30
+
31
+ private
32
+
33
+ def submit(method, url, parameters={}, headers={})
34
+ clientVersion = Seeuletter::VERSION
35
+
36
+ begin
37
+ if method == :get || method == :delete
38
+ # Hack to URL encode nested objects like metadata.
39
+ url = "#{url}?#{build_nested_query(parameters)}"
40
+ response = RestClient.send(method, url, {
41
+ user_agent: 'Seeuletter/v1 RubyBindings/' + clientVersion,
42
+ "Seeuletter-Version" => config[:api_version]
43
+ })
44
+ else
45
+ headers = headers.merge({
46
+ user_agent: 'Seeuletter/v1 RubyBindings/' + clientVersion,
47
+ "Seeuletter-Version" => config[:api_version]
48
+ })
49
+ response = RestClient.send(method, url, parameters, headers)
50
+ end
51
+
52
+ body = JSON.parse(response)
53
+
54
+ body.define_singleton_method(:_response) do
55
+ response
56
+ end
57
+
58
+ return body
59
+
60
+ rescue RestClient::ExceptionWithResponse => e
61
+ handle_api_error(e)
62
+ end
63
+ end
64
+
65
+ private
66
+
67
+ def handle_api_error(error)
68
+ begin
69
+ response = JSON.parse(error.http_body.to_s)
70
+ message = response.fetch("error").fetch("message")
71
+ raise InvalidRequestError.new(message, error.http_code, error.http_body, error.response)
72
+ rescue JSON::ParserError, KeyError
73
+ # :nocov:
74
+ raise SeeuletterError.new("Invalid response object:", error.http_code, error.http_body)
75
+ # :nocov:
76
+ end
77
+ end
78
+
79
+ def build_nested_query(value, prefix = nil)
80
+ case value
81
+ when Array
82
+ value.map { |v|
83
+ build_nested_query(v, "#{prefix}[]")
84
+ }.join("&")
85
+ when Hash
86
+ value.map { |k, v|
87
+ build_nested_query(v, prefix ? "#{prefix}[#{URI.encode_www_form_component(k)}]" : URI.encode_www_form_component(k))
88
+ }.reject(&:empty?).join('&')
89
+ else
90
+ raise ArgumentError, "value must be an Array or Hash" if prefix.nil?
91
+ "#{prefix}=#{URI.encode_www_form_component(value)}"
92
+ end
93
+ end
94
+
95
+ def base_url
96
+ "https://#{config[:api_key]}:@api.seeuletter.com"
97
+ end
98
+
99
+ def endpoint_url
100
+ "#{base_url}/#{endpoint}"
101
+ end
102
+
103
+ def resource_url(resource_id)
104
+ "#{endpoint_url}/#{resource_id}"
105
+ end
106
+
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,16 @@
1
+ require "seeuletter/resources/resource_base"
2
+
3
+ module Seeuletter
4
+ module Resources
5
+ class User < Seeuletter::Resources::ResourceBase
6
+ def initialize(config)
7
+ super(config)
8
+ @endpoint = "users"
9
+ end
10
+
11
+ def create_from_api(options={}, headers={})
12
+ submit :post, "#{endpoint_url}/create_from_api", options, headers
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,3 +1,3 @@
1
- module Seeuletter
2
- VERSION = "1.0.0"
3
- end
1
+ module Seeuletter
2
+ VERSION = "1.4.0"
3
+ end
data/lib/seeuletter.rb CHANGED
@@ -1,7 +1,7 @@
1
- require "seeuletter/client"
2
- require "seeuletter/version"
3
- require "seeuletter/errors/seeuletter_error"
4
- require "seeuletter/errors/invalid_request_error"
5
-
6
- module Seeuletter
7
- end
1
+ require "seeuletter/client"
2
+ require "seeuletter/version"
3
+ require "seeuletter/errors/seeuletter_error"
4
+ require "seeuletter/errors/invalid_request_error"
5
+
6
+ module Seeuletter
7
+ end
data/seeuletter.gemspec CHANGED
@@ -1,24 +1,24 @@
1
- # coding: utf-8
2
- $:.unshift(File.join(File.dirname(__FILE__), 'lib'))
3
-
4
- require "seeuletter/version"
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "seeuletter"
8
- spec.version = Seeuletter::VERSION
9
- spec.authors = ["Seeuletter"]
10
- spec.email = ["hello@seeuletter.com"]
11
- spec.description = %q{Seeuletter API Ruby wrapper}
12
- spec.summary = %q{Ruby wrapper for Seeuletter.com API - ActiveRecord-style syntax}
13
- spec.homepage = "https://github.com/seeuletter/seeuletter-ruby"
14
- spec.license = "MIT"
15
-
16
- spec.files = `git ls-files`.split($/)
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.require_paths = ["lib"]
19
-
20
- spec.add_dependency "rest-client", ">= 1.8", "< 3.0"
21
-
22
- spec.add_development_dependency "bundler", "~> 1.3"
23
- spec.add_development_dependency "rake", "~> 10.4.2"
24
- end
1
+ # coding: utf-8
2
+ $:.unshift(File.join(File.dirname(__FILE__), 'lib'))
3
+
4
+ require "seeuletter/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "seeuletter"
8
+ spec.version = Seeuletter::VERSION
9
+ spec.authors = ["Seeuletter"]
10
+ spec.email = ["hello@seeuletter.com"]
11
+ spec.description = %q{Seeuletter API Ruby wrapper}
12
+ spec.summary = %q{Ruby wrapper for Seeuletter.com API - ActiveRecord-style syntax}
13
+ spec.homepage = "https://github.com/seeuletter/seeuletter-ruby"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "rest-client", ">= 1.8", "< 3.0"
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.3"
23
+ spec.add_development_dependency "rake", "~> 10.4.2"
24
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seeuletter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seeuletter
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-26 00:00:00.000000000 Z
11
+ date: 2022-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -71,20 +71,29 @@ files:
71
71
  - README.md
72
72
  - Rakefile
73
73
  - examples/README.md
74
+ - examples/accounts.rb
75
+ - examples/invoices.rb
76
+ - examples/letter_price.rb
74
77
  - examples/letters.rb
78
+ - examples/letters_electronic.rb
79
+ - examples/users.rb
75
80
  - lib/seeuletter.rb
76
81
  - lib/seeuletter/client.rb
77
82
  - lib/seeuletter/errors/invalid_request_error.rb
78
83
  - lib/seeuletter/errors/seeuletter_error.rb
84
+ - lib/seeuletter/resources/account.rb
85
+ - lib/seeuletter/resources/invoice.rb
79
86
  - lib/seeuletter/resources/letter.rb
87
+ - lib/seeuletter/resources/letter_price.rb
80
88
  - lib/seeuletter/resources/resource_base.rb
89
+ - lib/seeuletter/resources/user.rb
81
90
  - lib/seeuletter/version.rb
82
91
  - seeuletter.gemspec
83
92
  homepage: https://github.com/seeuletter/seeuletter-ruby
84
93
  licenses:
85
94
  - MIT
86
95
  metadata: {}
87
- post_install_message:
96
+ post_install_message:
88
97
  rdoc_options: []
89
98
  require_paths:
90
99
  - lib
@@ -99,9 +108,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
108
  - !ruby/object:Gem::Version
100
109
  version: '0'
101
110
  requirements: []
102
- rubyforge_project:
103
- rubygems_version: 2.6.11
104
- signing_key:
111
+ rubygems_version: 3.1.4
112
+ signing_key:
105
113
  specification_version: 4
106
114
  summary: Ruby wrapper for Seeuletter.com API - ActiveRecord-style syntax
107
115
  test_files: []