socketlabs-injectionapi 1.1.0 → 1.4.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.
@@ -0,0 +1,61 @@
1
+ require_relative '../version.rb'
2
+
3
+ module SocketLabs
4
+ module InjectionApi
5
+ class RetrySettings
6
+
7
+ private
8
+ attr_accessor :default_number_of_retries
9
+ attr_accessor :maximum_allowed_number_of_retries
10
+ attr_accessor :minimum_retry_time
11
+ attr_accessor :maximum_retry_time
12
+
13
+ public
14
+ attr_accessor :maximum_number_of_retries
15
+
16
+ def initialize(maximum_retries=nil)
17
+
18
+ @default_number_of_retries = 0
19
+ @maximum_allowed_number_of_retries = 5
20
+ @minimum_retry_time = 1
21
+ @maximum_retry_time = 10
22
+
23
+ unless maximum_retries.nil?
24
+
25
+ if maximum_retries < 0
26
+ raise ArgumentError.new "maximum_number_of_retries must be greater than 0"
27
+ end
28
+
29
+ if maximum_retries > @maximum_allowed_number_of_retries
30
+ raise ArgumentError.new "The maximum number of allowed retries is " + @maximum_allowed_number_of_retries
31
+ end
32
+
33
+ @maximum_number_of_retries = maximum_retries
34
+
35
+ else
36
+ @maximum_number_of_retries = @default_number_of_retries
37
+ end
38
+
39
+ end
40
+
41
+ def get_next_wait_interval(number_of_attempts)
42
+
43
+ interval = [@minimum_retry_time * 1000 + get_retry_delta(number_of_attempts), @maximum_retry_time * 1000].min
44
+ interval
45
+
46
+ end
47
+
48
+ def get_retry_delta(number_of_attempts)
49
+
50
+ random = Random.new
51
+
52
+ min = (1 * 1000 * 0.8).to_i
53
+ max = (1 * 1000 * 1.2).to_i
54
+
55
+ (((2.0 ** number_of_attempts) - 1.0) * random.rand(min..max)).to_i
56
+
57
+ end
58
+
59
+ end
60
+ end
61
+ end
@@ -308,6 +308,14 @@ module SocketLabs
308
308
  :value =>37,
309
309
  :message =>"SDK Validation Error: Expected messageType of basic or bulk"
310
310
 
311
+ },
312
+
313
+ # SDK Validation Error: Message contains invalid metadata
314
+ "MessageValidationInvalidMetadata" =>
315
+ {
316
+ :name =>"MessageValidationInvalidMetadata",
317
+ :value =>38,
318
+ :message =>"SDK Validation Error: Message contains invalid metadata"
311
319
  }
312
320
 
313
321
  }
@@ -7,6 +7,8 @@ require_relative 'message/basic_message.rb'
7
7
  require_relative 'message/bulk_message.rb'
8
8
  require_relative 'core/injection_request_factory.rb'
9
9
  require_relative 'core/http_request.rb'
10
+ require_relative 'core/retryhandler.rb'
11
+ require_relative 'retrysettings.rb'
10
12
 
11
13
  module SocketLabs
12
14
  module InjectionApi
@@ -27,6 +29,8 @@ module SocketLabs
27
29
  @api_key = api_key
28
30
  @proxy = proxy
29
31
  @endpoint = "https://inject.socketlabs.com/api/v1/email"
32
+ @request_timeout = 120
33
+ @number_of_retries = 0
30
34
  end
31
35
 
32
36
  # Sends a Message message and returns the response from the Injection API.
@@ -62,6 +66,11 @@ module SocketLabs
62
66
  # The SocketLabs Injection API endpoint Url
63
67
  attr_accessor :endpoint
64
68
 
69
+ public
70
+ # The SocketLabs Injection API Request Timeout
71
+ attr_accessor :request_timeout
72
+ attr_accessor :number_of_retries
73
+
65
74
  def http_method
66
75
  HttpRequest.http_request_method[:Post]
67
76
  end
@@ -84,9 +93,14 @@ module SocketLabs
84
93
  debug_json = request_hash.to_json
85
94
  @request_json = debug_json
86
95
 
87
- http_request = HttpRequest.new(http_method, { :http_endpoint => @endpoint, :proxy => @proxy })
88
- response = http_request.send_request(request)
89
- @response_json = response.to_json
96
+ http_request = HttpRequest.new(http_method, { :http_endpoint => @endpoint, :proxy => @proxy, :timeout => @request_timeout })
97
+ retry_handler = RetryHandler.new(http_request, @endpoint, RetrySettings.new(@number_of_retries))
98
+ response = retry_handler.send(request)
99
+
100
+ parser = InjectionResponseParser.new
101
+ result = parser.parse(response)
102
+
103
+ @response_json = result.to_json
90
104
 
91
105
  end
92
106
 
@@ -108,9 +122,14 @@ module SocketLabs
108
122
  debug_json = request_hash.to_json
109
123
  @request_json = debug_json
110
124
 
111
- http_request = HttpRequest.new(http_method, { :http_endpoint => @endpoint, :proxy => @proxy })
112
- response = http_request.send_request(request)
113
- @response_json = response.to_json
125
+ http_request = HttpRequest.new(http_method, { :http_endpoint => @endpoint, :proxy => @proxy, :timeout => @request_timeout })
126
+ retry_handler = RetryHandler.new(http_request, @endpoint, RetrySettings.new(@number_of_retries))
127
+ response = retry_handler.send(request)
128
+
129
+ parser = InjectionResponseParser.new
130
+ result = parser.parse(response)
131
+
132
+ @response_json = result.to_json
114
133
 
115
134
  end
116
135
 
@@ -1,5 +1,5 @@
1
1
  module SocketLabs
2
2
  module InjectionApi
3
- VERSION = '1.1.0'
3
+ VERSION = '1.4.0'
4
4
  end
5
5
  end
@@ -1,3 +1,5 @@
1
+ require 'json'
2
+
1
3
  require_relative 'socketlabs/injectionapi/core/send_validator'
2
4
  require_relative 'socketlabs/injectionapi/core/string_extension'
3
5
  require_relative 'socketlabs/injectionapi/address_result'
@@ -5,6 +7,7 @@ require_relative 'socketlabs/injectionapi/proxy'
5
7
  require_relative 'socketlabs/injectionapi/send_response'
6
8
  require_relative 'socketlabs/injectionapi/send_result'
7
9
  require_relative 'socketlabs/injectionapi/socketlabsclient'
10
+ require_relative 'socketlabs/injectionapi/retrysettings'
8
11
  require_relative 'socketlabs/injectionapi/message/attachment'
9
12
  require_relative 'socketlabs/injectionapi/message/message_base'
10
13
  require_relative 'socketlabs/injectionapi/message/basic_message'
@@ -24,4 +27,6 @@ require_relative 'socketlabs/injectionapi/core/serialization/message_json'
24
27
  require_relative 'socketlabs/injectionapi/core/serialization/message_result_dto'
25
28
  require_relative 'socketlabs/injectionapi/core/injection_request_factory'
26
29
  require_relative 'socketlabs/injectionapi/core/http_request'
27
- require_relative 'socketlabs/injectionapi/core/http_response'
30
+ require_relative 'socketlabs/injectionapi/core/retryhandler'
31
+ require_relative 'socketlabs/injectionapi/core/http_response'
32
+ require_relative 'socketlabs/injectionapi/exceptions/server_exception'
@@ -6,13 +6,13 @@ require 'socketlabs/version.rb'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'socketlabs-injectionapi'
8
8
  spec.version = SocketLabs::InjectionApi::VERSION
9
- spec.authors = ['David Schrenker']
9
+ spec.authors = ['David Schrenker', 'Praneeth Chandra', 'Reid Workman']
10
10
  spec.email = 'developers@socketlabs.com'
11
11
  spec.summary = 'SocketLabs Injection Api'
12
12
  spec.description = 'SocketLabs Email Delivery Ruby Client library'
13
13
  spec.homepage = 'https://github.com/socketlabs/socketlabs-ruby'
14
14
 
15
- spec.required_ruby_version = '>= 2.4'
15
+ spec.required_ruby_version = '>= 3.1.2'
16
16
 
17
17
  spec.license = 'MIT'
18
18
  files = `git ls-files -z`.split("\x0").reject do |f|
metadata CHANGED
@@ -1,14 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: socketlabs-injectionapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Schrenker
8
- autorequire:
8
+ - Praneeth Chandra
9
+ - Reid Workman
10
+ autorequire:
9
11
  bindir: bin
10
12
  cert_chain: []
11
- date: 2020-08-25 00:00:00.000000000 Z
13
+ date: 2023-01-18 00:00:00.000000000 Z
12
14
  dependencies: []
13
15
  description: SocketLabs Email Delivery Ruby Client library
14
16
  email: developers@socketlabs.com
@@ -17,12 +19,6 @@ extensions: []
17
19
  extra_rdoc_files: []
18
20
  files:
19
21
  - ".gitignore"
20
- - ".idea/inspectionProfiles/Project_Default.xml"
21
- - ".idea/misc.xml"
22
- - ".idea/modules.xml"
23
- - ".idea/socketlabs-ruby.iml"
24
- - ".idea/vcs.xml"
25
- - ".idea/workspace.xml"
26
22
  - CONTRIBUTING.md
27
23
  - LICENSE.MD
28
24
  - README.MD
@@ -34,6 +30,7 @@ files:
34
30
  - lib/socketlabs/injectionapi/core/http_response.rb
35
31
  - lib/socketlabs/injectionapi/core/injection_request_factory.rb
36
32
  - lib/socketlabs/injectionapi/core/injection_response_parser.rb
33
+ - lib/socketlabs/injectionapi/core/retryhandler.rb
37
34
  - lib/socketlabs/injectionapi/core/send_validator.rb
38
35
  - lib/socketlabs/injectionapi/core/serialization/address_json.rb
39
36
  - lib/socketlabs/injectionapi/core/serialization/attachment_json.rb
@@ -44,7 +41,9 @@ files:
44
41
  - lib/socketlabs/injectionapi/core/serialization/merge_field_json.rb
45
42
  - lib/socketlabs/injectionapi/core/serialization/message_json.rb
46
43
  - lib/socketlabs/injectionapi/core/serialization/message_result_dto.rb
44
+ - lib/socketlabs/injectionapi/core/serialization/metadata_json.rb
47
45
  - lib/socketlabs/injectionapi/core/string_extension.rb
46
+ - lib/socketlabs/injectionapi/exceptions/server_exception.rb
48
47
  - lib/socketlabs/injectionapi/message/attachment.rb
49
48
  - lib/socketlabs/injectionapi/message/basic_message.rb
50
49
  - lib/socketlabs/injectionapi/message/bulk_message.rb
@@ -53,7 +52,9 @@ files:
53
52
  - lib/socketlabs/injectionapi/message/email_address.rb
54
53
  - lib/socketlabs/injectionapi/message/merge_data.rb
55
54
  - lib/socketlabs/injectionapi/message/message_base.rb
55
+ - lib/socketlabs/injectionapi/message/metadata.rb
56
56
  - lib/socketlabs/injectionapi/proxy.rb
57
+ - lib/socketlabs/injectionapi/retrysettings.rb
57
58
  - lib/socketlabs/injectionapi/send_response.rb
58
59
  - lib/socketlabs/injectionapi/send_result.rb
59
60
  - lib/socketlabs/injectionapi/socketlabsclient.rb
@@ -63,7 +64,7 @@ homepage: https://github.com/socketlabs/socketlabs-ruby
63
64
  licenses:
64
65
  - MIT
65
66
  metadata: {}
66
- post_install_message:
67
+ post_install_message:
67
68
  rdoc_options: []
68
69
  require_paths:
69
70
  - lib
@@ -71,15 +72,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
71
72
  requirements:
72
73
  - - ">="
73
74
  - !ruby/object:Gem::Version
74
- version: '2.4'
75
+ version: 3.1.2
75
76
  required_rubygems_version: !ruby/object:Gem::Requirement
76
77
  requirements:
77
78
  - - ">="
78
79
  - !ruby/object:Gem::Version
79
80
  version: '0'
80
81
  requirements: []
81
- rubygems_version: 3.0.3
82
- signing_key:
82
+ rubygems_version: 3.3.7
83
+ signing_key:
83
84
  specification_version: 4
84
85
  summary: SocketLabs Injection Api
85
86
  test_files: []
@@ -1,7 +0,0 @@
1
- <component name="InspectionProjectProfileManager">
2
- <profile version="1.0">
3
- <option name="myName" value="Project Default" />
4
- <inspection_tool class="Rubocop" enabled="false" level="WARNING" enabled_by_default="false" />
5
- <inspection_tool class="RubyTooManyInstanceVariablesInspection" enabled="false" level="WARNING" enabled_by_default="false" />
6
- </profile>
7
- </component>
data/.idea/misc.xml DELETED
@@ -1,7 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="JavaScriptSettings">
4
- <option name="languageLevel" value="ES6" />
5
- </component>
6
- <component name="ProjectRootManager" version="2" project-jdk-name="ruby-2.2.6-p396" project-jdk-type="RUBY_SDK" />
7
- </project>
data/.idea/modules.xml DELETED
@@ -1,8 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="ProjectModuleManager">
4
- <modules>
5
- <module fileurl="file://$PROJECT_DIR$/.idea/socketlabs-ruby.iml" filepath="$PROJECT_DIR$/.idea/socketlabs-ruby.iml" />
6
- </modules>
7
- </component>
8
- </project>
@@ -1,12 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <module type="RUBY_MODULE" version="4">
3
- <component name="ModuleRunConfigurationManager">
4
- <shared />
5
- </component>
6
- <component name="NewModuleRootManager">
7
- <content url="file://$MODULE_DIR$" />
8
- <orderEntry type="jdk" jdkName="ruby-2.6.6-p146" jdkType="RUBY_SDK" />
9
- <orderEntry type="sourceFolder" forTests="false" />
10
- <orderEntry type="library" scope="PROVIDED" name="bundler (v1.17.2, ruby-2.6.6-p146) [gem]" level="application" />
11
- </component>
12
- </module>
data/.idea/vcs.xml DELETED
@@ -1,7 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="VcsDirectoryMappings">
4
- <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
- <mapping directory="$PROJECT_DIR$/socketlabs-injectionapi-1.0.0" vcs="Git" />
6
- </component>
7
- </project>