fast_curl 0.4.0 → 0.5.1

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.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FastCurl
4
- VERSION = "0.4.0"
4
+ VERSION = "0.5.1"
5
5
  end
data/lib/fast_curl.rb CHANGED
@@ -88,7 +88,8 @@ module FastCurl
88
88
  execute(build_requests(requests, method), **DEFAULT_OPTIONS.merge(options))
89
89
  end
90
90
 
91
- define_method(:"first_#{method}") do |requests, count: 1, **options|
91
+ define_method(:"first_#{method}") do |requests, count: 1, accept: nil, **options|
92
+ options[:accept] = accept unless accept.nil?
92
93
  first_execute(build_requests(requests, method), count: count, **DEFAULT_OPTIONS.merge(options))
93
94
  end
94
95
 
@@ -100,24 +101,38 @@ module FastCurl
100
101
  private
101
102
 
102
103
  def build_requests(requests, method)
103
- requests.map do |req|
104
- r = { url: build_url(req), method: method.to_s.upcase }
105
- headers = req[:headers] ? req[:headers].dup : nil
106
-
107
- if BODY_METHODS.include?(method)
108
- body, content_type = build_body(req)
109
- if body
110
- r[:body] = body
111
- if content_type && !content_type?(headers)
112
- headers ||= {}
113
- headers["Content-Type"] = content_type
114
- end
115
- end
104
+ source = requests.is_a?(Hash) ? [requests] : requests
105
+
106
+ if source.is_a?(Array)
107
+ source.map { |request| build_request(request, method) }
108
+ elsif source.respond_to?(:each)
109
+ Enumerator.new do |yielder|
110
+ source.each { |request| yielder << build_request(request, method) }
116
111
  end
112
+ else
113
+ raise ArgumentError, "requests must be a Hash, Array or respond to #each"
114
+ end
115
+ end
116
+
117
+ def build_request(req, method)
118
+ raise ArgumentError, "request must be a Hash" unless req.is_a?(Hash)
117
119
 
118
- r[:headers] = headers if headers && !headers.empty?
119
- r
120
+ r = { url: build_url(req), method: method.to_s.upcase }
121
+ headers = req[:headers] ? req[:headers].dup : nil
122
+
123
+ if BODY_METHODS.include?(method)
124
+ body, content_type = build_body(req)
125
+ if body
126
+ r[:body] = body
127
+ if content_type && !content_type?(headers)
128
+ headers ||= {}
129
+ headers["Content-Type"] = content_type
130
+ end
131
+ end
120
132
  end
133
+
134
+ r[:headers] = headers if headers && !headers.empty?
135
+ r
121
136
  end
122
137
 
123
138
  def build_url(req)
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fast_curl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - roman-haidarov
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2026-07-28 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: json
@@ -125,7 +124,6 @@ homepage: https://github.com/roman-haidarov/fast_curl
125
124
  licenses:
126
125
  - MIT
127
126
  metadata: {}
128
- post_install_message:
129
127
  rdoc_options: []
130
128
  require_paths:
131
129
  - lib
@@ -140,8 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
138
  - !ruby/object:Gem::Version
141
139
  version: '0'
142
140
  requirements: []
143
- rubygems_version: 3.4.22
144
- signing_key:
141
+ rubygems_version: 3.6.7
145
142
  specification_version: 4
146
143
  summary: Ultra-fast parallel HTTP client as Ruby C extension on libcurl multi
147
144
  test_files: []