socketlabs-injectionapi 1.4.0 → 1.4.2
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 +4 -4
- data/gemfile.lock +18 -18
- data/lib/socketlabs/injectionapi/core/api_key_parse_result.rb +45 -0
- data/lib/socketlabs/injectionapi/core/api_key_parser.rb +62 -0
- data/lib/socketlabs/injectionapi/core/http_request.rb +14 -18
- data/lib/socketlabs/injectionapi/socketlabsclient.rb +16 -1
- data/lib/socketlabs/version.rb +1 -1
- data/lib/socketlabs-injectionapi.rb +4 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f557916e593c897978060429a0bdb300c61f5047fc879902a2f43ad7a8bffbab
|
4
|
+
data.tar.gz: 31a2adba06e1794c3c1b49e23bb7dbdc6de4be1bc1349e6c0d0cc5ed53cc4757
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 143016ece80ad2d42de386599a0455e1fad50172c5471ff74773fb180ec6cbd3a8d100baec4d31ffcf776a11f29bf7e2541c93633acd20bfa70fc8d397919a11
|
7
|
+
data.tar.gz: 13097dbd02d8ba26a590b42fe1da47c115049642c2eb74cad3cf1571b4e8c28ce08efbe56cabc266dd9e2e1d4a5bbc8f94fc7da25a84f4336de1971e013ea8b5
|
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,45 @@
|
|
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
|
+
# The key was found to be blank or invalid.
|
17
|
+
"InvalidEmptyOrWhitespace" =>
|
18
|
+
{
|
19
|
+
:name => "InvalidEmptyOrWhitespace",
|
20
|
+
:value =>1,
|
21
|
+
},
|
22
|
+
# The public portion of the key was unable to be parsed.
|
23
|
+
"InvalidUnableToExtractPublicPart" =>
|
24
|
+
{
|
25
|
+
:name => "InvalidUnableToExtractPublicPart",
|
26
|
+
:value =>2,
|
27
|
+
},
|
28
|
+
# The secret portion of the key was unable to be parsed.
|
29
|
+
"InvalidUnableToExtractSecretPart" =>
|
30
|
+
{
|
31
|
+
:name => "InvalidUnableToExtractSecretPart",
|
32
|
+
:value =>3,
|
33
|
+
},
|
34
|
+
# Key was successfully parsed.
|
35
|
+
"Success" =>
|
36
|
+
{
|
37
|
+
:name => "Success",
|
38
|
+
:value =>4,
|
39
|
+
}
|
40
|
+
}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
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 SendResponse 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
|
-
|
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
|
-
|
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
|
|
data/lib/socketlabs/version.rb
CHANGED
@@ -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.
|
4
|
+
version: 1.4.2
|
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-
|
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.
|
84
|
+
rubygems_version: 3.4.10
|
83
85
|
signing_key:
|
84
86
|
specification_version: 4
|
85
87
|
summary: SocketLabs Injection Api
|