seeuletter 1.2.0 → 1.3.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
2
  SHA256:
3
- metadata.gz: 232a914d2965e550893e1f0106701c8c4884d99661a6e732207aa4f005a3f856
4
- data.tar.gz: 3c38fd6eb931633be5ac6f0c0949a1a8595a5d1a338f2e01c7d93dc722dbd1ed
3
+ metadata.gz: 284252da8f82460f38f266680cfecf47656d62b85330ac4255cf27fccd42c6b9
4
+ data.tar.gz: 7ab5f0b7293860a22edc668f0e7e5156727473a48816dd5a6fd7db50c5b27781
5
5
  SHA512:
6
- metadata.gz: 6a9c65463bff2977b0141213594c3e093c055e29791fa7ff53508e591664f0aa2deba66f8d4ce026df3d5b587771b50e0a8e108d0224e819b2bf37505bb868fd
7
- data.tar.gz: 4a6d85148fcfd069dce34dbe17a544af9967df4efdee28bc16530418a8873d3c39c8e9b5ee68d645f633f0b1ac7a9b03edd7a55bff11102092db5dadeaa02010
6
+ metadata.gz: 9b81fccbcee63546ead51c7ef2c2f8216bdd4b669a2f6ac5d606e59820ae924a959b2ee0cbcb193195fbaa9e60ffc7f287f5b05f0a21b3071108e224d984c4b7
7
+ data.tar.gz: dd284c14229ad9ad70889f6eedfd59bbc72418398009cae49a0557cd444fd908675f658489ee02da1c76ba891911e5c1296d5944c756a2ceccb3c7451a3246cc
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,143 +1,169 @@
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
- - [Examples](#examples)
19
-
20
- ## Getting Started
21
-
22
- Here's a general overview of the Seeuletter services available, click through to read more.
23
-
24
- Please read through the official [API Documentation](https://docs.seeuletter.com/?ruby#) to get a complete sense of what to expect from each endpoint.
25
-
26
- ### Registration
27
-
28
- 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.
29
-
30
- Once you have created an account, you can access your API Keys from the [API Keys Panel](https://www.seeuletter.com/app/dashboard/keys).
31
-
32
- ### Installation
33
-
34
- Add this line to your application's `Gemfile`:
35
-
36
- gem 'seeuletter'
37
-
38
- And then execute:
39
-
40
- $ bundle
41
-
42
- Or manually install it yourself:
43
-
44
- $ gem install seeuletter
45
-
46
- ### Usage
47
-
48
- The library uses an ActiveRecord-style interface.
49
-
50
- For optional parameters and other details, refer to the docs [here](https://docs.seeuletter.com/?ruby#).
51
-
52
- #### Initialization and Configuration
53
-
54
- ```ruby
55
- # To initialize a Seeuletter object
56
- seeuletter = Seeuletter::Client.new(api_key: "your-api-key")
57
- ```
58
-
59
- #### Create a new letter
60
-
61
- ```ruby
62
- # send the letter
63
- require 'seeuletter'
64
-
65
- # initialize Seeuletter object
66
- seeuletter = Seeuletter::Client.new(api_key: '<PUT_YOU_API_KEY_HERE>')
67
-
68
- puts seeuletter.letters.create(
69
- description: "Test letter from the Ruby Wrapper",
70
- to: {
71
- name: 'Erlich',
72
- address_line1: '30 rue de rivoli',
73
- address_line2: '',
74
- address_city: 'Paris',
75
- address_country: 'France',
76
- address_postalcode: '75004'
77
- },
78
- source_file: '<html>Hello {{name}}</html>',
79
- source_file_type: 'html',
80
- postage_type: 'prioritaire',
81
- variables: { name: 'Erlich'},
82
- color: 'color'
83
- )
84
- ```
85
-
86
- #### List all letters
87
-
88
- ```ruby
89
- require 'seeuletter'
90
-
91
- seeuletter = Seeuletter::Client.new(api_key: 'test_12345678901234567890')
92
-
93
- puts seeuletter.letters.list()
94
- ```
95
-
96
- #### Get a specific letter
97
-
98
- ```ruby
99
- require 'seeuletter'
100
-
101
- seeuletter = Seeuletter::Client.new(api_key: 'test_12345678901234567890')
102
-
103
- puts seeuletter.letters.find('LETTER_ID')
104
- ```
105
- #### Get the price of a letter
106
-
107
- ```ruby
108
- require 'seeuletter'
109
-
110
- seeuletter = Seeuletter::Client.new(api_key: 'test_12345678901234567890')
111
-
112
- puts seeuletter.letter_price.get(color: 'bw', postage_type: 'prioritaire', postage_speed: 'D1', page_count: 1)
113
- ```
114
-
115
- #### Caution: Pass zero-prefixed postal codes as strings
116
-
117
- 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.
118
-
119
- 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.
120
-
121
- #### Accessing Response Headers
122
-
123
- You can access response headers via a hidden `headers` method on the response hash.
124
-
125
- ```ruby
126
- addresses = seeuletter.addresses.list
127
-
128
- addresses._response.headers[:content_type]
129
- # => "application/json"
130
- ```
131
-
132
-
133
- ## Examples
134
-
135
- We've provided various examples for you to try out [here](https://github.com/seeuletter/seeuletter-ruby/tree/master/examples).
136
-
137
- There are simple scripts to demonstrate how to create all letters with the Seeuletter API Ruby wrapper.
138
-
139
- =======================
140
-
141
- Copyright &copy; 2017 Seeuletter.com
142
-
143
- 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
+ - [Examples](#examples)
19
+
20
+ ## Getting Started
21
+
22
+ Here's a general overview of the Seeuletter services available, click through to read more.
23
+
24
+ Please read through the official [API Documentation](https://docs.seeuletter.com/?ruby#) to get a complete sense of what to expect from each endpoint.
25
+
26
+ ### Registration
27
+
28
+ 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.
29
+
30
+ Once you have created an account, you can access your API Keys from the [API Keys Panel](https://www.seeuletter.com/app/dashboard/keys).
31
+
32
+ ### Installation
33
+
34
+ Add this line to your application's `Gemfile`:
35
+
36
+ gem 'seeuletter'
37
+
38
+ And then execute:
39
+
40
+ $ bundle
41
+
42
+ Or manually install it yourself:
43
+
44
+ $ gem install seeuletter
45
+
46
+ ### Usage
47
+
48
+ The library uses an ActiveRecord-style interface.
49
+
50
+ For optional parameters and other details, refer to the docs [here](https://docs.seeuletter.com/?ruby#).
51
+
52
+ #### Initialization and Configuration
53
+
54
+ ```ruby
55
+ # To initialize a Seeuletter object
56
+ seeuletter = Seeuletter::Client.new(api_key: "your-api-key")
57
+ ```
58
+
59
+ #### Create a new letter
60
+
61
+ ```ruby
62
+ # send the letter
63
+ require 'seeuletter'
64
+
65
+ # initialize Seeuletter object
66
+ seeuletter = Seeuletter::Client.new(api_key: '<PUT_YOU_API_KEY_HERE>')
67
+
68
+ puts seeuletter.letters.create(
69
+ description: "Test letter from the Ruby Wrapper",
70
+ to: {
71
+ name: 'Erlich',
72
+ address_line1: '30 rue de rivoli',
73
+ address_line2: '',
74
+ address_city: 'Paris',
75
+ address_country: 'France',
76
+ address_postalcode: '75004'
77
+ },
78
+ source_file: '<html>Hello {{name}}</html>',
79
+ source_file_type: 'html',
80
+ postage_type: 'prioritaire',
81
+ variables: { name: 'Erlich'},
82
+ color: 'color'
83
+ )
84
+ ```
85
+
86
+ #### Create a new electronic letter
87
+
88
+ ```ruby
89
+ # send the letter
90
+ require 'seeuletter'
91
+
92
+ # initialize Seeuletter object
93
+ seeuletter = Seeuletter::Client.new(api_key: '<PUT_YOU_API_KEY_HERE>')
94
+
95
+ puts seeuletter.letters.createElectronic(
96
+ description: "Test electronic letter from the Ruby Wrapper",
97
+ to: {
98
+ email: 'erlich.dumas@example.com',
99
+ first_name: 'Erlich',
100
+ last_name: 'Dumas',
101
+ status: 'individual'
102
+ },
103
+ source_file: '<html>Hello {{name}}</html>',
104
+ source_file_type: 'html',
105
+ postage_type: 'lre',
106
+ variables: {
107
+ name: 'Erlich'
108
+ }
109
+ )
110
+ ```
111
+
112
+ #### List all letters
113
+
114
+ ```ruby
115
+ require 'seeuletter'
116
+
117
+ seeuletter = Seeuletter::Client.new(api_key: 'test_12345678901234567890')
118
+
119
+ puts seeuletter.letters.list()
120
+ ```
121
+
122
+ #### Get a specific letter
123
+
124
+ ```ruby
125
+ require 'seeuletter'
126
+
127
+ seeuletter = Seeuletter::Client.new(api_key: 'test_12345678901234567890')
128
+
129
+ puts seeuletter.letters.find('LETTER_ID')
130
+ ```
131
+ #### Get the price of a letter
132
+
133
+ ```ruby
134
+ require 'seeuletter'
135
+
136
+ seeuletter = Seeuletter::Client.new(api_key: 'test_12345678901234567890')
137
+
138
+ puts seeuletter.letter_price.get(color: 'bw', postage_type: 'prioritaire', postage_speed: 'D1', page_count: 1)
139
+ ```
140
+
141
+ #### Caution: Pass zero-prefixed postal codes as strings
142
+
143
+ 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.
144
+
145
+ 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.
146
+
147
+ #### Accessing Response Headers
148
+
149
+ You can access response headers via a hidden `headers` method on the response hash.
150
+
151
+ ```ruby
152
+ addresses = seeuletter.addresses.list
153
+
154
+ addresses._response.headers[:content_type]
155
+ # => "application/json"
156
+ ```
157
+
158
+
159
+ ## Examples
160
+
161
+ We've provided various examples for you to try out [here](https://github.com/seeuletter/seeuletter-ruby/tree/master/examples).
162
+
163
+ There are simple scripts to demonstrate how to create all letters with the Seeuletter API Ruby wrapper.
164
+
165
+ =======================
166
+
167
+ Copyright &copy; 2017 Seeuletter.com
168
+
169
+ 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,21 @@
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
+ ```
@@ -1,6 +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
-
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
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 CHANGED
@@ -1,6 +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
+ $:.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')
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
@@ -1,30 +1,30 @@
1
- require "seeuletter/resources/letter"
2
- require 'seeuletter/resources/letter_price'
3
- require "seeuletter/resources/user"
4
-
5
- module Seeuletter
6
- class Client
7
-
8
- attr_reader :config
9
-
10
- def initialize(config = nil)
11
- if config.nil? || config[:api_key].nil?
12
- raise ArgumentError.new(":api_key is a required argument to initialize Seeuletter")
13
- end
14
-
15
- @config = config
16
- end
17
-
18
- def letters
19
- Seeuletter::Resources::Letter.new(config)
20
- end
21
-
22
- def letter_price
23
- Seeuletter::Resources::LetterPrice.new(config)
24
- end
25
-
26
- def users
27
- Seeuletter::Resources::User.new(config)
28
- end
29
- end
30
- end
1
+ require "seeuletter/resources/letter"
2
+ require 'seeuletter/resources/letter_price'
3
+ require "seeuletter/resources/user"
4
+
5
+ module Seeuletter
6
+ class Client
7
+
8
+ attr_reader :config
9
+
10
+ def initialize(config = nil)
11
+ if config.nil? || config[:api_key].nil?
12
+ raise ArgumentError.new(":api_key is a required argument to initialize Seeuletter")
13
+ end
14
+
15
+ @config = config
16
+ end
17
+
18
+ def letters
19
+ Seeuletter::Resources::Letter.new(config)
20
+ end
21
+
22
+ def letter_price
23
+ Seeuletter::Resources::LetterPrice.new(config)
24
+ end
25
+
26
+ def users
27
+ Seeuletter::Resources::User.new(config)
28
+ end
29
+ end
30
+ 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
@@ -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
@@ -1,14 +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
+ 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
@@ -1,16 +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
+ 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.2.0"
3
- end
1
+ module Seeuletter
2
+ VERSION = "1.3.0"
3
+ 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.2.0
4
+ version: 1.3.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: 2019-03-26 00:00:00.000000000 Z
11
+ date: 2021-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -73,6 +73,7 @@ files:
73
73
  - examples/README.md
74
74
  - examples/letter_price.rb
75
75
  - examples/letters.rb
76
+ - examples/letters_electronic.rb
76
77
  - examples/users.rb
77
78
  - lib/seeuletter.rb
78
79
  - lib/seeuletter/client.rb
@@ -88,7 +89,7 @@ homepage: https://github.com/seeuletter/seeuletter-ruby
88
89
  licenses:
89
90
  - MIT
90
91
  metadata: {}
91
- post_install_message:
92
+ post_install_message:
92
93
  rdoc_options: []
93
94
  require_paths:
94
95
  - lib
@@ -103,9 +104,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
104
  - !ruby/object:Gem::Version
104
105
  version: '0'
105
106
  requirements: []
106
- rubyforge_project:
107
- rubygems_version: 2.7.8
108
- signing_key:
107
+ rubygems_version: 3.1.4
108
+ signing_key:
109
109
  specification_version: 4
110
110
  summary: Ruby wrapper for Seeuletter.com API - ActiveRecord-style syntax
111
111
  test_files: []