def api_call(method, endpoint, params={})
      # add api token to params
      params.merge!({ :token => self.token })

      # dispatch to the right method, with the full path (/api/v2 + endpoint)
      request = self.send("format_#{method}", "#{@url.path}/#{endpoint}", params)
      response = @http.request(request)
      
      # Possible Responses
      #
      # 200 - (OK) The request was received successfully.
      # 400 - (Bad Request) There was a problem with your request parameters. Check
      #       the error field of the response object for info on what was wrong.
      # 401 - (Unauthorized) Your API token in the token parameter was either missing
      #       or incorrect.
      # 404 - (Not Found) The API method was not found. Check yor request URL for
      #       typos.
      # 405 - (Method Not Allowed) An incorrect HTTP verb (i.e. GET, POST, etc) was
      #       used for the request
      # 5XX - There was an error Crocodoc could not recover from. We are generally
      #       notified of these automatically. If they are repeatedly received, you
      #       should contact Crocodoc Support.

      unless response.code == '200'
        raise Crocodoc::Error, "HTTP Error #{response.code}: #{response.body}"
      end
      response.body
    end
def api_call(method, endpoint, params={})
      # add api token to params
      params.merge!({ :token => self.token })

      # dispatch to the right method, with the full path (/api/v2 + endpoint)
      request = self.send("format_#{method}", "#{@url.path}/#{endpoint}", params)
      response = @http.request(request)
      
      # Possible Responses
      #
      # 200 - (OK) The request was received successfully.
      # 400 - (Bad Request) There was a problem with your request parameters. Check
      #       the error field of the response object for info on what was wrong.
      # 401 - (Unauthorized) Your API token in the token parameter was either missing
      #       or incorrect.
      # 404 - (Not Found) The API method was not found. Check yor request URL for
      #       typos.
      # 405 - (Method Not Allowed) An incorrect HTTP verb (i.e. GET, POST, etc) was
      #       used for the request
      # 5XX - There was an error Crocodoc could not recover from. We are generally
      #       notified of these automatically. If they are repeatedly received, you
      #       should contact Crocodoc Support.

      unless response.code == '200'
        raise Crocodoc::Error, "HTTP Error #{response.code}: #{response.body}"
      end
      response.body
    end
-- API Glue --
 Internal: Setup the api call, format the parameters, send the request,
 parse the response and return it.

 method   - The http verb to use, currently :get or :post
 endpoint - The api endpoint to hit. this is the part after
            crocodoc.com/api/v2. please do not include a beginning slash.
 params   - Parameters to send with the api call, either as a query string
            (get) or form params (post). Don't worry about including the
            api token, it will automatically be included with all
            requests (default: {}).

 Examples

   api_call(:post,
            "document/upload",
            { :url => "http://www.example.com/test.doc" })
   # => { "uuid": "8e5b0721-26c4-11df-b354-002170de47d3" }

 Returns the json parsed response body of the call