Module HTTParty::ClassMethods
In: lib/httparty.rb
lib/httparty.rb

Methods

base_uri   base_uri   basic_auth   basic_auth   cookies   cookies   default_params   default_params   delete   delete   format   format   get   get   headers   headers   http_proxy   http_proxy   post   post   put   put  

Public Instance methods

Allows setting a base uri to be used for each request. Will normalize uri to include http, etc.

  class Foo
    include HTTParty
    base_uri 'twitter.com'
  end

[Source]

    # File lib/httparty.rb, line 51
51:     def base_uri(uri=nil)
52:       return default_options[:base_uri] unless uri
53:       default_options[:base_uri] = HTTParty.normalize_base_uri(uri)
54:     end

Allows setting a base uri to be used for each request. Will normalize uri to include http, etc.

  class Foo
    include HTTParty
    base_uri 'twitter.com'
  end

[Source]

    # File lib/httparty.rb, line 51
51:     def base_uri(uri=nil)
52:       return default_options[:base_uri] unless uri
53:       default_options[:base_uri] = HTTParty.normalize_base_uri(uri)
54:     end

Allows setting basic authentication username and password.

  class Foo
    include HTTParty
    basic_auth 'username', 'password'
  end

[Source]

    # File lib/httparty.rb, line 62
62:     def basic_auth(u, p)
63:       default_options[:basic_auth] = {:username => u, :password => p}
64:     end

Allows setting basic authentication username and password.

  class Foo
    include HTTParty
    basic_auth 'username', 'password'
  end

[Source]

    # File lib/httparty.rb, line 62
62:     def basic_auth(u, p)
63:       default_options[:basic_auth] = {:username => u, :password => p}
64:     end

[Source]

    # File lib/httparty.rb, line 91
91:     def cookies(h={})
92:       raise ArgumentError, 'Cookies must be a hash' unless h.is_a?(Hash)
93:       default_options[:cookies] ||= CookieHash.new
94:       default_options[:cookies].add_cookies(h)
95:     end

[Source]

    # File lib/httparty.rb, line 91
91:     def cookies(h={})
92:       raise ArgumentError, 'Cookies must be a hash' unless h.is_a?(Hash)
93:       default_options[:cookies] ||= CookieHash.new
94:       default_options[:cookies].add_cookies(h)
95:     end

Allows setting default parameters to be appended to each request. Great for api keys and such.

  class Foo
    include HTTParty
    default_params :api_key => 'secret', :another => 'foo'
  end

[Source]

    # File lib/httparty.rb, line 73
73:     def default_params(h={})
74:       raise ArgumentError, 'Default params must be a hash' unless h.is_a?(Hash)
75:       default_options[:default_params] ||= {}
76:       default_options[:default_params].merge!(h)
77:     end

Allows setting default parameters to be appended to each request. Great for api keys and such.

  class Foo
    include HTTParty
    default_params :api_key => 'secret', :another => 'foo'
  end

[Source]

    # File lib/httparty.rb, line 73
73:     def default_params(h={})
74:       raise ArgumentError, 'Default params must be a hash' unless h.is_a?(Hash)
75:       default_options[:default_params] ||= {}
76:       default_options[:default_params].merge!(h)
77:     end

[Source]

     # File lib/httparty.rb, line 145
145:     def delete(path, options={})
146:       perform_request Net::HTTP::Delete, path, options
147:     end

[Source]

     # File lib/httparty.rb, line 145
145:     def delete(path, options={})
146:       perform_request Net::HTTP::Delete, path, options
147:     end

Allows setting the format with which to parse. Must be one of the allowed formats ie: json, xml

  class Foo
    include HTTParty
    format :json
  end

[Source]

     # File lib/httparty.rb, line 104
104:     def format(f)
105:       raise UnsupportedFormat, "Must be one of: #{AllowedFormats.values.uniq.join(', ')}" unless AllowedFormats.value?(f)
106:       default_options[:format] = f
107:     end

Allows setting the format with which to parse. Must be one of the allowed formats ie: json, xml

  class Foo
    include HTTParty
    format :json
  end

[Source]

     # File lib/httparty.rb, line 104
104:     def format(f)
105:       raise UnsupportedFormat, "Must be one of: #{AllowedFormats.values.uniq.join(', ')}" unless AllowedFormats.value?(f)
106:       default_options[:format] = f
107:     end

Allows making a get request to a url.

  class Foo
    include HTTParty
  end

  # Simple get with full url
  Foo.get('http://foo.com/resource.json')

  # Simple get with full url and query parameters
  # ie: http://foo.com/resource.json?limit=10
  Foo.get('http://foo.com/resource.json', :query => {:limit => 10})

[Source]

     # File lib/httparty.rb, line 121
121:     def get(path, options={})
122:       perform_request Net::HTTP::Get, path, options
123:     end

Allows making a get request to a url.

  class Foo
    include HTTParty
  end

  # Simple get with full url
  Foo.get('http://foo.com/resource.json')

  # Simple get with full url and query parameters
  # ie: http://foo.com/resource.json?limit=10
  Foo.get('http://foo.com/resource.json', :query => {:limit => 10})

[Source]

     # File lib/httparty.rb, line 121
121:     def get(path, options={})
122:       perform_request Net::HTTP::Get, path, options
123:     end

Allows setting a base uri to be used for each request.

  class Foo
    include HTTParty
    headers 'Accept' => 'text/html'
  end

[Source]

    # File lib/httparty.rb, line 85
85:     def headers(h={})
86:       raise ArgumentError, 'Headers must be a hash' unless h.is_a?(Hash)
87:       default_options[:headers] ||= {}
88:       default_options[:headers].merge!(h)
89:     end

Allows setting a base uri to be used for each request.

  class Foo
    include HTTParty
    headers 'Accept' => 'text/html'
  end

[Source]

    # File lib/httparty.rb, line 85
85:     def headers(h={})
86:       raise ArgumentError, 'Headers must be a hash' unless h.is_a?(Hash)
87:       default_options[:headers] ||= {}
88:       default_options[:headers].merge!(h)
89:     end

Allows setting http proxy information to be used

  class Foo
    include HTTParty
    http_proxy 'http://foo.com', 80
  end

[Source]

    # File lib/httparty.rb, line 39
39:     def http_proxy(addr=nil, port = nil)
40:       default_options[:http_proxyaddr] = addr
41:       default_options[:http_proxyport] = port
42:     end

Allows setting http proxy information to be used

  class Foo
    include HTTParty
    http_proxy 'http://foo.com', 80
  end

[Source]

    # File lib/httparty.rb, line 39
39:     def http_proxy(addr=nil, port = nil)
40:       default_options[:http_proxyaddr] = addr
41:       default_options[:http_proxyport] = port
42:     end

Allows making a post request to a url.

  class Foo
    include HTTParty
  end

  # Simple post with full url and setting the body
  Foo.post('http://foo.com/resources', :body => {:bar => 'baz'})

  # Simple post with full url using :query option,
  # which gets set as form data on the request.
  Foo.post('http://foo.com/resources', :query => {:bar => 'baz'})

[Source]

     # File lib/httparty.rb, line 137
137:     def post(path, options={})
138:       perform_request Net::HTTP::Post, path, options
139:     end

Allows making a post request to a url.

  class Foo
    include HTTParty
  end

  # Simple post with full url and setting the body
  Foo.post('http://foo.com/resources', :body => {:bar => 'baz'})

  # Simple post with full url using :query option,
  # which gets set as form data on the request.
  Foo.post('http://foo.com/resources', :query => {:bar => 'baz'})

[Source]

     # File lib/httparty.rb, line 137
137:     def post(path, options={})
138:       perform_request Net::HTTP::Post, path, options
139:     end

[Source]

     # File lib/httparty.rb, line 141
141:     def put(path, options={})
142:       perform_request Net::HTTP::Put, path, options
143:     end

[Source]

     # File lib/httparty.rb, line 141
141:     def put(path, options={})
142:       perform_request Net::HTTP::Put, path, options
143:     end

[Validate]