def build_url(api_method, options = {})
        if api_method['mediaUpload'] && options[:media]
          # we need to do [1..-1] to remove the prepended slash
          url = GoogleAPI.discovered_apis[api]['rootUrl'] + api_method['mediaUpload']['protocols']['resumable']['path'][1..-1]
        else
          url = GoogleAPI.discovered_apis[api]['baseUrl'] + api_method['path']
          query_params = []
          api_method['parameters'].each_with_index do |(param, settings), index|
            param = param.to_sym
            case settings['location']
            when 'path'
              raise ArgumentError, ":#{param} was not passed" if settings['required'] && !options[param]
              url.sub!("{#{param}}", options.delete(param).to_s)
            when 'query'
              query_params << "#{param}=#{options.delete(param)}" if options[param]
            end
          end if api_method['parameters']
          url += "?#{query_params.join('&')}" if query_params.length > 0
        end

        [url, options]
      end
def build_url(api_method, options = {})
        if api_method['mediaUpload'] && options[:media]
          # we need to do [1..-1] to remove the prepended slash
          url = GoogleAPI.discovered_apis[api]['rootUrl'] + api_method['mediaUpload']['protocols']['resumable']['path'][1..-1]
        else
          url = GoogleAPI.discovered_apis[api]['baseUrl'] + api_method['path']
          query_params = []
          api_method['parameters'].each_with_index do |(param, settings), index|
            param = param.to_sym
            case settings['location']
            when 'path'
              raise ArgumentError, ":#{param} was not passed" if settings['required'] && !options[param]
              url.sub!("{#{param}}", options.delete(param).to_s)
            when 'query'
              query_params << "#{param}=#{options.delete(param)}" if options[param]
            end
          end if api_method['parameters']
          url += "?#{query_params.join('&')}" if query_params.length > 0
        end

        [url, options]
      end
Put together the full URL we will send a request to.
 First we join the API's base URL with the current method's path, forming the main URL.

 If the method is mediaUpload-enabled (like uploading a file to Google Drive), then we want
 to take the path from the resumable upload protocol.

 If not, then, we are going to iterate through each of the parameters for the current method.
 When the parameter's location is within the path, we first check that we have had that
 option passed, and if so, substitute it in the correct place.
 When the parameter's location is a query, we add it to our query parameters hash, provided it is present.
 Before returning the URL and remaining options, we have to build the query parameters hash
 into a string and append it to the end of the URL.