signalwire-sdk 2.0.0

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.
Files changed (85) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +259 -0
  4. data/bin/swaig-test +872 -0
  5. data/lib/signalwire/agent/agent_base.rb +2134 -0
  6. data/lib/signalwire/contexts/context_builder.rb +861 -0
  7. data/lib/signalwire/core/logging_config.rb +54 -0
  8. data/lib/signalwire/datamap/data_map.rb +315 -0
  9. data/lib/signalwire/logging.rb +92 -0
  10. data/lib/signalwire/pom/prompt_object_model.rb +269 -0
  11. data/lib/signalwire/pom/section.rb +202 -0
  12. data/lib/signalwire/prefabs/concierge.rb +92 -0
  13. data/lib/signalwire/prefabs/faq_bot.rb +67 -0
  14. data/lib/signalwire/prefabs/info_gatherer.rb +79 -0
  15. data/lib/signalwire/prefabs/receptionist.rb +74 -0
  16. data/lib/signalwire/prefabs/survey.rb +75 -0
  17. data/lib/signalwire/relay/action.rb +291 -0
  18. data/lib/signalwire/relay/call.rb +523 -0
  19. data/lib/signalwire/relay/client.rb +789 -0
  20. data/lib/signalwire/relay/constants.rb +124 -0
  21. data/lib/signalwire/relay/message.rb +137 -0
  22. data/lib/signalwire/relay/relay_event.rb +670 -0
  23. data/lib/signalwire/rest/http_client.rb +159 -0
  24. data/lib/signalwire/rest/namespaces/addresses.rb +19 -0
  25. data/lib/signalwire/rest/namespaces/calling.rb +179 -0
  26. data/lib/signalwire/rest/namespaces/chat.rb +18 -0
  27. data/lib/signalwire/rest/namespaces/compat.rb +229 -0
  28. data/lib/signalwire/rest/namespaces/datasphere.rb +39 -0
  29. data/lib/signalwire/rest/namespaces/fabric.rb +235 -0
  30. data/lib/signalwire/rest/namespaces/imported_numbers.rb +18 -0
  31. data/lib/signalwire/rest/namespaces/logs.rb +46 -0
  32. data/lib/signalwire/rest/namespaces/lookup.rb +18 -0
  33. data/lib/signalwire/rest/namespaces/mfa.rb +26 -0
  34. data/lib/signalwire/rest/namespaces/number_groups.rb +32 -0
  35. data/lib/signalwire/rest/namespaces/phone_numbers.rb +124 -0
  36. data/lib/signalwire/rest/namespaces/project.rb +33 -0
  37. data/lib/signalwire/rest/namespaces/pubsub.rb +18 -0
  38. data/lib/signalwire/rest/namespaces/queues.rb +28 -0
  39. data/lib/signalwire/rest/namespaces/recordings.rb +18 -0
  40. data/lib/signalwire/rest/namespaces/registry.rb +67 -0
  41. data/lib/signalwire/rest/namespaces/short_codes.rb +26 -0
  42. data/lib/signalwire/rest/namespaces/sip_profile.rb +22 -0
  43. data/lib/signalwire/rest/namespaces/verified_callers.rb +24 -0
  44. data/lib/signalwire/rest/namespaces/video.rb +129 -0
  45. data/lib/signalwire/rest/pagination.rb +89 -0
  46. data/lib/signalwire/rest/phone_call_handler.rb +56 -0
  47. data/lib/signalwire/rest/rest_client.rb +114 -0
  48. data/lib/signalwire/runtime.rb +98 -0
  49. data/lib/signalwire/security/session_manager.rb +124 -0
  50. data/lib/signalwire/security/webhook_middleware.rb +191 -0
  51. data/lib/signalwire/security/webhook_validator.rb +327 -0
  52. data/lib/signalwire/server/agent_server.rb +413 -0
  53. data/lib/signalwire/serverless/lambda_handler.rb +251 -0
  54. data/lib/signalwire/skills/builtin/api_ninjas_trivia.rb +99 -0
  55. data/lib/signalwire/skills/builtin/claude_skills.rb +92 -0
  56. data/lib/signalwire/skills/builtin/custom_skills.rb +54 -0
  57. data/lib/signalwire/skills/builtin/datasphere.rb +153 -0
  58. data/lib/signalwire/skills/builtin/datasphere_serverless.rb +107 -0
  59. data/lib/signalwire/skills/builtin/datetime.rb +97 -0
  60. data/lib/signalwire/skills/builtin/google_maps.rb +168 -0
  61. data/lib/signalwire/skills/builtin/info_gatherer.rb +189 -0
  62. data/lib/signalwire/skills/builtin/joke.rb +65 -0
  63. data/lib/signalwire/skills/builtin/math.rb +176 -0
  64. data/lib/signalwire/skills/builtin/mcp_gateway.rb +121 -0
  65. data/lib/signalwire/skills/builtin/native_vector_search.rb +116 -0
  66. data/lib/signalwire/skills/builtin/play_background_file.rb +86 -0
  67. data/lib/signalwire/skills/builtin/spider.rb +169 -0
  68. data/lib/signalwire/skills/builtin/swml_transfer.rb +118 -0
  69. data/lib/signalwire/skills/builtin/weather_api.rb +92 -0
  70. data/lib/signalwire/skills/builtin/web_search.rb +141 -0
  71. data/lib/signalwire/skills/builtin/wikipedia_search.rb +125 -0
  72. data/lib/signalwire/skills/skill_base.rb +82 -0
  73. data/lib/signalwire/skills/skill_manager.rb +97 -0
  74. data/lib/signalwire/skills/skill_registry.rb +258 -0
  75. data/lib/signalwire/swaig/function_result.rb +777 -0
  76. data/lib/signalwire/swml/document.rb +84 -0
  77. data/lib/signalwire/swml/schema.json +12250 -0
  78. data/lib/signalwire/swml/schema.rb +81 -0
  79. data/lib/signalwire/swml/service.rb +650 -0
  80. data/lib/signalwire/utils/schema_utils.rb +298 -0
  81. data/lib/signalwire/utils/serverless.rb +19 -0
  82. data/lib/signalwire/utils/url_validator.rb +138 -0
  83. data/lib/signalwire/version.rb +5 -0
  84. data/lib/signalwire.rb +114 -0
  85. metadata +225 -0
@@ -0,0 +1,159 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'net/http'
4
+ require 'json'
5
+ require 'uri'
6
+ require 'base64'
7
+
8
+ module SignalWire
9
+ module REST
10
+ # Raised when the SignalWire REST API returns a non-2xx response.
11
+ class SignalWireRestError < StandardError
12
+ attr_reader :status_code, :body, :url, :method_name
13
+
14
+ def initialize(status_code, body, url, method_name = 'GET')
15
+ @status_code = status_code
16
+ @body = body
17
+ @url = url
18
+ @method_name = method_name
19
+ super("#{method_name} #{url} returned #{status_code}: #{body}")
20
+ end
21
+ end
22
+
23
+ # Thin wrapper around Net::HTTP with Basic Auth and JSON handling.
24
+ class HttpClient
25
+ attr_reader :base_url
26
+
27
+ # +base_url+ overrides the derived +https://{space}+ value when set,
28
+ # which is how the audit fixture and tests point the client at a
29
+ # loopback server. Pass either +space+ ("acme") / a host
30
+ # ("acme.signalwire.com") OR an explicit +base_url+ ("http://127.0.0.1:NNNN").
31
+ def initialize(project_id, token, space, base_url: nil)
32
+ if base_url && !base_url.empty?
33
+ @base_url = base_url.sub(/\/$/, '')
34
+ else
35
+ host = space.include?('.') ? space : "#{space}.signalwire.com"
36
+ @base_url = "https://#{host}"
37
+ end
38
+ @project_id = project_id
39
+ @token = token
40
+ @auth_header = 'Basic ' + Base64.strict_encode64("#{project_id}:#{token}")
41
+ end
42
+
43
+ def project_id
44
+ @project_id
45
+ end
46
+
47
+ def get(path, params = nil)
48
+ _request('GET', path, params: params)
49
+ end
50
+
51
+ def post(path, body = nil, params: nil)
52
+ _request('POST', path, body: body, params: params)
53
+ end
54
+
55
+ def put(path, body = nil)
56
+ _request('PUT', path, body: body)
57
+ end
58
+
59
+ def patch(path, body = nil)
60
+ _request('PATCH', path, body: body)
61
+ end
62
+
63
+ def delete(path)
64
+ _request('DELETE', path)
65
+ end
66
+
67
+ private
68
+
69
+ def _request(method, path, body: nil, params: nil)
70
+ uri = URI("#{@base_url}#{path}")
71
+ if params && !params.empty?
72
+ uri.query = URI.encode_www_form(params)
73
+ end
74
+
75
+ req = case method
76
+ when 'GET' then Net::HTTP::Get.new(uri)
77
+ when 'POST' then Net::HTTP::Post.new(uri)
78
+ when 'PUT' then Net::HTTP::Put.new(uri)
79
+ when 'PATCH' then Net::HTTP::Patch.new(uri)
80
+ when 'DELETE' then Net::HTTP::Delete.new(uri)
81
+ else raise ArgumentError, "Unknown HTTP method: #{method}"
82
+ end
83
+
84
+ req['Authorization'] = @auth_header
85
+ req['Content-Type'] = 'application/json'
86
+ req['Accept'] = 'application/json'
87
+ req['User-Agent'] = 'signalwire-agents-ruby-rest/1.0'
88
+
89
+ if body && %w[POST PUT PATCH].include?(method)
90
+ req.body = JSON.generate(body)
91
+ end
92
+
93
+ http = Net::HTTP.new(uri.host, uri.port)
94
+ http.use_ssl = (uri.scheme == 'https')
95
+
96
+ response = http.request(req)
97
+
98
+ unless response.is_a?(Net::HTTPSuccess)
99
+ err_body = begin
100
+ JSON.parse(response.body)
101
+ rescue
102
+ response.body
103
+ end
104
+ raise SignalWireRestError.new(response.code.to_i, err_body, path, method)
105
+ end
106
+
107
+ return {} if response.code.to_i == 204 || response.body.nil? || response.body.empty?
108
+
109
+ JSON.parse(response.body)
110
+ end
111
+ end
112
+
113
+ # Base for all namespace/resource classes.
114
+ class BaseResource
115
+ def initialize(http, base_path)
116
+ @http = http
117
+ @base_path = base_path
118
+ end
119
+
120
+ private
121
+
122
+ def _path(*parts)
123
+ ([@base_path] + parts.map(&:to_s)).join('/')
124
+ end
125
+ end
126
+
127
+ # Standard CRUD resource with list/create/get/update/delete.
128
+ class CrudResource < BaseResource
129
+ def self.update_method
130
+ @update_method || 'PATCH'
131
+ end
132
+
133
+ def self.update_method=(m)
134
+ @update_method = m
135
+ end
136
+
137
+ def list(**params)
138
+ @http.get(@base_path, params.empty? ? nil : params)
139
+ end
140
+
141
+ def create(**kwargs)
142
+ @http.post(@base_path, kwargs)
143
+ end
144
+
145
+ def get(resource_id)
146
+ @http.get(_path(resource_id))
147
+ end
148
+
149
+ def update(resource_id, **kwargs)
150
+ m = self.class.update_method.downcase
151
+ @http.send(m, _path(resource_id), kwargs)
152
+ end
153
+
154
+ def delete(resource_id)
155
+ @http.delete(_path(resource_id))
156
+ end
157
+ end
158
+ end
159
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SignalWire
4
+ module REST
5
+ module Namespaces
6
+ # Address management (no update endpoint).
7
+ class AddressesResource < BaseResource
8
+ def initialize(http)
9
+ super(http, '/api/relay/rest/addresses')
10
+ end
11
+
12
+ def list(**params) = @http.get(@base_path, params.empty? ? nil : params)
13
+ def create(**kwargs) = @http.post(@base_path, kwargs)
14
+ def get(address_id) = @http.get(_path(address_id))
15
+ def delete(address_id) = @http.delete(_path(address_id))
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,179 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SignalWire
4
+ module REST
5
+ module Namespaces
6
+ # REST call control -- all 37 commands dispatched via single POST endpoint.
7
+ class CallingNamespace < BaseResource
8
+ def initialize(http)
9
+ super(http, '/api/calling/calls')
10
+ end
11
+
12
+ # Call lifecycle
13
+ def dial(**params) = _execute('dial', **params)
14
+ def update(**params) = _execute('update', **params)
15
+
16
+ def end_call(call_id, **params)
17
+ _execute('calling.end', call_id: call_id, **params)
18
+ end
19
+
20
+ def transfer(call_id, **params)
21
+ _execute('calling.transfer', call_id: call_id, **params)
22
+ end
23
+
24
+ def disconnect(call_id, **params)
25
+ _execute('calling.disconnect', call_id: call_id, **params)
26
+ end
27
+
28
+ # Play
29
+ def play(call_id, **params)
30
+ _execute('calling.play', call_id: call_id, **params)
31
+ end
32
+
33
+ def play_pause(call_id, **params)
34
+ _execute('calling.play.pause', call_id: call_id, **params)
35
+ end
36
+
37
+ def play_resume(call_id, **params)
38
+ _execute('calling.play.resume', call_id: call_id, **params)
39
+ end
40
+
41
+ def play_stop(call_id, **params)
42
+ _execute('calling.play.stop', call_id: call_id, **params)
43
+ end
44
+
45
+ def play_volume(call_id, **params)
46
+ _execute('calling.play.volume', call_id: call_id, **params)
47
+ end
48
+
49
+ # Record
50
+ def record(call_id, **params)
51
+ _execute('calling.record', call_id: call_id, **params)
52
+ end
53
+
54
+ def record_pause(call_id, **params)
55
+ _execute('calling.record.pause', call_id: call_id, **params)
56
+ end
57
+
58
+ def record_resume(call_id, **params)
59
+ _execute('calling.record.resume', call_id: call_id, **params)
60
+ end
61
+
62
+ def record_stop(call_id, **params)
63
+ _execute('calling.record.stop', call_id: call_id, **params)
64
+ end
65
+
66
+ # Collect
67
+ def collect(call_id, **params)
68
+ _execute('calling.collect', call_id: call_id, **params)
69
+ end
70
+
71
+ def collect_stop(call_id, **params)
72
+ _execute('calling.collect.stop', call_id: call_id, **params)
73
+ end
74
+
75
+ def collect_start_input_timers(call_id, **params)
76
+ _execute('calling.collect.start_input_timers', call_id: call_id, **params)
77
+ end
78
+
79
+ # Detect
80
+ def detect(call_id, **params)
81
+ _execute('calling.detect', call_id: call_id, **params)
82
+ end
83
+
84
+ def detect_stop(call_id, **params)
85
+ _execute('calling.detect.stop', call_id: call_id, **params)
86
+ end
87
+
88
+ # Tap
89
+ def tap(call_id, **params)
90
+ _execute('calling.tap', call_id: call_id, **params)
91
+ end
92
+
93
+ def tap_stop(call_id, **params)
94
+ _execute('calling.tap.stop', call_id: call_id, **params)
95
+ end
96
+
97
+ # Stream
98
+ def stream(call_id, **params)
99
+ _execute('calling.stream', call_id: call_id, **params)
100
+ end
101
+
102
+ def stream_stop(call_id, **params)
103
+ _execute('calling.stream.stop', call_id: call_id, **params)
104
+ end
105
+
106
+ # Denoise
107
+ def denoise(call_id, **params)
108
+ _execute('calling.denoise', call_id: call_id, **params)
109
+ end
110
+
111
+ def denoise_stop(call_id, **params)
112
+ _execute('calling.denoise.stop', call_id: call_id, **params)
113
+ end
114
+
115
+ # Transcribe
116
+ def transcribe(call_id, **params)
117
+ _execute('calling.transcribe', call_id: call_id, **params)
118
+ end
119
+
120
+ def transcribe_stop(call_id, **params)
121
+ _execute('calling.transcribe.stop', call_id: call_id, **params)
122
+ end
123
+
124
+ # AI
125
+ def ai_message(call_id, **params)
126
+ _execute('calling.ai_message', call_id: call_id, **params)
127
+ end
128
+
129
+ def ai_hold(call_id, **params)
130
+ _execute('calling.ai_hold', call_id: call_id, **params)
131
+ end
132
+
133
+ def ai_unhold(call_id, **params)
134
+ _execute('calling.ai_unhold', call_id: call_id, **params)
135
+ end
136
+
137
+ def ai_stop(call_id, **params)
138
+ _execute('calling.ai.stop', call_id: call_id, **params)
139
+ end
140
+
141
+ # Live transcribe / translate
142
+ def live_transcribe(call_id, **params)
143
+ _execute('calling.live_transcribe', call_id: call_id, **params)
144
+ end
145
+
146
+ def live_translate(call_id, **params)
147
+ _execute('calling.live_translate', call_id: call_id, **params)
148
+ end
149
+
150
+ # Fax
151
+ def send_fax_stop(call_id, **params)
152
+ _execute('calling.send_fax.stop', call_id: call_id, **params)
153
+ end
154
+
155
+ def receive_fax_stop(call_id, **params)
156
+ _execute('calling.receive_fax.stop', call_id: call_id, **params)
157
+ end
158
+
159
+ # SIP
160
+ def refer(call_id, **params)
161
+ _execute('calling.refer', call_id: call_id, **params)
162
+ end
163
+
164
+ # Custom events
165
+ def user_event(call_id, **params)
166
+ _execute('calling.user_event', call_id: call_id, **params)
167
+ end
168
+
169
+ private
170
+
171
+ def _execute(command, call_id: nil, **params)
172
+ body = { 'command' => command, 'params' => params.transform_keys(&:to_s) }
173
+ body['id'] = call_id if call_id
174
+ @http.post(@base_path, body)
175
+ end
176
+ end
177
+ end
178
+ end
179
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SignalWire
4
+ module REST
5
+ module Namespaces
6
+ # Chat token generation.
7
+ class ChatResource < BaseResource
8
+ def initialize(http)
9
+ super(http, '/api/chat/tokens')
10
+ end
11
+
12
+ def create_token(**kwargs)
13
+ @http.post(@base_path, kwargs)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,229 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SignalWire
4
+ module REST
5
+ module Namespaces
6
+ # Compat account/subproject management.
7
+ class CompatAccounts < BaseResource
8
+ def initialize(http)
9
+ super(http, '/api/laml/2010-04-01/Accounts')
10
+ end
11
+
12
+ def list(**params) = @http.get(@base_path, params.empty? ? nil : params)
13
+ def create(**kwargs) = @http.post(@base_path, kwargs)
14
+ def get(sid) = @http.get(_path(sid))
15
+ def update(sid, **kwargs) = @http.post(_path(sid), kwargs)
16
+ end
17
+
18
+ # Compat call management with recording and stream sub-resources.
19
+ class CompatCalls < CrudResource
20
+ def update(sid, **kwargs)
21
+ @http.post(_path(sid), kwargs)
22
+ end
23
+
24
+ def start_recording(call_sid, **kwargs)
25
+ @http.post(_path(call_sid, 'Recordings'), kwargs)
26
+ end
27
+
28
+ def update_recording(call_sid, recording_sid, **kwargs)
29
+ @http.post(_path(call_sid, 'Recordings', recording_sid), kwargs)
30
+ end
31
+
32
+ def start_stream(call_sid, **kwargs)
33
+ @http.post(_path(call_sid, 'Streams'), kwargs)
34
+ end
35
+
36
+ def stop_stream(call_sid, stream_sid, **kwargs)
37
+ @http.post(_path(call_sid, 'Streams', stream_sid), kwargs)
38
+ end
39
+ end
40
+
41
+ # Compat message management with media sub-resources.
42
+ class CompatMessages < CrudResource
43
+ def update(sid, **kwargs) = @http.post(_path(sid), kwargs)
44
+
45
+ def list_media(message_sid, **params)
46
+ @http.get(_path(message_sid, 'Media'), params.empty? ? nil : params)
47
+ end
48
+
49
+ def get_media(message_sid, media_sid)
50
+ @http.get(_path(message_sid, 'Media', media_sid))
51
+ end
52
+
53
+ def delete_media(message_sid, media_sid)
54
+ @http.delete(_path(message_sid, 'Media', media_sid))
55
+ end
56
+ end
57
+
58
+ # Compat fax management with media sub-resources.
59
+ class CompatFaxes < CrudResource
60
+ def update(sid, **kwargs) = @http.post(_path(sid), kwargs)
61
+
62
+ def list_media(fax_sid, **params)
63
+ @http.get(_path(fax_sid, 'Media'), params.empty? ? nil : params)
64
+ end
65
+
66
+ def get_media(fax_sid, media_sid)
67
+ @http.get(_path(fax_sid, 'Media', media_sid))
68
+ end
69
+
70
+ def delete_media(fax_sid, media_sid)
71
+ @http.delete(_path(fax_sid, 'Media', media_sid))
72
+ end
73
+ end
74
+
75
+ # Compat conference management.
76
+ class CompatConferences < BaseResource
77
+ def list(**params) = @http.get(@base_path, params.empty? ? nil : params)
78
+ def get(sid) = @http.get(_path(sid))
79
+ def update(sid, **kw) = @http.post(_path(sid), kw)
80
+
81
+ # Participants
82
+ def list_participants(conference_sid, **params)
83
+ @http.get(_path(conference_sid, 'Participants'), params.empty? ? nil : params)
84
+ end
85
+
86
+ def get_participant(conference_sid, call_sid)
87
+ @http.get(_path(conference_sid, 'Participants', call_sid))
88
+ end
89
+
90
+ def update_participant(conference_sid, call_sid, **kwargs)
91
+ @http.post(_path(conference_sid, 'Participants', call_sid), kwargs)
92
+ end
93
+
94
+ def remove_participant(conference_sid, call_sid)
95
+ @http.delete(_path(conference_sid, 'Participants', call_sid))
96
+ end
97
+
98
+ # Conference recordings
99
+ def list_recordings(conference_sid, **params)
100
+ @http.get(_path(conference_sid, 'Recordings'), params.empty? ? nil : params)
101
+ end
102
+
103
+ def get_recording(conference_sid, recording_sid)
104
+ @http.get(_path(conference_sid, 'Recordings', recording_sid))
105
+ end
106
+
107
+ def update_recording(conference_sid, recording_sid, **kwargs)
108
+ @http.post(_path(conference_sid, 'Recordings', recording_sid), kwargs)
109
+ end
110
+
111
+ def delete_recording(conference_sid, recording_sid)
112
+ @http.delete(_path(conference_sid, 'Recordings', recording_sid))
113
+ end
114
+
115
+ # Conference streams
116
+ def start_stream(conference_sid, **kwargs)
117
+ @http.post(_path(conference_sid, 'Streams'), kwargs)
118
+ end
119
+
120
+ def stop_stream(conference_sid, stream_sid, **kwargs)
121
+ @http.post(_path(conference_sid, 'Streams', stream_sid), kwargs)
122
+ end
123
+ end
124
+
125
+ # Compat phone number management.
126
+ class CompatPhoneNumbers < BaseResource
127
+ def initialize(http, base)
128
+ super(http, base)
129
+ @available_base = base.sub('/IncomingPhoneNumbers', '/AvailablePhoneNumbers')
130
+ end
131
+
132
+ def list(**params) = @http.get(@base_path, params.empty? ? nil : params)
133
+ def purchase(**kwargs) = @http.post(@base_path, kwargs)
134
+ def get(sid) = @http.get(_path(sid))
135
+ def update(sid, **kwargs) = @http.post(_path(sid), kwargs)
136
+ def delete(sid) = @http.delete(_path(sid))
137
+
138
+ def import_number(**kwargs)
139
+ path = @base_path.sub('/IncomingPhoneNumbers', '/ImportedPhoneNumbers')
140
+ @http.post(path, kwargs)
141
+ end
142
+
143
+ def list_available_countries(**params)
144
+ @http.get(@available_base, params.empty? ? nil : params)
145
+ end
146
+
147
+ def search_local(country, **params)
148
+ @http.get("#{@available_base}/#{country}/Local", params.empty? ? nil : params)
149
+ end
150
+
151
+ def search_toll_free(country, **params)
152
+ @http.get("#{@available_base}/#{country}/TollFree", params.empty? ? nil : params)
153
+ end
154
+ end
155
+
156
+ # Compat application management.
157
+ class CompatApplications < CrudResource
158
+ def update(sid, **kwargs) = @http.post(_path(sid), kwargs)
159
+ end
160
+
161
+ # Compat cXML/LaML script management.
162
+ class CompatLamlBins < CrudResource
163
+ def update(sid, **kwargs) = @http.post(_path(sid), kwargs)
164
+ end
165
+
166
+ # Compat queue management with members.
167
+ class CompatQueues < CrudResource
168
+ def update(sid, **kwargs) = @http.post(_path(sid), kwargs)
169
+
170
+ def list_members(queue_sid, **params)
171
+ @http.get(_path(queue_sid, 'Members'), params.empty? ? nil : params)
172
+ end
173
+
174
+ def get_member(queue_sid, call_sid)
175
+ @http.get(_path(queue_sid, 'Members', call_sid))
176
+ end
177
+
178
+ def dequeue_member(queue_sid, call_sid, **kwargs)
179
+ @http.post(_path(queue_sid, 'Members', call_sid), kwargs)
180
+ end
181
+ end
182
+
183
+ # Compat recording management.
184
+ class CompatRecordings < BaseResource
185
+ def list(**params) = @http.get(@base_path, params.empty? ? nil : params)
186
+ def get(sid) = @http.get(_path(sid))
187
+ def delete(sid) = @http.delete(_path(sid))
188
+ end
189
+
190
+ # Compat transcription management.
191
+ class CompatTranscriptions < BaseResource
192
+ def list(**params) = @http.get(@base_path, params.empty? ? nil : params)
193
+ def get(sid) = @http.get(_path(sid))
194
+ def delete(sid) = @http.delete(_path(sid))
195
+ end
196
+
197
+ # Compat API token management.
198
+ class CompatTokens < BaseResource
199
+ def create(**kwargs) = @http.post(@base_path, kwargs)
200
+ def update(token_id, **kwargs) = @http.patch(_path(token_id), kwargs)
201
+ def delete(token_id) = @http.delete(_path(token_id))
202
+ end
203
+
204
+ # Twilio-compatible LAML API namespace.
205
+ class CompatNamespace
206
+ attr_reader :accounts, :calls, :messages, :faxes, :conferences,
207
+ :phone_numbers, :applications, :laml_bins, :queues,
208
+ :recordings, :transcriptions, :tokens
209
+
210
+ def initialize(http, account_sid)
211
+ base = "/api/laml/2010-04-01/Accounts/#{account_sid}"
212
+
213
+ @accounts = CompatAccounts.new(http)
214
+ @calls = CompatCalls.new(http, "#{base}/Calls")
215
+ @messages = CompatMessages.new(http, "#{base}/Messages")
216
+ @faxes = CompatFaxes.new(http, "#{base}/Faxes")
217
+ @conferences = CompatConferences.new(http, "#{base}/Conferences")
218
+ @phone_numbers = CompatPhoneNumbers.new(http, "#{base}/IncomingPhoneNumbers")
219
+ @applications = CompatApplications.new(http, "#{base}/Applications")
220
+ @laml_bins = CompatLamlBins.new(http, "#{base}/LamlBins")
221
+ @queues = CompatQueues.new(http, "#{base}/Queues")
222
+ @recordings = CompatRecordings.new(http, "#{base}/Recordings")
223
+ @transcriptions = CompatTranscriptions.new(http, "#{base}/Transcriptions")
224
+ @tokens = CompatTokens.new(http, "#{base}/tokens")
225
+ end
226
+ end
227
+ end
228
+ end
229
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SignalWire
4
+ module REST
5
+ module Namespaces
6
+ # Document management with search and chunk operations.
7
+ class DatasphereDocuments < CrudResource
8
+ def initialize(http)
9
+ super(http, '/api/datasphere/documents')
10
+ end
11
+
12
+ def search(**kwargs)
13
+ @http.post(_path('search'), kwargs)
14
+ end
15
+
16
+ def list_chunks(document_id, **params)
17
+ @http.get(_path(document_id, 'chunks'), params.empty? ? nil : params)
18
+ end
19
+
20
+ def get_chunk(document_id, chunk_id)
21
+ @http.get(_path(document_id, 'chunks', chunk_id))
22
+ end
23
+
24
+ def delete_chunk(document_id, chunk_id)
25
+ @http.delete(_path(document_id, 'chunks', chunk_id))
26
+ end
27
+ end
28
+
29
+ # Datasphere API namespace.
30
+ class DatasphereNamespace
31
+ attr_reader :documents
32
+
33
+ def initialize(http)
34
+ @documents = DatasphereDocuments.new(http)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end