socketlabs-injectionapi 1.4.0 → 1.4.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 166ba13c298ad93c8c2ea44c9a2af22399a3a00c5bde303e7daabfd080cd0563
4
- data.tar.gz: b1fcab9c9778c858306c8dfa5bc3f117a043df81383207878c2c4cb566196ec6
3
+ metadata.gz: 8cb53859e473d0b39783967b98f0c1d44a5bbd2d9e3a41518e9831dad9d3274a
4
+ data.tar.gz: c710342add94849a727216e28ab82e33c07bb57b4ec80fd370f246a11c34520d
5
5
  SHA512:
6
- metadata.gz: 9b793d816754372596a2c8681bb6d5ec226d4a06a4b6985d0ebe801883adbbdeab1c2973a666500c95b642639084c24dd03e6e524cc0b45e4424eb15c548053d
7
- data.tar.gz: 3700a0da0d4a12a79446dd45fcf63043909cc454efc6963341164a5cfdf55e6b33f2c5337540cb1b9035dbcaa4ba15f3e79e93b2352e07d16285e9b5eaffef04
6
+ metadata.gz: 56d7c9867149469570940396836f8c69c2bf1e060774932ae5f7d8a3b98ecb9a89faf5544b03318cb489984222e003361078518bf6cecc12c2f1caa8e0f9ee1d
7
+ data.tar.gz: f09a1e585ba59a97862ff888dc659f2a49ce3e91b419c984389daea0910843d60829afe915ea1614ec816da8d0aae3c101ff9ff440e21a27d6c276016f81bb16
data/README.MD CHANGED
@@ -216,6 +216,8 @@ For more information about AMP please see [AMP Project](https://amp.dev/document
216
216
 
217
217
  <a name="version"></a>
218
218
  # Version
219
+ * 1.4.2 - Adding API Key Authorization
220
+ * 1.4.0 - Adding Metadata and Tags
219
221
  * 1.2.1 - Adding optional retry logic for Http requests. If configured, the request will retry when certain 500 errors occur (500, 502, 503, 504)
220
222
  * 1.1.1 - Adding request timeout value on the client for Http requests
221
223
  * 1.1.0 - Adds Amp Html Support
data/gemfile.lock CHANGED
@@ -1,18 +1,18 @@
1
- PATH
2
- remote: .
3
- specs:
4
- socketlabs-injectionapi (1.4.1)
5
-
6
- GEM
7
- remote: http://rubygems.org/
8
- specs:
9
-
10
- PLATFORMS
11
- x64-mingw-ucrt
12
- x64-mingw32
13
-
14
- DEPENDENCIES
15
- socketlabs-injectionapi!
16
-
17
- BUNDLED WITH
18
- 2.3.7
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ socketlabs-injectionapi (1.4.1)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+
10
+ PLATFORMS
11
+ x64-mingw-ucrt
12
+ x64-mingw32
13
+
14
+ DEPENDENCIES
15
+ socketlabs-injectionapi!
16
+
17
+ BUNDLED WITH
18
+ 2.3.7
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+
4
+ module SocketLabs
5
+ module InjectionApi
6
+ module Core
7
+ class ApiKeyParseResult
8
+ def self.enum
9
+ {
10
+ # No result could be produced.
11
+ "None" =>
12
+ {
13
+ :name => "None",
14
+ :value => 0,
15
+ },
16
+ # Invalid key length was found.
17
+ "InvalidKeyLength" =>
18
+ {
19
+ :name => "InvalidKeyLength",
20
+ :value => 1,
21
+ },
22
+ # Invalid key format was found.
23
+ "InvalidKeyFormat" =>
24
+ {
25
+ :name => "InvalidKeyFormat",
26
+ :value => 2,
27
+ },
28
+ # The key was found to be blank or invalid.
29
+ "InvalidEmptyOrWhitespace" =>
30
+ {
31
+ :name => "InvalidEmptyOrWhitespace",
32
+ :value => 3,
33
+ },
34
+ # The public portion of the key was unable to be parsed.
35
+ "InvalidUnableToExtractPublicPart" =>
36
+ {
37
+ :name => "InvalidUnableToExtractPublicPart",
38
+ :value => 4,
39
+ },
40
+ # The secret portion of the key was unable to be parsed.
41
+ "InvalidUnableToExtractSecretPart" =>
42
+ {
43
+ :name => "InvalidUnableToExtractSecretPart",
44
+ :value => 5,
45
+ },
46
+ # The public portion of the key is the incorrect length.
47
+ "InvalidPublicPartLength" =>
48
+ {
49
+ :name => "InvalidPublicPartLength",
50
+ :value => 6,
51
+ },
52
+ # The secret portion of the key is the incorrect length.
53
+ "InvalidSecretPartLength" =>
54
+ {
55
+ :name => "InvalidSecretPartLength",
56
+ :value => 7,
57
+ },
58
+ # Key was successfully parsed.
59
+ "Success" =>
60
+ {
61
+ :name => "Success",
62
+ :value => 8,
63
+ }
64
+ }
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+
4
+ module SocketLabs
5
+ module InjectionApi
6
+ module Core
7
+ class ApiKeyParser
8
+
9
+
10
+ # Parse the API key to determine what kind of key was provided.
11
+ # @param [String] wholeApiKey: A ApiKeyParseResult with the parsing results
12
+ # @return [ApiKeyParseResult] the ApiKeyParseResult from the request
13
+ def parse(
14
+ wholeApiKey
15
+ )
16
+
17
+
18
+
19
+
20
+ if wholeApiKey.nil? || wholeApiKey.empty?
21
+ ApiKeyParseResult.enum["InvalidEmptyOrWhitespace"]
22
+ end
23
+
24
+ if wholeApiKey.length != 61
25
+ ApiKeyParseResult.enum["InvalidKeyLength"]
26
+ end
27
+
28
+ if wholeApiKey.index('.') == -1
29
+ ApiKeyParseResult.enum["InvalidKeyFormat"]
30
+ end
31
+
32
+ # extract public part
33
+ # don't check more than 50 chars
34
+ publicPartEnd = wholeApiKey[0..50].index('.')
35
+ if publicPartEnd == -1
36
+ ApiKeyParseResult.enum["InvalidUnableToExtractPublicPart"]
37
+ end
38
+
39
+ publicPart = wholeApiKey[0..publicPartEnd]
40
+ if publicPart != 20
41
+ ApiKeyParseResult.enum["InvalidPublicPartLength"]
42
+ end
43
+
44
+ # now extract the private part
45
+ if wholeApiKey.length <= publicPartEnd + 1
46
+ ApiKeyParseResult.enum["InvalidUnableToExtractSecretPart"]
47
+ end
48
+
49
+ privatePart = wholeApiKey[publicPartEnd + 1..wholeApiKey.length]
50
+
51
+ if privatePart.length != 40
52
+ ApiKeyParseResult.enum["InvalidSecretPartLength"]
53
+ end
54
+
55
+ ApiKeyParseResult.enum["Success"]
56
+
57
+ end
58
+
59
+ end
60
+ end
61
+ end
62
+ end
@@ -43,6 +43,12 @@ module SocketLabs
43
43
  @endpoint = "https://inject.socketlabs.com/api/v1/email"
44
44
  @proxy = Array.new
45
45
  @timeout = 120
46
+ @headers =
47
+ [
48
+ { :key => "User-Agent", :value => user_agent},
49
+ { :key => "Content-Type", :value => "application/json; charset=utf-8" },
50
+ { :key => "Accept", :value => "application/json"}
51
+ ]
46
52
 
47
53
  unless arguments.nil? || arguments.empty?
48
54
 
@@ -58,6 +64,10 @@ module SocketLabs
58
64
  @timeout = arguments[:timeout]
59
65
  end
60
66
 
67
+ unless arguments[:authorization].nil? || arguments[:authorization].empty?
68
+ @headers.push({ :key => "Authorization", :value => 'Bearer ' + arguments[:authorization]})
69
+ end
70
+
61
71
  end
62
72
 
63
73
  @http = nil
@@ -73,6 +83,7 @@ module SocketLabs
73
83
 
74
84
  # send request
75
85
  response = @http.request(@request)
86
+
76
87
  http_response = HttpResponse.new(response)
77
88
 
78
89
  http_response
@@ -87,25 +98,17 @@ module SocketLabs
87
98
  "SocketLabs-ruby/#{VERSION};ruby(#{RUBY_VERSION})"
88
99
  end
89
100
 
90
- # headers to add to the request
91
- def headers
92
- [
93
- { :key => "User-Agent", :value => user_agent},
94
- { :key => "Content-Type", :value => "application/json; charset=utf-8" },
95
- { :key => "Accept", :value => "application/json"}
96
- ]
97
- end
98
-
99
101
  # add request headers
100
102
  # @param [HTTP::NET] request: the request object
101
103
  # @return [HTTP::NET] the resulting request
102
104
  def add_request_headers(request)
103
105
 
104
- request.add_field('Content-Type', 'application/json')
105
- headers.each do |item|
106
+ @headers.each do |item|
106
107
  request[item[:key]] = item[:value]
107
108
  end
109
+
108
110
  request
111
+
109
112
  end
110
113
 
111
114
  # Build the API request for HTTP::NET
@@ -130,14 +133,7 @@ module SocketLabs
130
133
  @request = add_request_headers(net_http.new(uri.request_uri))
131
134
 
132
135
  end
133
-
134
136
  end
135
-
136
-
137
-
138
-
139
-
140
-
141
137
  end
142
138
  end
143
139
  end
@@ -93,7 +93,22 @@ module SocketLabs
93
93
  debug_json = request_hash.to_json
94
94
  @request_json = debug_json
95
95
 
96
- http_request = HttpRequest.new(http_method, { :http_endpoint => @endpoint, :proxy => @proxy, :timeout => @request_timeout })
96
+ apiKeyParser = ApiKeyParser.new()
97
+ parseResult = apiKeyParser.parse(@api_key);
98
+
99
+ httpArguments = {
100
+ :http_endpoint => @endpoint,
101
+ :proxy => @proxy,
102
+ :timeout => @request_timeout,
103
+ :authorization => ''
104
+ }
105
+ if parseResult == ApiKeyParseResult.enum["Success"]
106
+ httpArguments[:authorization] = @api_key
107
+ request.api_key = ''
108
+ end
109
+
110
+ http_request = HttpRequest.new(http_method, httpArguments)
111
+
97
112
  retry_handler = RetryHandler.new(http_request, @endpoint, RetrySettings.new(@number_of_retries))
98
113
  response = retry_handler.send(request)
99
114
 
@@ -122,6 +137,20 @@ module SocketLabs
122
137
  debug_json = request_hash.to_json
123
138
  @request_json = debug_json
124
139
 
140
+ apiKeyParser = ApiKeyParser.new()
141
+ parseResult = apiKeyParser.parse(@api_key);
142
+
143
+ httpArguments = {
144
+ :http_endpoint => @endpoint,
145
+ :proxy => @proxy,
146
+ :timeout => @request_timeout,
147
+ :authorization => ''
148
+ }
149
+ if parseResult == ApiKeyParseResult.enum["Success"]
150
+ httpArguments[:authorization] = @api_key
151
+ request.api_key = ''
152
+ end
153
+
125
154
  http_request = HttpRequest.new(http_method, { :http_endpoint => @endpoint, :proxy => @proxy, :timeout => @request_timeout })
126
155
  retry_handler = RetryHandler.new(http_request, @endpoint, RetrySettings.new(@number_of_retries))
127
156
  response = retry_handler.send(request)
@@ -1,5 +1,5 @@
1
1
  module SocketLabs
2
2
  module InjectionApi
3
- VERSION = '1.4.0'
3
+ VERSION = '1.4.3'
4
4
  end
5
5
  end
@@ -16,6 +16,8 @@ require_relative 'socketlabs/injectionapi/message/bulk_recipient'
16
16
  require_relative 'socketlabs/injectionapi/message/custom_header'
17
17
  require_relative 'socketlabs/injectionapi/message/email_address'
18
18
  require_relative 'socketlabs/injectionapi/message/merge_data'
19
+
20
+ require_relative 'socketlabs/injectionapi/core/serialization/message_result_dto'
19
21
  require_relative 'socketlabs/injectionapi/core/serialization/address_json'
20
22
  require_relative 'socketlabs/injectionapi/core/serialization/attachment_json'
21
23
  require_relative 'socketlabs/injectionapi/core/serialization/custom_header_json'
@@ -26,6 +28,8 @@ require_relative 'socketlabs/injectionapi/core/serialization/merge_field_json'
26
28
  require_relative 'socketlabs/injectionapi/core/serialization/message_json'
27
29
  require_relative 'socketlabs/injectionapi/core/serialization/message_result_dto'
28
30
  require_relative 'socketlabs/injectionapi/core/injection_request_factory'
31
+ require_relative 'socketlabs/injectionapi/core/api_key_parser'
32
+ require_relative 'socketlabs/injectionapi/core/api_key_parse_result'
29
33
  require_relative 'socketlabs/injectionapi/core/http_request'
30
34
  require_relative 'socketlabs/injectionapi/core/retryhandler'
31
35
  require_relative 'socketlabs/injectionapi/core/http_response'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: socketlabs-injectionapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Schrenker
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2023-01-18 00:00:00.000000000 Z
13
+ date: 2023-05-22 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: SocketLabs Email Delivery Ruby Client library
16
16
  email: developers@socketlabs.com
@@ -26,6 +26,8 @@ files:
26
26
  - gemfile.lock
27
27
  - lib/socketlabs-injectionapi.rb
28
28
  - lib/socketlabs/injectionapi/address_result.rb
29
+ - lib/socketlabs/injectionapi/core/api_key_parse_result.rb
30
+ - lib/socketlabs/injectionapi/core/api_key_parser.rb
29
31
  - lib/socketlabs/injectionapi/core/http_request.rb
30
32
  - lib/socketlabs/injectionapi/core/http_response.rb
31
33
  - lib/socketlabs/injectionapi/core/injection_request_factory.rb
@@ -79,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
81
  - !ruby/object:Gem::Version
80
82
  version: '0'
81
83
  requirements: []
82
- rubygems_version: 3.3.7
84
+ rubygems_version: 3.4.10
83
85
  signing_key:
84
86
  specification_version: 4
85
87
  summary: SocketLabs Injection Api