Module: HTTParty::ClassMethods

Defined in:
lib/httparty.rb

Instance Method Summary collapse

Instance Method Details

#base_uri(base_uri = nil) ⇒ Object



34
35
36
37
# File 'lib/httparty.rb', line 34

def base_uri(base_uri=nil)
  return @base_uri unless base_uri
  @base_uri = normalize_base_uri(base_uri)
end

#basic_auth(u, p) ⇒ Object

Warning: This is not thread safe most likely and only works if you use one set of credentials. I leave it because it is convenient on some occasions.



42
43
44
# File 'lib/httparty.rb', line 42

def basic_auth(u, p)
  @auth = {:username => u, :password => p}
end

#default_params(h = {}) ⇒ Object

Updates the default query string parameters that should be appended to each request.

Raises:

  • (ArgumentError)


48
49
50
51
52
53
# File 'lib/httparty.rb', line 48

def default_params(h={})
  raise ArgumentError, 'Default params must be a hash' unless h.is_a?(Hash)
  @default_params ||= {}
  return @default_params if h.blank?
  @default_params.merge!(h)
end

#delete(path, options = {}) ⇒ Object

TODO: spec out this



83
84
85
# File 'lib/httparty.rb', line 83

def delete(path, options={})
  send_request 'delete', path, options
end

#format(f) ⇒ Object

Raises:



62
63
64
65
# File 'lib/httparty.rb', line 62

def format(f)
  raise UnsupportedFormat, "Must be one of: #{AllowedFormats.keys.join(', ')}" unless AllowedFormats.key?(f)
  @format = f
end

#get(path, options = {}) ⇒ Object

TODO: spec out this



68
69
70
# File 'lib/httparty.rb', line 68

def get(path, options={})
  send_request 'get', path, options
end

#headers(h = {}) ⇒ Object

Raises:

  • (ArgumentError)


55
56
57
58
59
60
# File 'lib/httparty.rb', line 55

def headers(h={})
  raise ArgumentError, 'Headers must be a hash' unless h.is_a?(Hash)
  @headers ||= {}
  return @headers if h.blank?
  @headers.merge!(h)
end

#http_proxy(addr = nil, port = nil) ⇒ Object

Set an http proxy

class Twitter

include HTTParty
http_proxy http://myProxy, 1080

.…



29
30
31
32
# File 'lib/httparty.rb', line 29

def http_proxy(addr=nil, port = nil)
@http_proxyaddr = addr
@http_proxyport = port
end

#post(path, options = {}) ⇒ Object

TODO: spec out this



73
74
75
# File 'lib/httparty.rb', line 73

def post(path, options={})
  send_request 'post', path, options
end

#put(path, options = {}) ⇒ Object

TODO: spec out this



78
79
80
# File 'lib/httparty.rb', line 78

def put(path, options={})
  send_request 'put', path, options
end