Skip to content

Commit

Permalink
fix telnyx response cases
Browse files Browse the repository at this point in the history
  • Loading branch information
ADandyGuyInSpace committed Oct 18, 2024
1 parent 3bb6715 commit 5b10fbd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.4
3.0.5
12 changes: 11 additions & 1 deletion lib/telnyx/telnyx_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,17 @@ class << self

# Helper to handle when the server responds with a blank body (as is the case with SimCards).
def preprocess_response(resp)
resp.empty? ? "{}" : resp
return "{}" if resp.empty?

return resp if valid_json?(resp)

# If the response is a plain string (as is with JWTs), wrap it in a JSON object
{ token: resp }.to_json
end

# Helper method to check if the string is a valid JSON format
def valid_json?(resp)
resp.strip.start_with?("{", "[")
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/telnyx/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Telnyx
VERSION = "3.0.4".freeze
VERSION = "3.0.5".freeze
end

0 comments on commit 5b10fbd

Please sign in to comment.