pepipost_gem 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3b7d3643dbb6d993e1cb1a312c1ea16c036782e7
4
+ data.tar.gz: d4212c3932c2a138dc45bfd76985ac579c1e3fe0
5
+ SHA512:
6
+ metadata.gz: 2c255f736b76d2e5337efc58c8e322801c4ebd3648e146c48b13c508d16c572fe3c608669cc8f072abc6a04eb35402f1e09455aea7a23a1c18065d0839e3d63e
7
+ data.tar.gz: c7c9a87fe5b4f7da863c41a69859d1304ea0e6b9f004f1b475e9b91b6bcac6854504a08c1d20a2a3861092365fa92028523f965bedd16a33e2532ab93b7f016c
data/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ License:
2
+ ========
3
+ The MIT License (MIT)
4
+ http://opensource.org/licenses/MIT
5
+
6
+ Copyright (c) 2014 - 2016 APIMATIC Limited
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in
16
+ all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ THE SOFTWARE.
25
+
26
+ Trade Mark:
27
+ ==========
28
+ APIMATIC is a trade mark for APIMATIC Limited
data/README.md ADDED
@@ -0,0 +1,141 @@
1
+ # Getting started
2
+
3
+ Pepipost is a cloud-based SMTP relay service that delivers highly personalised transactional emails to the inbox within seconds of your customer’s transaction
4
+
5
+ ## How to Build
6
+
7
+ This client library is a Ruby gem which can be compiled and used in your Ruby and Ruby on Rails project. This library requires a few gems from the RubyGems repository.
8
+
9
+ 1. Open the command line interface or the terminal and navigate to the folder containing the source code.
10
+ 2. Run ``` gem build pepipost_gem.gemspec ``` to build the gem.
11
+ 3. Once built, the gem can be installed on the current work environment using ``` gem install pepipost_gem-2.5.0.gem ```
12
+
13
+ ![Building Gem](https://apidocs.io/illustration/ruby?step=buildSDK&workspaceFolder=pepipost_gem-Ruby&workspaceName=pepipost_gem-Ruby&projectName=pepipost_gem&gemName=pepipost_gem&gemVer=2.5.0)
14
+
15
+ ## How to Use
16
+
17
+ The following section explains how to use the PepipostGem Ruby Gem in a new Rails project using RubyMine™. The basic workflow presented here is also applicable if you prefer using a different editor or IDE.
18
+
19
+ ### 1. Starting a new project
20
+
21
+ Close any existing projects in RubyMine™ by selecting ``` File -> Close Project ```. Next, click on ``` Create New Project ``` to create a new project from scratch.
22
+
23
+ ![Create a new project in RubyMine](https://apidocs.io/illustration/ruby?step=createNewProject0&workspaceFolder=pepipost_gem-Ruby&workspaceName=PepipostGem&projectName=pepipost_gem&gemName=pepipost_gem&gemVer=2.5.0)
24
+
25
+ Next, provide ``` TestApp ``` as the project name, choose ``` Rails Application ``` as the project type, and click ``` OK ```.
26
+
27
+ ![Create a new Rails Application in RubyMine - step 1](https://apidocs.io/illustration/ruby?step=createNewProject1&workspaceFolder=pepipost_gem-Ruby&workspaceName=PepipostGem&projectName=pepipost_gem&gemName=pepipost_gem&gemVer=2.5.0)
28
+
29
+ In the next dialog make sure that correct *Ruby SDK* is being used (minimum 2.0.0) and click ``` OK ```.
30
+
31
+ ![Create a new Rails Application in RubyMine - step 2](https://apidocs.io/illustration/ruby?step=createNewProject2&workspaceFolder=pepipost_gem-Ruby&workspaceName=PepipostGem&projectName=pepipost_gem&gemName=pepipost_gem&gemVer=2.5.0)
32
+
33
+ This will create a new Rails Application project with an existing set of files and folder.
34
+
35
+ ### 2. Add reference of the gem
36
+
37
+ In order to use the PepipostGem gem in the new project we must add a gem reference. Locate the ```Gemfile``` in the *Project Explorer* window under the ``` TestApp ``` project node. The file contains references to all gems being used in the project. Here, add the reference to the library gem by adding the following line: ``` gem 'pepipost_gem', '~> 2.5.0' ```
38
+
39
+ ![Add references of the Gemfile](https://apidocs.io/illustration/ruby?step=addReference&workspaceFolder=pepipost_gem-Ruby&workspaceName=PepipostGem&projectName=pepipost_gem&gemName=pepipost_gem&gemVer=2.5.0)
40
+
41
+ ### 3. Adding a new Rails Controller
42
+
43
+ Once the ``` TestApp ``` project is created, a folder named ``` controllers ``` will be visible in the *Project Explorer* under the following path: ``` TestApp > app > controllers ```. Right click on this folder and select ``` New -> Run Rails Generator... ```.
44
+
45
+ ![Run Rails Generator on Controllers Folder](https://apidocs.io/illustration/ruby?step=addCode0&workspaceFolder=pepipost_gem-Ruby&workspaceName=PepipostGem&projectName=pepipost_gem&gemName=pepipost_gem&gemVer=2.5.0)
46
+
47
+ Selecting the said option will popup a small window where the generator names are displayed. Here, select the ``` controller ``` template.
48
+
49
+ ![Create a new Controller](https://apidocs.io/illustration/ruby?step=addCode1&workspaceFolder=pepipost_gem-Ruby&workspaceName=PepipostGem&projectName=pepipost_gem&gemName=pepipost_gem&gemVer=2.5.0)
50
+
51
+ Next, a popup window will ask you for a Controller name and included Actions. For controller name provide ``` Hello ``` and include an action named ``` Index ``` and click ``` OK ```.
52
+
53
+ ![Add a new Controller](https://apidocs.io/illustration/ruby?step=addCode2&workspaceFolder=pepipost_gem-Ruby&workspaceName=PepipostGem&projectName=pepipost_gem&gemName=pepipost_gem&gemVer=2.5.0)
54
+
55
+ A new controller class anmed ``` HelloController ``` will be created in a file named ``` hello_controller.rb ``` containing a method named ``` Index ```. In this method, add code for initialization and a sample for its usage.
56
+
57
+ ![Initialize the library](https://apidocs.io/illustration/ruby?step=addCode3&workspaceFolder=pepipost_gem-Ruby&workspaceName=PepipostGem&projectName=pepipost_gem&gemName=pepipost_gem&gemVer=2.5.0)
58
+
59
+ ## How to Test
60
+
61
+ You can test the generated SDK and the server with automatically generated test
62
+ cases as follows:
63
+
64
+ 1. From terminal/cmd navigate to the root directory of the SDK.
65
+ 2. Invoke: `bundle exec rake`
66
+
67
+ ## Initialization
68
+
69
+ ###
70
+
71
+ API client can be initialized as following.
72
+
73
+ ```ruby
74
+
75
+ client = PepipostGem::PepipostGemClient.new
76
+ ```
77
+
78
+ The added initlization code can be debugged by putting a breakpoint in the ``` Index ``` method and running the project in debug mode by selecting ``` Run -> Debug 'Development: TestApp' ```.
79
+
80
+ ![Debug the TestApp](https://apidocs.io/illustration/ruby?step=addCode4&workspaceFolder=pepipost_gem-Ruby&workspaceName=PepipostGem&projectName=pepipost_gem&gemName=pepipost_gem&gemVer=2.5.0&initLine=client%2520%253D%2520PepipostGemClient.new)
81
+
82
+
83
+
84
+ # Class Reference
85
+
86
+ ## <a name="list_of_controllers"></a>List of Controllers
87
+
88
+ * [EmailController](#email_controller)
89
+
90
+ ## <a name="email_controller"></a>![Class: ](https://apidocs.io/img/class.png ".EmailController") EmailController
91
+
92
+ ### Get singleton instance
93
+
94
+ The singleton instance of the ``` EmailController ``` class can be accessed from the API Client.
95
+
96
+ ```ruby
97
+ email_controller = client.email
98
+ ```
99
+
100
+ ### <a name="create_send_email"></a>![Method: ](https://apidocs.io/img/method.png ".EmailController.create_send_email") create_send_email
101
+
102
+ > *Tags:* ``` Skips Authentication ```
103
+
104
+ > This Endpoint sends emails with the credentials passed.
105
+
106
+
107
+ ```ruby
108
+ def create_send_email(api_key = nil,
109
+ body = nil); end
110
+ ```
111
+
112
+ #### Parameters
113
+
114
+ | Parameter | Tags | Description |
115
+ |-----------|------|-------------|
116
+ | api_key | ``` Optional ``` | Generated header parameter. Example value ='5ce7096ed4bf2b39dfa932ff5fa84ed9ed8' |
117
+ | body | ``` Optional ``` | The body passed will be json format. |
118
+
119
+
120
+ #### Example Usage
121
+
122
+ ```ruby
123
+ api_key = 'api_key'
124
+ body = EmailBody.new
125
+
126
+ result = email_controller.create_send_email(api_key, body)
127
+
128
+ ```
129
+
130
+ #### Errors
131
+
132
+ | Error Code | Error Description |
133
+ |------------|-------------------|
134
+ | 405 | Method not allowed |
135
+
136
+
137
+
138
+ [Back to List of Controllers](#list_of_controllers)
139
+
140
+
141
+
@@ -0,0 +1,40 @@
1
+ # This file was automatically generated by APIMATIC v2.0
2
+ # ( https://apimatic.io ).
3
+ require 'date'
4
+ require 'json'
5
+ require 'faraday'
6
+ require 'certifi'
7
+ require 'logging'
8
+
9
+ require_relative 'pepipost_gem/api_helper.rb'
10
+ require_relative 'pepipost_gem/pepipost_gem_client.rb'
11
+
12
+ # Http
13
+ require_relative 'pepipost_gem/http/http_call_back.rb'
14
+ require_relative 'pepipost_gem/http/http_client.rb'
15
+ require_relative 'pepipost_gem/http/http_method_enum.rb'
16
+ require_relative 'pepipost_gem/http/http_request.rb'
17
+ require_relative 'pepipost_gem/http/http_response.rb'
18
+ require_relative 'pepipost_gem/http/http_context.rb'
19
+ require_relative 'pepipost_gem/http/faraday_client.rb'
20
+
21
+ # Models
22
+ require_relative 'pepipost_gem/models/base_model.rb'
23
+ require_relative 'pepipost_gem/models/attribute.rb'
24
+ require_relative 'pepipost_gem/models/from.rb'
25
+ require_relative 'pepipost_gem/models/email_body_attachments.rb'
26
+ require_relative 'pepipost_gem/models/attachments.rb'
27
+ require_relative 'pepipost_gem/models/personalizations.rb'
28
+ require_relative 'pepipost_gem/models/email_body.rb'
29
+ require_relative 'pepipost_gem/models/settings.rb'
30
+ require_relative 'pepipost_gem/models/send_email_error.rb'
31
+ require_relative 'pepipost_gem/models/send_email_response.rb'
32
+
33
+ # Exceptions
34
+ require_relative 'pepipost_gem/exceptions/api_exception.rb'
35
+
36
+ require_relative 'pepipost_gem/configuration.rb'
37
+
38
+ # Controllers
39
+ require_relative 'pepipost_gem/controllers/base_controller.rb'
40
+ require_relative 'pepipost_gem/controllers/email_controller.rb'
@@ -0,0 +1,273 @@
1
+ # This file was automatically generated by APIMATIC v2.0
2
+ # ( https://apimatic.io ).
3
+
4
+ module PepipostGem
5
+ # API utility class
6
+ class APIHelper
7
+ # Serializes an array parameter (creates key value pairs).
8
+ # @param [String] The name of the parameter.
9
+ # @param [Array] The value of the parameter.
10
+ # @param [String] The format of the serialization.
11
+ def self.serialize_array(key, array, formatting: 'indexed')
12
+ tuples = []
13
+
14
+ if formatting == 'unindexed'
15
+ tuples += array.map { |element| ["#{key}[]", element] }
16
+ elsif formatting == 'indexed'
17
+ tuples += array.map.with_index do |element, index|
18
+ ["#{key}[#{index}]", element]
19
+ end
20
+ elsif formatting == 'plain'
21
+ tuples += array.map { |element| [key, element] }
22
+ else
23
+ raise ArgumentError, 'Invalid format provided.'
24
+ end
25
+ tuples
26
+ end
27
+
28
+ # Replaces template parameters in the given url.
29
+ # @param [String] The query string builder to replace the template
30
+ # parameters.
31
+ # @param [Hash] The parameters to replace in the url.
32
+ def self.append_url_with_template_parameters(query_builder, parameters)
33
+ # perform parameter validation
34
+ unless query_builder.instance_of? String
35
+ raise ArgumentError, 'Given value for parameter \"query_builder\" is
36
+ invalid.'
37
+ end
38
+
39
+ # Return if there are no parameters to replace.
40
+ return query_builder if parameters.nil?
41
+
42
+ # Iterate and append parameters.
43
+ parameters.each do |key, value|
44
+ replace_value = ''
45
+
46
+ if value.nil?
47
+ replace_value = ''
48
+ elsif value.instance_of? Array
49
+ value.map! { |element| CGI.escape(element.to_s) }
50
+ replace_value = value.join('/')
51
+ else
52
+ replace_value = CGI.escape(value.to_s)
53
+ end
54
+
55
+ # Find the template parameter and replace it with its value.
56
+ query_builder = query_builder.gsub('{' + key.to_s + '}', replace_value)
57
+ end
58
+ query_builder
59
+ end
60
+
61
+ # Appends the given set of parameters to the given query string.
62
+ # @param [String] The query string builder to add the query parameters to.
63
+ # @param [Hash] The parameters to append.
64
+ # @param [String] The format of array parameter serialization.
65
+ def self.append_url_with_query_parameters(query_builder, parameters,
66
+ array_serialization: 'indexed')
67
+ # Perform parameter validation.
68
+ unless query_builder.instance_of? String
69
+ raise ArgumentError, 'Given value for parameter \"query_builder\"
70
+ is invalid.'
71
+ end
72
+
73
+ # Return if there are no parameters to replace.
74
+ return query_builder if parameters.nil?
75
+
76
+ parameters.each do |key, value|
77
+ seperator = query_builder.include?('?') ? '&' : '?'
78
+ unless value.nil?
79
+ if value.instance_of? Array
80
+ value.compact!
81
+ query_builder += if array_serialization == 'csv'
82
+ "#{seperator}#{key}=#{value.map do |element|
83
+ CGI.escape(element.to_s)
84
+ end.join(',')}"
85
+ elsif array_serialization == 'psv'
86
+ "#{seperator}#{key}=#{value.map do |element|
87
+ CGI.escape(element.to_s)
88
+ end.join('|')}"
89
+ elsif array_serialization == 'tsv'
90
+ "#{seperator}#{key}=#{value.map do |element|
91
+ CGI.escape(element.to_s)
92
+ end.join("\t")}"
93
+ else
94
+ "#{seperator}#{APIHelper.serialize_array(
95
+ key, value, formatting: array_serialization
96
+ ).map { |k, v| "#{k}=#{CGI.escape(v.to_s)}" }
97
+ .join('&')}"
98
+ end
99
+ else
100
+ query_builder += "#{seperator}#{key}=#{CGI.escape(value.to_s)}"
101
+ end
102
+ end
103
+ end
104
+ query_builder
105
+ end
106
+
107
+ # Validates and processes the given Url.
108
+ # @param [String] The given Url to process.
109
+ # @return [String] Pre-processed Url as string.
110
+ def self.clean_url(url)
111
+ # Perform parameter validation.
112
+ raise ArgumentError, 'Invalid Url.' unless url.instance_of? String
113
+
114
+ # Ensure that the urls are absolute.
115
+ matches = url.match(%r{^(https?:\/\/[^\/]+)})
116
+ raise ArgumentError, 'Invalid Url format.' if matches.nil?
117
+
118
+ # Get the http protocol match.
119
+ protocol = matches[1]
120
+
121
+ # Check if parameters exist.
122
+ index = url.index('?')
123
+
124
+ # Remove redundant forward slashes.
125
+ query = url[protocol.length...(!index.nil? ? index : url.length)]
126
+ query.gsub!(%r{\/\/+}, '/')
127
+
128
+ # Get the parameters.
129
+ parameters = !index.nil? ? url[url.index('?')...url.length] : ''
130
+
131
+ # Return processed url.
132
+ protocol + query + parameters
133
+ end
134
+
135
+ # Parses JSON string.
136
+ # @param [String] A JSON string.
137
+ def self.json_deserialize(json)
138
+ return JSON.parse(json)
139
+ rescue StandardError
140
+ raise TypeError, 'Server responded with invalid JSON.'
141
+ end
142
+
143
+ # Removes elements with empty values from a hash.
144
+ # @param [Hash] The hash to clean.
145
+ def self.clean_hash(hash)
146
+ hash.delete_if { |_key, value| value.to_s.strip.empty? }
147
+ end
148
+
149
+ # Form encodes a hash of parameters.
150
+ # @param [Hash] The hash of parameters to encode.
151
+ # @return [Hash] A hash with the same parameters form encoded.
152
+ def self.form_encode_parameters(form_parameters)
153
+ encoded = {}
154
+ form_parameters.each do |key, value|
155
+ encoded.merge!(APIHelper.form_encode(value, key, formatting:
156
+ Configuration.array_serialization))
157
+ end
158
+ encoded
159
+ end
160
+
161
+ def self.custom_merge(a, b)
162
+ x = {}
163
+ a.each do |key, value_a|
164
+ b.each do |k, value_b|
165
+ next unless key == k
166
+ x[k] = []
167
+ if value_a.instance_of? Array
168
+ value_a.each do |v|
169
+ x[k].push(v)
170
+ end
171
+ else
172
+ x[k].push(value_a)
173
+ end
174
+ if value_b.instance_of? Array
175
+ value_b.each do |v|
176
+ x[k].push(v)
177
+ end
178
+ else
179
+ x[k].push(value_b)
180
+ end
181
+ a.delete(k)
182
+ b.delete(k)
183
+ end
184
+ end
185
+ x.merge!(a)
186
+ x.merge!(b)
187
+ x
188
+ end
189
+
190
+ # Form encodes an object.
191
+ # @param [Dynamic] An object to form encode.
192
+ # @param [String] The name of the object.
193
+ # @return [Hash] A form encoded representation of the object in the form
194
+ # of a hash.
195
+ def self.form_encode(obj, instance_name, formatting: 'indexed')
196
+ retval = {}
197
+
198
+ serializable_types = [String, Numeric, TrueClass,
199
+ FalseClass, Date, DateTime]
200
+
201
+ # If this is a structure, resolve it's field names.
202
+ obj = obj.to_hash if obj.is_a? BaseModel
203
+
204
+ # Create a form encoded hash for this object.
205
+ if obj.nil?
206
+ nil
207
+ elsif obj.instance_of? Array
208
+ if formatting == 'indexed'
209
+ obj.each_with_index do |value, index|
210
+ retval.merge!(APIHelper.form_encode(value, instance_name + '[' +
211
+ index.to_s + ']'))
212
+ end
213
+ elsif serializable_types.map { |x| obj[0].is_a? x }.any?
214
+ obj.each do |value|
215
+ abc = if formatting == 'unindexed'
216
+ APIHelper.form_encode(value, instance_name + '[]',
217
+ formatting: formatting)
218
+ else
219
+ APIHelper.form_encode(value, instance_name,
220
+ formatting: formatting)
221
+ end
222
+ retval = APIHelper.custom_merge(retval, abc)
223
+ # print retval
224
+ end
225
+ else
226
+ obj.each_with_index do |value, index|
227
+ retval.merge!(APIHelper.form_encode(value, instance_name + '[' +
228
+ index.to_s + ']', formatting: formatting))
229
+ end
230
+ end
231
+ elsif obj.instance_of? Hash
232
+ obj.each do |key, value|
233
+ retval.merge!(APIHelper.form_encode(value, instance_name + '[' +
234
+ key + ']', formatting: formatting))
235
+ end
236
+ else
237
+ retval[instance_name] = obj
238
+ end
239
+ retval
240
+ end
241
+
242
+ # Safely converts a string into an rfc3339 DateTime object
243
+ # @param [String] The datetime string
244
+ # @return [DateTime] A DateTime object of rfc3339 format
245
+ def self.rfc3339(date_time)
246
+ # missing timezone information
247
+ if date_time.end_with?('Z') || date_time.index('+')
248
+ DateTime.rfc3339(date_time)
249
+ else
250
+ DateTime.rfc3339(date_time + 'Z')
251
+ end
252
+ end
253
+ end
254
+ end
255
+
256
+ # Extend types to support to_bool.
257
+ module ToBoolean
258
+ def to_bool
259
+ return true if self == true || to_s.strip =~ /^(true|yes|y|1)$/i
260
+ false
261
+ end
262
+ end
263
+
264
+ # Extend NilClass type to support to_bool.
265
+ class NilClass; include ToBoolean; end
266
+ # Extend TrueClass type to support to_bool.
267
+ class TrueClass; include ToBoolean; end
268
+ # Extend FalseClass type to support to_bool.
269
+ class FalseClass; include ToBoolean; end
270
+ # Extend Numeric type to support to_bool.
271
+ class Numeric; include ToBoolean; end
272
+ # Extend String type to support to_bool.
273
+ class String; include ToBoolean; end