|
80aa3595
»
|
jnunemaker |
2008-12-06 |
Tweaked requires and such. |
1 |
$:.unshift(File.dirname(__FILE__)) |
| |
2 |
|
|
df29a552
»
|
jnunemaker |
2008-07-27 |
Initial commit |
3 |
require 'net/http' |
| |
4 |
require 'net/https' |
| |
5 |
require 'rubygems' |
| |
6 |
require 'active_support' |
|
aa09eb4c
»
|
jnunemaker |
2008-12-06 |
Moved module inheritable at... |
7 |
require 'module_level_inheritable_attributes' |
|
7bdca06b
»
|
reinh |
2008-11-08 |
Moving send_request and fri... |
8 |
|
|
1d48da03
»
|
jnunemaker |
2008-07-28 |
Renamed to HTTParty which i... |
9 |
module HTTParty |
|
76601ba0
»
|
jnunemaker |
2008-08-22 |
Changed format detection fr... |
10 |
class UnsupportedFormat < StandardError; end |
|
ae7ce309
»
|
evri |
2008-09-19 |
Add the ability to automati... |
11 |
class RedirectionTooDeep < StandardError; end |
|
c531652d
»
|
jnunemaker |
2008-11-30 |
Made it so that multiple cl... |
12 |
|
|
e0cb4311
»
|
jnunemaker |
2008-11-11 |
Added explicit html format ... |
13 |
AllowedFormats = {:xml => 'text/xml', :json => 'application/json', :html => 'text/html'} |
|
76601ba0
»
|
jnunemaker |
2008-08-22 |
Changed format detection fr... |
14 |
|
|
df29a552
»
|
jnunemaker |
2008-07-27 |
Initial commit |
15 |
def self.included(base) |
| |
16 |
base.extend ClassMethods |
|
c531652d
»
|
jnunemaker |
2008-11-30 |
Made it so that multiple cl... |
17 |
base.send :include, ModuleLevelInheritableAttributes |
| |
18 |
base.send(:mattr_inheritable, :default_options) |
| |
19 |
base.instance_variable_set("@default_options", {}) |
|
df29a552
»
|
jnunemaker |
2008-07-27 |
Initial commit |
20 |
end |
| |
21 |
|
|
c531652d
»
|
jnunemaker |
2008-11-30 |
Made it so that multiple cl... |
22 |
module ClassMethods |
|
7bdca06b
»
|
reinh |
2008-11-08 |
Moving send_request and fri... |
23 |
def default_options |
|
c531652d
»
|
jnunemaker |
2008-11-30 |
Made it so that multiple cl... |
24 |
@default_options |
|
7bdca06b
»
|
reinh |
2008-11-08 |
Moving send_request and fri... |
25 |
end |
| |
26 |
|
|
b0f1cc2a
»
|
francxk |
2008-08-18 |
Raises exception when http ... |
27 |
def http_proxy(addr=nil, port = nil) |
|
7bdca06b
»
|
reinh |
2008-11-08 |
Moving send_request and fri... |
28 |
default_options[:http_proxyaddr] = addr |
| |
29 |
default_options[:http_proxyport] = port |
|
b0f1cc2a
»
|
francxk |
2008-08-18 |
Raises exception when http ... |
30 |
end |
| |
31 |
|
|
7bdca06b
»
|
reinh |
2008-11-08 |
Moving send_request and fri... |
32 |
def base_uri(uri=nil) |
| |
33 |
return default_options[:base_uri] unless uri |
|
ab17bb37
»
|
jnunemaker |
2008-12-01 |
Fixed that base_uri was not... |
34 |
default_options[:base_uri] = uri |
|
8e143785
»
|
jnunemaker |
2008-07-27 |
get, post, put and delete n... |
35 |
end |
|
7bdca06b
»
|
reinh |
2008-11-08 |
Moving send_request and fri... |
36 |
|
|
8e143785
»
|
jnunemaker |
2008-07-27 |
get, post, put and delete n... |
37 |
def basic_auth(u, p) |
|
7bdca06b
»
|
reinh |
2008-11-08 |
Moving send_request and fri... |
38 |
default_options[:basic_auth] = {:username => u, :password => p} |
|
df29a552
»
|
jnunemaker |
2008-07-27 |
Initial commit |
39 |
end |
| |
40 |
|
|
236b3ad4
»
|
jnunemaker |
2008-07-28 |
Made it so default_params a... |
41 |
def default_params(h={}) |
| |
42 |
raise ArgumentError, 'Default params must be a hash' unless h.is_a?(Hash) |
|
7bdca06b
»
|
reinh |
2008-11-08 |
Moving send_request and fri... |
43 |
default_options[:default_params] ||= {} |
| |
44 |
default_options[:default_params].merge!(h) |
|
0c05dcda
»
|
jnunemaker |
2008-07-28 |
Added #default_params metho... |
45 |
end |
| |
46 |
|
| |
47 |
def headers(h={}) |
| |
48 |
raise ArgumentError, 'Headers must be a hash' unless h.is_a?(Hash) |
|
7bdca06b
»
|
reinh |
2008-11-08 |
Moving send_request and fri... |
49 |
default_options[:headers] ||= {} |
| |
50 |
default_options[:headers].merge!(h) |
|
0c05dcda
»
|
jnunemaker |
2008-07-28 |
Added #default_params metho... |
51 |
end |
| |
52 |
|
|
236b3ad4
»
|
jnunemaker |
2008-07-28 |
Made it so default_params a... |
53 |
def format(f) |
|
76601ba0
»
|
jnunemaker |
2008-08-22 |
Changed format detection fr... |
54 |
raise UnsupportedFormat, "Must be one of: #{AllowedFormats.keys.join(', ')}" unless AllowedFormats.key?(f) |
|
7bdca06b
»
|
reinh |
2008-11-08 |
Moving send_request and fri... |
55 |
default_options[:format] = f |
|
236b3ad4
»
|
jnunemaker |
2008-07-28 |
Made it so default_params a... |
56 |
end |
| |
57 |
|
|
8e143785
»
|
jnunemaker |
2008-07-27 |
get, post, put and delete n... |
58 |
def get(path, options={}) |
|
67cb5725
»
|
jnunemaker |
2008-11-11 |
Switched from send to perfo... |
59 |
perform_request Net::HTTP::Get, path, options |
|
8e143785
»
|
jnunemaker |
2008-07-27 |
get, post, put and delete n... |
60 |
end |
|
236b3ad4
»
|
jnunemaker |
2008-07-28 |
Made it so default_params a... |
61 |
|
|
8e143785
»
|
jnunemaker |
2008-07-27 |
get, post, put and delete n... |
62 |
def post(path, options={}) |
|
67cb5725
»
|
jnunemaker |
2008-11-11 |
Switched from send to perfo... |
63 |
perform_request Net::HTTP::Post, path, options |
|
8e143785
»
|
jnunemaker |
2008-07-27 |
get, post, put and delete n... |
64 |
end |
|
236b3ad4
»
|
jnunemaker |
2008-07-28 |
Made it so default_params a... |
65 |
|
|
8e143785
»
|
jnunemaker |
2008-07-27 |
get, post, put and delete n... |
66 |
def put(path, options={}) |
|
67cb5725
»
|
jnunemaker |
2008-11-11 |
Switched from send to perfo... |
67 |
perform_request Net::HTTP::Put, path, options |
|
8e143785
»
|
jnunemaker |
2008-07-27 |
get, post, put and delete n... |
68 |
end |
|
236b3ad4
»
|
jnunemaker |
2008-07-28 |
Made it so default_params a... |
69 |
|
|
8e143785
»
|
jnunemaker |
2008-07-27 |
get, post, put and delete n... |
70 |
def delete(path, options={}) |
|
67cb5725
»
|
jnunemaker |
2008-11-11 |
Switched from send to perfo... |
71 |
perform_request Net::HTTP::Delete, path, options |
|
8e143785
»
|
jnunemaker |
2008-07-27 |
get, post, put and delete n... |
72 |
end |
|
7bdca06b
»
|
reinh |
2008-11-08 |
Moving send_request and fri... |
73 |
|
|
df29a552
»
|
jnunemaker |
2008-07-27 |
Initial commit |
74 |
private |
|
9931e2a2
»
|
jnunemaker |
2008-11-11 |
Fixed failing specs. |
75 |
def perform_request(http_method, path, options) #:nodoc: |
|
b6340ed9
»
|
jnunemaker |
2008-11-11 |
First pass of refactoring t... |
76 |
Request.new(http_method, path, default_options.merge(options)).perform |
|
8e143785
»
|
jnunemaker |
2008-07-27 |
get, post, put and delete n... |
77 |
end |
|
df29a552
»
|
jnunemaker |
2008-07-27 |
Initial commit |
78 |
end |
|
1adf103b
»
|
jqr |
2008-12-05 |
Stupid simple support for H... |
79 |
|
| |
80 |
class Basement |
| |
81 |
include HTTParty |
| |
82 |
end |
| |
83 |
|
| |
84 |
def self.get(*args) |
| |
85 |
Basement.get(*args) |
| |
86 |
end |
| |
87 |
|
| |
88 |
def self.post(*args) |
| |
89 |
Basement.post(*args) |
| |
90 |
end |
| |
91 |
|
| |
92 |
def self.put(*args) |
| |
93 |
Basement.put(*args) |
| |
94 |
end |
| |
95 |
|
| |
96 |
def self.delete(*args) |
| |
97 |
Basement.delete(*args) |
| |
98 |
end |
|
a2fd0925
»
|
reinh |
2008-11-08 |
Replacing string parameters... |
99 |
end |
|
80aa3595
»
|
jnunemaker |
2008-12-06 |
Tweaked requires and such. |
100 |
|
| |
101 |
require 'httparty/request' |