Skip to content

Instantly share code, notes, and snippets.

@bananastalktome
Created June 2, 2010 15:20
Show Gist options
  • Save bananastalktome/422500 to your computer and use it in GitHub Desktop.
Save bananastalktome/422500 to your computer and use it in GitHub Desktop.
Recognized HTTParty parameters:
Class Foo
include HTTParty
http_proxy '<URL>', <PORT> # Allows setting http proxy information to be used
base_uri '<URL>' # Allows setting a base uri to be used for each request. Will normalize uri to include http, etc.
basic_auth '<USERNAME>', '<PASS>' # Allows setting basic authentication username and password.
digest_auth '<USERNAME>', '<PASS>' # Allows setting digest authentication username and password.
default_params <Default_Param_Hash> # Allows setting default parameters to be appended to each request. Great for api keys and such.
default_timeout <TIMEOUT_INT> # Allows setting a default timeout for all HTTP calls. Timeout is specified in seconds.
debug_output <STREAM> # Set an output stream for debugging, defaults to $stderr. The output stream is passed on to Net::HTTP#set_debug_output.
headers <HEADER_HASH> # Allows setting HTTP headers to be used for each request.
cookies <COOKIE_HASH> # Allows setting cookies to be used for each request.
format <PARSER_FORMAT> # Allows setting the format with which to parse. Must be one of the allowed formats ie: json, xml
no_follow <BOOLEAN> # Declare whether or not to follow redirects. When true, an {HTTParty::RedirectionTooDeep} error will raise upon encountering a redirect. You can then gain access to the response object via HTTParty::RedirectionTooDeep#response.
maintain_method_across_redirects <BOOLEAN> # Declare that you wish to maintain the chosen HTTP method across redirects. The default behavior is to follow redirects via the GET method. If you wish to maintain the original method, you can set this option to true.
pem <FILE_HANDLE> # Allows setting a PEM file to be used
parser <CUSTOM_PARSER_SCHEME> # Allows setting a custom parser for the response.
end
Request Methods:
Foo.get <PATH>, <OPTIONS>
Foo.post <PATH>, <OPTIONS>
Foo.put <PATH>, <OPTIONS>
Foo.delete <PATH>, <OPTIONS>
Foo.head <PATH>, <OPTIONS>
Foo.options <PATH>, <OPTIONS>
Options for request methods include:
:query => {} # Allows setting query parameters
:body => {} # Allows setting the body contents for post requests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment