ethon 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,20 @@
2
2
 
3
3
  ## Master
4
4
 
5
- [Full Changelog](http://github.com/typhoeus/ethon/compare/v0.2.0...master)
5
+ [Full Changelog](http://github.com/typhoeus/ethon/compare/v0.3.0...master)
6
+
7
+ ## 0.3.0
8
+
9
+ [Full Changelog](http://github.com/typhoeus/ethon/compare/v0.2.0...v0.3.0)
10
+
11
+ Enhancements:
12
+
13
+ * New libcurl option proxyport
14
+ * Raise invalid value error when providing a wrong key for sslversion or httpauth
15
+
16
+ Bugfixes:
17
+
18
+ * Libcurl option sslversion is handled correct
6
19
 
7
20
  ## 0.2.0
8
21
 
@@ -434,9 +434,12 @@ module Ethon
434
434
  attach_function :easy_cleanup, :curl_easy_cleanup, [:pointer], :void
435
435
  attach_function :easy_getinfo, :curl_easy_getinfo, [:pointer, :info, :pointer], :easy_code
436
436
  attach_function :easy_setopt, :curl_easy_setopt, [:pointer, :option, :pointer], :easy_code
437
+ attach_function :easy_setopt_ffi_pointer, :curl_easy_setopt, [:pointer, :option, :pointer], :easy_code
437
438
  attach_function :easy_setopt_string, :curl_easy_setopt, [:pointer, :option, :string], :easy_code
438
439
  attach_function :easy_setopt_long, :curl_easy_setopt, [:pointer, :option, :long], :easy_code
440
+ attach_function :easy_setopt_fixnum, :curl_easy_setopt, [:pointer, :option, :long], :easy_code
439
441
  attach_function :easy_setopt_callback, :curl_easy_setopt, [:pointer, :option, :callback], :easy_code
442
+ attach_function :easy_setopt_proc, :curl_easy_setopt, [:pointer, :option, :callback], :easy_code
440
443
  attach_function :easy_perform, :curl_easy_perform, [:pointer], :easy_code
441
444
  attach_function :easy_strerror, :curl_easy_strerror, [:int], :string
442
445
  attach_function :easy_escape, :curl_easy_escape, [:pointer, :pointer, :int], :string
@@ -498,16 +501,9 @@ module Ethon
498
501
 
499
502
  # Sets appropriate option for easy, depending on value type.
500
503
  def set_option(option, value, handle)
501
- case value
502
- when String
503
- easy_setopt_string(handle, option, value.to_s)
504
- when Integer
505
- easy_setopt_long(handle, option, value)
506
- when Proc, FFI::Function
507
- easy_setopt_callback(handle, option, value)
508
- else
509
- easy_setopt(handle, option, value) if value
510
- end
504
+ return unless value
505
+
506
+ method("easy_setopt_#{value.class.to_s.underscr}").call(handle, option, value)
511
507
  end
512
508
 
513
509
  # Return info as string.
@@ -522,7 +518,6 @@ module Ethon
522
518
  def get_info_string(option, handle)
523
519
  if easy_getinfo(handle, option, string_ptr) == :ok
524
520
  string_ptr.read_pointer.read_string
525
- else nil
526
521
  end
527
522
  end
528
523
 
@@ -538,7 +533,6 @@ module Ethon
538
533
  def get_info_long(option, handle)
539
534
  if easy_getinfo(handle, option, long_ptr) == :ok
540
535
  long_ptr.read_long
541
- else nil
542
536
  end
543
537
  end
544
538
 
@@ -554,7 +548,6 @@ module Ethon
554
548
  def get_info_double(option, handle)
555
549
  if easy_getinfo(handle, option, double_ptr) == :ok
556
550
  double_ptr.read_double
557
- else nil
558
551
  end
559
552
  end
560
553
 
@@ -13,9 +13,9 @@ module Ethon
13
13
  :customrequest, :cainfo, :capath, :connecttimeout,
14
14
  :followlocation, :httpauth, :infilesize, :interface,
15
15
  :maxredirs, :nosignal, :postfieldsize, :copypostfields, :proxy,
16
- :proxyauth, :proxytype, :timeout, :readdata, :sslcert, :ssl_verifypeer, :ssl_verifyhost,
17
- :sslcerttype, :sslkey, :sslkeytype, :sslversion,
18
- :url, :useragent, :userpwd, :verbose, :readfunction
16
+ :proxyauth, :proxyport, :proxytype, :timeout, :readdata, :sslcert,
17
+ :ssl_verifypeer, :ssl_verifyhost, :sslcerttype, :sslkey, :sslkeytype,
18
+ :sslversion, :url, :useragent, :userpwd, :verbose, :readfunction
19
19
  ])
20
20
  base.send(:attr_accessor, *Ethon::Easy::AVAILABLE_OPTIONS)
21
21
  end
@@ -52,7 +52,7 @@ module Ethon
52
52
  #
53
53
  # @return [ Hash ] The enum options.
54
54
  def enum_options
55
- { :httpauth => Curl::Auth }
55
+ { :httpauth => Curl::Auth, :sslversion => Curl::SSLVersion }
56
56
  end
57
57
 
58
58
  # Return the options which need to set as an integer for easy.
@@ -64,7 +64,7 @@ module Ethon
64
64
  def int_options
65
65
  [
66
66
  :connecttimeout, :dns_cache_timeout, :infilesize, :maxredirs,
67
- :postfieldsize, :ssl_verifyhost, :timeout
67
+ :postfieldsize, :proxyport, :ssl_verifyhost, :timeout
68
68
  ]
69
69
  end
70
70
  end
@@ -75,10 +75,7 @@ module Ethon
75
75
  # easy.set_options
76
76
  def set_options
77
77
  self.class.available_options.each do |option|
78
- value = value_for(option)
79
- next if value.nil?
80
-
81
- Curl.set_option(option, value, handle)
78
+ Curl.set_option(option, value_for(option), handle)
82
79
  end
83
80
  end
84
81
 
@@ -96,7 +93,9 @@ module Ethon
96
93
  if self.class.bool_options.include?(option)
97
94
  value ? 1 : 0
98
95
  elsif self.class.enum_options.key?(option)
99
- self.class.enum_options[option][value]
96
+ self.class.enum_options[option].to_h.fetch(value) do
97
+ raise Errors::InvalidValue.new(option, value)
98
+ end
100
99
  elsif self.class.int_options.include?(option)
101
100
  value.to_i
102
101
  elsif value.is_a?(::String)
@@ -104,6 +104,8 @@ module Ethon
104
104
  # http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTPROXYAUTH.
105
105
  # @option options :proxytype [String] See
106
106
  # http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTPROXYTYPE.
107
+ # @option options :proxyport [Integer] See
108
+ # http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTPROXYPORT.
107
109
  # @option options :put [String] See
108
110
  # http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTPUT.
109
111
  # @option options :readdata [String] See
@@ -6,6 +6,7 @@ require 'ethon/errors/multi_add'
6
6
  require 'ethon/errors/multi_remove'
7
7
  require 'ethon/errors/select'
8
8
  require 'ethon/errors/invalid_option'
9
+ require 'ethon/errors/invalid_value'
9
10
 
10
11
  module Ethon
11
12
 
@@ -0,0 +1,12 @@
1
+ module Ethon
2
+ module Errors
3
+
4
+ # Raises when option is invalid.
5
+ class InvalidValue < EthonError
6
+ def initialize(option, value)
7
+ super("The value: #{value} is invalid for option: #{option}.")
8
+ end
9
+ end
10
+ end
11
+ end
12
+
@@ -1 +1 @@
1
- require 'ethon/extensions/string.rb' unless ''.respond_to?(:byteslice)
1
+ require 'ethon/extensions/string.rb'
@@ -5,11 +5,33 @@ module Ethon
5
5
  module Extensions
6
6
  module String # :nodoc:
7
7
 
8
- # Return part of the string.
8
+ unless ''.respond_to?(:byteslice)
9
+ # Return part of the string.
10
+ #
11
+ # @return [ String ] Part of the string.
12
+ def byteslice(*args)
13
+ self[*args]
14
+ end
15
+ end
16
+
17
+ # Convert string to underscore. Taken from
18
+ # activesupport, renamed in order to no collide
19
+ # with it.
20
+ #
21
+ # @example Underscore.
22
+ # "ClassName".underscr
23
+ # #=> "class_name"
9
24
  #
10
- # @return [ String ] Part of the string.
11
- def byteslice(*args)
12
- self[*args]
25
+ # @return [ String ] Underscore string.
26
+ def underscr
27
+ word = self.dup
28
+ word.gsub!('::', '_')
29
+ word.gsub!(/(?:([A-Za-z\d])|^)(#{/(?=a)b/})(?=\b|[^a-z])/) { "#{$1}#{$1 && '_'}#{$2.downcase}" }
30
+ word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
31
+ word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
32
+ word.tr!("-", "_")
33
+ word.downcase!
34
+ word
13
35
  end
14
36
  end
15
37
  end
@@ -24,6 +24,7 @@ module Ethon
24
24
  # @raise [Ethon::Errors::MultiAdd] when adding an easy failed.
25
25
  def add(easy)
26
26
  return nil if easy_handles.include?(easy)
27
+
27
28
  code = Curl.multi_add_handle(handle, easy.handle)
28
29
  raise Errors::MultiAdd.new(code, easy) unless code == :ok
29
30
  easy_handles << easy
@@ -1,5 +1,5 @@
1
1
  module Ethon
2
2
 
3
3
  # Ethon version.
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.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.2.0
4
+ version: 0.3.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-29 00:00:00.000000000 Z
12
+ date: 2012-07-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi
@@ -219,6 +219,7 @@ files:
219
219
  - lib/ethon/errors/ethon_error.rb
220
220
  - lib/ethon/errors/global_init.rb
221
221
  - lib/ethon/errors/invalid_option.rb
222
+ - lib/ethon/errors/invalid_value.rb
222
223
  - lib/ethon/errors/multi_add.rb
223
224
  - lib/ethon/errors/multi_fdset.rb
224
225
  - lib/ethon/errors/multi_remove.rb
@@ -251,7 +252,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
251
252
  version: '0'
252
253
  segments:
253
254
  - 0
254
- hash: -2145906903079108779
255
+ hash: 1054475577707452411
255
256
  required_rubygems_version: !ruby/object:Gem::Requirement
256
257
  none: false
257
258
  requirements: