diff --git a/flowroute_numbers_and_messaging-3.0.0.gem b/flowroute_numbers_and_messaging-3.0.0.gem deleted file mode 100644 index 84b89d4..0000000 Binary files a/flowroute_numbers_and_messaging-3.0.0.gem and /dev/null differ diff --git a/flowroute_numbers_and_messaging-3.0.1.gem b/flowroute_numbers_and_messaging-3.0.1.gem new file mode 100644 index 0000000..9226b05 Binary files /dev/null and b/flowroute_numbers_and_messaging-3.0.1.gem differ diff --git a/flowroute_numbers_and_messaging.gemspec b/flowroute_numbers_and_messaging.gemspec index 34bbffd..73a42be 100644 --- a/flowroute_numbers_and_messaging.gemspec +++ b/flowroute_numbers_and_messaging.gemspec @@ -1,18 +1,18 @@ -Gem::Specification.new do |s| - s.name = 'flowroute_numbers_and_messaging' - s.version = '3.0.0' - s.summary = 'flowroute_numbers_and_messaging' - s.description = 'The Flowroute APIs are organized around REST. Our APIs have resource-oriented URLs, support HTTP Verbs, and respond with HTTP Status Codes. All API requests and responses, including errors, will be represented as JSON objects. You can use the Flowroute APIs to manage your Flowroute phone numbers including setting primary and failover routes for inbound calls, and sending text messages (SMS and MMS) using long-code or toll-free numbers in your account.' - s.authors = ['APIMatic SDK Generator'] - s.email = 'support@flowroute.com' - s.homepage = 'http://developer.flowroute.com' - s.license = 'MIT' - s.add_dependency('logging', '~> 2.0') - s.add_dependency('faraday', '~> 0.10.0') - s.add_dependency('test-unit', '~> 3.1', '~> 3.1.5') - s.add_dependency('certifi', '~> 2016.9', '>= 2016.09.26') - s.add_dependency('faraday-http-cache', '~> 1.2', '>= 1.2.2') - s.required_ruby_version = '~> 2.0' - s.files = Dir['{bin,lib,man,test,spec}/**/*', 'README*', 'LICENSE*'] - s.require_paths = ['lib'] -end +Gem::Specification.new do |s| + s.name = 'flowroute_numbers_and_messaging' + s.version = '3.0.1' + s.summary = 'flowroute_numbers_and_messaging' + s.description = 'The Flowroute APIs are organized around REST. Our APIs have resource-oriented URLs, support HTTP Verbs, and respond with HTTP Status Codes. All API requests and responses, including errors, will be represented as JSON objects. You can use the Flowroute APIs to manage your Flowroute phone numbers including setting primary and failover routes for inbound calls, and sending text messages (SMS and MMS) using long-code or toll-free numbers in your account.' + s.authors = ['APIMatic SDK Generator'] + s.email = 'support@flowroute.com' + s.homepage = 'http://developer.flowroute.com' + s.license = 'MIT' + s.add_dependency('logging', '~> 2.0') + s.add_dependency('faraday', '~> 0.10.0') + s.add_dependency('test-unit', '~> 3.1', '~> 3.1.5') + s.add_dependency('certifi', '~> 2016.9', '>= 2016.09.26') + s.add_dependency('faraday-http-cache', '~> 1.2', '>= 1.2.2') + s.required_ruby_version = '~> 2.0' + s.files = Dir['{bin,lib,man,test,spec}/**/*', 'README*', 'LICENSE*'] + s.require_paths = ['lib'] +end diff --git a/lib/flowroute_numbers_and_messaging.rb b/lib/flowroute_numbers_and_messaging.rb index 9b3c19a..7eda576 100644 --- a/lib/flowroute_numbers_and_messaging.rb +++ b/lib/flowroute_numbers_and_messaging.rb @@ -1,58 +1,60 @@ -# This file was automatically generated by APIMATIC v2.0 -# ( https://apimatic.io ). -require 'date' -require 'json' -require 'faraday' -require 'certifi' -require 'logging' - -require_relative 'flowroute_numbers_and_messaging/api_helper.rb' -require_relative 'flowroute_numbers_and_messaging' \ - '/flowroute_numbers_and_messaging_client.rb' - -# Http -require_relative 'flowroute_numbers_and_messaging/http/http_call_back.rb' -require_relative 'flowroute_numbers_and_messaging/http/http_client.rb' -require_relative 'flowroute_numbers_and_messaging/http/http_method_enum.rb' -require_relative 'flowroute_numbers_and_messaging/http/http_request.rb' -require_relative 'flowroute_numbers_and_messaging/http/http_response.rb' -require_relative 'flowroute_numbers_and_messaging/http/http_context.rb' -require_relative 'flowroute_numbers_and_messaging/http/faraday_client.rb' -require_relative 'flowroute_numbers_and_messaging/http/auth/basic_auth.rb' - -# Models -require_relative 'flowroute_numbers_and_messaging/models/base_model.rb' -require_relative 'flowroute_numbers_and_messaging/models/error_1.rb' -require_relative 'flowroute_numbers_and_messaging/models/message.rb' -require_relative 'flowroute_numbers_and_messaging/models/mdr_2.rb' -require_relative 'flowroute_numbers_and_messaging/models/data.rb' -require_relative 'flowroute_numbers_and_messaging/models/attributes.rb' -require_relative 'flowroute_numbers_and_messaging/models/delivery_receipt.rb' -require_relative 'flowroute_numbers_and_messaging/models/number_26.rb' -require_relative 'flowroute_numbers_and_messaging/models/data_27.rb' -require_relative 'flowroute_numbers_and_messaging/models/attributes_28.rb' -require_relative 'flowroute_numbers_and_messaging/models/links.rb' -require_relative 'flowroute_numbers_and_messaging/models/new_route.rb' -require_relative 'flowroute_numbers_and_messaging/models/data_61.rb' -require_relative 'flowroute_numbers_and_messaging/models/attributes_62.rb' -require_relative 'flowroute_numbers_and_messaging/models/account_routes.rb' -require_relative 'flowroute_numbers_and_messaging/models/error_84.rb' -require_relative 'flowroute_numbers_and_messaging/models/message_type_enum.rb' -require_relative 'flowroute_numbers_and_messaging/models/number_type_enum.rb' -require_relative 'flowroute_numbers_and_messaging/models/route_type_enum.rb' -require_relative 'flowroute_numbers_and_messaging/models/e911.rb' - -# Exceptions -require_relative 'flowroute_numbers_and_messaging/exceptions/api_exception.rb' -require_relative 'flowroute_numbers_and_messaging/exceptions/error_exception.rb' - -require_relative 'flowroute_numbers_and_messaging/configuration.rb' - -# Controllers -require_relative 'flowroute_numbers_and_messaging/controllers/base_controller.rb' -require_relative 'flowroute_numbers_and_messaging/controllers/messages_controller.rb' -require_relative 'flowroute_numbers_and_messaging/controllers/numbers_controller.rb' -require_relative 'flowroute_numbers_and_messaging/controllers/routes_controller.rb' -require_relative 'flowroute_numbers_and_messaging/controllers/e911_controller.rb' -require_relative 'flowroute_numbers_and_messaging/controllers/cnam_controller.rb' -require_relative 'flowroute_numbers_and_messaging/controllers/portability_controller.rb' +# This file was automatically generated by APIMATIC v2.0 +# ( https://apimatic.io ). +require 'date' +require 'json' +require 'faraday' +require 'certifi' +require 'logging' + +require_relative 'flowroute_numbers_and_messaging/api_helper.rb' +require_relative 'flowroute_numbers_and_messaging' \ + '/flowroute_numbers_and_messaging_client.rb' + +# Http +require_relative 'flowroute_numbers_and_messaging/http/http_call_back.rb' +require_relative 'flowroute_numbers_and_messaging/http/http_client.rb' +require_relative 'flowroute_numbers_and_messaging/http/http_method_enum.rb' +require_relative 'flowroute_numbers_and_messaging/http/http_request.rb' +require_relative 'flowroute_numbers_and_messaging/http/http_response.rb' +require_relative 'flowroute_numbers_and_messaging/http/http_context.rb' +require_relative 'flowroute_numbers_and_messaging/http/faraday_client.rb' +require_relative 'flowroute_numbers_and_messaging/http/auth/basic_auth.rb' + +# Models +require_relative 'flowroute_numbers_and_messaging/models/base_model.rb' +require_relative 'flowroute_numbers_and_messaging/models/error_1.rb' +require_relative 'flowroute_numbers_and_messaging/models/message.rb' +require_relative 'flowroute_numbers_and_messaging/models/mdr_2.rb' +require_relative 'flowroute_numbers_and_messaging/models/data.rb' +require_relative 'flowroute_numbers_and_messaging/models/attributes.rb' +require_relative 'flowroute_numbers_and_messaging/models/delivery_receipt.rb' +require_relative 'flowroute_numbers_and_messaging/models/number_26.rb' +require_relative 'flowroute_numbers_and_messaging/models/data_27.rb' +require_relative 'flowroute_numbers_and_messaging/models/attributes_28.rb' +require_relative 'flowroute_numbers_and_messaging/models/links.rb' +require_relative 'flowroute_numbers_and_messaging/models/new_route.rb' +require_relative 'flowroute_numbers_and_messaging/models/data_61.rb' +require_relative 'flowroute_numbers_and_messaging/models/attributes_62.rb' +require_relative 'flowroute_numbers_and_messaging/models/account_routes.rb' +require_relative 'flowroute_numbers_and_messaging/models/error_84.rb' +require_relative 'flowroute_numbers_and_messaging/models/message_type_enum.rb' +require_relative 'flowroute_numbers_and_messaging/models/number_type_enum.rb' +require_relative 'flowroute_numbers_and_messaging/models/route_type_enum.rb' +require_relative 'flowroute_numbers_and_messaging/models/e911.rb' + +# Exceptions +require_relative 'flowroute_numbers_and_messaging/exceptions/api_exception.rb' +require_relative 'flowroute_numbers_and_messaging/exceptions/error_exception.rb' + +require_relative 'flowroute_numbers_and_messaging/configuration.rb' + +# Controllers +require_relative 'flowroute_numbers_and_messaging/controllers/base_controller.rb' +require_relative 'flowroute_numbers_and_messaging/controllers/messages_controller.rb' +require_relative 'flowroute_numbers_and_messaging/controllers/numbers_controller.rb' +require_relative 'flowroute_numbers_and_messaging/controllers/routes_controller.rb' +require_relative 'flowroute_numbers_and_messaging/controllers/e911_controller.rb' +require_relative 'flowroute_numbers_and_messaging/controllers/cnam_controller.rb' +require_relative 'flowroute_numbers_and_messaging/controllers/portability_controller.rb' + +require_relative 'flowroute_numbers_and_messaging/railtie' if defined?(Rails) diff --git a/lib/flowroute_numbers_and_messaging/configuration.rb b/lib/flowroute_numbers_and_messaging/configuration.rb index ec70917..1158321 100644 --- a/lib/flowroute_numbers_and_messaging/configuration.rb +++ b/lib/flowroute_numbers_and_messaging/configuration.rb @@ -1,25 +1,28 @@ -# This file was automatically generated by APIMATIC v2.0 -# ( https://apimatic.io ). - -module FlowrouteNumbersAndMessaging - # All configuration including auth info and base URI for the API access - # are configured in this class. - class Configuration - # The base Uri for API calls - @base_uri = 'https://api.flowroute.com' - - # The username to use with basic authentication - @basic_auth_user_name = 'TODO: Replace' - - # The password to use with basic authentication - @basic_auth_password = 'TODO: Replace' - - # The attribute accessors for public properties. - class << self - attr_accessor :array_serialization - attr_accessor :base_uri - attr_accessor :basic_auth_user_name - attr_accessor :basic_auth_password - end - end -end +# This file was automatically generated by APIMATIC v2.0 +# ( https://apimatic.io ). + +module FlowrouteNumbersAndMessaging + # All configuration including auth info and base URI for the API access + # are configured in this class. + class Configuration + # The base Uri for API calls + @base_uri = 'https://api.flowroute.com' + + # The username to use with basic authentication + @basic_auth_user_name = 'TODO: Replace' + + # The password to use with basic authentication + @basic_auth_password = 'TODO: Replace' + + @flowroute_logger = Logger.new(STDOUT) + + # The attribute accessors for public properties. + class << self + attr_accessor :array_serialization + attr_accessor :base_uri + attr_accessor :basic_auth_user_name + attr_accessor :basic_auth_password + attr_accessor :flowroute_logger + end + end +end diff --git a/lib/flowroute_numbers_and_messaging/controllers/numbers_controller.rb b/lib/flowroute_numbers_and_messaging/controllers/numbers_controller.rb index 74c0e13..7edd9fd 100644 --- a/lib/flowroute_numbers_and_messaging/controllers/numbers_controller.rb +++ b/lib/flowroute_numbers_and_messaging/controllers/numbers_controller.rb @@ -1,518 +1,518 @@ -# This file was automatically generated by APIMATIC v2.0 -# ( https://apimatic.io ). - -module FlowrouteNumbersAndMessaging - # NumbersController - class NumbersController < BaseController - @instance = NumbersController.new - - class << self - attr_accessor :instance - end - - def instance - self.class.instance - end - - # Returns a list of all phone numbers currently on your Flowroute account. - # The response includes details such as the phone number's rate center, - # state, number type, and whether CNAM Lookup is enabled for that number. - # @param [Integer] starts_with Optional parameter: Retrieves phone numbers - # that start with the specified value. - # @param [Integer] ends_with Optional parameter: Retrieves phone numbers - # that end with the specified value. - # @param [Integer] contains Optional parameter: Retrieves phone numbers - # containing the specified value. - # @param [Integer] limit Optional parameter: Limits the number of items to - # retrieve. A maximum of 200 items can be retrieved. - # @param [Integer] offset Optional parameter: Offsets the list of phone - # numbers by your specified value. For example, if you have 4 phone numbers - # and you entered 1 as your offset value, then only 3 of your phone numbers - # will be displayed in the response. - # @return Mixed response from the API call - def list_account_phone_numbers(starts_with = nil, - ends_with = nil, - contains = nil, - limit = nil, - offset = nil) - # Prepare query url. - _query_builder = Configuration.base_uri.dup - _query_builder << '/v2/numbers' - _query_builder = APIHelper.append_url_with_query_parameters( - _query_builder, - { - 'starts_with' => starts_with, - 'ends_with' => ends_with, - 'contains' => contains, - 'limit' => limit, - 'offset' => offset - }, - array_serialization: Configuration.array_serialization - ) - _query_url = APIHelper.clean_url _query_builder - - # Prepare headers. - _headers = { - 'accept' => 'application/vnd.api+json' - } - - # Prepare and execute HttpRequest. - _request = @http_client.get( - _query_url, - headers: _headers - ) - BasicAuth.apply(_request) - _context = execute_request(_request) - - # Validate response against endpoint and global error codes. - if _context.response.status_code == 401 - raise ErrorException.new( - 'Unauthorized – There was an issue with your API credentials.', - _context - ) - elsif _context.response.status_code == 404 - raise ErrorException.new( - 'The specified resource was not found', - _context - ) - end - validate_response(_context) - - # Return appropriate response type. - decoded = APIHelper.json_deserialize(_context.response.raw_body) unless - _context.response.raw_body.nil? || - _context.response.raw_body.to_s.strip.empty? - decoded - end - - # Lists all of the information associated with any of the phone numbers in - # your account, including billing method, primary voice route, and failover - # voice route. - # @param [Integer] id Required parameter: Phone number to search for which - # must be a number that you own. Must be in 11-digit E.164 format; e.g. - # 12061231234. - # @return Number26 response from the API call - def list_phone_number_details(id) - # Prepare query url. - _query_builder = Configuration.base_uri.dup - _query_builder << '/v2/numbers/{id}' - _query_builder = APIHelper.append_url_with_template_parameters( - _query_builder, - 'id' => id - ) - _query_url = APIHelper.clean_url _query_builder - - # Prepare headers. - _headers = { - 'accept' => 'application/vnd.api+json' - } - - # Prepare and execute HttpRequest. - _request = @http_client.get( - _query_url, - headers: _headers - ) - BasicAuth.apply(_request) - _context = execute_request(_request) - - # Validate response against endpoint and global error codes. - if _context.response.status_code == 401 - raise APIException.new( - 'Unauthorized', - _context - ) - elsif _context.response.status_code == 404 - raise APIException.new( - 'Not Found', - _context - ) - end - validate_response(_context) - - # Return appropriate response type. - decoded = APIHelper.json_deserialize(_context.response.raw_body) unless - _context.response.raw_body.nil? || - _context.response.raw_body.to_s.strip.empty? - decoded - end - - # Lets you purchase a phone number from available Flowroute inventory. - # @param [Integer] id Required parameter: Phone number to purchase. Must be - # in 11-digit E.164 format; e.g. 12061231234. - # @return Number26 response from the API call - def purchase_a_phone_number(id) - # Prepare query url. - _query_builder = Configuration.base_uri.dup - _query_builder << '/v2/numbers/{id}' - _query_builder = APIHelper.append_url_with_template_parameters( - _query_builder, - 'id' => id - ) - _query_url = APIHelper.clean_url _query_builder - - # Prepare headers. - _headers = { - 'accept' => 'application/vnd.api+json' - } - - # Prepare and execute HttpRequest. - _request = @http_client.post( - _query_url, - headers: _headers - ) - BasicAuth.apply(_request) - _context = execute_request(_request) - - # Validate response against endpoint and global error codes. - if _context.response.status_code == 401 - raise ErrorException.new( - 'Unauthorized – There was an issue with your API credentials.', - _context - ) - elsif _context.response.status_code == 404 - raise ErrorException.new( - 'The specified resource was not found', - _context - ) - end - validate_response(_context) - - # Return appropriate response type. - decoded = APIHelper.json_deserialize(_context.response.raw_body) unless - _context.response.raw_body.nil? || - _context.response.raw_body.to_s.strip.empty? - decoded - end - - # This endpoint lets you search for phone numbers by state or rate center, - # or by your specified search value. - # @param [Integer] starts_with Optional parameter: Retrieve phone numbers - # that start with the specified value. - # @param [Integer] contains Optional parameter: Retrieve phone numbers - # containing the specified value. - # @param [Integer] ends_with Optional parameter: Retrieve phone numbers that - # end with the specified value. - # @param [Integer] limit Optional parameter: Limits the number of items to - # retrieve. A maximum of 200 items can be retrieved. - # @param [Integer] offset Optional parameter: Offsets the list of phone - # numbers by your specified value. For example, if you have 4 phone numbers - # and you entered 1 as your offset value, then only 3 of your phone numbers - # will be displayed in the response. - # @param [String] rate_center Optional parameter: Filters by and displays - # phone numbers in the specified rate center. - # @param [String] state Optional parameter: Filters by and displays phone - # numbers in the specified state. Optional unless a ratecenter is - # specified. - # @return Mixed response from the API call - def search_for_purchasable_phone_numbers(starts_with = nil, - contains = nil, - ends_with = nil, - limit = nil, - offset = nil, - rate_center = nil, - state = nil) - # Prepare query url. - _query_builder = Configuration.base_uri.dup - _query_builder << '/v2/numbers/available' - _query_builder = APIHelper.append_url_with_query_parameters( - _query_builder, - { - 'starts_with' => starts_with, - 'contains' => contains, - 'ends_with' => ends_with, - 'limit' => limit, - 'offset' => offset, - 'rate_center' => rate_center, - 'state' => state - }, - array_serialization: Configuration.array_serialization - ) - _query_url = APIHelper.clean_url _query_builder - - # Prepare headers. - _headers = { - 'accept' => 'application/vnd.api+json' - } - - # Prepare and execute HttpRequest. - _request = @http_client.get( - _query_url, - headers: _headers - ) - BasicAuth.apply(_request) - _context = execute_request(_request) - - # Validate response against endpoint and global error codes. - if _context.response.status_code == 401 - raise ErrorException.new( - 'Unauthorized – There was an issue with your API credentials.', - _context - ) - elsif _context.response.status_code == 404 - raise ErrorException.new( - 'The specified resource was not found', - _context - ) - end - validate_response(_context) - - # Return appropriate response type. - decoded = APIHelper.json_deserialize(_context.response.raw_body) unless - _context.response.raw_body.nil? || - _context.response.raw_body.to_s.strip.empty? - decoded - end - - # Returns a list of all Numbering Plan Area (NPA) codes containing - # purchasable phone numbers. - # @param [Integer] limit Optional parameter: Limits the number of items to - # retrieve. A maximum of 400 items can be retrieved. - # @param [Integer] offset Optional parameter: Offsets the list of phone - # numbers by your specified value. For example, if you have 4 phone numbers - # and you entered 1 as your offset value, then only 3 of your phone numbers - # will be displayed in the response. - # @param [Float] max_setup_cost Optional parameter: Restricts the results to - # the specified maximum non-recurring setup cost. - # @return mixed response from the API call - def list_available_area_codes(limit = nil, - offset = nil, - max_setup_cost = nil) - # Prepare query url. - _query_builder = Configuration.base_uri.dup - _query_builder << '/v2/numbers/available/areacodes' - _query_builder = APIHelper.append_url_with_query_parameters( - _query_builder, - { - 'limit' => limit, - 'offset' => offset, - 'max_setup_cost' => max_setup_cost - }, - array_serialization: Configuration.array_serialization - ) - _query_url = APIHelper.clean_url _query_builder - - # Prepare and execute HttpRequest. - _request = @http_client.get( - _query_url - ) - BasicAuth.apply(_request) - _context = execute_request(_request) - - # Validate response against endpoint and global error codes. - if _context.response.status_code == 401 - raise ErrorException.new( - 'Unauthorized – There was an issue with your API credentials.', - _context - ) - elsif _context.response.status_code == 404 - raise ErrorException.new( - 'The specified resource was not found', - _context - ) - end - validate_response(_context) - # Return appropriate response type. - decoded = APIHelper.json_deserialize(_context.response.raw_body) unless - _context.response.raw_body.nil? || - _context.response.raw_body.to_s.strip.empty? - decoded - end - - # Returns a list of all Central Office (exchange) codes containing - # purchasable phone numbers. - # @param [Integer] limit Optional parameter: Limits the number of items to - # retrieve. A maximum of 200 items can be retrieved. - # @param [Integer] offset Optional parameter: Offsets the list of phone - # numbers by your specified value. For example, if you have 4 phone numbers - # and you entered 1 as your offset value, then only 3 of your phone numbers - # will be displayed in the response. - # @param [Float] max_setup_cost Optional parameter: Restricts the results to - # the specified maximum non-recurring setup cost. - # @param [Integer] areacode Optional parameter: Restricts the results to the - # specified area code. - # @return mixed response from the API call - def list_available_exchange_codes(limit = nil, - offset = nil, - max_setup_cost = nil, - areacode = nil) - # Prepare query url. - _query_builder = Configuration.base_uri.dup - _query_builder << '/v2/numbers/available/exchanges' - _query_builder = APIHelper.append_url_with_query_parameters( - _query_builder, - { - 'limit' => limit, - 'offset' => offset, - 'max_setup_cost' => max_setup_cost, - 'areacode' => areacode - }, - array_serialization: Configuration.array_serialization - ) - _query_url = APIHelper.clean_url _query_builder - - # Prepare and execute HttpRequest. - _request = @http_client.get( - _query_url - ) - BasicAuth.apply(_request) - _context = execute_request(_request) - - # Validate response against endpoint and global error codes. - if _context.response.status_code == 401 - raise ErrorException.new( - 'Unauthorized – There was an issue with your API credentials.', - _context - ) - elsif _context.response.status_code == 404 - raise ErrorException.new( - 'The specified resource was not found', - _context - ) - end - validate_response(_context) - # Return appropriate response type. - decoded = APIHelper.json_deserialize(_context.response.raw_body) unless - _context.response.raw_body.nil? || - _context.response.raw_body.to_s.strip.empty? - decoded - end - - def set_did_alias(did_id, did_alias) - # Prepare query url. - _query_builder = Configuration.base_uri.dup - _query_builder << '/v2/numbers/{did_id}' - _query_builder = APIHelper.append_url_with_template_parameters( - _query_builder, - 'did_id' => did_id - ) - - _query_url = APIHelper.clean_url _query_builder - body = '{ "type" : "number", "alias" : "' - body << did_alias - body << '"}' - - # Prepare and execute HttpRequest. - _request = @http_client.patch( - _query_url, - parameters: body - ) - - BasicAuth.apply(_request) - _context = execute_request(_request) - - # Validate response against endpoint and global error codes. - if _context.response.status_code == 401 - raise APIException.new( - 'Unauthorized', - _context - ) - elsif _context.response.status_code == 404 - raise APIException.new( - 'Not Found', - _context - ) - end - validate_response(_context) - - # Return appropriate response type. - decoded = APIHelper.json_deserialize(_context.response.raw_body) unless - _context.response.raw_body.nil? || - _context.response.raw_body.to_s.strip.empty? - decoded - end - - def release_did(did_id) - # Prepare query url. - _query_builder = Configuration.base_uri.dup - _query_builder << '/v2/numbers/{did_id}' - _query_builder = APIHelper.append_url_with_template_parameters( - _query_builder, - 'did_id' => did_id - ) - - _query_url = APIHelper.clean_url _query_builder - - # Prepare and execute HttpRequest. - _request = @http_client.delete( - _query_url - ) - - BasicAuth.apply(_request) - _context = execute_request(_request) - - # Validate response against endpoint and global error codes. - if _context.response.status_code == 401 - raise APIException.new( - 'Unauthorized', - _context - ) - elsif _context.response.status_code == 404 - raise APIException.new( - 'Not Found', - _context - ) - end - validate_response(_context) - - # Return appropriate response type. - decoded = APIHelper.json_deserialize(_context.response.raw_body) unless - _context.response.raw_body.nil? || - _context.response.raw_body.to_s.strip.empty? - decoded - end - - def set_didsms_callback(did_id, callback_url) - - # Prepare query url. - _query_builder = Configuration.base_uri.dup - _query_builder << '/v2/numbers/{did_id}/relationships/dlr_callback' - _query_builder = APIHelper.append_url_with_template_parameters( - _query_builder, - 'did_id' => did_id - ) - - _query_url = APIHelper.clean_url _query_builder - body = { - "data" => { - "attributes" => { - "callback_url": callback_url - } - } - } - puts(body.to_s) - - # Prepare and execute HttpRequest. - _request = @http_client.post( - _query_url, - parameters: body.to_s, - headers: {"Content-Type" => "application/vnd.api+json"} - ) - - BasicAuth.apply(_request) - _context = execute_request(_request) - puts(_context.response.status_code) - puts(_context.response.raw_body) - - # Validate response against endpoint and global error codes. - if _context.response.status_code == 401 - raise APIException.new( - 'Unauthorized', - _context - ) - elsif _context.response.status_code == 404 - raise APIException.new( - 'Not Found', - _context - ) - end - validate_response(_context) - - # Return appropriate response type. - decoded = APIHelper.json_deserialize(_context.response.raw_body) unless - _context.response.raw_body.nil? || - _context.response.raw_body.to_s.strip.empty? - decoded - end - - end -end +# This file was automatically generated by APIMATIC v2.0 +# ( https://apimatic.io ). + +module FlowrouteNumbersAndMessaging + # NumbersController + class NumbersController < BaseController + @instance = NumbersController.new + + class << self + attr_accessor :instance + end + + def instance + self.class.instance + end + + # Returns a list of all phone numbers currently on your Flowroute account. + # The response includes details such as the phone number's rate center, + # state, number type, and whether CNAM Lookup is enabled for that number. + # @param [Integer] starts_with Optional parameter: Retrieves phone numbers + # that start with the specified value. + # @param [Integer] ends_with Optional parameter: Retrieves phone numbers + # that end with the specified value. + # @param [Integer] contains Optional parameter: Retrieves phone numbers + # containing the specified value. + # @param [Integer] limit Optional parameter: Limits the number of items to + # retrieve. A maximum of 200 items can be retrieved. + # @param [Integer] offset Optional parameter: Offsets the list of phone + # numbers by your specified value. For example, if you have 4 phone numbers + # and you entered 1 as your offset value, then only 3 of your phone numbers + # will be displayed in the response. + # @return Mixed response from the API call + def list_account_phone_numbers(starts_with = nil, + ends_with = nil, + contains = nil, + limit = nil, + offset = nil) + # Prepare query url. + _query_builder = Configuration.base_uri.dup + _query_builder << '/v2/numbers' + _query_builder = APIHelper.append_url_with_query_parameters( + _query_builder, + { + 'starts_with' => starts_with, + 'ends_with' => ends_with, + 'contains' => contains, + 'limit' => limit, + 'offset' => offset + }, + array_serialization: Configuration.array_serialization + ) + _query_url = APIHelper.clean_url _query_builder + + # Prepare headers. + _headers = { + 'accept' => 'application/vnd.api+json' + } + + # Prepare and execute HttpRequest. + _request = @http_client.get( + _query_url, + headers: _headers + ) + BasicAuth.apply(_request) + _context = execute_request(_request) + + # Validate response against endpoint and global error codes. + if _context.response.status_code == 401 + raise ErrorException.new( + 'Unauthorized – There was an issue with your API credentials.', + _context + ) + elsif _context.response.status_code == 404 + raise ErrorException.new( + 'The specified resource was not found', + _context + ) + end + validate_response(_context) + + # Return appropriate response type. + decoded = APIHelper.json_deserialize(_context.response.raw_body) unless + _context.response.raw_body.nil? || + _context.response.raw_body.to_s.strip.empty? + decoded + end + + # Lists all of the information associated with any of the phone numbers in + # your account, including billing method, primary voice route, and failover + # voice route. + # @param [Integer] id Required parameter: Phone number to search for which + # must be a number that you own. Must be in 11-digit E.164 format; e.g. + # 12061231234. + # @return Number26 response from the API call + def list_phone_number_details(id) + # Prepare query url. + _query_builder = Configuration.base_uri.dup + _query_builder << '/v2/numbers/{id}' + _query_builder = APIHelper.append_url_with_template_parameters( + _query_builder, + 'id' => id + ) + _query_url = APIHelper.clean_url _query_builder + + # Prepare headers. + _headers = { + 'accept' => 'application/vnd.api+json' + } + + # Prepare and execute HttpRequest. + _request = @http_client.get( + _query_url, + headers: _headers + ) + BasicAuth.apply(_request) + _context = execute_request(_request) + + # Validate response against endpoint and global error codes. + if _context.response.status_code == 401 + raise APIException.new( + 'Unauthorized', + _context + ) + elsif _context.response.status_code == 404 + raise APIException.new( + 'Not Found', + _context + ) + end + validate_response(_context) + + # Return appropriate response type. + decoded = APIHelper.json_deserialize(_context.response.raw_body) unless + _context.response.raw_body.nil? || + _context.response.raw_body.to_s.strip.empty? + decoded + end + + # Lets you purchase a phone number from available Flowroute inventory. + # @param [Integer] id Required parameter: Phone number to purchase. Must be + # in 11-digit E.164 format; e.g. 12061231234. + # @return Number26 response from the API call + def purchase_a_phone_number(id) + # Prepare query url. + _query_builder = Configuration.base_uri.dup + _query_builder << '/v2/numbers/{id}' + _query_builder = APIHelper.append_url_with_template_parameters( + _query_builder, + 'id' => id + ) + _query_url = APIHelper.clean_url _query_builder + + # Prepare headers. + _headers = { + 'accept' => 'application/vnd.api+json' + } + + # Prepare and execute HttpRequest. + _request = @http_client.post( + _query_url, + headers: _headers + ) + BasicAuth.apply(_request) + _context = execute_request(_request) + + # Validate response against endpoint and global error codes. + if _context.response.status_code == 401 + raise ErrorException.new( + 'Unauthorized – There was an issue with your API credentials.', + _context + ) + elsif _context.response.status_code == 404 + raise ErrorException.new( + 'The specified resource was not found', + _context + ) + end + validate_response(_context) + + # Return appropriate response type. + decoded = APIHelper.json_deserialize(_context.response.raw_body) unless + _context.response.raw_body.nil? || + _context.response.raw_body.to_s.strip.empty? + decoded + end + + # This endpoint lets you search for phone numbers by state or rate center, + # or by your specified search value. + # @param [Integer] starts_with Optional parameter: Retrieve phone numbers + # that start with the specified value. + # @param [Integer] contains Optional parameter: Retrieve phone numbers + # containing the specified value. + # @param [Integer] ends_with Optional parameter: Retrieve phone numbers that + # end with the specified value. + # @param [Integer] limit Optional parameter: Limits the number of items to + # retrieve. A maximum of 200 items can be retrieved. + # @param [Integer] offset Optional parameter: Offsets the list of phone + # numbers by your specified value. For example, if you have 4 phone numbers + # and you entered 1 as your offset value, then only 3 of your phone numbers + # will be displayed in the response. + # @param [String] rate_center Optional parameter: Filters by and displays + # phone numbers in the specified rate center. + # @param [String] state Optional parameter: Filters by and displays phone + # numbers in the specified state. Optional unless a ratecenter is + # specified. + # @return Mixed response from the API call + def search_for_purchasable_phone_numbers(starts_with = nil, + contains = nil, + ends_with = nil, + limit = nil, + offset = nil, + rate_center = nil, + state = nil) + # Prepare query url. + _query_builder = Configuration.base_uri.dup + _query_builder << '/v2/numbers/available' + _query_builder = APIHelper.append_url_with_query_parameters( + _query_builder, + { + 'starts_with' => starts_with, + 'contains' => contains, + 'ends_with' => ends_with, + 'limit' => limit, + 'offset' => offset, + 'rate_center' => rate_center, + 'state' => state + }, + array_serialization: Configuration.array_serialization + ) + _query_url = APIHelper.clean_url _query_builder + + # Prepare headers. + _headers = { + 'accept' => 'application/vnd.api+json' + } + + # Prepare and execute HttpRequest. + _request = @http_client.get( + _query_url, + headers: _headers + ) + BasicAuth.apply(_request) + _context = execute_request(_request) + + # Validate response against endpoint and global error codes. + if _context.response.status_code == 401 + raise ErrorException.new( + 'Unauthorized – There was an issue with your API credentials.', + _context + ) + elsif _context.response.status_code == 404 + raise ErrorException.new( + 'The specified resource was not found', + _context + ) + end + validate_response(_context) + + # Return appropriate response type. + decoded = APIHelper.json_deserialize(_context.response.raw_body) unless + _context.response.raw_body.nil? || + _context.response.raw_body.to_s.strip.empty? + decoded + end + + # Returns a list of all Numbering Plan Area (NPA) codes containing + # purchasable phone numbers. + # @param [Integer] limit Optional parameter: Limits the number of items to + # retrieve. A maximum of 400 items can be retrieved. + # @param [Integer] offset Optional parameter: Offsets the list of phone + # numbers by your specified value. For example, if you have 4 phone numbers + # and you entered 1 as your offset value, then only 3 of your phone numbers + # will be displayed in the response. + # @param [Float] max_setup_cost Optional parameter: Restricts the results to + # the specified maximum non-recurring setup cost. + # @return mixed response from the API call + def list_available_area_codes(limit = nil, + offset = nil, + max_setup_cost = nil) + # Prepare query url. + _query_builder = Configuration.base_uri.dup + _query_builder << '/v2/numbers/available/areacodes' + _query_builder = APIHelper.append_url_with_query_parameters( + _query_builder, + { + 'limit' => limit, + 'offset' => offset, + 'max_setup_cost' => max_setup_cost + }, + array_serialization: Configuration.array_serialization + ) + _query_url = APIHelper.clean_url _query_builder + + # Prepare and execute HttpRequest. + _request = @http_client.get( + _query_url + ) + BasicAuth.apply(_request) + _context = execute_request(_request) + + # Validate response against endpoint and global error codes. + if _context.response.status_code == 401 + raise ErrorException.new( + 'Unauthorized – There was an issue with your API credentials.', + _context + ) + elsif _context.response.status_code == 404 + raise ErrorException.new( + 'The specified resource was not found', + _context + ) + end + validate_response(_context) + # Return appropriate response type. + decoded = APIHelper.json_deserialize(_context.response.raw_body) unless + _context.response.raw_body.nil? || + _context.response.raw_body.to_s.strip.empty? + decoded + end + + # Returns a list of all Central Office (exchange) codes containing + # purchasable phone numbers. + # @param [Integer] limit Optional parameter: Limits the number of items to + # retrieve. A maximum of 200 items can be retrieved. + # @param [Integer] offset Optional parameter: Offsets the list of phone + # numbers by your specified value. For example, if you have 4 phone numbers + # and you entered 1 as your offset value, then only 3 of your phone numbers + # will be displayed in the response. + # @param [Float] max_setup_cost Optional parameter: Restricts the results to + # the specified maximum non-recurring setup cost. + # @param [Integer] areacode Optional parameter: Restricts the results to the + # specified area code. + # @return mixed response from the API call + def list_available_exchange_codes(limit = nil, + offset = nil, + max_setup_cost = nil, + areacode = nil) + # Prepare query url. + _query_builder = Configuration.base_uri.dup + _query_builder << '/v2/numbers/available/exchanges' + _query_builder = APIHelper.append_url_with_query_parameters( + _query_builder, + { + 'limit' => limit, + 'offset' => offset, + 'max_setup_cost' => max_setup_cost, + 'areacode' => areacode + }, + array_serialization: Configuration.array_serialization + ) + _query_url = APIHelper.clean_url _query_builder + + # Prepare and execute HttpRequest. + _request = @http_client.get( + _query_url + ) + BasicAuth.apply(_request) + _context = execute_request(_request) + + # Validate response against endpoint and global error codes. + if _context.response.status_code == 401 + raise ErrorException.new( + 'Unauthorized – There was an issue with your API credentials.', + _context + ) + elsif _context.response.status_code == 404 + raise ErrorException.new( + 'The specified resource was not found', + _context + ) + end + validate_response(_context) + # Return appropriate response type. + decoded = APIHelper.json_deserialize(_context.response.raw_body) unless + _context.response.raw_body.nil? || + _context.response.raw_body.to_s.strip.empty? + decoded + end + + def set_did_alias(did_id, did_alias) + # Prepare query url. + _query_builder = Configuration.base_uri.dup + _query_builder << '/v2/numbers/{did_id}' + _query_builder = APIHelper.append_url_with_template_parameters( + _query_builder, + 'did_id' => did_id + ) + + _query_url = APIHelper.clean_url _query_builder + body = '{ "type" : "number", "alias" : "' + body << did_alias + body << '"}' + + # Prepare and execute HttpRequest. + _request = @http_client.patch( + _query_url, + parameters: body + ) + + BasicAuth.apply(_request) + _context = execute_request(_request) + + # Validate response against endpoint and global error codes. + if _context.response.status_code == 401 + raise APIException.new( + 'Unauthorized', + _context + ) + elsif _context.response.status_code == 404 + raise APIException.new( + 'Not Found', + _context + ) + end + validate_response(_context) + + # Return appropriate response type. + decoded = APIHelper.json_deserialize(_context.response.raw_body) unless + _context.response.raw_body.nil? || + _context.response.raw_body.to_s.strip.empty? + decoded + end + + def release_did(did_id) + # Prepare query url. + _query_builder = Configuration.base_uri.dup + _query_builder << '/v2/numbers/{did_id}' + _query_builder = APIHelper.append_url_with_template_parameters( + _query_builder, + 'did_id' => did_id + ) + + _query_url = APIHelper.clean_url _query_builder + + # Prepare and execute HttpRequest. + _request = @http_client.delete( + _query_url + ) + + BasicAuth.apply(_request) + _context = execute_request(_request) + + # Validate response against endpoint and global error codes. + if _context.response.status_code == 401 + raise APIException.new( + 'Unauthorized', + _context + ) + elsif _context.response.status_code == 404 + raise APIException.new( + 'Not Found', + _context + ) + end + validate_response(_context) + + # Return appropriate response type. + decoded = APIHelper.json_deserialize(_context.response.raw_body) unless + _context.response.raw_body.nil? || + _context.response.raw_body.to_s.strip.empty? + decoded + end + + def set_didsms_callback(did_id, callback_url) + + # Prepare query url. + _query_builder = Configuration.base_uri.dup + _query_builder << '/v2/numbers/{did_id}/relationships/dlr_callback' + _query_builder = APIHelper.append_url_with_template_parameters( + _query_builder, + 'did_id' => did_id + ) + + _query_url = APIHelper.clean_url _query_builder + body = { + "data" => { + "attributes" => { + "callback_url": callback_url + } + } + } + Configuration.flowroute_logger.debug(body.to_s) + + # Prepare and execute HttpRequest. + _request = @http_client.post( + _query_url, + parameters: body.to_s, + headers: {"Content-Type" => "application/vnd.api+json"} + ) + + BasicAuth.apply(_request) + _context = execute_request(_request) + Configuration.flowroute_logger.debug(_context.response.status_code) + Configuration.flowroute_logger.debug(_context.response.raw_body) + + # Validate response against endpoint and global error codes. + if _context.response.status_code == 401 + raise APIException.new( + 'Unauthorized', + _context + ) + elsif _context.response.status_code == 404 + raise APIException.new( + 'Not Found', + _context + ) + end + validate_response(_context) + + # Return appropriate response type. + decoded = APIHelper.json_deserialize(_context.response.raw_body) unless + _context.response.raw_body.nil? || + _context.response.raw_body.to_s.strip.empty? + decoded + end + + end +end diff --git a/lib/flowroute_numbers_and_messaging/exceptions/api_exception.rb b/lib/flowroute_numbers_and_messaging/exceptions/api_exception.rb index 9e283e8..19d885c 100644 --- a/lib/flowroute_numbers_and_messaging/exceptions/api_exception.rb +++ b/lib/flowroute_numbers_and_messaging/exceptions/api_exception.rb @@ -1,20 +1,20 @@ -# This file was automatically generated by APIMATIC v2.0 -# ( https://apimatic.io ). - -module FlowrouteNumbersAndMessaging - # Class for exceptions when there is a network error, status code error, etc. - class APIException < StandardError - attr_reader :context, :response_code - - # The constructor. - # @param [String] The reason for raising an exception. - # @param [HttpContext] The HttpContext of the API call. - def initialize(reason, context) - super(reason) - @context = context - @response_code = context.response.status_code - puts(context.response.status_code) - puts(context.response.raw_body) - end - end -end +# This file was automatically generated by APIMATIC v2.0 +# ( https://apimatic.io ). + +module FlowrouteNumbersAndMessaging + # Class for exceptions when there is a network error, status code error, etc. + class APIException < StandardError + attr_reader :context, :response_code + + # The constructor. + # @param [String] The reason for raising an exception. + # @param [HttpContext] The HttpContext of the API call. + def initialize(reason, context) + super(reason) + @context = context + @response_code = context.response.status_code + Configuration.flowroute_logger.error(context.response.status_code) + Configuration.flowroute_logger.error(context.response.raw_body) + end + end +end diff --git a/lib/flowroute_numbers_and_messaging/railtie.rb b/lib/flowroute_numbers_and_messaging/railtie.rb new file mode 100644 index 0000000..516c2e1 --- /dev/null +++ b/lib/flowroute_numbers_and_messaging/railtie.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'rails/railtie' + +module Lograge + class Railtie < Rails::Railtie + config.after_initialize do |app| + ::FlowrouteNumbersAndMessaging::Configuration.flowroute_logger = Rails.logger if Rails.logger + end + end +end