Class: Bandwidth::Voice::APIController
- Inherits:
-
BaseController
- Object
- BaseController
- Bandwidth::Voice::APIController
- Defined in:
- lib/bandwidth/voice_lib/voice/controllers/api_controller.rb
Overview
APIController
Instance Attribute Summary
Attributes inherited from BaseController
Instance Method Summary collapse
-
#create_call(account_id, body: nil) ⇒ ApiCallResponse
Creates a call request.
-
#initialize(config, http_call_back: nil) ⇒ APIController
constructor
A new instance of APIController.
-
#modify_call(account_id, call_id, body: nil) ⇒ void
Creates a call request.
Methods inherited from BaseController
#execute_request, #validate_parameters, #validate_response
Constructor Details
#initialize(config, http_call_back: nil) ⇒ APIController
Returns a new instance of APIController.
10 11 12 |
# File 'lib/bandwidth/voice_lib/voice/controllers/api_controller.rb', line 10 def initialize(config, http_call_back: nil) super(config, http_call_back: http_call_back) end |
Instance Method Details
#create_call(account_id, body: nil) ⇒ ApiCallResponse
Creates a call request
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 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 |
# File 'lib/bandwidth/voice_lib/voice/controllers/api_controller.rb', line 18 def create_call(account_id, body: nil) # Prepare query url. _query_builder = config.get_base_uri(Server::VOICEDEFAULT) _query_builder << '/accounts/{accountId}/calls' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'accountId' => account_id ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json', 'content-type' => 'application/json; charset=utf-8' } # Prepare and execute HttpRequest. _request = config.http_client.post( _query_url, headers: _headers, parameters: body.to_json ) VoiceBasicAuth.apply(config, _request) _response = execute_request(_request) # Validate response against endpoint and global error codes. if _response.status_code == 400 raise BandwidthException.new( '400 request is malformed or invalid', _response ) elsif _response.status_code == 401 raise BandwidthException.new( '401 The specified user does not have access to the account', _response ) elsif _response.status_code == 403 raise BandwidthException.new( '403 The user does not have access to the API', _response ) elsif _response.status_code == 404 raise BandwidthNotFoundException.new( '404 he call-id is no longer active, or the path is not found', _response ) elsif _response.status_code == 409 raise BandwidthException.new( '409 Error when modifying a call that is unable to be modified', _response ) elsif _response.status_code == 415 raise BandwidthException.new( '415 The content-type of the request is incorrect', _response ) elsif _response.status_code == 429 raise BandwidthRateLimitErrorException.new( '429 The rate limit has been reached', _response ) elsif _response.status_code == 500 raise BandwidthException.new( '500 Unknown server error', _response ) elsif _response.status_code == 503 raise BandwidthException.new( '503 The service is unavailable for some reason', _response ) end validate_response(_response) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) ApiResponse.new(_response, data: ApiCallResponse.from_hash(decoded)) end |
#modify_call(account_id, call_id, body: nil) ⇒ void
This method returns an undefined value.
Creates a call request
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/bandwidth/voice_lib/voice/controllers/api_controller.rb', line 103 def modify_call(account_id, call_id, body: nil) # Prepare query url. _query_builder = config.get_base_uri(Server::VOICEDEFAULT) _query_builder << '/accounts/{accountId}/calls/{callId}' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'accountId' => account_id, 'callId' => call_id ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'content-type' => 'application/json; charset=utf-8' } # Prepare and execute HttpRequest. _request = config.http_client.post( _query_url, headers: _headers, parameters: body.to_json ) VoiceBasicAuth.apply(config, _request) _response = execute_request(_request) # Validate response against endpoint and global error codes. if _response.status_code == 400 raise BandwidthException.new( '400 request is malformed or invalid', _response ) elsif _response.status_code == 401 raise BandwidthException.new( '401 The specified user does not have access to the account', _response ) elsif _response.status_code == 403 raise BandwidthException.new( '403 The user does not have access to the API', _response ) elsif _response.status_code == 404 raise BandwidthNotFoundException.new( '404 he call-id is no longer active, or the path is not found', _response ) elsif _response.status_code == 409 raise BandwidthException.new( '409 Error when modifying a call that is unable to be modified', _response ) elsif _response.status_code == 415 raise BandwidthException.new( '415 The content-type of the request is incorrect', _response ) elsif _response.status_code == 429 raise BandwidthRateLimitErrorException.new( '429 The rate limit has been reached', _response ) elsif _response.status_code == 500 raise BandwidthException.new( '500 Unknown server error', _response ) elsif _response.status_code == 503 raise BandwidthException.new( '503 The service is unavailable for some reason', _response ) end validate_response(_response) # Return appropriate response type. ApiResponse.new(_response) end |