Class: SignalWire::REST::RestClient

Inherits:
Object
  • Object
show all
Defined in:
lib/signalwire/rest/rest_client.rb

Overview

REST client for the SignalWire platform APIs.

Usage:

client = SignalWire::REST::RestClient.new(
  project: 'your-project-id',
  token:   'your-api-token',
  host:    'your-space.signalwire.com'
)

# Or use environment variables:
#   SIGNALWIRE_PROJECT_ID, SIGNALWIRE_API_TOKEN, SIGNALWIRE_SPACE
client = SignalWire::REST::RestClient.new

# Use namespaced resources
client.fabric.ai_agents.list
client.calling.play(call_id, play: [...])
client.phone_numbers.search(area_code: '512')
client.video.rooms.create(name: 'standup')
client.compat.calls.list

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project: nil, token: nil, host: nil, base_url: nil) ⇒ RestClient

base_url overrides the derived https://{space} default. The audit harness uses this to point at the local fixture server.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/signalwire/rest/rest_client.rb', line 58

def initialize(project: nil, token: nil, host: nil, base_url: nil)
  project_id = project || ENV['SIGNALWIRE_PROJECT_ID'] || ''
  api_token  = token || ENV['SIGNALWIRE_API_TOKEN'] || ''
  space      = host || ENV['SIGNALWIRE_SPACE'] || ''

  if project_id.empty? || api_token.empty? || (space.empty? && (base_url.nil? || base_url.empty?))
    raise ArgumentError,
          'project, token, and host are required. ' \
          'Provide them as arguments or set SIGNALWIRE_PROJECT_ID, ' \
          'SIGNALWIRE_API_TOKEN, and SIGNALWIRE_SPACE environment variables.'
  end

  @project_id = project_id
  @http = HttpClient.new(project_id, api_token, space, base_url: base_url)

  # Fabric API
  @fabric = Namespaces::FabricNamespace.new(@http)

  # Calling API
  @calling = Namespaces::CallingNamespace.new(@http)

  # Relay REST resources
  @phone_numbers    = Namespaces::PhoneNumbersResource.new(@http)
  @addresses        = Namespaces::AddressesResource.new(@http)
  @queues           = Namespaces::QueuesResource.new(@http)
  @recordings       = Namespaces::RecordingsResource.new(@http)
  @number_groups    = Namespaces::NumberGroupsResource.new(@http)
  @verified_callers = Namespaces::VerifiedCallersResource.new(@http)
  @sip_profile      = Namespaces::SipProfileResource.new(@http)
  @lookup           = Namespaces::LookupResource.new(@http)
  @short_codes      = Namespaces::ShortCodesResource.new(@http)
  @imported_numbers = Namespaces::ImportedNumbersResource.new(@http)
  @mfa              = Namespaces::MfaResource.new(@http)
  @registry         = Namespaces::RegistryNamespace.new(@http)

  # Datasphere API
  @datasphere = Namespaces::DatasphereNamespace.new(@http)

  # Video API
  @video = Namespaces::VideoNamespace.new(@http)

  # Logs
  @logs = Namespaces::LogsNamespace.new(@http)

  # Project management
  @project = Namespaces::ProjectNamespace.new(@http)

  # PubSub & Chat
  @pubsub = Namespaces::PubSubResource.new(@http)
  @chat   = Namespaces::ChatResource.new(@http)

  # Compatibility (Twilio-compatible) API
  @compat = Namespaces::CompatNamespace.new(@http, project_id)
end

Instance Attribute Details

#addressesObject (readonly)

Returns the value of attribute addresses.



50
51
52
# File 'lib/signalwire/rest/rest_client.rb', line 50

def addresses
  @addresses
end

#callingObject (readonly)

Returns the value of attribute calling.



50
51
52
# File 'lib/signalwire/rest/rest_client.rb', line 50

def calling
  @calling
end

#chatObject (readonly)

Returns the value of attribute chat.



50
51
52
# File 'lib/signalwire/rest/rest_client.rb', line 50

def chat
  @chat
end

#compatObject (readonly)

Returns the value of attribute compat.



50
51
52
# File 'lib/signalwire/rest/rest_client.rb', line 50

def compat
  @compat
end

#datasphereObject (readonly)

Returns the value of attribute datasphere.



50
51
52
# File 'lib/signalwire/rest/rest_client.rb', line 50

def datasphere
  @datasphere
end

#fabricObject (readonly)

Returns the value of attribute fabric.



50
51
52
# File 'lib/signalwire/rest/rest_client.rb', line 50

def fabric
  @fabric
end

#httpObject (readonly)

Returns the value of attribute http.



50
51
52
# File 'lib/signalwire/rest/rest_client.rb', line 50

def http
  @http
end

#imported_numbersObject (readonly)

Returns the value of attribute imported_numbers.



50
51
52
# File 'lib/signalwire/rest/rest_client.rb', line 50

def imported_numbers
  @imported_numbers
end

#logsObject (readonly)

Returns the value of attribute logs.



50
51
52
# File 'lib/signalwire/rest/rest_client.rb', line 50

def logs
  @logs
end

#lookupObject (readonly)

Returns the value of attribute lookup.



50
51
52
# File 'lib/signalwire/rest/rest_client.rb', line 50

def lookup
  @lookup
end

#mfaObject (readonly)

Returns the value of attribute mfa.



50
51
52
# File 'lib/signalwire/rest/rest_client.rb', line 50

def mfa
  @mfa
end

#number_groupsObject (readonly)

Returns the value of attribute number_groups.



50
51
52
# File 'lib/signalwire/rest/rest_client.rb', line 50

def number_groups
  @number_groups
end

#phone_numbersObject (readonly)

Returns the value of attribute phone_numbers.



50
51
52
# File 'lib/signalwire/rest/rest_client.rb', line 50

def phone_numbers
  @phone_numbers
end

#projectObject (readonly)

Returns the value of attribute project.



50
51
52
# File 'lib/signalwire/rest/rest_client.rb', line 50

def project
  @project
end

#project_idObject (readonly)

Returns the value of attribute project_id.



50
51
52
# File 'lib/signalwire/rest/rest_client.rb', line 50

def project_id
  @project_id
end

#pubsubObject (readonly)

Returns the value of attribute pubsub.



50
51
52
# File 'lib/signalwire/rest/rest_client.rb', line 50

def pubsub
  @pubsub
end

#queuesObject (readonly)

Returns the value of attribute queues.



50
51
52
# File 'lib/signalwire/rest/rest_client.rb', line 50

def queues
  @queues
end

#recordingsObject (readonly)

Returns the value of attribute recordings.



50
51
52
# File 'lib/signalwire/rest/rest_client.rb', line 50

def recordings
  @recordings
end

#registryObject (readonly)

Returns the value of attribute registry.



50
51
52
# File 'lib/signalwire/rest/rest_client.rb', line 50

def registry
  @registry
end

#short_codesObject (readonly)

Returns the value of attribute short_codes.



50
51
52
# File 'lib/signalwire/rest/rest_client.rb', line 50

def short_codes
  @short_codes
end

#sip_profileObject (readonly)

Returns the value of attribute sip_profile.



50
51
52
# File 'lib/signalwire/rest/rest_client.rb', line 50

def sip_profile
  @sip_profile
end

#verified_callersObject (readonly)

Returns the value of attribute verified_callers.



50
51
52
# File 'lib/signalwire/rest/rest_client.rb', line 50

def verified_callers
  @verified_callers
end

#videoObject (readonly)

Returns the value of attribute video.



50
51
52
# File 'lib/signalwire/rest/rest_client.rb', line 50

def video
  @video
end