# This file was automatically generated by APIMATIC v2.0 on 06/23/2016

module MagicTelecomApi
  class AccountsController
    @@instance = AccountsController.new
    # Singleton instance of the controller class
    def self.instance
      @@instance
    end

    # Create a new caller location
    # @param [String] account_number Required parameter: Number of the account
    # @param [CallerLocationForm] caller_location_form Required parameter: Caller Location Data
    # @return mixed response from the API call
    def create_caller_locations(account_number, caller_location_form)
      # the base uri for api requests
      query_builder = Configuration.base_uri.dup

      # prepare query string for API call
      query_builder << '/accounts/{account_number}/caller_locations'

      # process optional query parameters
      query_builder = APIHelper.append_url_with_template_parameters query_builder, {
        'account_number' => account_number
      }

      # validate and preprocess url
      query_url = APIHelper.clean_url query_builder

      # prepare headers
      headers = {
        'user-agent' => 'APIMATIC 2.0',
        'accept' => 'application/json',
        'content-type' => 'application/json; charset=utf-8',
        'X-Auth-Token' => Configuration.x_auth_token
      }

      # invoke the API call request to fetch the response
      response = Unirest.post query_url, headers: headers, parameters: caller_location_form.to_json

      # Error handling using HTTP status codes
      if response.code == 401
        raise APIException.new 'You are not authenticated', 401, response.raw_body
      elsif response.code == 403
        raise APIException.new 'This action needs a valid WSSE header', 403, response.raw_body
      elsif response.code == 404
        raise APIException.new 'Resource not found', 404, response.raw_body
      elsif response.code == 400
        raise APIException.new 'Http bad request', 400, response.raw_body
      elsif !response.code.between?(200, 206) # [200,206] = HTTP OK
        raise APIException.new 'HTTP Response Not OK', response.code, response.raw_body
      end

      response.body
    end

    # Get a caller location by Id
    # @param [String] account_number Required parameter: Account Number
    # @param [Numeric] caller_location_id Required parameter: a caller location id
    # @return mixed response from the API call
    def get_caller_location_by_id(account_number, caller_location_id)
      # the base uri for api requests
      query_builder = Configuration.base_uri.dup

      # prepare query string for API call
      query_builder << '/accounts/{account_number}/caller_locations/{caller_location_id}'

      # process optional query parameters
      query_builder = APIHelper.append_url_with_template_parameters query_builder, {
        'account_number' => account_number,
        'caller_location_id' => caller_location_id
      }

      # validate and preprocess url
      query_url = APIHelper.clean_url query_builder

      # prepare headers
      headers = {
        'user-agent' => 'APIMATIC 2.0',
        'accept' => 'application/json',
        'X-Auth-Token' => Configuration.x_auth_token
      }

      # invoke the API call request to fetch the response
      response = Unirest.get query_url, headers: headers

      # Error handling using HTTP status codes
      if response.code == 401
        raise APIException.new 'You are not authenticated', 401, response.raw_body
      elsif response.code == 403
        raise APIException.new 'This action needs a valid WSSE header', 403, response.raw_body
      elsif response.code == 404
        raise APIException.new 'Resource not found', 404, response.raw_body
      elsif response.code == 400
        raise APIException.new 'Http bad request', 400, response.raw_body
      elsif !response.code.between?(200, 206) # [200,206] = HTTP OK
        raise APIException.new 'HTTP Response Not OK', response.code, response.raw_body
      end

      response.body
    end

    # Delete all caller locations
    # @param [String] account_number Required parameter: Account Number
    # @return String response from the API call
    def delete_caller_locations(account_number)
      # the base uri for api requests
      query_builder = Configuration.base_uri.dup

      # prepare query string for API call
      query_builder << '/accounts/{account_number}/caller_locations'

      # process optional query parameters
      query_builder = APIHelper.append_url_with_template_parameters query_builder, {
        'account_number' => account_number
      }

      # validate and preprocess url
      query_url = APIHelper.clean_url query_builder

      # prepare headers
      headers = {
        'user-agent' => 'APIMATIC 2.0',
        'X-Auth-Token' => Configuration.x_auth_token
      }

      # invoke the API call request to fetch the response
      response = Unirest.delete query_url, headers: headers

      # Error handling using HTTP status codes
      if response.code == 401
        raise APIException.new 'You are not authenticated', 401, response.raw_body
      elsif response.code == 403
        raise APIException.new 'This action needs a valid WSSE header', 403, response.raw_body
      elsif response.code == 404
        raise APIException.new 'Resource not found', 404, response.raw_body
      elsif response.code == 400
        raise APIException.new 'Http bad request', 400, response.raw_body
      elsif !response.code.between?(200, 206) # [200,206] = HTTP OK
        raise APIException.new 'HTTP Response Not OK', response.code, response.raw_body
      end

      response.body
    end

    # Update a caller location
    # @param [String] account_number Required parameter: Account Number
    # @param [Numeric] caller_location_id Required parameter: Caller Location Id
    # @param [CallerLocationForm] caller_location_form Required parameter: Caller Location Params
    # @return String response from the API call
    def update_caller_location_by_id(account_number, caller_location_id, caller_location_form)
      # the base uri for api requests
      query_builder = Configuration.base_uri.dup

      # prepare query string for API call
      query_builder << '/accounts/{account_number}/caller_locations/{caller_location_id}'

      # process optional query parameters
      query_builder = APIHelper.append_url_with_template_parameters query_builder, {
        'account_number' => account_number,
        'caller_location_id' => caller_location_id
      }

      # validate and preprocess url
      query_url = APIHelper.clean_url query_builder

      # prepare headers
      headers = {
        'user-agent' => 'APIMATIC 2.0',
        'content-type' => 'application/json; charset=utf-8',
        'X-Auth-Token' => Configuration.x_auth_token
      }

      # invoke the API call request to fetch the response
      response = Unirest.put query_url, headers: headers, parameters: caller_location_form.to_json

      # Error handling using HTTP status codes
      if response.code == 401
        raise APIException.new 'You are not authenticated', 401, response.raw_body
      elsif response.code == 403
        raise APIException.new 'This action needs a valid WSSE header', 403, response.raw_body
      elsif response.code == 404
        raise APIException.new '	 Resource not found', 404, response.raw_body
      elsif response.code == 400
        raise APIException.new 'Http bad request', 400, response.raw_body
      elsif !response.code.between?(200, 206) # [200,206] = HTTP OK
        raise APIException.new 'HTTP Response Not OK', response.code, response.raw_body
      end

      response.body
    end

    # Delete a caller location by id
    # @param [String] account_number Required parameter: Account Number
    # @param [Numeric] caller_location_id Required parameter: Caller Location Id
    # @return String response from the API call
    def delete_caller_location_by_id(account_number, caller_location_id)
      # the base uri for api requests
      query_builder = Configuration.base_uri.dup

      # prepare query string for API call
      query_builder << '/accounts/{account_number}/caller_locations/{caller_location_id}'

      # process optional query parameters
      query_builder = APIHelper.append_url_with_template_parameters query_builder, {
        'account_number' => account_number,
        'caller_location_id' => caller_location_id
      }

      # validate and preprocess url
      query_url = APIHelper.clean_url query_builder

      # prepare headers
      headers = {
        'user-agent' => 'APIMATIC 2.0',
        'X-Auth-Token' => Configuration.x_auth_token
      }

      # invoke the API call request to fetch the response
      response = Unirest.delete query_url, headers: headers

      # Error handling using HTTP status codes
      if response.code == 401
        raise APIException.new 'You are not authenticated', 401, response.raw_body
      elsif response.code == 403
        raise APIException.new 'This action needs a valid WSSE header', 403, response.raw_body
      elsif response.code == 404
        raise APIException.new '	 Resource not found', 404, response.raw_body
      elsif response.code == 400
        raise APIException.new 'Http bad request', 400, response.raw_body
      elsif !response.code.between?(200, 206) # [200,206] = HTTP OK
        raise APIException.new 'HTTP Response Not OK', response.code, response.raw_body
      end

      response.body
    end

    # Allow clients to get the list of caller locations for the specific account.
    # @param [String] account_number Required parameter: Number of the account
    # @param [Numeric] page Optional parameter: Zero based offset index for the results. e.g. 0 would start at the first result and 10 would start at the eleventh result
    # @param [Numeric] limit Optional parameter: Maximum number of results to return in the response.
    # @return mixed response from the API call
    def get_caller_locations(account_number, page = 1, limit = 10)
      # the base uri for api requests
      query_builder = Configuration.base_uri.dup

      # prepare query string for API call
      query_builder << '/accounts/{account_number}/caller_locations'

      # process optional query parameters
      query_builder = APIHelper.append_url_with_template_parameters query_builder, {
        'account_number' => account_number
      }

      # process optional query parameters
      query_builder = APIHelper.append_url_with_query_parameters query_builder, {
        'page' => if page.nil? then 1 else page end,
        'limit' => if limit.nil? then 10 else limit end
      }

      # validate and preprocess url
      query_url = APIHelper.clean_url query_builder

      # prepare headers
      headers = {
        'user-agent' => 'APIMATIC 2.0',
        'accept' => 'application/json',
        'X-Auth-Token' => Configuration.x_auth_token
      }

      # invoke the API call request to fetch the response
      response = Unirest.get query_url, headers: headers

      # Error handling using HTTP status codes
      if response.code == 401
        raise APIException.new 'You are not authenticated', 401, response.raw_body
      elsif response.code == 403
        raise APIException.new 'This action needs a valid WSSE header', 403, response.raw_body
      elsif response.code == 404
        raise APIException.new 'Resource not found', 404, response.raw_body
      elsif response.code == 400
        raise APIException.new 'Http bad request', 400, response.raw_body
      elsif !response.code.between?(200, 206) # [200,206] = HTTP OK
        raise APIException.new 'HTTP Response Not OK', response.code, response.raw_body
      end

      response.body
    end

    # Allow the admin to get the list of all accounts.
    # @param [Numeric] page Optional parameter: Zero based offset index for the results. e.g. 0 would start at the first result and 10 would start at the eleventh result.
    # @param [Numeric] limit Optional parameter: Maximum number of results to return in the response.
    # @param [String] filter Optional parameter: Allowed fields: number, email, contact_number, firstname, lastname. Use the following delimiters to build your filters params. The vertical bar ('|') to separate individual filter phrases and a double colon ('::') to separate the names and values. The delimiter of the double colon (':') separates the property name from the comparison value, enabling the comparison value to contain spaces. Example: www.example.com\\\/users?filter='name::todd|city::denver|title::grand poobah
    # @return mixed response from the API call
    def get_accounts(page = 1, limit = 10, filter = nil)
      # the base uri for api requests
      query_builder = Configuration.base_uri.dup

      # prepare query string for API call
      query_builder << '/accounts'

      # process optional query parameters
      query_builder = APIHelper.append_url_with_query_parameters query_builder, {
        'page' => if page.nil? then 1 else page end,
        'limit' => if limit.nil? then 10 else limit end,
        'filter' => filter
      }

      # validate and preprocess url
      query_url = APIHelper.clean_url query_builder

      # prepare headers
      headers = {
        'user-agent' => 'APIMATIC 2.0',
        'accept' => 'application/json',
        'X-Auth-Token' => Configuration.x_auth_token
      }

      # invoke the API call request to fetch the response
      response = Unirest.get query_url, headers: headers

      # Error handling using HTTP status codes
      if response.code == 401
        raise APIException.new 'You are not authenticated', 401, response.raw_body
      elsif response.code == 403
        raise APIException.new 'This action needs a valid WSSE header', 403, response.raw_body
      elsif response.code == 404
        raise APIException.new 'Resource not found', 404, response.raw_body
      elsif response.code == 400
        raise APIException.new 'Http bad request', 400, response.raw_body
      elsif !response.code.between?(200, 206) # [200,206] = HTTP OK
        raise APIException.new 'HTTP Response Not OK', response.code, response.raw_body
      end

      response.body
    end

    # Create a new account.
    # @param [AccountForm] account_form Required parameter: TODO: type description here
    # @return mixed response from the API call
    def create_account(account_form)
      # the base uri for api requests
      query_builder = Configuration.base_uri.dup

      # prepare query string for API call
      query_builder << '/accounts'

      # validate and preprocess url
      query_url = APIHelper.clean_url query_builder

      # prepare headers
      headers = {
        'user-agent' => 'APIMATIC 2.0',
        'accept' => 'application/json',
        'content-type' => 'application/json; charset=utf-8',
        'X-Auth-Token' => Configuration.x_auth_token
      }

      # invoke the API call request to fetch the response
      response = Unirest.post query_url, headers: headers, parameters: account_form.to_json

      # Error handling using HTTP status codes
      if response.code == 401
        raise APIException.new 'You are not authenticated', 401, response.raw_body
      elsif response.code == 403
        raise APIException.new 'This action needs a valid WSSE header', 403, response.raw_body
      elsif response.code == 404
        raise APIException.new 'Resource not found', 404, response.raw_body
      elsif response.code == 400
        raise APIException.new 'Http bad request', 400, response.raw_body
      elsif !response.code.between?(200, 206) # [200,206] = HTTP OK
        raise APIException.new 'HTTP Response Not OK', response.code, response.raw_body
      end

      response.body
    end

    # Delete an account
    # @param [String] account_number Required parameter: Account Number
    # @return String response from the API call
    def delete_account(account_number)
      # the base uri for api requests
      query_builder = Configuration.base_uri.dup

      # prepare query string for API call
      query_builder << '/accounts/{account_number}'

      # process optional query parameters
      query_builder = APIHelper.append_url_with_template_parameters query_builder, {
        'account_number' => account_number
      }

      # validate and preprocess url
      query_url = APIHelper.clean_url query_builder

      # prepare headers
      headers = {
        'user-agent' => 'APIMATIC 2.0',
        'X-Auth-Token' => Configuration.x_auth_token
      }

      # invoke the API call request to fetch the response
      response = Unirest.delete query_url, headers: headers

      # Error handling using HTTP status codes
      if response.code == 401
        raise APIException.new 'You are not authenticated', 401, response.raw_body
      elsif response.code == 403
        raise APIException.new 'This action needs a valid WSSE header', 403, response.raw_body
      elsif response.code == 404
        raise APIException.new 'Resource not found', 404, response.raw_body
      elsif response.code == 400
        raise APIException.new 'Http bad request', 400, response.raw_body
      elsif !response.code.between?(200, 206) # [200,206] = HTTP OK
        raise APIException.new 'HTTP Response Not OK', response.code, response.raw_body
      end

      response.body
    end

    # Allow clients to get a specific account.
    # @param [String] account_number Required parameter: Account Number
    # @return mixed response from the API call
    def get_account(account_number)
      # the base uri for api requests
      query_builder = Configuration.base_uri.dup

      # prepare query string for API call
      query_builder << '/accounts/{account_number}'

      # process optional query parameters
      query_builder = APIHelper.append_url_with_template_parameters query_builder, {
        'account_number' => account_number
      }

      # validate and preprocess url
      query_url = APIHelper.clean_url query_builder

      # prepare headers
      headers = {
        'user-agent' => 'APIMATIC 2.0',
        'accept' => 'application/json',
        'X-Auth-Token' => Configuration.x_auth_token
      }

      # invoke the API call request to fetch the response
      response = Unirest.get query_url, headers: headers

      # Error handling using HTTP status codes
      if response.code == 401
        raise APIException.new 'You are not authenticated', 401, response.raw_body
      elsif response.code == 403
        raise APIException.new 'This action needs a valid WSSE header', 403, response.raw_body
      elsif response.code == 404
        raise APIException.new 'Resource not found', 404, response.raw_body
      elsif response.code == 400
        raise APIException.new 'Http bad request', 400, response.raw_body
      elsif !response.code.between?(200, 206) # [200,206] = HTTP OK
        raise APIException.new 'HTTP Response Not OK', response.code, response.raw_body
      end

      response.body
    end

    #  Update an account by a given account_number
    # @param [String] account_number Required parameter: Account Number
    # @param [AccountForm] account_form Required parameter: Form parameters
    # @return String response from the API call
    def update_account(account_number, account_form)
      # the base uri for api requests
      query_builder = Configuration.base_uri.dup

      # prepare query string for API call
      query_builder << '/accounts/{account_number}'

      # process optional query parameters
      query_builder = APIHelper.append_url_with_template_parameters query_builder, {
        'account_number' => account_number
      }

      # validate and preprocess url
      query_url = APIHelper.clean_url query_builder

      # prepare headers
      headers = {
        'user-agent' => 'APIMATIC 2.0',
        'content-type' => 'application/json; charset=utf-8',
        'X-Auth-Token' => Configuration.x_auth_token
      }

      # invoke the API call request to fetch the response
      response = Unirest.put query_url, headers: headers, parameters: account_form.to_json

      # Error handling using HTTP status codes
      if response.code == 401
        raise APIException.new 'You are not authenticated', 401, response.raw_body
      elsif response.code == 403
        raise APIException.new 'This action needs a valid WSSE header', 403, response.raw_body
      elsif response.code == 404
        raise APIException.new 'Resource not found', 404, response.raw_body
      elsif response.code == 400
        raise APIException.new 'Http bad request', 400, response.raw_body
      elsif !response.code.between?(200, 206) # [200,206] = HTTP OK
        raise APIException.new 'HTTP Response Not OK', response.code, response.raw_body
      end

      response.body
    end

    # Deletes all cdrs requests from customer's account.
    # @param [String] account_number Required parameter: Account Number
    # @return String response from the API call
    def delete_cdrs(account_number)
      # the base uri for api requests
      query_builder = Configuration.base_uri.dup

      # prepare query string for API call
      query_builder << '/accounts/{account_number}/cdrs'

      # process optional query parameters
      query_builder = APIHelper.append_url_with_template_parameters query_builder, {
        'account_number' => account_number
      }

      # validate and preprocess url
      query_url = APIHelper.clean_url query_builder

      # prepare headers
      headers = {
        'user-agent' => 'APIMATIC 2.0',
        'X-Auth-Token' => Configuration.x_auth_token
      }

      # invoke the API call request to fetch the response
      response = Unirest.delete query_url, headers: headers

      # Error handling using HTTP status codes
      if response.code == 401
        raise APIException.new 'You are not authenticated', 401, response.raw_body
      elsif response.code == 403
        raise APIException.new 'This action needs a valid WSSE header', 403, response.raw_body
      elsif response.code == 404
        raise APIException.new 'Resource not found', 404, response.raw_body
      elsif response.code == 400
        raise APIException.new 'Http bad request', 400, response.raw_body
      elsif !response.code.between?(200, 206) # [200,206] = HTTP OK
        raise APIException.new 'HTTP Response Not OK', response.code, response.raw_body
      end

      response.body
    end

    # Allow clients to get the list of cdr request for the specific account.
    # @param [String] account_number Required parameter: Account Number
    # @param [Numeric] page Optional parameter: Zero based offset index for the results. e.g. 0 would start at the first result and 10 would start at the eleventh result.
    # @param [Numeric] limit Optional parameter: Maximum number of results to return in the response.
    # @param [String] filter Optional parameter: Allowed fields: service_type, from, to and created. Use the following delimiters to build your filters params. The vertical bar ('|') to separate individual filter phrases and a double colon ('::') to separate the names and values. The delimiter of the double colon (':') separates the property name from the comparison value, enabling the comparison value to contain spaces. Example: www.example.com\\\/users?filter='name::todd|city::denver|title::grand poobah
    # @return mixed response from the API call
    def get_cdrs(account_number, page = 1, limit = 10, filter = nil)
      # the base uri for api requests
      query_builder = Configuration.base_uri.dup

      # prepare query string for API call
      query_builder << '/accounts/{account_number}/cdrs'

      # process optional query parameters
      query_builder = APIHelper.append_url_with_template_parameters query_builder, {
        'account_number' => account_number
      }

      # process optional query parameters
      query_builder = APIHelper.append_url_with_query_parameters query_builder, {
        'page' => if page.nil? then 1 else page end,
        'limit' => if limit.nil? then 10 else limit end,
        'filter' => filter
      }

      # validate and preprocess url
      query_url = APIHelper.clean_url query_builder

      # prepare headers
      headers = {
        'user-agent' => 'APIMATIC 2.0',
        'accept' => 'application/json',
        'X-Auth-Token' => Configuration.x_auth_token
      }

      # invoke the API call request to fetch the response
      response = Unirest.get query_url, headers: headers

      # Error handling using HTTP status codes
      if response.code == 401
        raise APIException.new 'You are not authenticated', 401, response.raw_body
      elsif response.code == 403
        raise APIException.new 'This action needs a valid WSSE header', 403, response.raw_body
      elsif response.code == 404
        raise APIException.new 'Resource not found', 404, response.raw_body
      elsif response.code == 400
        raise APIException.new 'Http bad request', 400, response.raw_body
      elsif !response.code.between?(200, 206) # [200,206] = HTTP OK
        raise APIException.new 'HTTP Response Not OK', response.code, response.raw_body
      end

      response.body
    end

    # Creates a cdr request
    # @param [String] account_number Required parameter: Account Number
    # @param [CdrForm] cdrs_form Required parameter: cdrs params
    # @return mixed response from the API call
    def create_cdrs(account_number, cdrs_form)
      # the base uri for api requests
      query_builder = Configuration.base_uri.dup

      # prepare query string for API call
      query_builder << '/accounts/{account_number}/cdrs'

      # process optional query parameters
      query_builder = APIHelper.append_url_with_template_parameters query_builder, {
        'account_number' => account_number
      }

      # validate and preprocess url
      query_url = APIHelper.clean_url query_builder

      # prepare headers
      headers = {
        'user-agent' => 'APIMATIC 2.0',
        'accept' => 'application/json',
        'content-type' => 'application/json; charset=utf-8',
        'X-Auth-Token' => Configuration.x_auth_token
      }

      # invoke the API call request to fetch the response
      response = Unirest.post query_url, headers: headers, parameters: cdrs_form.to_json

      # Error handling using HTTP status codes
      if response.code == 401
        raise APIException.new 'You are not authenticated', 401, response.raw_body
      elsif response.code == 403
        raise APIException.new 'This action needs a valid WSSE header', 403, response.raw_body
      elsif response.code == 404
        raise APIException.new 'Resource not found', 404, response.raw_body
      elsif response.code == 400
        raise APIException.new 'Http bad request', 400, response.raw_body
      elsif !response.code.between?(200, 206) # [200,206] = HTTP OK
        raise APIException.new 'HTTP Response Not OK', response.code, response.raw_body
      end

      response.body
    end

    # Allow clients to download the cdrs in a file
    # @param [String] account_number Required parameter: Account Number
    # @param [String] cdr_id Required parameter: Cdr Id
    # @return mixed response from the API call
    def get_cdr_by_id(account_number, cdr_id)
      # the base uri for api requests
      query_builder = Configuration.base_uri.dup

      # prepare query string for API call
      query_builder << '/accounts/{account_number}/cdrs/{cdr_id}'

      # process optional query parameters
      query_builder = APIHelper.append_url_with_template_parameters query_builder, {
        'account_number' => account_number,
        'cdr_id' => cdr_id
      }

      # validate and preprocess url
      query_url = APIHelper.clean_url query_builder

      # prepare headers
      headers = {
        'user-agent' => 'APIMATIC 2.0',
        'accept' => 'application/json',
        'X-Auth-Token' => Configuration.x_auth_token
      }

      # invoke the API call request to fetch the response
      response = Unirest.get query_url, headers: headers

      # Error handling using HTTP status codes
      if response.code == 401
        raise APIException.new 'You are not authenticated', 401, response.raw_body
      elsif response.code == 403
        raise APIException.new 'This action needs a valid WSSE header', 403, response.raw_body
      elsif response.code == 404
        raise APIException.new '	 Resource not found', 404, response.raw_body
      elsif response.code == 400
        raise APIException.new 'Http bad request', 400, response.raw_body
      elsif !response.code.between?(200, 206) # [200,206] = HTTP OK
        raise APIException.new 'HTTP Response Not OK', response.code, response.raw_body
      end

      response.body
    end

    # Deletes a cdr file from customer's account.
    # @param [String] account_number Required parameter: Account Number
    # @param [String] cdr_id Required parameter: Cdr Id
    # @return String response from the API call
    def delete_cdr_by_id(account_number, cdr_id)
      # the base uri for api requests
      query_builder = Configuration.base_uri.dup

      # prepare query string for API call
      query_builder << '/accounts/{account_number}/cdrs/{cdr_id}'

      # process optional query parameters
      query_builder = APIHelper.append_url_with_template_parameters query_builder, {
        'account_number' => account_number,
        'cdr_id' => cdr_id
      }

      # validate and preprocess url
      query_url = APIHelper.clean_url query_builder

      # prepare headers
      headers = {
        'user-agent' => 'APIMATIC 2.0',
        'X-Auth-Token' => Configuration.x_auth_token
      }

      # invoke the API call request to fetch the response
      response = Unirest.delete query_url, headers: headers

      # Error handling using HTTP status codes
      if response.code == 401
        raise APIException.new 'You are not authenticated', 401, response.raw_body
      elsif response.code == 403
        raise APIException.new 'This action needs a valid WSSE header', 403, response.raw_body
      elsif response.code == 404
        raise APIException.new 'Resource not found', 404, response.raw_body
      elsif response.code == 400
        raise APIException.new 'Http bad request', 400, response.raw_body
      elsif !response.code.between?(200, 206) # [200,206] = HTTP OK
        raise APIException.new 'HTTP Response Not OK', response.code, response.raw_body
      end

      response.body
    end

    # Deletes all phone_number from customer's account. These numbers must be unassigned and returned to Magic stock.
    # @param [String] account_number Required parameter: Account Number
    # @return String response from the API call
    def delete_dids(account_number)
      # the base uri for api requests
      query_builder = Configuration.base_uri.dup

      # prepare query string for API call
      query_builder << '/accounts/{account_number}/dids'

      # process optional query parameters
      query_builder = APIHelper.append_url_with_template_parameters query_builder, {
        'account_number' => account_number
      }

      # validate and preprocess url
      query_url = APIHelper.clean_url query_builder

      # prepare headers
      headers = {
        'user-agent' => 'APIMATIC 2.0',
        'X-Auth-Token' => Configuration.x_auth_token
      }

      # invoke the API call request to fetch the response
      response = Unirest.delete query_url, headers: headers

      # Error handling using HTTP status codes
      if response.code == 401
        raise APIException.new 'You are not authenticated', 401, response.raw_body
      elsif response.code == 403
        raise APIException.new 'This action needs a valid WSSE header', 403, response.raw_body
      elsif response.code == 404
        raise APIException.new 'Resource not found', 404, response.raw_body
      elsif response.code == 400
        raise APIException.new 'Http bad request', 400, response.raw_body
      elsif !response.code.between?(200, 206) # [200,206] = HTTP OK
        raise APIException.new 'HTTP Response Not OK', response.code, response.raw_body
      end

      response.body
    end

    # Deletes a phone_number from customer's account. This number must be unassigned and returned to Magic stock.
    # @param [String] account_number Required parameter: Account Number
    # @param [String] telephone_number Required parameter: Telephone Number
    # @return String response from the API call
    def delete_telephone_number(account_number, telephone_number)
      # the base uri for api requests
      query_builder = Configuration.base_uri.dup

      # prepare query string for API call
      query_builder << '/accounts/{account_number}/dids/{telephone_number}'

      # process optional query parameters
      query_builder = APIHelper.append_url_with_template_parameters query_builder, {
        'account_number' => account_number,
        'telephone_number' => telephone_number
      }

      # validate and preprocess url
      query_url = APIHelper.clean_url query_builder

      # prepare headers
      headers = {
        'user-agent' => 'APIMATIC 2.0',
        'X-Auth-Token' => Configuration.x_auth_token
      }

      # invoke the API call request to fetch the response
      response = Unirest.delete query_url, headers: headers

      # Error handling using HTTP status codes
      if response.code == 401
        raise APIException.new 'You are not authenticated', 401, response.raw_body
      elsif response.code == 403
        raise APIException.new 'This action needs a valid WSSE header', 403, response.raw_body
      elsif response.code == 404
        raise APIException.new 'Resource not found', 404, response.raw_body
      elsif response.code == 400
        raise APIException.new 'Http bad request', 400, response.raw_body
      elsif !response.code.between?(200, 206) # [200,206] = HTTP OK
        raise APIException.new 'HTTP Response Not OK', response.code, response.raw_body
      end

      response.body
    end

    # Allow clients to get the a specific phone number.
    # @param [String] account_number Required parameter: Account Number
    # @param [String] telephone_number Required parameter: Telephone Number
    # @return mixed response from the API call
    def get_telephone_number(account_number, telephone_number)
      # the base uri for api requests
      query_builder = Configuration.base_uri.dup

      # prepare query string for API call
      query_builder << '/accounts/{account_number}/dids/{telephone_number}'

      # process optional query parameters
      query_builder = APIHelper.append_url_with_template_parameters query_builder, {
        'account_number' => account_number,
        'telephone_number' => telephone_number
      }

      # validate and preprocess url
      query_url = APIHelper.clean_url query_builder

      # prepare headers
      headers = {
        'user-agent' => 'APIMATIC 2.0',
        'accept' => 'application/json',
        'X-Auth-Token' => Configuration.x_auth_token
      }

      # invoke the API call request to fetch the response
      response = Unirest.get query_url, headers: headers

      # Error handling using HTTP status codes
      if response.code == 401
        raise APIException.new 'You are not authenticated', 401, response.raw_body
      elsif response.code == 403
        raise APIException.new 'This action needs a valid WSSE header', 403, response.raw_body
      elsif response.code == 404
        raise APIException.new 'Resource not found', 404, response.raw_body
      elsif response.code == 400
        raise APIException.new 'Http bad request', 400, response.raw_body
      elsif !response.code.between?(200, 206) # [200,206] = HTTP OK
        raise APIException.new 'HTTP Response Not OK', response.code, response.raw_body
      end

      response.body
    end

    # Allow client to perform operations on a specific did
    # @param [String] account_number Required parameter: Account Number
    # @param [String] telephone_number Required parameter: Telephone Number
    # @param [TelephoneNumberForm] telephone_number_form Required parameter: Phone params
    # @return void response from the API call
    def update_telephone_number(account_number, telephone_number, telephone_number_form)
      # the base uri for api requests
      query_builder = Configuration.base_uri.dup

      # prepare query string for API call
      query_builder << '/accounts/{account_number}/dids/{telephone_number}'

      # process optional query parameters
      query_builder = APIHelper.append_url_with_template_parameters query_builder, {
        'account_number' => account_number,
        'telephone_number' => telephone_number
      }

      # validate and preprocess url
      query_url = APIHelper.clean_url query_builder

      # prepare headers
      headers = {
        'user-agent' => 'APIMATIC 2.0',
        'content-type' => 'application/json; charset=utf-8',
        'X-Auth-Token' => Configuration.x_auth_token
      }

      # invoke the API call request to fetch the response
      response = Unirest.patch query_url, headers: headers, parameters: telephone_number_form.to_json

      # Error handling using HTTP status codes
      if response.code == 401
        raise APIException.new 'You are not authenticated', 401, response.raw_body
      elsif response.code == 403
        raise APIException.new 'This action needs a valid WSSE header', 403, response.raw_body
      elsif response.code == 404
        raise APIException.new 'Resource not found', 404, response.raw_body
      elsif response.code == 400
        raise APIException.new 'Http bad request', 400, response.raw_body
      elsif !response.code.between?(200, 206) # [200,206] = HTTP OK
        raise APIException.new 'HTTP Response Not OK', response.code, response.raw_body
      end
    end

    # Allow clients to get the list of numbers for the specific account
    # @param [String] account_number Required parameter: Account Number
    # @param [Numeric] page Optional parameter: Zero based offset index for the results. e.g. 0 would start at the first result and 10 would start at the eleventh result.
    # @param [Numeric] limit Optional parameter: Maximum number of results to return in the response.
    # @param [String] filter Optional parameter: Allowed fields: trunk_id, phone_number, country_iso2, region_handle, location_handle, sip_end_point_uri.\n * Use the following delimiters to build your filters params. The vertical bar ('|') to separate individual filter phrases and a double colon ('::') to separate the names and values. \n * The delimiter of the double colon (':') separates the property name from the comparison value, enabling the comparison value to contain spaces. \n * Example: www.example.com\\\/users?filter='name::todd|city::denver|title::grand poobah
    # @return mixed response from the API call
    def get_dids(account_number, page = 1, limit = 10, filter = nil)
      # the base uri for api requests
      query_builder = Configuration.base_uri.dup

      # prepare query string for API call
      query_builder << '/accounts/{account_number}/dids'

      # process optional query parameters
      query_builder = APIHelper.append_url_with_template_parameters query_builder, {
        'account_number' => account_number
      }

      # process optional query parameters
      query_builder = APIHelper.append_url_with_query_parameters query_builder, {
        'page' => if page.nil? then 1 else page end,
        'limit' => if limit.nil? then 10 else limit end,
        'filter' => filter
      }

      # validate and preprocess url
      query_url = APIHelper.clean_url query_builder

      # prepare headers
      headers = {
        'user-agent' => 'APIMATIC 2.0',
        'accept' => 'application/json',
        'X-Auth-Token' => Configuration.x_auth_token
      }

      # invoke the API call request to fetch the response
      response = Unirest.get query_url, headers: headers

      # Error handling using HTTP status codes
      if response.code == 401
        raise APIException.new 'You are not authenticated', 401, response.raw_body
      elsif response.code == 403
        raise APIException.new 'This action needs a valid WSSE header', 403, response.raw_body
      elsif response.code == 404
        raise APIException.new 'Resource not found', 404, response.raw_body
      elsif response.code == 400
        raise APIException.new 'Http bad request', 400, response.raw_body
      elsif !response.code.between?(200, 206) # [200,206] = HTTP OK
        raise APIException.new 'HTTP Response Not OK', response.code, response.raw_body
      end

      response.body
    end

    # Deletes all trunks from customer's account. Numbers on that trunk must be unassigned and returned to Magic stock
    # @param [String] account_number Required parameter: Account Number
    # @return String response from the API call
    def delete_trunks(account_number)
      # the base uri for api requests
      query_builder = Configuration.base_uri.dup

      # prepare query string for API call
      query_builder << '/accounts/{account_number}/trunks'

      # process optional query parameters
      query_builder = APIHelper.append_url_with_template_parameters query_builder, {
        'account_number' => account_number
      }

      # validate and preprocess url
      query_url = APIHelper.clean_url query_builder

      # prepare headers
      headers = {
        'user-agent' => 'APIMATIC 2.0',
        'X-Auth-Token' => Configuration.x_auth_token
      }

      # invoke the API call request to fetch the response
      response = Unirest.delete query_url, headers: headers

      # Error handling using HTTP status codes
      if response.code == 401
        raise APIException.new 'You are not authenticated', 401, response.raw_body
      elsif response.code == 403
        raise APIException.new 'This action needs a valid WSSE header', 403, response.raw_body
      elsif response.code == 404
        raise APIException.new 'Resource not found', 404, response.raw_body
      elsif response.code == 400
        raise APIException.new 'Http bad request', 400, response.raw_body
      elsif !response.code.between?(200, 206) # [200,206] = HTTP OK
        raise APIException.new 'HTTP Response Not OK', response.code, response.raw_body
      end

      response.body
    end

    # Allow clients to get the list of trunks for the specific account
    # @param [String] account_number Required parameter: Account Number
    # @param [Numeric] page Optional parameter: Zero based offset index for the results. e.g. 0 would start at the first result and 10 would start at the eleventh result.
    # @param [Numeric] limit Optional parameter: Maximum number of results to return in the response
    # @param [String] filter Optional parameter: Allowed fields: trunk_handle. Use the following delimiters to build your filters params. The vertical bar ('|') to separate individual filter phrases and a double colon ('::') to separate the names and values. The delimiter of the double colon (':') separates the property name from the comparison value, enabling the comparison value to contain spaces. Example: www.example.com\\\/users?filter='name::todd|city::denver|title::grand poobah
    # @return mixed response from the API call
    def get_trunks(account_number, page = 1, limit = 10, filter = nil)
      # the base uri for api requests
      query_builder = Configuration.base_uri.dup

      # prepare query string for API call
      query_builder << '/accounts/{account_number}/trunks'

      # process optional query parameters
      query_builder = APIHelper.append_url_with_template_parameters query_builder, {
        'account_number' => account_number
      }

      # process optional query parameters
      query_builder = APIHelper.append_url_with_query_parameters query_builder, {
        'page' => if page.nil? then 1 else page end,
        'limit' => if limit.nil? then 10 else limit end,
        'filter' => filter
      }

      # validate and preprocess url
      query_url = APIHelper.clean_url query_builder

      # prepare headers
      headers = {
        'user-agent' => 'APIMATIC 2.0',
        'accept' => 'application/json',
        'X-Auth-Token' => Configuration.x_auth_token
      }

      # invoke the API call request to fetch the response
      response = Unirest.get query_url, headers: headers

      # Error handling using HTTP status codes
      if response.code == 401
        raise APIException.new 'You are not authenticated', 401, response.raw_body
      elsif response.code == 403
        raise APIException.new 'This action needs a valid WSSE header', 403, response.raw_body
      elsif response.code == 404
        raise APIException.new 'Resource not found', 404, response.raw_body
      elsif response.code == 400
        raise APIException.new 'Http bad request', 400, response.raw_body
      elsif !response.code.between?(200, 206) # [200,206] = HTTP OK
        raise APIException.new 'HTTP Response Not OK', response.code, response.raw_body
      end

      response.body
    end

    # Deletes a trunk from customer's account. Numbers on that trunk must be unassigned and returned to Magic stock.
    # @param [String] account_number Required parameter: Accoubt Number
    # @param [String] trunk_id Required parameter: Trunk id
    # @return String response from the API call
    def delete_trunk_by_id(account_number, trunk_id)
      # the base uri for api requests
      query_builder = Configuration.base_uri.dup

      # prepare query string for API call
      query_builder << '/accounts/{account_number}/trunks/{trunk_id}'

      # process optional query parameters
      query_builder = APIHelper.append_url_with_template_parameters query_builder, {
        'account_number' => account_number,
        'trunk_id' => trunk_id
      }

      # validate and preprocess url
      query_url = APIHelper.clean_url query_builder

      # prepare headers
      headers = {
        'user-agent' => 'APIMATIC 2.0',
        'X-Auth-Token' => Configuration.x_auth_token
      }

      # invoke the API call request to fetch the response
      response = Unirest.delete query_url, headers: headers

      # Error handling using HTTP status codes
      if response.code == 401
        raise APIException.new 'You are not authenticated', 401, response.raw_body
      elsif response.code == 403
        raise APIException.new 'This action needs a valid WSSE header', 403, response.raw_body
      elsif response.code == 404
        raise APIException.new 'Resource not found', 404, response.raw_body
      elsif response.code == 400
        raise APIException.new 'Http bad request', 400, response.raw_body
      elsif !response.code.between?(200, 206) # [200,206] = HTTP OK
        raise APIException.new 'HTTP Response Not OK', response.code, response.raw_body
      end

      response.body
    end

    # Allow clients to get the a specific trunk
    # @param [String] account_number Required parameter: Account Number
    # @param [String] trunk_id Required parameter: Trunk id
    # @return mixed response from the API call
    def get_trunk_by_id(account_number, trunk_id)
      # the base uri for api requests
      query_builder = Configuration.base_uri.dup

      # prepare query string for API call
      query_builder << '/accounts/{account_number}/trunks/{trunk_id}'

      # process optional query parameters
      query_builder = APIHelper.append_url_with_template_parameters query_builder, {
        'account_number' => account_number,
        'trunk_id' => trunk_id
      }

      # validate and preprocess url
      query_url = APIHelper.clean_url query_builder

      # prepare headers
      headers = {
        'user-agent' => 'APIMATIC 2.0',
        'accept' => 'application/json',
        'X-Auth-Token' => Configuration.x_auth_token
      }

      # invoke the API call request to fetch the response
      response = Unirest.get query_url, headers: headers

      # Error handling using HTTP status codes
      if response.code == 401
        raise APIException.new 'You are not authenticated', 401, response.raw_body
      elsif response.code == 403
        raise APIException.new 'This action needs a valid WSSE header', 403, response.raw_body
      elsif response.code == 404
        raise APIException.new 'Resource not found', 404, response.raw_body
      elsif response.code == 400
        raise APIException.new 'Http bad request', 400, response.raw_body
      elsif !response.code.between?(200, 206) # [200,206] = HTTP OK
        raise APIException.new 'HTTP Response Not OK', response.code, response.raw_body
      end

      response.body
    end

    # Delete all carts from an account
    # @param [String] account_number Required parameter: Account Number
    # @return void response from the API call
    def delete_carts(account_number)
      # the base uri for api requests
      query_builder = Configuration.base_uri.dup

      # prepare query string for API call
      query_builder << '/accounts/{account_number}/carts'

      # process optional query parameters
      query_builder = APIHelper.append_url_with_template_parameters query_builder, {
        'account_number' => account_number
      }

      # validate and preprocess url
      query_url = APIHelper.clean_url query_builder

      # prepare headers
      headers = {
        'user-agent' => 'APIMATIC 2.0',
        'X-Auth-Token' => Configuration.x_auth_token
      }

      # invoke the API call request to fetch the response
      response = Unirest.delete query_url, headers: headers

      # Error handling using HTTP status codes
      if response.code == 401
        raise APIException.new 'You are not authenticated', 401, response.raw_body
      elsif response.code == 403
        raise APIException.new 'This action needs a valid WSSE header', 403, response.raw_body
      elsif response.code == 404
        raise APIException.new 'Resource not found', 404, response.raw_body
      elsif response.code == 400
        raise APIException.new 'Http bad request', 400, response.raw_body
      elsif !response.code.between?(200, 206) # [200,206] = HTTP OK
        raise APIException.new 'HTTP Response Not OK', response.code, response.raw_body
      end
    end

    # Allow clients to get the list of carts.
    # @param [String] account_number Required parameter: Account number
    # @param [Numeric] page Optional parameter: Zero based offset index for the results. e.g. 0 would start at the first result and 10 would start at the eleventh result.
    # @param [Numeric] limit Optional parameter: Maximum number of results to return in the response.
    # @param [String] filter Optional parameter: Allowed fields: cart_status_handle, created. Use the following delimiters to build your filters params. The vertical bar ('|') to separate individual filter phrases and a double colon ('::') to separate the names and values. The delimiter of the double colon (':') separates the property name from the comparison value, enabling the comparison value to contain spaces. Example: www.example.com\\/users?filter='name::todd|city::denver|title::grand poobah'
    # @param [String] sort Optional parameter: Allowed fields: created. Use sort query-string parameter that contains a delimited set of property names. For each property name, sort in ascending order, and for each property prefixed with a dash ('-') sort in descending order. Separate each property name with a vertical bar ('|'), which is consistent with the separation of the name\\/value pairs in filtering, above. For example, if we want to retrieve users in order of their last name (ascending), first name (ascending) and hire date (descending), the request might look like this www.example.com\\/users?sort='last_name|first_name|-hire_date'
    # @return mixed response from the API call
    def get_carts(account_number, page = 1, limit = 10, filter = nil, sort = nil)
      # the base uri for api requests
      query_builder = Configuration.base_uri.dup

      # prepare query string for API call
      query_builder << '/accounts/{account_number}/carts'

      # process optional query parameters
      query_builder = APIHelper.append_url_with_template_parameters query_builder, {
        'account_number' => account_number
      }

      # process optional query parameters
      query_builder = APIHelper.append_url_with_query_parameters query_builder, {
        'page' => if page.nil? then 1 else page end,
        'limit' => if limit.nil? then 10 else limit end,
        'filter' => filter,
        'sort' => sort
      }

      # validate and preprocess url
      query_url = APIHelper.clean_url query_builder

      # prepare headers
      headers = {
        'user-agent' => 'APIMATIC 2.0',
        'accept' => 'application/json',
        'X-Auth-Token' => Configuration.x_auth_token
      }

      # invoke the API call request to fetch the response
      response = Unirest.get query_url, headers: headers

      # Error handling using HTTP status codes
      if response.code == 401
        raise APIException.new 'You are not authenticated', 401, response.raw_body
      elsif response.code == 403
        raise APIException.new 'This action needs a valid WSSE header', 403, response.raw_body
      elsif response.code == 404
        raise APIException.new 'Resource not found', 404, response.raw_body
      elsif response.code == 400
        raise APIException.new 'Http bad request', 400, response.raw_body
      elsif !response.code.between?(200, 206) # [200,206] = HTTP OK
        raise APIException.new 'HTTP Response Not OK', response.code, response.raw_body
      end

      response.body
    end

    # Create an cart
    # @param [String] account_number Required parameter: Account number
    # @return mixed response from the API call
    def create_carts(account_number)
      # the base uri for api requests
      query_builder = Configuration.base_uri.dup

      # prepare query string for API call
      query_builder << '/accounts/{account_number}/carts'

      # process optional query parameters
      query_builder = APIHelper.append_url_with_template_parameters query_builder, {
        'account_number' => account_number
      }

      # validate and preprocess url
      query_url = APIHelper.clean_url query_builder

      # prepare headers
      headers = {
        'user-agent' => 'APIMATIC 2.0',
        'accept' => 'application/json',
        'X-Auth-Token' => Configuration.x_auth_token
      }

      # invoke the API call request to fetch the response
      response = Unirest.post query_url, headers: headers

      # Error handling using HTTP status codes
      if response.code == 403
        raise APIException.new 'User not authorized to perform the operation', 403, response.raw_body
      elsif response.code == 404
        raise APIException.new 'Resource not found', 404, response.raw_body
      elsif response.code == 401
        raise APIException.new 'You are not authenticated', 401, response.raw_body
      elsif response.code == 400
        raise APIException.new 'Http bad request', 400, response.raw_body
      elsif !response.code.between?(200, 206) # [200,206] = HTTP OK
        raise APIException.new 'HTTP Response Not OK', response.code, response.raw_body
      end

      response.body
    end

    # Delete a cart
    # @param [String] account_number Required parameter: Account number
    # @param [String] cart_id Required parameter: Cart Id
    # @return void response from the API call
    def delete_cart(account_number, cart_id)
      # the base uri for api requests
      query_builder = Configuration.base_uri.dup

      # prepare query string for API call
      query_builder << '/accounts/{account_number}/carts/{cart_id}'

      # process optional query parameters
      query_builder = APIHelper.append_url_with_template_parameters query_builder, {
        'account_number' => account_number,
        'cart_id' => cart_id
      }

      # validate and preprocess url
      query_url = APIHelper.clean_url query_builder

      # prepare headers
      headers = {
        'user-agent' => 'APIMATIC 2.0',
        'X-Auth-Token' => Configuration.x_auth_token
      }

      # invoke the API call request to fetch the response
      response = Unirest.delete query_url, headers: headers

      # Error handling using HTTP status codes
      if response.code == 401
        raise APIException.new 'You are not authenticated', 401, response.raw_body
      elsif response.code == 403
        raise APIException.new 'This action needs a valid WSSE header', 403, response.raw_body
      elsif response.code == 404
        raise APIException.new 'Resource not found', 404, response.raw_body
      elsif response.code == 400
        raise APIException.new 'Http bad request', 400, response.raw_body
      elsif !response.code.between?(200, 206) # [200,206] = HTTP OK
        raise APIException.new 'HTTP Response Not OK', response.code, response.raw_body
      end
    end

    # Allow clients to get a specific cart.
    # @param [String] account_number Required parameter: Account number
    # @param [String] cart_id Required parameter: Cart id
    # @return mixed response from the API call
    def get_cart(account_number, cart_id)
      # the base uri for api requests
      query_builder = Configuration.base_uri.dup

      # prepare query string for API call
      query_builder << '/accounts/{account_number}/carts/{cart_id}'

      # process optional query parameters
      query_builder = APIHelper.append_url_with_template_parameters query_builder, {
        'account_number' => account_number,
        'cart_id' => cart_id
      }

      # validate and preprocess url
      query_url = APIHelper.clean_url query_builder

      # prepare headers
      headers = {
        'user-agent' => 'APIMATIC 2.0',
        'accept' => 'application/json',
        'X-Auth-Token' => Configuration.x_auth_token
      }

      # invoke the API call request to fetch the response
      response = Unirest.get query_url, headers: headers

      # Error handling using HTTP status codes
      if response.code == 401
        raise APIException.new 'You are not authenticated', 401, response.raw_body
      elsif response.code == 403
        raise APIException.new 'This action needs a valid WSSE header', 403, response.raw_body
      elsif response.code == 404
        raise APIException.new 'Resource not found', 404, response.raw_body
      elsif response.code == 400
        raise APIException.new 'Http bad request', 400, response.raw_body
      elsif !response.code.between?(200, 206) # [200,206] = HTTP OK
        raise APIException.new 'HTTP Response Not OK', response.code, response.raw_body
      end

      response.body
    end

    # Checkout a cart and create an order
    # @param [String] account_number Required parameter: Account Number
    # @param [String] cart_id Required parameter: Cart Id
    # @param [CartCheckoutForm] cart_checkout_form Required parameter: TODO: type description here
    # @return mixed response from the API call
    def create_cart_checkout(account_number, cart_id, cart_checkout_form)
      # the base uri for api requests
      query_builder = Configuration.base_uri.dup

      # prepare query string for API call
      query_builder << '/accounts/{account_number}/carts/{cart_id}/checkout'

      # process optional query parameters
      query_builder = APIHelper.append_url_with_template_parameters query_builder, {
        'account_number' => account_number,
        'cart_id' => cart_id
      }

      # validate and preprocess url
      query_url = APIHelper.clean_url query_builder

      # prepare headers
      headers = {
        'user-agent' => 'APIMATIC 2.0',
        'accept' => 'application/json',
        'content-type' => 'application/json; charset=utf-8',
        'X-Auth-Token' => Configuration.x_auth_token
      }

      # invoke the API call request to fetch the response
      response = Unirest.post query_url, headers: headers, parameters: cart_checkout_form.to_json

      # Error handling using HTTP status codes
      if response.code == 403
        raise APIException.new 'User not authorized to perform the operation', 403, response.raw_body
      elsif response.code == 404
        raise APIException.new 'Resource not found', 404, response.raw_body
      elsif response.code == 401
        raise APIException.new 'You are not authenticated', 401, response.raw_body
      elsif response.code == 400
        raise APIException.new 'Http bad request', 400, response.raw_body
      elsif !response.code.between?(200, 206) # [200,206] = HTTP OK
        raise APIException.new 'HTTP Response Not OK', response.code, response.raw_body
      end

      response.body
    end

    # Delete all carts items
    # @param [String] account_number Required parameter: Account Number
    # @param [Numeric] cart_id Required parameter: Cart Id
    # @return String response from the API call
    def delete_items(account_number, cart_id)
      # the base uri for api requests
      query_builder = Configuration.base_uri.dup

      # prepare query string for API call
      query_builder << '/accounts/{account_number}/carts/{cart_id}/items'

      # process optional query parameters
      query_builder = APIHelper.append_url_with_template_parameters query_builder, {
        'account_number' => account_number,
        'cart_id' => cart_id
      }

      # validate and preprocess url
      query_url = APIHelper.clean_url query_builder

      # prepare headers
      headers = {
        'user-agent' => 'APIMATIC 2.0',
        'X-Auth-Token' => Configuration.x_auth_token
      }

      # invoke the API call request to fetch the response
      response = Unirest.delete query_url, headers: headers

      # Error handling using HTTP status codes
      if response.code == 401
        raise APIException.new 'You are not authenticated', 401, response.raw_body
      elsif response.code == 403
        raise APIException.new 'This action needs a valid WSSE header', 403, response.raw_body
      elsif response.code == 404
        raise APIException.new 'Resource not found', 404, response.raw_body
      elsif response.code == 400
        raise APIException.new 'Http bad request', 400, response.raw_body
      elsif !response.code.between?(200, 206) # [200,206] = HTTP OK
        raise APIException.new 'HTTP Response Not OK', response.code, response.raw_body
      end

      response.body
    end

    # Allow clients to get the list of cart items.
    # @param [String] account_number Required parameter: Account Number
    # @param [Numeric] cart_id Required parameter: Cart Id
    # @param [Numeric] page Optional parameter: Zero based offset index for the results. e.g. 0 would start at the first result and 10 would start at the eleventh result.
    # @param [Numeric] limit Optional parameter: Maximum number of results to return in the response.
    # @return mixed response from the API call
    def get_items(account_number, cart_id, page = 1, limit = 10)
      # the base uri for api requests
      query_builder = Configuration.base_uri.dup

      # prepare query string for API call
      query_builder << '/accounts/{account_number}/carts/{cart_id}/items'

      # process optional query parameters
      query_builder = APIHelper.append_url_with_template_parameters query_builder, {
        'account_number' => account_number,
        'cart_id' => cart_id
      }

      # process optional query parameters
      query_builder = APIHelper.append_url_with_query_parameters query_builder, {
        'page' => if page.nil? then 1 else page end,
        'limit' => if limit.nil? then 10 else limit end
      }

      # validate and preprocess url
      query_url = APIHelper.clean_url query_builder

      # prepare headers
      headers = {
        'user-agent' => 'APIMATIC 2.0',
        'accept' => 'application/json',
        'X-Auth-Token' => Configuration.x_auth_token
      }

      # invoke the API call request to fetch the response
      response = Unirest.get query_url, headers: headers

      # Error handling using HTTP status codes
      if response.code == 401
        raise APIException.new 'You are not authenticated', 401, response.raw_body
      elsif response.code == 403
        raise APIException.new 'This action needs a valid WSSE header', 403, response.raw_body
      elsif response.code == 404
        raise APIException.new 'Resource not found', 404, response.raw_body
      elsif response.code == 400
        raise APIException.new 'Http bad request', 400, response.raw_body
      elsif !response.code.between?(200, 206) # [200,206] = HTTP OK
        raise APIException.new 'HTTP Response Not OK', response.code, response.raw_body
      end

      response.body
    end

    # TODO: type endpoint description here
    # @param [String] account_number Required parameter: Account Number
    # @param [Numeric] cart_id Required parameter: Cart Id
    # @param [ItemForm] item_form Required parameter: TODO: type description here
    # @return mixed response from the API call
    def create_items(account_number, cart_id, item_form)
      # the base uri for api requests
      query_builder = Configuration.base_uri.dup

      # prepare query string for API call
      query_builder << '/accounts/{account_number}/carts/{cart_id}/items'

      # process optional query parameters
      query_builder = APIHelper.append_url_with_template_parameters query_builder, {
        'account_number' => account_number,
        'cart_id' => cart_id
      }

      # validate and preprocess url
      query_url = APIHelper.clean_url query_builder

      # prepare headers
      headers = {
        'user-agent' => 'APIMATIC 2.0',
        'accept' => 'application/json',
        'content-type' => 'application/json; charset=utf-8',
        'X-Auth-Token' => Configuration.x_auth_token
      }

      # invoke the API call request to fetch the response
      response = Unirest.post query_url, headers: headers, parameters: item_form.to_json

      # Error handling using HTTP status codes
      if response.code == 403
        raise APIException.new 'User not authorized to perform the operation', 403, response.raw_body
      elsif response.code == 404
        raise APIException.new 'Resource', 404, response.raw_body
      elsif response.code == 401
        raise APIException.new 'You are not authenticated', 401, response.raw_body
      elsif response.code == 400
        raise APIException.new 'Http bad request', 400, response.raw_body
      elsif !response.code.between?(200, 206) # [200,206] = HTTP OK
        raise APIException.new 'HTTP Response Not OK', response.code, response.raw_body
      end

      response.body
    end

    # Delete a cart item
    # @param [String] account_number Required parameter: Account Number
    # @param [Numeric] cart_id Required parameter: Cart Id
    # @param [Numeric] item_id Required parameter: Item Id
    # @return String response from the API call
    def delete_item(account_number, cart_id, item_id)
      # the base uri for api requests
      query_builder = Configuration.base_uri.dup

      # prepare query string for API call
      query_builder << '/accounts/{account_number}/carts/{cart_id}/items/{item_id}'

      # process optional query parameters
      query_builder = APIHelper.append_url_with_template_parameters query_builder, {
        'account_number' => account_number,
        'cart_id' => cart_id,
        'item_id' => item_id
      }

      # validate and preprocess url
      query_url = APIHelper.clean_url query_builder

      # prepare headers
      headers = {
        'user-agent' => 'APIMATIC 2.0',
        'X-Auth-Token' => Configuration.x_auth_token
      }

      # invoke the API call request to fetch the response
      response = Unirest.delete query_url, headers: headers

      # Error handling using HTTP status codes
      if response.code == 401
        raise APIException.new 'You are not authenticated', 401, response.raw_body
      elsif response.code == 403
        raise APIException.new 'This action needs a valid WSSE header', 403, response.raw_body
      elsif response.code == 404
        raise APIException.new 'Resource not found', 404, response.raw_body
      elsif response.code == 400
        raise APIException.new 'Http bad request', 400, response.raw_body
      elsif !response.code.between?(200, 206) # [200,206] = HTTP OK
        raise APIException.new 'HTTP Response Not OK', response.code, response.raw_body
      end

      response.body
    end

    # Allow clients to get a specific cart item.
    # @param [String] account_number Required parameter: TODO: type description here
    # @param [Numeric] cart_id Required parameter: TODO: type description here
    # @param [Numeric] item_id Required parameter: TODO: type description here
    # @return mixed response from the API call
    def get_item(account_number, cart_id, item_id)
      # the base uri for api requests
      query_builder = Configuration.base_uri.dup

      # prepare query string for API call
      query_builder << '/accounts/{account_number}/carts/{cart_id}/items/{item_id}'

      # process optional query parameters
      query_builder = APIHelper.append_url_with_template_parameters query_builder, {
        'account_number' => account_number,
        'cart_id' => cart_id,
        'item_id' => item_id
      }

      # validate and preprocess url
      query_url = APIHelper.clean_url query_builder

      # prepare headers
      headers = {
        'user-agent' => 'APIMATIC 2.0',
        'accept' => 'application/json',
        'X-Auth-Token' => Configuration.x_auth_token
      }

      # invoke the API call request to fetch the response
      response = Unirest.get query_url, headers: headers

      # Error handling using HTTP status codes
      if response.code == 401
        raise APIException.new 'You are not authenticated', 401, response.raw_body
      elsif response.code == 403
        raise APIException.new 'This action needs a valid WSSE header', 403, response.raw_body
      elsif response.code == 404
        raise APIException.new 'Resource not found', 404, response.raw_body
      elsif response.code == 400
        raise APIException.new 'Http bad request', 400, response.raw_body
      elsif !response.code.between?(200, 206) # [200,206] = HTTP OK
        raise APIException.new 'HTTP Response Not OK', response.code, response.raw_body
      end

      response.body
    end

    # Allow clients to get the list of orders.
    # @param [String] account_number Required parameter: Account Number
    # @param [Numeric] page Optional parameter: Zero based offset index for the results. e.g. 0 would start at the first result and 10 would start at the eleventh result.
    # @param [Numeric] limit Optional parameter: Maximum number of results to return in the response.
    # @param [String] filter Optional parameter: Allowed fields: from, to, created. Use the following delimiters to build your filters params. The vertical bar ('|') to separate individual filter phrases and a double colon ('::') to separate the names and values. The delimiter of the double colon (':') separates the property name from the comparison value, enabling the comparison value to contain spaces. Example: www.example.com\\\/users?filter='name::todd|city::denver|title::grand poobah
    # @return mixed response from the API call
    def get_orders(account_number, page = 1, limit = 10, filter = nil)
      # the base uri for api requests
      query_builder = Configuration.base_uri.dup

      # prepare query string for API call
      query_builder << '/accounts/{account_number}/orders'

      # process optional query parameters
      query_builder = APIHelper.append_url_with_template_parameters query_builder, {
        'account_number' => account_number
      }

      # process optional query parameters
      query_builder = APIHelper.append_url_with_query_parameters query_builder, {
        'page' => if page.nil? then 1 else page end,
        'limit' => if limit.nil? then 10 else limit end,
        'filter' => filter
      }

      # validate and preprocess url
      query_url = APIHelper.clean_url query_builder

      # prepare headers
      headers = {
        'user-agent' => 'APIMATIC 2.0',
        'accept' => 'application/json',
        'X-Auth-Token' => Configuration.x_auth_token
      }

      # invoke the API call request to fetch the response
      response = Unirest.get query_url, headers: headers

      # Error handling using HTTP status codes
      if response.code == 401
        raise APIException.new 'You are not authenticated', 401, response.raw_body
      elsif response.code == 403
        raise APIException.new 'This action needs a valid WSSE header', 403, response.raw_body
      elsif response.code == 404
        raise APIException.new 'Resource not found', 404, response.raw_body
      elsif response.code == 400
        raise APIException.new 'Http bad request', 400, response.raw_body
      elsif !response.code.between?(200, 206) # [200,206] = HTTP OK
        raise APIException.new 'HTTP Response Not OK', response.code, response.raw_body
      end

      response.body
    end

    # Allow clients to get a specific order.
    # @param [String] account_number Required parameter: Account Number
    # @param [Numeric] order_id Required parameter: Order Id
    # @return mixed response from the API call
    def get_order(account_number, order_id)
      # the base uri for api requests
      query_builder = Configuration.base_uri.dup

      # prepare query string for API call
      query_builder << '/accounts/{account_number}/orders/{order_id}'

      # process optional query parameters
      query_builder = APIHelper.append_url_with_template_parameters query_builder, {
        'account_number' => account_number,
        'order_id' => order_id
      }

      # validate and preprocess url
      query_url = APIHelper.clean_url query_builder

      # prepare headers
      headers = {
        'user-agent' => 'APIMATIC 2.0',
        'accept' => 'application/json',
        'X-Auth-Token' => Configuration.x_auth_token
      }

      # invoke the API call request to fetch the response
      response = Unirest.get query_url, headers: headers

      # Error handling using HTTP status codes
      if response.code == 401
        raise APIException.new 'You are not authenticated', 401, response.raw_body
      elsif response.code == 403
        raise APIException.new 'This action needs a valid WSSE header', 403, response.raw_body
      elsif response.code == 404
        raise APIException.new 'Resource not found', 404, response.raw_body
      elsif response.code == 400
        raise APIException.new 'Http bad request', 400, response.raw_body
      elsif !response.code.between?(200, 206) # [200,206] = HTTP OK
        raise APIException.new 'HTTP Response Not OK', response.code, response.raw_body
      end

      response.body
    end

    # Update a trunk
    # @param [String] account_number Required parameter: TODO: type description here
    # @param [Numeric] trunk_id Required parameter: TODO: type description here
    # @param [TrunkForm] trunk_form Required parameter: TODO: type description here
    # @return String response from the API call
    def update_trunk(account_number, trunk_id, trunk_form)
      # the base uri for api requests
      query_builder = Configuration.base_uri.dup

      # prepare query string for API call
      query_builder << '/accounts/{account_number}/trunks/{trunk_id}'

      # process optional query parameters
      query_builder = APIHelper.append_url_with_template_parameters query_builder, {
        'account_number' => account_number,
        'trunk_id' => trunk_id
      }

      # validate and preprocess url
      query_url = APIHelper.clean_url query_builder

      # prepare headers
      headers = {
        'user-agent' => 'APIMATIC 2.0',
        'content-type' => 'application/json; charset=utf-8',
        'X-Auth-Token' => Configuration.x_auth_token
      }

      # invoke the API call request to fetch the response
      response = Unirest.patch query_url, headers: headers, parameters: trunk_form.to_json

      # Error handling using HTTP status codes
      if response.code == 401
        raise APIException.new 'You are not authenticated', 401, response.raw_body
      elsif response.code == 403
        raise APIException.new 'This action needs a valid WSSE header', 403, response.raw_body
      elsif response.code == 404
        raise APIException.new 'Resource not found', 404, response.raw_body
      elsif response.code == 400
        raise APIException.new 'Http bad request', 400, response.raw_body
      elsif !response.code.between?(200, 206) # [200,206] = HTTP OK
        raise APIException.new 'HTTP Response Not OK', response.code, response.raw_body
      end

      response.body
    end

    # Allow clients to get the list of tokens for the specific account.
    # @param [String] account_number Required parameter: Account Number
    # @param [Numeric] page Optional parameter: Zero based offset index for the results. e.g. 0 would start at the first result and 10 would start at the eleventh result.
    # @param [Numeric] limit Optional parameter: Maximum number of results to return in the response.
    # @return mixed response from the API call
    def get_access_tokens(account_number, page = 1, limit = 10)
      # the base uri for api requests
      query_builder = Configuration.base_uri.dup

      # prepare query string for API call
      query_builder << '/accounts/{account_number}/access-tokens'

      # process optional query parameters
      query_builder = APIHelper.append_url_with_template_parameters query_builder, {
        'account_number' => account_number
      }

      # process optional query parameters
      query_builder = APIHelper.append_url_with_query_parameters query_builder, {
        'page' => if page.nil? then 1 else page end,
        'limit' => if limit.nil? then 10 else limit end
      }

      # validate and preprocess url
      query_url = APIHelper.clean_url query_builder

      # prepare headers
      headers = {
        'user-agent' => 'APIMATIC 2.0',
        'accept' => 'application/json',
        'X-Auth-Token' => Configuration.x_auth_token
      }

      # invoke the API call request to fetch the response
      response = Unirest.get query_url, headers: headers

      # Error handling using HTTP status codes
      if response.code == 401
        raise APIException.new 'You are not authenticated', 401, response.raw_body
      elsif response.code == 403
        raise APIException.new 'This action needs a valid WSSE header', 403, response.raw_body
      elsif response.code == 404
        raise APIException.new 'Resource not found', 404, response.raw_body
      elsif response.code == 400
        raise APIException.new 'Http bad request', 400, response.raw_body
      elsif !response.code.between?(200, 206) # [200,206] = HTTP OK
        raise APIException.new 'HTTP Response Not OK', response.code, response.raw_body
      end

      response.body
    end

    # Delete an access token
    # @param [String] account_number Required parameter: Account Number
    # @param [String] token Required parameter: Token
    # @return String response from the API call
    def delete_access_token(account_number, token)
      # the base uri for api requests
      query_builder = Configuration.base_uri.dup

      # prepare query string for API call
      query_builder << '/accounts/{account_number}/access-tokens/{token}'

      # process optional query parameters
      query_builder = APIHelper.append_url_with_template_parameters query_builder, {
        'account_number' => account_number,
        'token' => token
      }

      # validate and preprocess url
      query_url = APIHelper.clean_url query_builder

      # prepare headers
      headers = {
        'user-agent' => 'APIMATIC 2.0',
        'X-Auth-Token' => Configuration.x_auth_token
      }

      # invoke the API call request to fetch the response
      response = Unirest.delete query_url, headers: headers

      # Error handling using HTTP status codes
      if response.code == 401
        raise APIException.new 'You are not authenticated', 401, response.raw_body
      elsif response.code == 403
        raise APIException.new 'This action needs a valid WSSE header', 403, response.raw_body
      elsif response.code == 404
        raise APIException.new 'Resource not found', 404, response.raw_body
      elsif response.code == 400
        raise APIException.new 'Http bad request', 400, response.raw_body
      elsif !response.code.between?(200, 206) # [200,206] = HTTP OK
        raise APIException.new 'HTTP Response Not OK', response.code, response.raw_body
      end

      response.body
    end

    # Allow clients to get a specific token.
    # @param [String] account_number Required parameter: Account Number
    # @param [String] token Required parameter: Token
    # @return mixed response from the API call
    def get_access_token(account_number, token)
      # the base uri for api requests
      query_builder = Configuration.base_uri.dup

      # prepare query string for API call
      query_builder << '/accounts/{account_number}/access-tokens/{token}'

      # process optional query parameters
      query_builder = APIHelper.append_url_with_template_parameters query_builder, {
        'account_number' => account_number,
        'token' => token
      }

      # validate and preprocess url
      query_url = APIHelper.clean_url query_builder

      # prepare headers
      headers = {
        'user-agent' => 'APIMATIC 2.0',
        'accept' => 'application/json',
        'X-Auth-Token' => Configuration.x_auth_token
      }

      # invoke the API call request to fetch the response
      response = Unirest.get query_url, headers: headers

      # Error handling using HTTP status codes
      if response.code == 401
        raise APIException.new 'You are not authenticated', 401, response.raw_body
      elsif response.code == 403
        raise APIException.new 'This action needs a valid WSSE header', 403, response.raw_body
      elsif response.code == 404
        raise APIException.new 'Resource not found', 404, response.raw_body
      elsif response.code == 400
        raise APIException.new 'Http bad request', 400, response.raw_body
      elsif !response.code.between?(200, 206) # [200,206] = HTTP OK
        raise APIException.new 'HTTP Response Not OK', response.code, response.raw_body
      end

      response.body
    end

    # Update an account by a given account_number
    # @param [String] account_number Required parameter: Account Number
    # @param [String] token Required parameter: Token
    # @param [TokenForm] token_form Required parameter: TODO: type description here
    # @return String response from the API call
    def update_access_token(account_number, token, token_form)
      # the base uri for api requests
      query_builder = Configuration.base_uri.dup

      # prepare query string for API call
      query_builder << '/accounts/{account_number}/access-tokens/{token}'

      # process optional query parameters
      query_builder = APIHelper.append_url_with_template_parameters query_builder, {
        'account_number' => account_number,
        'token' => token
      }

      # validate and preprocess url
      query_url = APIHelper.clean_url query_builder

      # prepare headers
      headers = {
        'user-agent' => 'APIMATIC 2.0',
        'content-type' => 'application/json; charset=utf-8',
        'X-Auth-Token' => Configuration.x_auth_token
      }

      # invoke the API call request to fetch the response
      response = Unirest.patch query_url, headers: headers, parameters: token_form.to_json

      # Error handling using HTTP status codes
      if response.code == 401
        raise APIException.new 'You are not authenticated', 401, response.raw_body
      elsif response.code == 403
        raise APIException.new 'This action needs a valid WSSE header', 403, response.raw_body
      elsif response.code == 404
        raise APIException.new 'Resource not found', 404, response.raw_body
      elsif response.code == 400
        raise APIException.new 'Http bad request', 400, response.raw_body
      elsif !response.code.between?(200, 206) # [200,206] = HTTP OK
        raise APIException.new 'HTTP Response Not OK', response.code, response.raw_body
      end

      response.body
    end

    # Create a new Access Token.
    # @param [String] account_number Required parameter: Account Number
    # @param [TokenForm] access_token_form Required parameter: TODO: type description here
    # @return mixed response from the API call
    def create_access_tokens(account_number, access_token_form)
      # the base uri for api requests
      query_builder = Configuration.base_uri.dup

      # prepare query string for API call
      query_builder << '/accounts/{account_number}/access-tokens'

      # process optional query parameters
      query_builder = APIHelper.append_url_with_template_parameters query_builder, {
        'account_number' => account_number
      }

      # validate and preprocess url
      query_url = APIHelper.clean_url query_builder

      # prepare headers
      headers = {
        'user-agent' => 'APIMATIC 2.0',
        'accept' => 'application/json',
        'content-type' => 'application/json; charset=utf-8',
        'X-Auth-Token' => Configuration.x_auth_token
      }

      # invoke the API call request to fetch the response
      response = Unirest.post query_url, headers: headers, parameters: access_token_form.to_json

      # Error handling using HTTP status codes
      if response.code == 401
        raise APIException.new 'You are not authenticated', 401, response.raw_body
      elsif response.code == 403
        raise APIException.new 'This action needs a valid WSSE header', 403, response.raw_body
      elsif response.code == 404
        raise APIException.new 'Resource not found', 404, response.raw_body
      elsif response.code == 400
        raise APIException.new 'Http bad request', 400, response.raw_body
      elsif !response.code.between?(200, 206) # [200,206] = HTTP OK
        raise APIException.new 'HTTP Response Not OK', response.code, response.raw_body
      end

      response.body
    end
  end
end
