ethon 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,19 @@
2
2
 
3
3
  ## Master
4
4
 
5
- [Full Changelog](http://github.com/typhoeus/ethon/compare/v0.1.0...master)
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
@@ -9,7 +9,11 @@ In the modern world Ethon is a very basic libcurl wrapper using ffi.
9
9
 
10
10
  With bundler:
11
11
 
12
- gem "ethon", :git => "https://github.com/typhoeus/ethon.git", :branch => "master"
12
+ gem "ethon"
13
+
14
+ With rubygems:
15
+
16
+ gem install ethon
13
17
 
14
18
  ## Usage
15
19
 
data/Rakefile CHANGED
@@ -28,7 +28,7 @@ end
28
28
 
29
29
  desc "Start up the test servers"
30
30
  task :start do
31
- require 'spec/support/boot'
31
+ require_relative 'spec/support/boot'
32
32
  begin
33
33
  Boot.start_servers(:rake)
34
34
  rescue Exception
@@ -12,7 +12,11 @@ require 'ethon/easy'
12
12
  require 'ethon/multi'
13
13
  require 'ethon/version'
14
14
 
15
- # The toplevel namespace which includes everything
16
- # belonging to ethon.
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
@@ -490,7 +490,7 @@ module Ethon
490
490
  def init
491
491
  @@init_mutex.synchronize {
492
492
  if not @@initialized
493
- raise RuntimeError.new('curl failed to initialise') if Curl.global_init(GLOBAL_ALL) != 0
493
+ raise Errors::GlobalInit.new if Curl.global_init(GLOBAL_ALL) != 0
494
494
  @@initialized = true
495
495
  end
496
496
  }
@@ -5,6 +5,7 @@ module Ethon
5
5
  # which are needed to interact with libcurl.
6
6
  module Callbacks
7
7
 
8
+ # :nodoc:
8
9
  def self.included(base)
9
10
  base.send(:attr_accessor, *[:response_body, :response_header])
10
11
  end
@@ -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[:params])
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[:body])
62
+ @form ||= Form.new(options.delete(:body))
63
63
  end
64
64
 
65
65
  # Setup everything necessary for a proper request.
@@ -15,7 +15,7 @@ module Ethon
15
15
  # @param [ Easy ] easy The easy to setup.
16
16
  def setup(easy)
17
17
  super
18
- easy.customrequest = "GET"
18
+ easy.customrequest = "GET" unless form.empty?
19
19
  end
20
20
  end
21
21
  end
@@ -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
- # Execute preset complete callback.
24
+
25
+ # Set on_complete callback.
8
26
  #
9
- # @example Execute complete callback.
10
- # easy.complete
11
- def complete
12
- return if !defined?(@complete) || @complete.nil?
13
- @complete.call(self)
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
- # Set complete callback.
37
+ # Execute on_complete callbacks.
17
38
  #
18
- # @example Set complete callback.
19
- # easy.on_complete = block
20
- def on_complete(&block)
21
- @complete = block
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
@@ -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
- method("#{key}=").call(value) if respond_to?("#{key}=")
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
 
@@ -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
 
@@ -0,0 +1,12 @@
1
+ module Ethon
2
+ module Errors
3
+
4
+ # Raises when global_init failed.
5
+ class GlobalInit < EthonError
6
+ def initialize
7
+ super("An error occured initializing curl.")
8
+ end
9
+ end
10
+ end
11
+ end
12
+
@@ -0,0 +1,12 @@
1
+ module Ethon
2
+ module Errors
3
+
4
+ # Raises when option is invalid.
5
+ class InvalidOption < EthonError
6
+ def initialize(option)
7
+ super("The option: #{option} is invalid.")
8
+ end
9
+ end
10
+ end
11
+ end
12
+
@@ -5,7 +5,6 @@ module Ethon
5
5
  class MultiAdd < EthonError
6
6
  def initialize(code, easy)
7
7
  super("An error occured adding the easy handle: #{easy} to the multi: #{code}")
8
- # "an error occured getting the fdset: #{code}: #{Curl.multi_strerror(code)}"
9
8
  end
10
9
  end
11
10
  end
@@ -1,5 +1,5 @@
1
1
  module Ethon
2
2
 
3
3
  # Ethon version.
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
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.1.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-26 00:00:00.000000000 Z
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: -4546024795644378522
254
+ hash: -2145906903079108779
237
255
  required_rubygems_version: !ruby/object:Gem::Requirement
238
256
  none: false
239
257
  requirements: