Include sgx jid in JSON format for calls

Stephen Paul Weber created

Change summary

lib/call_attempt.rb | 20 ++++++--------------
lib/customer.rb     |  4 ++++
2 files changed, 10 insertions(+), 14 deletions(-)

Detailed changes

lib/call_attempt.rb 🔗

@@ -41,6 +41,7 @@ class CallAttempt
 		customer_id String
 		from String
 		to(/\A\+\d+\Z/)
+		sgx Blather::JID
 		call_id String
 		direction Either(:inbound, :outbound)
 		limit_remaining Integer
@@ -60,13 +61,7 @@ class CallAttempt
 	end
 
 	def as_json(*)
-		{
-			from: from,
-			to: to,
-			customer_id: customer_id,
-			limit_remaining: limit_remaining,
-			max_minutes: max_minutes
-		}
+		to_h
 	end
 
 	def to_json(*args)
@@ -78,7 +73,7 @@ class CallAttempt
 			if rate&.zero?
 				new(
 					**kwargs
-						.merge(customer_id: customer.customer_id)
+						.merge(customer_id: customer.customer_id, sgx: customer.sgx)
 						.slice(*value_semantics.attributes.map(&:name))
 				)
 			end
@@ -88,6 +83,7 @@ class CallAttempt
 			customer_id String
 			from String
 			to(/\A\+\d+\Z/)
+			sgx Blather::JID
 			call_id String
 			direction Either(:inbound, :outbound)
 		end
@@ -105,11 +101,7 @@ class CallAttempt
 		end
 
 		def as_json(*)
-			{
-				from: from,
-				to: to,
-				customer_id: customer_id
-			}.compact
+			to_h
 		end
 
 		def to_json(*args)
@@ -302,7 +294,7 @@ class CallAttempt
 	register do |customer:, **kwargs|
 		new(
 			**kwargs
-				.merge(customer_id: customer.customer_id)
+				.merge(customer_id: customer.customer_id, sgx: customer.sgx)
 				.slice(*value_semantics.attributes.map(&:name))
 		)
 	end

lib/customer.rb 🔗

@@ -122,6 +122,10 @@ class Customer
 		SipAccount.find(customer_id)
 	end
 
+	def sgx
+		@sgx.jid
+	end
+
 	def reset_sip_account
 		sip_account.with_random_password.put
 	end