xenda-typhoeus 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/.gitignore +4 -0
  2. data/CHANGELOG.markdown +70 -0
  3. data/Gemfile +3 -0
  4. data/Gemfile.lock +38 -0
  5. data/LICENSE +20 -0
  6. data/README.textile +397 -0
  7. data/Rakefile +56 -0
  8. data/VERSION +1 -0
  9. data/benchmarks/profile.rb +25 -0
  10. data/benchmarks/vs_nethttp.rb +35 -0
  11. data/examples/file.rb +12 -0
  12. data/examples/times.rb +40 -0
  13. data/examples/twitter.rb +21 -0
  14. data/ext/typhoeus/.gitignore +7 -0
  15. data/ext/typhoeus/extconf.rb +65 -0
  16. data/ext/typhoeus/native.c +12 -0
  17. data/ext/typhoeus/native.h +22 -0
  18. data/ext/typhoeus/typhoeus_easy.c +232 -0
  19. data/ext/typhoeus/typhoeus_easy.h +20 -0
  20. data/ext/typhoeus/typhoeus_form.c +59 -0
  21. data/ext/typhoeus/typhoeus_form.h +13 -0
  22. data/ext/typhoeus/typhoeus_multi.c +217 -0
  23. data/ext/typhoeus/typhoeus_multi.h +16 -0
  24. data/lib/typhoeus.rb +58 -0
  25. data/lib/typhoeus/.gitignore +1 -0
  26. data/lib/typhoeus/easy.rb +379 -0
  27. data/lib/typhoeus/filter.rb +28 -0
  28. data/lib/typhoeus/form.rb +32 -0
  29. data/lib/typhoeus/hydra.rb +247 -0
  30. data/lib/typhoeus/hydra/callbacks.rb +24 -0
  31. data/lib/typhoeus/hydra/connect_options.rb +61 -0
  32. data/lib/typhoeus/hydra/stubbing.rb +52 -0
  33. data/lib/typhoeus/hydra_mock.rb +131 -0
  34. data/lib/typhoeus/multi.rb +37 -0
  35. data/lib/typhoeus/normalized_header_hash.rb +58 -0
  36. data/lib/typhoeus/remote.rb +306 -0
  37. data/lib/typhoeus/remote_method.rb +108 -0
  38. data/lib/typhoeus/remote_proxy_object.rb +50 -0
  39. data/lib/typhoeus/request.rb +203 -0
  40. data/lib/typhoeus/response.rb +91 -0
  41. data/lib/typhoeus/service.rb +20 -0
  42. data/lib/typhoeus/utils.rb +63 -0
  43. data/profilers/valgrind.rb +24 -0
  44. data/spec/fixtures/placeholder.gif +0 -0
  45. data/spec/fixtures/placeholder.txt +1 -0
  46. data/spec/fixtures/placeholder.ukn +0 -0
  47. data/spec/fixtures/result_set.xml +60 -0
  48. data/spec/servers/app.rb +94 -0
  49. data/spec/spec.opts +3 -0
  50. data/spec/spec_helper.rb +14 -0
  51. data/spec/typhoeus/easy_spec.rb +343 -0
  52. data/spec/typhoeus/filter_spec.rb +35 -0
  53. data/spec/typhoeus/form_spec.rb +117 -0
  54. data/spec/typhoeus/hydra_mock_spec.rb +300 -0
  55. data/spec/typhoeus/hydra_spec.rb +574 -0
  56. data/spec/typhoeus/multi_spec.rb +74 -0
  57. data/spec/typhoeus/normalized_header_hash_spec.rb +41 -0
  58. data/spec/typhoeus/remote_method_spec.rb +141 -0
  59. data/spec/typhoeus/remote_proxy_object_spec.rb +65 -0
  60. data/spec/typhoeus/remote_spec.rb +695 -0
  61. data/spec/typhoeus/request_spec.rb +300 -0
  62. data/spec/typhoeus/response_spec.rb +151 -0
  63. data/spec/typhoeus/utils_spec.rb +22 -0
  64. data/xenda-typhoeus.gemspec +139 -0
  65. metadata +203 -0
@@ -0,0 +1,56 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+
3
+ require "spec"
4
+ require "spec/rake/spectask"
5
+ require "lib/typhoeus/version"
6
+
7
+ begin
8
+ require 'jeweler'
9
+ Jeweler::Tasks.new do |gemspec|
10
+ gemspec.name = "typhoeus"
11
+ gemspec.summary = "A library for interacting with web services (and building SOAs) at blinding speed."
12
+ gemspec.description = "Like a modern code version of the mythical beast with 100 serpent heads, Typhoeus runs HTTP requests in parallel while cleanly encapsulating handling logic."
13
+ gemspec.email = "dbalatero@gmail.com"
14
+ gemspec.homepage = "http://github.com/dbalatero/typhoeus"
15
+ gemspec.authors = ["Paul Dix", "David Balatero"]
16
+ gemspec.add_dependency "mime-types"
17
+ gemspec.add_development_dependency "rspec"
18
+ gemspec.add_development_dependency "jeweler"
19
+ gemspec.add_development_dependency "diff-lcs"
20
+ gemspec.add_development_dependency "sinatra"
21
+ gemspec.add_development_dependency "json"
22
+ end
23
+
24
+ Jeweler::GemcutterTasks.new
25
+ rescue LoadError
26
+ puts "Jeweler not available. Install it with: gem install jeweler"
27
+ end
28
+
29
+ Spec::Rake::SpecTask.new do |t|
30
+ t.spec_opts = ['--options', "\"#{File.dirname(__FILE__)}/spec/spec.opts\""]
31
+ t.spec_files = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ task :install do
35
+ rm_rf "*.gem"
36
+ puts `gem build typhoeus.gemspec`
37
+ puts `gem install typhoeus-#{Typhoeus::VERSION}.gem`
38
+ end
39
+
40
+ desc "Builds the native code"
41
+ task :build_native do
42
+ system("cd ext/typhoeus && ruby extconf.rb && make")
43
+ end
44
+
45
+ desc "Start up the test servers"
46
+ task :start_test_servers do
47
+ puts "Starting 3 test servers"
48
+ (3000..3002).map do |port|
49
+ Thread.new do
50
+ system("ruby spec/servers/app.rb -p #{port}")
51
+ end
52
+ end.each(&:join)
53
+ end
54
+
55
+ desc "Run all the tests"
56
+ task :default => :spec
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.4
@@ -0,0 +1,25 @@
1
+ require File.dirname(__FILE__) + '/../lib/typhoeus.rb'
2
+ require 'rubygems'
3
+ require 'ruby-prof'
4
+
5
+ calls = 20
6
+ @klass = Class.new do
7
+ include Typhoeus
8
+ end
9
+
10
+ Typhoeus.init_easy_objects
11
+
12
+ RubyProf.start
13
+
14
+ responses = []
15
+ calls.times do |i|
16
+ responses << @klass.get("http://127.0.0.1:3000/#{i}")
17
+ end
18
+
19
+ responses.each {|r| }#raise unless r.response_body == "whatever"}
20
+
21
+ result = RubyProf.stop
22
+
23
+ # Print a flat profile to text
24
+ printer = RubyProf::FlatPrinter.new(result)
25
+ printer.print(STDOUT, 0)
@@ -0,0 +1,35 @@
1
+ require 'rubygems'
2
+ require File.dirname(__FILE__) + '/../lib/typhoeus.rb'
3
+ require 'open-uri'
4
+ require 'benchmark'
5
+ include Benchmark
6
+
7
+
8
+ calls = 20
9
+ @klass = Class.new do
10
+ include Typhoeus
11
+ end
12
+
13
+ Typhoeus.init_easy_object_pool
14
+
15
+ benchmark do |t|
16
+ t.report("net::http") do
17
+ responses = []
18
+
19
+ calls.times do |i|
20
+ responses << open("http://127.0.0.1:3000/#{i}").read
21
+ end
22
+
23
+ responses.each {|r| raise unless r == "whatever"}
24
+ end
25
+
26
+ t.report("typhoeus") do
27
+ responses = []
28
+
29
+ calls.times do |i|
30
+ responses << @klass.get("http://127.0.0.1:3000/#{i}")
31
+ end
32
+
33
+ responses.each {|r| raise unless r.body == "whatever"}
34
+ end
35
+ end
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require File.dirname(__FILE__) + '/../lib/typhoeus.rb'
3
+
4
+
5
+ response = Typhoeus::Request.post(
6
+ "http://video-feed.local",
7
+ :params => {
8
+ :file => File.new("file.rb")
9
+ }
10
+ )
11
+
12
+ puts response.inspect
@@ -0,0 +1,40 @@
1
+ require File.dirname(__FILE__) + '/../lib/typhoeus.rb'
2
+
3
+ hydra = Typhoeus::Hydra.new
4
+ hydra.disable_memoization
5
+
6
+ urls = [
7
+ 'http://google.com',
8
+ 'http://testphp.vulnweb.com',
9
+ 'http://demo.testfire.net',
10
+ 'http://example.net',
11
+ ]
12
+
13
+ 10.times {
14
+ |i|
15
+
16
+ req = Typhoeus::Request.new( urls[ i % urls.size] )
17
+ req.on_complete {
18
+ |res|
19
+ puts 'URL: ' + res.effective_url
20
+ puts 'Time: ' + res.time.to_s
21
+ puts 'Connect time: ' + res.connect_time.to_s
22
+ puts 'App connect time: ' + res.app_connect_time.to_s
23
+ puts 'Start transfer time: ' + res.start_transfer_time.to_s
24
+ puts 'Pre transfer time: ' + res.pretransfer_time.to_s
25
+ puts '-------------'
26
+ }
27
+
28
+ hydra.queue( req )
29
+ puts 'Queued: ' + req.url
30
+ }
31
+
32
+ puts
33
+ puts 'Harvesting responses...'
34
+ puts
35
+
36
+ hydra.run
37
+
38
+ puts
39
+ puts 'Done.'
40
+ puts
@@ -0,0 +1,21 @@
1
+ require 'rubygems'
2
+ require File.dirname(__FILE__) + '/../lib/typhoeus.rb'
3
+ require 'json'
4
+
5
+ class Twitter
6
+ include Typhoeus
7
+ remote_defaults :on_success => lambda {|response| JSON.parse(response.body)},
8
+ :on_failure => lambda {|response| puts "error code: #{response.code}"},
9
+ :base_uri => "http://search.twitter.com"
10
+
11
+ define_remote_method :search, :path => '/search.json'
12
+ define_remote_method :trends, :path => '/trends/:time_frame.json'
13
+ end
14
+
15
+ tweets = Twitter.search(:params => {:q => "railsconf"})
16
+ trends = Twitter.trends(:time_frame => :current)
17
+
18
+ # and then the calls don't actually happen until the first time you
19
+ # call a method on one of the objects returned from the remote_method
20
+
21
+ puts tweets.keys # it's a hash from parsed JSON
@@ -0,0 +1,7 @@
1
+ conftest.dSYM/*
2
+ conftest.dSYM
3
+ mkmf.log
4
+ *.o
5
+ native.bundle
6
+ Makefile
7
+ *.bundle
@@ -0,0 +1,65 @@
1
+ ENV['RC_ARCHS'] = '' if RUBY_PLATFORM =~ /darwin/
2
+
3
+ # :stopdoc:
4
+
5
+ require 'mkmf'
6
+
7
+ ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
8
+ specified_curl = ARGV[0] =~ /^--with-curl/ ? ARGV[0].split("=")[1] : nil
9
+ LIBDIR = specified_curl ? "#{specified_curl}/lib": Config::CONFIG['libdir']
10
+ INCLUDEDIR = specified_curl ? "#{specified_curl}/include" : Config::CONFIG['includedir']
11
+
12
+ if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'macruby'
13
+ $LIBRUBYARG_STATIC.gsub!(/-static/, '')
14
+ end
15
+
16
+ $CFLAGS << " #{ENV["CFLAGS"]}"
17
+ if Config::CONFIG['target_os'] == 'mingw32'
18
+ $CFLAGS << " -DXP_WIN -DXP_WIN32 -DUSE_INCLUDED_VASPRINTF"
19
+ elsif Config::CONFIG['target_os'] == 'solaris2'
20
+ $CFLAGS << " -DUSE_INCLUDED_VASPRINTF"
21
+ else
22
+ $CFLAGS << " -g -DXP_UNIX"
23
+ end
24
+
25
+ use_macports = !(defined?(RUBY_ENGINE) && RUBY_ENGINE != 'ruby')
26
+ $LIBPATH << "/opt/local/lib" if use_macports
27
+
28
+ $CFLAGS << " -O3 -Wall -Wcast-qual -Wwrite-strings -Wconversion -Wmissing-noreturn -Winline"
29
+
30
+ if Config::CONFIG['target_os'] == 'mingw32'
31
+ header = File.join(ROOT, 'cross', 'curl-7.19.4.win32', 'include')
32
+ unless find_header('curl/curl.h', header)
33
+ abort "need libcurl"
34
+ end
35
+ else
36
+ HEADER_DIRS = [
37
+ File.join(INCLUDEDIR, "curl"),
38
+ INCLUDEDIR,
39
+ '/usr/include/curl',
40
+ '/usr/local/include/curl'
41
+ ]
42
+
43
+ [
44
+ '/opt/local/include/curl',
45
+ '/opt/local/include',
46
+ ].each { |x| HEADER_DIRS.unshift(x) } if use_macports
47
+
48
+ unless find_header('curl/curl.h', *HEADER_DIRS)
49
+ abort "need libcurl"
50
+ end
51
+ end
52
+
53
+ if Config::CONFIG['target_os'] == 'mingw32'
54
+ find_library('curl', 'curl_easy_init',
55
+ File.join(ROOT, 'cross', 'curl-7.19.4.win32', 'bin'))
56
+ else
57
+ find_library('curl', 'curl_easy_init',
58
+ LIBDIR,
59
+ '/opt/local/lib',
60
+ '/usr/local/lib',
61
+ '/usr/lib'
62
+ )
63
+ end
64
+
65
+ create_makefile("typhoeus/native")
@@ -0,0 +1,12 @@
1
+ #include <native.h>
2
+
3
+ VALUE mTyphoeus;
4
+
5
+ void Init_native()
6
+ {
7
+ mTyphoeus = rb_const_get(rb_cObject, rb_intern("Typhoeus"));
8
+
9
+ init_typhoeus_easy();
10
+ init_typhoeus_multi();
11
+ init_typhoeus_form();
12
+ }
@@ -0,0 +1,22 @@
1
+ #ifndef TYPHOEUS_NATIVE
2
+ #define TYPHOEUS_NATIVE
3
+
4
+ #include <ruby.h>
5
+ #include <curl/curl.h>
6
+ #include <curl/easy.h>
7
+ #include <curl/multi.h>
8
+
9
+ void Init_native();
10
+ extern VALUE mTyphoeus;
11
+ extern void init_typhoeus_easy();
12
+ extern void init_typhoeus_multi();
13
+ extern void init_typhoeus_form();
14
+
15
+ #endif
16
+
17
+ #ifndef RSTRING_PTR
18
+
19
+ #define RSTRING_PTR(s) (RSTRING(s)->ptr)
20
+ #define RSTRING_LEN(s) (RSTRING(s)->len)
21
+
22
+ #endif
@@ -0,0 +1,232 @@
1
+ #include <typhoeus_easy.h>
2
+
3
+ static VALUE idAppend;
4
+ VALUE cTyphoeusEasy;
5
+
6
+ static void dealloc(CurlEasy *curl_easy) {
7
+ if (curl_easy->request_chunk != NULL) {
8
+ free(curl_easy->request_chunk);
9
+ }
10
+
11
+ if (curl_easy->headers != NULL) {
12
+ curl_slist_free_all(curl_easy->headers);
13
+ }
14
+
15
+ curl_easy_cleanup(curl_easy->curl);
16
+
17
+ free(curl_easy);
18
+ }
19
+
20
+ static VALUE easy_setopt_string(VALUE self, VALUE opt_name, VALUE parameter) {
21
+ CurlEasy *curl_easy;
22
+ Data_Get_Struct(self, CurlEasy, curl_easy);
23
+
24
+ CURLoption opt = NUM2LONG(opt_name);
25
+ curl_easy_setopt(curl_easy->curl, opt, StringValuePtr(parameter));
26
+ return opt_name;
27
+ }
28
+
29
+ static VALUE easy_setopt_form(VALUE self, VALUE opt_name, VALUE parameter) {
30
+ CurlEasy *curl_easy;
31
+ CurlForm *curl_form;
32
+ Data_Get_Struct(self, CurlEasy, curl_easy);
33
+ Data_Get_Struct(parameter, CurlForm, curl_form);
34
+
35
+ CURLoption opt = NUM2LONG(opt_name);
36
+ curl_easy_setopt(curl_easy->curl, opt, curl_form->first);
37
+ return opt_name;
38
+ }
39
+
40
+ static VALUE easy_setopt_long(VALUE self, VALUE opt_name, VALUE parameter) {
41
+ CurlEasy *curl_easy;
42
+ Data_Get_Struct(self, CurlEasy, curl_easy);
43
+
44
+ CURLoption opt = NUM2LONG(opt_name);
45
+ curl_easy_setopt(curl_easy->curl, opt, NUM2LONG(parameter));
46
+ return opt_name;
47
+ }
48
+
49
+ static VALUE easy_getinfo_string(VALUE self, VALUE info) {
50
+ char *info_string;
51
+ CurlEasy *curl_easy;
52
+ Data_Get_Struct(self, CurlEasy, curl_easy);
53
+
54
+ CURLoption opt = NUM2LONG(info);
55
+ curl_easy_getinfo(curl_easy->curl, opt, &info_string);
56
+
57
+ return rb_str_new2(info_string);
58
+ }
59
+
60
+ static VALUE easy_getinfo_long(VALUE self, VALUE info) {
61
+ long info_long;
62
+ CurlEasy *curl_easy;
63
+ Data_Get_Struct(self, CurlEasy, curl_easy);
64
+
65
+ CURLoption opt = NUM2LONG(info);
66
+ curl_easy_getinfo(curl_easy->curl, opt, &info_long);
67
+
68
+ return LONG2NUM(info_long);
69
+ }
70
+
71
+ static VALUE easy_getinfo_double(VALUE self, VALUE info) {
72
+ double info_double = 0;
73
+ CurlEasy *curl_easy;
74
+ Data_Get_Struct(self, CurlEasy, curl_easy);
75
+
76
+ CURLoption opt = NUM2LONG(info);
77
+ curl_easy_getinfo(curl_easy->curl, opt, &info_double);
78
+
79
+ return rb_float_new(info_double);
80
+ }
81
+
82
+ static VALUE easy_perform(VALUE self) {
83
+ CurlEasy *curl_easy;
84
+ CURLcode return_code;
85
+ Data_Get_Struct(self, CurlEasy, curl_easy);
86
+ return_code = curl_easy_perform(curl_easy->curl);
87
+ rb_iv_set(self, "@curl_return_code", INT2FIX(return_code));
88
+
89
+ return Qnil;
90
+ }
91
+
92
+ static size_t write_data_handler(char *stream, size_t size, size_t nmemb, VALUE val) {
93
+ long stream_size = (long)(size * nmemb);
94
+ rb_funcall(val, idAppend, 1, rb_str_new(stream, stream_size));
95
+ return size * nmemb;
96
+ }
97
+
98
+ static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *data) {
99
+ size_t realsize = size * nmemb;
100
+ RequestChunk *mem = (RequestChunk *)data;
101
+
102
+ if (realsize > mem->size - mem->read) {
103
+ realsize = mem->size - mem->read;
104
+ }
105
+
106
+ if (realsize != 0) {
107
+ memcpy(ptr, &(mem->memory[mem->read]), realsize);
108
+ mem->read += realsize;
109
+ }
110
+
111
+ return realsize;
112
+ }
113
+
114
+ static void set_response_handlers(VALUE easy, CURL *curl) {
115
+ rb_iv_set(easy, "@response_body", rb_str_new2(""));
116
+ rb_iv_set(easy, "@response_header", rb_str_new2(""));
117
+
118
+ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, (curl_write_callback)&write_data_handler);
119
+ curl_easy_setopt(curl, CURLOPT_WRITEDATA, rb_iv_get(easy, "@response_body"));
120
+ curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, (curl_write_callback)&write_data_handler);
121
+ curl_easy_setopt(curl, CURLOPT_HEADERDATA, rb_iv_get(easy, "@response_header"));
122
+ }
123
+
124
+ static VALUE easy_reset(VALUE self) {
125
+ CurlEasy *curl_easy;
126
+ Data_Get_Struct(self, CurlEasy, curl_easy);
127
+
128
+ if (curl_easy->request_chunk != NULL) {
129
+ free(curl_easy->request_chunk);
130
+ curl_easy->request_chunk = NULL;
131
+ }
132
+
133
+ if (curl_easy->headers != NULL) {
134
+ curl_slist_free_all(curl_easy->headers);
135
+ curl_easy->headers = NULL;
136
+ }
137
+
138
+ curl_easy_reset(curl_easy->curl);
139
+
140
+ set_response_handlers(self, curl_easy->curl);
141
+
142
+ return Qnil;
143
+ }
144
+
145
+ static VALUE easy_add_header(VALUE self, VALUE header) {
146
+ CurlEasy *curl_easy;
147
+ Data_Get_Struct(self, CurlEasy, curl_easy);
148
+
149
+ curl_easy->headers = curl_slist_append(curl_easy->headers, RSTRING_PTR(header));
150
+ return header;
151
+ }
152
+
153
+ static VALUE easy_set_headers(VALUE self) {
154
+ CurlEasy *curl_easy;
155
+ Data_Get_Struct(self, CurlEasy, curl_easy);
156
+
157
+ curl_easy_setopt(curl_easy->curl, CURLOPT_HTTPHEADER, curl_easy->headers);
158
+
159
+ return Qnil;
160
+ }
161
+
162
+ static VALUE easy_set_request_body(VALUE self, VALUE data, VALUE content_length_header) {
163
+ CurlEasy *curl_easy;
164
+ Data_Get_Struct(self, CurlEasy, curl_easy);
165
+
166
+ curl_easy->request_chunk = ALLOC(RequestChunk);
167
+ curl_easy->request_chunk->size = RSTRING_LEN(data);
168
+ curl_easy->request_chunk->memory = StringValuePtr(data);
169
+ curl_easy->request_chunk->read = 0;
170
+
171
+ curl_easy_setopt(curl_easy->curl, CURLOPT_READFUNCTION, (curl_read_callback)read_callback);
172
+ curl_easy_setopt(curl_easy->curl, CURLOPT_READDATA, curl_easy->request_chunk);
173
+ curl_easy_setopt(curl_easy->curl, CURLOPT_INFILESIZE, RSTRING_LEN(data));
174
+
175
+ return Qnil;
176
+ }
177
+
178
+ static VALUE easy_escape(VALUE self, VALUE data, VALUE length) {
179
+ CurlEasy *curl_easy;
180
+ Data_Get_Struct(self, CurlEasy, curl_easy);
181
+
182
+ return rb_str_new2(curl_easy_escape(curl_easy->curl, StringValuePtr(data), (int)NUM2INT(length)));
183
+ }
184
+
185
+ static VALUE version(VALUE self) {
186
+ return rb_str_new2(curl_version());
187
+ }
188
+
189
+ static VALUE new(int argc, VALUE *argv, VALUE klass) {
190
+ CURL *curl = curl_easy_init();
191
+ CurlEasy *curl_easy = ALLOC(CurlEasy);
192
+ curl_easy->curl = curl;
193
+ curl_easy->headers = NULL;
194
+ curl_easy->request_chunk = NULL;
195
+ VALUE easy = Data_Wrap_Struct(cTyphoeusEasy, 0, dealloc, curl_easy);
196
+
197
+ set_response_handlers(easy, curl);
198
+
199
+ rb_obj_call_init(easy, argc, argv);
200
+
201
+ return easy;
202
+ }
203
+
204
+ static VALUE curl_error_message(VALUE self) {
205
+ VALUE return_code = rb_iv_get(self, "@curl_return_code");
206
+ if (return_code == Qnil)
207
+ return Qnil;
208
+ else {
209
+ CURLcode rc = (CURLcode)FIX2INT(return_code);
210
+ return rb_str_new2(curl_easy_strerror(rc));
211
+ }
212
+ }
213
+
214
+ void init_typhoeus_easy() {
215
+ VALUE klass = cTyphoeusEasy = rb_define_class_under(mTyphoeus, "Easy", rb_cObject);
216
+ idAppend = rb_intern("<<");
217
+ rb_define_singleton_method(klass, "new", new, -1);
218
+ rb_define_method(klass, "curl_error_message", curl_error_message, 0);
219
+ rb_define_private_method(klass, "easy_setopt_string", easy_setopt_string, 2);
220
+ rb_define_private_method(klass, "easy_setopt_form", easy_setopt_form, 2);
221
+ rb_define_private_method(klass, "easy_setopt_long", easy_setopt_long, 2);
222
+ rb_define_private_method(klass, "easy_getinfo_string", easy_getinfo_string, 1);
223
+ rb_define_private_method(klass, "easy_getinfo_long", easy_getinfo_long, 1);
224
+ rb_define_private_method(klass, "easy_getinfo_double", easy_getinfo_double, 1);
225
+ rb_define_private_method(klass, "easy_perform", easy_perform, 0);
226
+ rb_define_private_method(klass, "easy_reset", easy_reset, 0);
227
+ rb_define_private_method(klass, "easy_set_request_body", easy_set_request_body, 1);
228
+ rb_define_private_method(klass, "easy_set_headers", easy_set_headers, 0);
229
+ rb_define_private_method(klass, "easy_add_header", easy_add_header, 1);
230
+ rb_define_private_method(klass, "easy_escape", easy_escape, 2);
231
+ rb_define_private_method(klass, "version", version, 0);
232
+ }