api_header_optimizer 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3b97eb0b9a2eca8956b285777447469840f688bfdf861b01d16de01456ba4104
4
- data.tar.gz: 2401266c155e0f60f815f96e507fff86b969374af5d33292b253a1b8ed886949
3
+ metadata.gz: d70771bd55e301295b8ea91d45ce8272ab7aee7240a59a356873eea37004f63e
4
+ data.tar.gz: e883e11934321c8f62dd4cbc7cb128bdeff1b109f056fee1f92591f23d3acdd0
5
5
  SHA512:
6
- metadata.gz: 075d21858be1267b3c6f5f628b617945cc7ce2d8396ab91a2743f6e83bc97f29ccb38eb04ff04423b666b91f60b9f02049d08988102bf160141add52ec3e61bd
7
- data.tar.gz: 0fcdb7d46f331bb596466b4b75835e33ad4dc9d0d45aca32465960410ee95582fd1f8b0faf91a53c3387ae842d07fff74b5cf89b45ad851d68e605b5879bbb88
6
+ metadata.gz: d95fda627e12c840fc4f33b1976cbf09d89bcada61086fdf71a4d750da204e4e03508413769582c492e605cf31a30109df0ff253a80618acd06b5e856a919415
7
+ data.tar.gz: 5bdebb97c62b8c128a7640b367dc3344d1978b95b4e1f85951d72ecb2c446f7dcb878bf0d4a0c72d3ca6d58882acaaf61ddece304544e8f931acd6d95c1db1bf
data/README.md CHANGED
@@ -13,7 +13,7 @@ If bundler is not being used to manage dependencies, install the gem by executin
13
13
  ## Usage
14
14
 
15
15
  This gem allows to extract the headers required in httparty requests.
16
-
16
+ If you have some issue with rails c, you can install or update the gem 'globalid'
17
17
  ## Development
18
18
 
19
19
  After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -9,25 +9,35 @@ module ApiHeaderOptimizer
9
9
  @uri = URI(uri)
10
10
  @all_headers = all_headers
11
11
  @results = []
12
+ @mutex = Mutex.new # Erişim problemlerini önlemek için mutex kullanıyoruz
12
13
  end
13
14
 
14
15
  # Tek bir header seti ile istek yapar ve sonucu kontrol eder
15
16
  def test_header_set(header_set)
16
17
  response = make_request(header_set)
17
18
  return unless response # İstek başarısızsa geç
18
- @results << { headers: header_set, code: response.code, body: response.body }
19
+
20
+ # Sonuçları güvenli bir şekilde eklemek için mutex kullanıyoruz
21
+ @mutex.synchronize do
22
+ @results << { headers: header_set, code: response.code, body: response.body }
23
+ end
19
24
  end
20
25
 
21
26
  # Header kombinasyonlarını test eder
22
27
  def test_combinations
23
- # Tüm header kombinasyonlarını oluştur ve test et
24
28
  header_keys = @all_headers.keys
25
29
  subsets = ApiHeaderOptimizer::Helpers.subsets(header_keys)
26
30
 
27
- subsets.each do |subset|
28
- header_set = subset.to_h { |key| [key, @all_headers[key]] }
29
- test_header_set(header_set)
31
+ # Eşzamanlılık için thread'ler oluşturuyoruz
32
+ threads = subsets.map do |subset|
33
+ Thread.new do
34
+ header_set = subset.to_h { |key| [key, @all_headers[key]] }
35
+ test_header_set(header_set)
36
+ end
30
37
  end
38
+
39
+ # Tüm thread'lerin bitmesini bekliyoruz
40
+ threads.each(&:join)
31
41
  end
32
42
 
33
43
  private
@@ -35,15 +45,18 @@ module ApiHeaderOptimizer
35
45
  def make_request(headers)
36
46
  http = Net::HTTP.new(@uri.host, @uri.port)
37
47
  http.use_ssl = @uri.scheme == 'https'
38
- request = Net::HTTP::Get.new(@uri.path)
39
- headers.each { |key, value| request[key] = value }
40
-
41
- begin
42
- response = http.request(request)
43
- return response if response.code.to_i.between?(200, 299) # Başarılı yanıtlar
44
- rescue StandardError => e
45
- puts "Request failed: #{e.message}"
46
- return nil
48
+ http.start do |http|
49
+ headers.each do |header_set|
50
+ request = Net::HTTP::Get.new(@uri.path)
51
+ header_set.each { |key, value| request[key] = value }
52
+ begin
53
+ response = http.request(request)
54
+ return response if response.code.to_i.between?(200, 299) # Başarılı yanıtlar
55
+ rescue => e
56
+ puts "Request failed: #{e.message}"
57
+ return nil
58
+ end
59
+ end
47
60
  end
48
61
  end
49
62
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ApiHeaderOptimizer
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
@@ -6,6 +6,8 @@ require_relative "api_header_optimizer/optimizer"
6
6
  require_relative "api_header_optimizer/tester"
7
7
 
8
8
  module ApiHeaderOptimizer
9
- class Error < StandardError; end
10
- # Your code goes here...
9
+ def self.optimize(address_url, headers)
10
+ optimizer = Optimizer.new(address_url, headers)
11
+ optimizer.optimize
12
+ end
11
13
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_header_optimizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ziya Gökalp
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-09-21 00:00:00.000000000 Z
11
+ date: 2024-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-http