Module: HTTParty::ClassMethods

Defined in:
lib/httparty.rb

Instance Method Summary collapse

Instance Method Details

#base_uri(uri = nil) ⇒ Object



32
33
34
35
# File 'lib/httparty.rb', line 32

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

#basic_auth(u, p) ⇒ Object



37
38
39
# File 'lib/httparty.rb', line 37

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

#default_optionsObject



23
24
25
# File 'lib/httparty.rb', line 23

def default_options
  @default_options
end

#default_params(h = {}) ⇒ Object

Raises:

  • (ArgumentError)


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

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



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

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

#format(f) ⇒ Object

Raises:



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

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



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

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

#headers(h = {}) ⇒ Object

Raises:

  • (ArgumentError)


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

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



27
28
29
30
# File 'lib/httparty.rb', line 27

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

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



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

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

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



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

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