ethon 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +15 -1
- data/README.md +5 -1
- data/Rakefile +1 -1
- data/lib/ethon.rb +6 -2
- data/lib/ethon/curl.rb +1 -1
- data/lib/ethon/easies/callbacks.rb +1 -0
- data/lib/ethon/easies/http/actionable.rb +3 -3
- data/lib/ethon/easies/http/get.rb +1 -1
- data/lib/ethon/easies/response_callbacks.rb +34 -11
- data/lib/ethon/easy.rb +24 -1
- data/lib/ethon/errors.rb +2 -0
- data/lib/ethon/errors/global_init.rb +12 -0
- data/lib/ethon/errors/invalid_option.rb +12 -0
- data/lib/ethon/errors/multi_add.rb +0 -1
- data/lib/ethon/version.rb +1 -1
- metadata +21 -3
data/CHANGELOG.md
CHANGED
@@ -2,7 +2,19 @@
|
|
2
2
|
|
3
3
|
## Master
|
4
4
|
|
5
|
-
[Full Changelog](http://github.com/typhoeus/ethon/compare/v0.
|
5
|
+
[Full Changelog](http://github.com/typhoeus/ethon/compare/v0.2.0...master)
|
6
|
+
|
7
|
+
## 0.2.0
|
8
|
+
|
9
|
+
[Full Changelog](http://github.com/typhoeus/ethon/compare/v0.1.0...v0.2.0)
|
10
|
+
|
11
|
+
Enhancements:
|
12
|
+
|
13
|
+
* GET requests are using custom requests only when there is a request body
|
14
|
+
* Easy#on_complete takes multiple callbacks
|
15
|
+
* raise Errors::GlobalInit when libcurls global_init failed instead of
|
16
|
+
runtime error
|
17
|
+
* raise Errors::InvalidOption if option is invalid
|
6
18
|
|
7
19
|
## 0.1.0
|
8
20
|
|
@@ -22,6 +34,8 @@ Bugfixes:
|
|
22
34
|
|
23
35
|
## 0.0.2
|
24
36
|
|
37
|
+
[Full Changelog](http://github.com/typhoeus/ethon/compare/v0.0.1...v0.0.2)
|
38
|
+
|
25
39
|
Bugfixes:
|
26
40
|
|
27
41
|
* Add libcurl.so.4 to ffi_lib in order to load correct lib on Debian.
|
data/README.md
CHANGED
data/Rakefile
CHANGED
data/lib/ethon.rb
CHANGED
@@ -12,7 +12,11 @@ require 'ethon/easy'
|
|
12
12
|
require 'ethon/multi'
|
13
13
|
require 'ethon/version'
|
14
14
|
|
15
|
-
#
|
16
|
-
#
|
15
|
+
# Ethon is a very simple libcurl.
|
16
|
+
# It provides direct access to libcurl functionality
|
17
|
+
# as well as some helpers for doing http requests.
|
18
|
+
#
|
19
|
+
# Ethon was extracted from Typhoeus. If you want to
|
20
|
+
# see how others use Ethon look at the Typhoeus code.
|
17
21
|
module Ethon
|
18
22
|
end
|
data/lib/ethon/curl.rb
CHANGED
@@ -490,7 +490,7 @@ module Ethon
|
|
490
490
|
def init
|
491
491
|
@@init_mutex.synchronize {
|
492
492
|
if not @@initialized
|
493
|
-
raise
|
493
|
+
raise Errors::GlobalInit.new if Curl.global_init(GLOBAL_ALL) != 0
|
494
494
|
@@initialized = true
|
495
495
|
end
|
496
496
|
}
|
@@ -19,7 +19,7 @@ module Ethon
|
|
19
19
|
# @return [ Action ] A new action.
|
20
20
|
def initialize(url, options)
|
21
21
|
@url = url
|
22
|
-
@options = options
|
22
|
+
@options = options.dup
|
23
23
|
end
|
24
24
|
|
25
25
|
# Return the url.
|
@@ -49,7 +49,7 @@ module Ethon
|
|
49
49
|
#
|
50
50
|
# @return [ Params ] The params.
|
51
51
|
def params
|
52
|
-
@params ||= Params.new(options
|
52
|
+
@params ||= Params.new(options.delete(:params))
|
53
53
|
end
|
54
54
|
|
55
55
|
# Return the form.
|
@@ -59,7 +59,7 @@ module Ethon
|
|
59
59
|
#
|
60
60
|
# @return [ Form ] The form.
|
61
61
|
def form
|
62
|
-
@form ||= Form.new(options
|
62
|
+
@form ||= Form.new(options.delete(:body))
|
63
63
|
end
|
64
64
|
|
65
65
|
# Setup everything necessary for a proper request.
|
@@ -3,22 +3,45 @@ module Ethon
|
|
3
3
|
|
4
4
|
# This module contains the logic for the response callbacks.
|
5
5
|
# The on_complete callback is the only one at the moment.
|
6
|
+
#
|
7
|
+
# You can set multiple callbacks, which are then executed
|
8
|
+
# in the same order.
|
9
|
+
#
|
10
|
+
# easy.on_complete { p 1 }
|
11
|
+
# easy.on_complete { p 2 }
|
12
|
+
# easy.complete
|
13
|
+
# #=> 1
|
14
|
+
# #=> 2
|
15
|
+
#
|
16
|
+
# You can clear the callbacks:
|
17
|
+
#
|
18
|
+
# easy.on_complete { p 1 }
|
19
|
+
# easy.on_complete { p 2 }
|
20
|
+
# easy.on_complete.clear
|
21
|
+
# easy.on_complete
|
22
|
+
# #=> []
|
6
23
|
module ResponseCallbacks
|
7
|
-
|
24
|
+
|
25
|
+
# Set on_complete callback.
|
8
26
|
#
|
9
|
-
# @example
|
10
|
-
#
|
11
|
-
|
12
|
-
|
13
|
-
|
27
|
+
# @example Set on_complete.
|
28
|
+
# request.on_complete { p "yay" }
|
29
|
+
#
|
30
|
+
# @param [ Block ] block The block to execute.
|
31
|
+
def on_complete(&block)
|
32
|
+
@on_complete ||= []
|
33
|
+
@on_complete << block if block_given?
|
34
|
+
@on_complete
|
14
35
|
end
|
15
36
|
|
16
|
-
#
|
37
|
+
# Execute on_complete callbacks.
|
17
38
|
#
|
18
|
-
# @example
|
19
|
-
#
|
20
|
-
def
|
21
|
-
@
|
39
|
+
# @example Execute on_completes.
|
40
|
+
# request.complete
|
41
|
+
def complete
|
42
|
+
if defined?(@on_complete)
|
43
|
+
@on_complete.map{ |callback| callback.call(self) }
|
44
|
+
end
|
22
45
|
end
|
23
46
|
end
|
24
47
|
end
|
data/lib/ethon/easy.rb
CHANGED
@@ -13,6 +13,24 @@ module Ethon
|
|
13
13
|
|
14
14
|
# This is the class representing the libcurl easy interface
|
15
15
|
# See http://curl.haxx.se/libcurl/c/libcurl-easy.html for more informations.
|
16
|
+
#
|
17
|
+
# @example You can access the libcurl easy interface through this class, every request is based on it. The simplest setup looks like that:
|
18
|
+
#
|
19
|
+
# e = Ethon::Easy.new(url: "www.example.com")
|
20
|
+
# e.prepare
|
21
|
+
# e.perform
|
22
|
+
# #=> :ok
|
23
|
+
#
|
24
|
+
# @example You can the reuse this Easy for the next request:
|
25
|
+
#
|
26
|
+
# e.reset # reset easy handle
|
27
|
+
# e.url = "www.google.com"
|
28
|
+
# e.followlocation = true
|
29
|
+
# e.prepare
|
30
|
+
# e.perform
|
31
|
+
# #=> :ok
|
32
|
+
#
|
33
|
+
# @see initialize
|
16
34
|
class Easy
|
17
35
|
include Ethon::Easies::Informations
|
18
36
|
include Ethon::Easies::Callbacks
|
@@ -133,10 +151,15 @@ module Ethon
|
|
133
151
|
#
|
134
152
|
# @param [ Hash ] options The options.
|
135
153
|
#
|
154
|
+
# @raise InvalidOption
|
155
|
+
#
|
136
156
|
# @see initialize
|
137
157
|
def set_attributes(options)
|
138
158
|
options.each_pair do |key, value|
|
139
|
-
|
159
|
+
unless respond_to?("#{key}=")
|
160
|
+
raise Errors::InvalidOption.new(key)
|
161
|
+
end
|
162
|
+
method("#{key}=").call(value)
|
140
163
|
end
|
141
164
|
end
|
142
165
|
|
data/lib/ethon/errors.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
require 'ethon/errors/ethon_error'
|
2
|
+
require 'ethon/errors/global_init'
|
2
3
|
require 'ethon/errors/multi_timeout'
|
3
4
|
require 'ethon/errors/multi_fdset'
|
4
5
|
require 'ethon/errors/multi_add'
|
5
6
|
require 'ethon/errors/multi_remove'
|
6
7
|
require 'ethon/errors/select'
|
8
|
+
require 'ethon/errors/invalid_option'
|
7
9
|
|
8
10
|
module Ethon
|
9
11
|
|
data/lib/ethon/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ethon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ffi
|
@@ -171,6 +171,22 @@ dependencies:
|
|
171
171
|
- - ~>
|
172
172
|
- !ruby/object:Gem::Version
|
173
173
|
version: 0.8.0
|
174
|
+
- !ruby/object:Gem::Dependency
|
175
|
+
name: simplecov
|
176
|
+
requirement: !ruby/object:Gem::Requirement
|
177
|
+
none: false
|
178
|
+
requirements:
|
179
|
+
- - ~>
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: 0.5.3
|
182
|
+
type: :development
|
183
|
+
prerelease: false
|
184
|
+
version_requirements: !ruby/object:Gem::Requirement
|
185
|
+
none: false
|
186
|
+
requirements:
|
187
|
+
- - ~>
|
188
|
+
- !ruby/object:Gem::Version
|
189
|
+
version: 0.5.3
|
174
190
|
description: Very lightweight libcurl wrapper.
|
175
191
|
email:
|
176
192
|
- me@hans.io
|
@@ -201,6 +217,8 @@ files:
|
|
201
217
|
- lib/ethon/easies/util.rb
|
202
218
|
- lib/ethon/easy.rb
|
203
219
|
- lib/ethon/errors/ethon_error.rb
|
220
|
+
- lib/ethon/errors/global_init.rb
|
221
|
+
- lib/ethon/errors/invalid_option.rb
|
204
222
|
- lib/ethon/errors/multi_add.rb
|
205
223
|
- lib/ethon/errors/multi_fdset.rb
|
206
224
|
- lib/ethon/errors/multi_remove.rb
|
@@ -233,7 +251,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
233
251
|
version: '0'
|
234
252
|
segments:
|
235
253
|
- 0
|
236
|
-
hash: -
|
254
|
+
hash: -2145906903079108779
|
237
255
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
238
256
|
none: false
|
239
257
|
requirements:
|