Module: HTTParty::ClassMethods
- Defined in:
- lib/httparty.rb
Instance Method Summary collapse
- #base_uri(base_uri = nil) ⇒ Object
-
#basic_auth(u, p) ⇒ Object
Warning: This is not thread safe most likely and only works if you use one set of credentials.
-
#default_params(h = {}) ⇒ Object
Updates the default query string parameters that should be appended to each request.
-
#delete(path, options = {}) ⇒ Object
TODO: spec out this.
- #format(f) ⇒ Object
-
#get(path, options = {}) ⇒ Object
TODO: spec out this.
- #headers(h = {}) ⇒ Object
-
#http_proxy(addr = nil, port = nil) ⇒ Object
Set an http proxy.
-
#post(path, options = {}) ⇒ Object
TODO: spec out this.
-
#put(path, options = {}) ⇒ Object
TODO: spec out this.
Instance Method Details
#base_uri(base_uri = nil) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/httparty.rb', line 46 def base_uri(base_uri=nil) return @base_uri unless base_uri # don't want this to ever end with / base_uri = base_uri.ends_with?('/') ? base_uri.chop : 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.
56 57 58 |
# File 'lib/httparty.rb', line 56 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.
62 63 64 65 66 67 |
# File 'lib/httparty.rb', line 62 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
97 98 99 |
# File 'lib/httparty.rb', line 97 def delete(path, ={}) send_request 'delete', path, end |
#format(f) ⇒ Object
76 77 78 79 |
# File 'lib/httparty.rb', line 76 def format(f) raise UnsupportedFormat, "Must be one of: #{AllowedFormats.join(', ')}" unless AllowedFormats.include?(f) @format = f end |
#get(path, options = {}) ⇒ Object
TODO: spec out this
82 83 84 |
# File 'lib/httparty.rb', line 82 def get(path, ={}) send_request 'get', path, end |
#headers(h = {}) ⇒ Object
69 70 71 72 73 74 |
# File 'lib/httparty.rb', line 69 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
.…
41 42 43 44 |
# File 'lib/httparty.rb', line 41 def http_proxy(addr=nil, port = nil) @http_proxyaddr = addr @http_proxyport = port end |
#post(path, options = {}) ⇒ Object
TODO: spec out this
87 88 89 |
# File 'lib/httparty.rb', line 87 def post(path, ={}) send_request 'post', path, end |
#put(path, options = {}) ⇒ Object
TODO: spec out this
92 93 94 |
# File 'lib/httparty.rb', line 92 def put(path, ={}) send_request 'put', path, end |