pepipost_gem 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ # This file was automatically generated by APIMATIC v2.0
2
+ # ( https://apimatic.io ).
3
+
4
+ module PepipostGem
5
+ # All configuration including auth info and base URI for the API access
6
+ # are configured in this class.
7
+ class Configuration
8
+ # The base Uri for API calls
9
+ @base_uri = 'http://api.pepipost.com'
10
+
11
+ # The attribute accessors for public properties.
12
+ class << self
13
+ attr_accessor :array_serialization
14
+ attr_accessor :base_uri
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,49 @@
1
+ # This file was automatically generated by APIMATIC v2.0
2
+ # ( https://apimatic.io ).
3
+
4
+ module PepipostGem
5
+ # Base controller.
6
+ class BaseController
7
+ attr_accessor :http_client, :http_call_back
8
+
9
+ def initialize(http_client: nil, http_call_back: nil)
10
+ @http_client = http_client || FaradayClient.new
11
+ @http_call_back = http_call_back
12
+
13
+ @global_headers = {
14
+ 'user-agent' => 'APIMATIC 2.0'
15
+ }
16
+ end
17
+
18
+ def validate_parameters(args)
19
+ args.each do |_name, value|
20
+ if value.nil?
21
+ raise ArgumentError, "Required parameter #{_name} cannot be nil."
22
+ end
23
+ end
24
+ end
25
+
26
+ def execute_request(request, binary: false)
27
+ @http_call_back.on_before_request(request) if @http_call_back
28
+
29
+ APIHelper.clean_hash(request.headers)
30
+ request.headers = @global_headers.clone.merge(request.headers)
31
+
32
+ response = if binary
33
+ @http_client.execute_as_binary(request)
34
+ else
35
+ @http_client.execute_as_string(request)
36
+ end
37
+ context = HttpContext.new(request, response)
38
+
39
+ @http_call_back.on_after_response(context) if @http_call_back
40
+
41
+ context
42
+ end
43
+
44
+ def validate_response(context)
45
+ # raise APIException.new 'HTTP Response Not OK', context unless
46
+ # context.response.status_code.between?(200, 208) # [200,208] = HTTP OK
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,59 @@
1
+ # This file was automatically generated by APIMATIC v2.0
2
+ # ( https://apimatic.io ).
3
+
4
+ module PepipostGem
5
+ # EmailController
6
+ class EmailController < BaseController
7
+ @instance = EmailController.new
8
+
9
+ class << self
10
+ attr_accessor :instance
11
+ end
12
+
13
+ def instance
14
+ self.class.instance
15
+ end
16
+
17
+ # This Endpoint sends emails with the credentials passed.
18
+ # @param [String] api_key Optional parameter: Generated header parameter.
19
+ # Example value ='5ce7096ed4bf2b39dfa932ff5fa84ed9ed8'
20
+ # @param [EmailBody] body Optional parameter: The body passed will be json
21
+ # format.
22
+ # @return SendEmailResponse response from the API call
23
+ def create_send_email(api_key = nil,
24
+ body = nil)
25
+ # Prepare query url.
26
+ _query_builder = Configuration.base_uri.dup
27
+ _query_builder << '/v2/sendEmail'
28
+ _query_url = APIHelper.clean_url _query_builder
29
+
30
+ # Prepare headers.
31
+ _headers = {
32
+ 'accept' => 'application/json',
33
+ 'content-type' => 'application/json; charset=utf-8',
34
+ 'api_key' => api_key
35
+ }
36
+
37
+ # Prepare and execute HttpRequest.
38
+ _request = @http_client.post(
39
+ _query_url,
40
+ headers: _headers,
41
+ parameters: body.to_json
42
+ )
43
+ _context = execute_request(_request)
44
+
45
+ # Validate response against endpoint and global error codes.
46
+ if _context.response.status_code == 405
47
+ raise APIException.new(
48
+ 'Method not allowed',
49
+ _context
50
+ )
51
+ end
52
+ validate_response(_context)
53
+
54
+ # Return appropriate response type.
55
+ decoded = APIHelper.json_deserialize(_context.response.raw_body)
56
+ SendEmailResponse.from_hash(decoded)
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,18 @@
1
+ # This file was automatically generated by APIMATIC v2.0
2
+ # ( https://apimatic.io ).
3
+
4
+ module PepipostGem
5
+ # Class for exceptions when there is a network error, status code error, etc.
6
+ class APIException < StandardError
7
+ attr_reader :context, :response_code
8
+
9
+ # The constructor.
10
+ # @param [String] The reason for raising an exception.
11
+ # @param [HttpContext] The HttpContext of the API call.
12
+ def initialize(reason, context)
13
+ super(reason)
14
+ @context = context
15
+ @response_code = context.response.status_code
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,55 @@
1
+ # This file was automatically generated by APIMATIC v2.0
2
+ # ( https://apimatic.io ).
3
+ require 'faraday/http_cache'
4
+
5
+ module PepipostGem
6
+ # An implementation of HttpClient.
7
+ class FaradayClient < HttpClient
8
+ # The constructor.
9
+ def initialize(timeout: nil, cache: false,
10
+ max_retries: nil, retry_interval: nil)
11
+ @connection = Faraday.new do |faraday|
12
+ faraday.use Faraday::HttpCache, serializer: Marshal if cache
13
+ faraday.request :multipart
14
+ faraday.request :url_encoded
15
+ faraday.ssl[:ca_file] = Certifi.where
16
+ faraday.adapter Faraday.default_adapter
17
+ faraday.options[:params_encoder] = Faraday::FlatParamsEncoder
18
+ faraday.options[:open_timeout] = timeout if timeout
19
+ faraday.request :retry, max: max_retries, interval: if max_retries &&
20
+ retry_interval
21
+ retry_interval
22
+ end
23
+ end
24
+ end
25
+
26
+ # Method overridden from HttpClient.
27
+ def execute_as_string(http_request)
28
+ response = @connection.send(
29
+ http_request.http_method.downcase,
30
+ http_request.query_url
31
+ ) do |request|
32
+ request.headers = http_request.headers
33
+ request.body = http_request.parameters
34
+ end
35
+ convert_response(response)
36
+ end
37
+
38
+ # Method overridden from HttpClient.
39
+ def execute_as_binary(http_request)
40
+ response = @connection.send(
41
+ http_request.http_method.downcase,
42
+ http_request.query_url
43
+ ) do |request|
44
+ request.headers = http_request.headers
45
+ request.body = http_request.parameters
46
+ end
47
+ convert_response(response)
48
+ end
49
+
50
+ # Method overridden from HttpClient.
51
+ def convert_response(response)
52
+ HttpResponse.new(response.status, response.headers, response.body)
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,22 @@
1
+ # This file was automatically generated by APIMATIC v2.0
2
+ # ( https://apimatic.io ).
3
+
4
+ module PepipostGem
5
+ # HttpCallBack allows defining callables for pre and post API calls.
6
+ class HttpCallBack
7
+ # A controller will call this method before making an HTTP Request.
8
+ # @param [HttpRequest] The HttpRequest object which the HttpClient
9
+ # will execute.
10
+ def on_before_request(_http_request)
11
+ raise NotImplementedError, 'This method needs
12
+ to be implemented in a child class.'
13
+ end
14
+
15
+ # A controller will call this method after making an HTTP Request.
16
+ # @param [HttpContext] The HttpContext of the API call.
17
+ def on_after_response(_http_context)
18
+ raise NotImplementedError, 'This method needs
19
+ to be implemented in a child class.'
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,102 @@
1
+ # This file was automatically generated by APIMATIC v2.0
2
+ # ( https://apimatic.io ).
3
+
4
+ module PepipostGem
5
+ # An interface for the methods that an HTTP Client must implement.
6
+ #
7
+ # This class should not be instantiated but should be used as a base class
8
+ # for HTTP Client classes.
9
+ class HttpClient
10
+ # Execute an HttpRequest when the response is expected to be a string.
11
+ # @param [HttpRequest] The HttpRequest to be executed.
12
+ def execute_as_string(_http_request)
13
+ raise NotImplementedError, 'This method needs
14
+ to be implemented in a child class.'
15
+ end
16
+
17
+ # Execute an HttpRequest when the response is expected to be binary.
18
+ # @param [HttpRequest] The HttpRequest to be executed.
19
+ def execute_as_binary(_http_request)
20
+ raise NotImplementedError, 'This method needs
21
+ to be implemented in a child class.'
22
+ end
23
+
24
+ # Converts the HTTP Response from the client to an HttpResponse object.
25
+ # @param [Dynamic] The response object received from the client.
26
+ def convert_response(_response)
27
+ raise NotImplementedError, 'This method needs
28
+ to be implemented in a child class.'
29
+ end
30
+
31
+ # Get a GET HttpRequest object.
32
+ # @param [String] The URL to send the request to.
33
+ # @param [Hash, Optional] The headers for the HTTP Request.
34
+ def get(query_url,
35
+ headers: {})
36
+ HttpRequest.new(HttpMethodEnum::GET,
37
+ query_url,
38
+ headers: headers)
39
+ end
40
+
41
+ # Get a HEAD HttpRequest object.
42
+ # @param [String] The URL to send the request to.
43
+ # @param [Hash, Optional] The headers for the HTTP Request.
44
+ def head(query_url,
45
+ headers: {})
46
+ HttpRequest.new(HttpMethodEnum::HEAD,
47
+ query_url,
48
+ headers: headers)
49
+ end
50
+
51
+ # Get a POST HttpRequest object.
52
+ # @param [String] The URL to send the request to.
53
+ # @param [Hash, Optional] The headers for the HTTP Request.
54
+ # @param [Hash, Optional] The parameters for the HTTP Request.
55
+ def post(query_url,
56
+ headers: {},
57
+ parameters: {})
58
+ HttpRequest.new(HttpMethodEnum::POST,
59
+ query_url,
60
+ headers: headers,
61
+ parameters: parameters)
62
+ end
63
+
64
+ # Get a PUT HttpRequest object.
65
+ # @param [String] The URL to send the request to.
66
+ # @param [Hash, Optional] The headers for the HTTP Request.
67
+ # @param [Hash, Optional] The parameters for the HTTP Request.
68
+ def put(query_url,
69
+ headers: {},
70
+ parameters: {})
71
+ HttpRequest.new(HttpMethodEnum::PUT,
72
+ query_url,
73
+ headers: headers,
74
+ parameters: parameters)
75
+ end
76
+
77
+ # Get a PATCH HttpRequest object.
78
+ # @param [String] The URL to send the request to.
79
+ # @param [Hash, Optional] The headers for the HTTP Request.
80
+ # @param [Hash, Optional] The parameters for the HTTP Request.
81
+ def patch(query_url,
82
+ headers: {},
83
+ parameters: {})
84
+ HttpRequest.new(HttpMethodEnum::PATCH,
85
+ query_url,
86
+ headers: headers,
87
+ parameters: parameters)
88
+ end
89
+
90
+ # Get a DELETE HttpRequest object.
91
+ # @param [String] The URL to send the request to.
92
+ # @param [Hash, Optional] The headers for the HTTP Request.
93
+ def delete(query_url,
94
+ headers: {},
95
+ parameters: {})
96
+ HttpRequest.new(HttpMethodEnum::DELETE,
97
+ query_url,
98
+ headers: headers,
99
+ parameters: parameters)
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,18 @@
1
+ # This file was automatically generated by APIMATIC v2.0
2
+ # ( https://apimatic.io ).
3
+
4
+ module PepipostGem
5
+ # Represents an Http call in context.
6
+ class HttpContext
7
+ attr_accessor :request, :response
8
+
9
+ # The constructor.
10
+ # @param [HttpRequest] An HttpRequest object representing the HTTP request.
11
+ # @param [HttpResponse] An HttpResponse object representing the HTTP
12
+ # response.
13
+ def initialize(request, response)
14
+ @request = request
15
+ @response = response
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,11 @@
1
+ # This file was automatically generated by APIMATIC v2.0
2
+ # ( https://apimatic.io ).
3
+
4
+ module PepipostGem
5
+ # HTTP Methods Enumeration.
6
+ class HttpMethodEnum
7
+ HTTPMETHODENUM = [GET = 'GET'.freeze, POST = 'POST'.freeze,
8
+ PUT = 'PUT'.freeze, PATCH = 'PATCH'.freeze,
9
+ DELETE = 'DELETE'.freeze, HEAD = 'HEAD'.freeze].freeze
10
+ end
11
+ end
@@ -0,0 +1,48 @@
1
+ # This file was automatically generated by APIMATIC v2.0
2
+ # ( https://apimatic.io ).
3
+
4
+ module PepipostGem
5
+ # Represents a single Http Request.
6
+ class HttpRequest
7
+ attr_accessor :http_method, :query_url, :headers,
8
+ :parameters, :username, :password
9
+
10
+ # The constructor.
11
+ # @param [HttpMethodEnum] The HTTP method.
12
+ # @param [String] The URL to send the request to.
13
+ # @param [Hash, Optional] The headers for the HTTP Request.
14
+ # @param [Hash, Optional] The parameters for the HTTP Request.
15
+ def initialize(http_method,
16
+ query_url,
17
+ headers: {},
18
+ parameters: {})
19
+ @http_method = http_method
20
+ @query_url = query_url
21
+ @headers = headers
22
+ @parameters = parameters
23
+ end
24
+
25
+ # Add a header to the HttpRequest.
26
+ # @param [String] The name of the header.
27
+ # @param [String] The value of the header.
28
+ def add_header(name, value)
29
+ @headers[name] = value
30
+ end
31
+
32
+ # Add a parameter to the HttpRequest.
33
+ # @param [String] The name of the parameter.
34
+ # @param [String] The value of the parameter.
35
+ def add_parameter(name, value)
36
+ @parameters[name] = value
37
+ end
38
+
39
+ # Add a query parameter to the HttpRequest.
40
+ # @param [String] The name of the query parameter.
41
+ # @param [String] The value of the query parameter.
42
+ def add_query_parameter(name, value)
43
+ @query_url = APIHelper.append_url_with_query_parameters(@query_url,
44
+ name => value)
45
+ @query_url = APIHelper.clean_url(@query_url)
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,21 @@
1
+ # This file was automatically generated by APIMATIC v2.0
2
+ # ( https://apimatic.io ).
3
+
4
+ module PepipostGem
5
+ # Http response received.
6
+ class HttpResponse
7
+ attr_accessor :status_code, :headers, :raw_body
8
+
9
+ # The constructor
10
+ # @param [Integer] The status code returned by the server.
11
+ # @param [Hash] The headers sent by the server in the response.
12
+ # @param [String] The raw body of the response.
13
+ def initialize(status_code,
14
+ headers,
15
+ raw_body)
16
+ @status_code = status_code
17
+ @headers = headers
18
+ @raw_body = raw_body
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,42 @@
1
+ # This file was automatically generated by APIMATIC v2.0
2
+ # ( https://apimatic.io ).
3
+
4
+ module PepipostGem
5
+ # Attachments Model.
6
+ class Attachments < BaseModel
7
+ # TODO: Write general description for this method
8
+ # @return [String]
9
+ attr_accessor :file_content
10
+
11
+ # TODO: Write general description for this method
12
+ # @return [String]
13
+ attr_accessor :file_name
14
+
15
+ # A mapping from model property names to API property names.
16
+ def self.names
17
+ @_hash = {} if @_hash.nil?
18
+ @_hash['file_content'] = 'fileContent'
19
+ @_hash['file_name'] = 'fileName'
20
+ @_hash
21
+ end
22
+
23
+ def initialize(file_content = nil,
24
+ file_name = nil)
25
+ @file_content = file_content
26
+ @file_name = file_name
27
+ end
28
+
29
+ # Creates an instance of the object from a hash.
30
+ def self.from_hash(hash)
31
+ return nil unless hash
32
+
33
+ # Extract variables from the hash.
34
+ file_content = hash['fileContent']
35
+ file_name = hash['fileName']
36
+
37
+ # Create object from extracted values.
38
+ Attachments.new(file_content,
39
+ file_name)
40
+ end
41
+ end
42
+ end