telnyx 3.0.3 → 3.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5be54d16caf13e685a75cbfd110887e83dc2dce545f31174a31fe81e6812edac
4
- data.tar.gz: c614552e81376c52708450f026de087f027b77f12d51bdf35be139c94a2b3583
3
+ metadata.gz: 1c54ee2fae1e5040ea3a33bab7b8d103e0727f9a4bfd966d3ce33bd8c5fef194
4
+ data.tar.gz: f9c16f95c3bf511e70002362b18caf01f4455bbfcb79252946b665f968b1131d
5
5
  SHA512:
6
- metadata.gz: 9bc852c96c976262f1626df33ed8d7e267994ef7bbff8cff627bf5069af14b78248e38685cceb5cd4ea3a7dd29991e6f0cf85cfa214e19eb3ee2d6893937131c
7
- data.tar.gz: df43a6367eecb402752fb6a6b4603c7caada2eee86c2b951cafcb861790fefbfc54d4583f3a0dde976112020bc4d7726e50e581332c0a79a6da9f76ebc128b57
6
+ metadata.gz: 19b78fe8dab94fc40f4ed470339e612dccd1db21b059d5ee58620f57f3d02035d1aece4778d9c0179cb9f212908c62e8bddbe26894dae231dd823293b22ba2a3
7
+ data.tar.gz: 8065a019140e93780bd21c69b3479b02ebd2b90ddf1b29945e2053c768e811e12d11aa9e94f28de3ffd5f42d3a4bec576b6f8aa5b39bb132c5860cacffc901d1
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.0.3
1
+ 3.0.5
@@ -16,12 +16,13 @@ module Telnyx
16
16
  instance_methods: { create: action }
17
17
  end
18
18
 
19
- %w[token].each do |action|
20
- nested_resource_class_methods action,
21
- path: %W[#{action}],
22
- operations: [:create],
23
- instance_methods: { create: action }
19
+ # Manually create JSON response object from JWT when calling token
20
+ def create_token(params = {}, opts = {})
21
+ url = "#{resource_url}/token"
22
+ resp, opts = request(:post, url, params, opts)
23
+ Util.convert_to_telnyx_object(resp.data, opts)
24
24
  end
25
+
25
26
  # Additional action to list tags
26
27
  def self.tags(params = {}, opts = {})
27
28
  opts = Util.normalize_opts(opts)
@@ -26,7 +26,7 @@ module Telnyx
26
26
  # This may throw JSON::ParserError if the response body is not valid JSON.
27
27
  def self.from_faraday_hash(http_resp)
28
28
  resp = TelnyxResponse.new
29
- resp.data = JSON.parse(preprocess_response(http_resp[:body]), symbolize_names: true)
29
+ resp.data = parse_response_body(http_resp[:body])
30
30
  resp.http_body = http_resp[:body]
31
31
  resp.http_headers = http_resp[:headers]
32
32
  resp.http_status = http_resp[:status]
@@ -34,6 +34,18 @@ module Telnyx
34
34
  resp
35
35
  end
36
36
 
37
+ def self.parse_response_body(body)
38
+ if jwt_format?(body)
39
+ { token: body }
40
+ else
41
+ JSON.parse(preprocess_response(body), symbolize_names: true)
42
+ end
43
+ end
44
+
45
+ def self.jwt_format?(body)
46
+ body.count(".") == 2 && body.split(".").all? { |segment| segment.match?(/\A[a-zA-Z0-9_-]+\z/) }
47
+ end
48
+
37
49
  # Initializes a TelnyxResponse object from a Faraday HTTP response object.
38
50
  #
39
51
  # This may throw JSON::ParserError if the response body is not valid JSON.
@@ -52,7 +64,17 @@ module Telnyx
52
64
 
53
65
  # Helper to handle when the server responds with a blank body (as is the case with SimCards).
54
66
  def preprocess_response(resp)
55
- resp.empty? ? "{}" : resp
67
+ return "{}" if resp.empty?
68
+
69
+ return resp if valid_json?(resp)
70
+
71
+ # If the response is a plain string (as is with JWTs), wrap it in a JSON object
72
+ { token: resp }.to_json
73
+ end
74
+
75
+ # Helper method to check if the string is a valid JSON format
76
+ def valid_json?(resp)
77
+ resp.strip.start_with?("{", "[")
56
78
  end
57
79
  end
58
80
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Telnyx
4
- VERSION = "3.0.3".freeze
4
+ VERSION = "3.0.5".freeze
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: telnyx
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.3
4
+ version: 3.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Telnyx
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-09-18 00:00:00.000000000 Z
11
+ date: 2024-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday