Module: HTTParty::ClassMethods

Defined in:
lib/httparty.rb

Instance Method Summary collapse

Instance Method Details

#base_uri(uri = nil) ⇒ Object



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

def base_uri(uri=nil)
  return default_options[:base_uri] unless uri
  default_options[:base_uri] = normalize_base_uri(uri)
end

#basic_auth(u, p) ⇒ Object



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

def basic_auth(u, p)
  default_options[:basic_auth] = {:username => u, :password => p}
end

#default_optionsObject



53
54
55
# File 'lib/httparty.rb', line 53

def default_options
  @default_options
end

#default_params(h = {}) ⇒ Object

Raises:

  • (ArgumentError)


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

def default_params(h={})
  raise ArgumentError, 'Default params must be a hash' unless h.is_a?(Hash)
  default_options[:default_params] ||= {}
  default_options[:default_params].merge!(h)
end

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



107
108
109
# File 'lib/httparty.rb', line 107

def delete(path, options={})
  perform_request Net::HTTP::Delete, path, options
end

#format(f) ⇒ Object

Raises:



90
91
92
93
# File 'lib/httparty.rb', line 90

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

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



95
96
97
# File 'lib/httparty.rb', line 95

def get(path, options={})
  perform_request Net::HTTP::Get, path, options
end

#headers(h = {}) ⇒ Object

Raises:

  • (ArgumentError)


84
85
86
87
88
# File 'lib/httparty.rb', line 84

def headers(h={})
  raise ArgumentError, 'Headers must be a hash' unless h.is_a?(Hash)
  default_options[:headers] ||= {}
  default_options[:headers].merge!(h)
end

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

Set an http proxy

class Twitter

include HTTParty
http_proxy 'http://myProxy', 1080

.…



64
65
66
67
# File 'lib/httparty.rb', line 64

def http_proxy(addr=nil, port = nil)
  default_options[:http_proxyaddr] = addr
  default_options[:http_proxyport] = port
end

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



99
100
101
# File 'lib/httparty.rb', line 99

def post(path, options={})
  perform_request Net::HTTP::Post, path, options
end

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



103
104
105
# File 'lib/httparty.rb', line 103

def put(path, options={})
  perform_request Net::HTTP::Put, path, options
end