curlyrest 0.1.33 → 0.1.37

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 49b176a2a74978da6565b6807a35669e4c70a10f8953bcb8f266d2b1bea90482
4
- data.tar.gz: ee9999169292ce953f871021600a8838d2435d05b6305ec969de61dc93003edb
3
+ metadata.gz: f962af4bf3323d1e468ff1793f776c66c3526de3425aa8e9403c10becc4b2385
4
+ data.tar.gz: a433e2943f6fe2038b87ab52f40f6dd245d7cd2948f0639e008ed294b94faaf2
5
5
  SHA512:
6
- metadata.gz: 020e9f8633037adcfeea3f3eed2503acc1591790dfd29cd12b4d32d52060ad34ba9d351e9f4a7e1c26a55e8b10c005f62c459546ed16b1b2906d46a8a336ec5b
7
- data.tar.gz: de73017da194b2520ef8c28362eed07771ab721eb8f617d5508595a6047535e3cd2277ba64fed958881fb02f05f4448e148e7f990724139ae7e2afec60253d87
6
+ metadata.gz: 611560868a36fdee9124bfe15fe4569118888ceb3138de7c480f05709b74bc2979984ba3cefed16838a7e1bcc6568bac13499816b6a91a9404d3d2bf2b2d5318
7
+ data.tar.gz: 469c72ee4ac5b2a70aee8adc5bbf66fd62244af93da9b448867daeaaef43d26e30533994c6fba778e93131c29e9b0f2e150c931ba7d7d3370e493ce3980da866
data/.gitignore CHANGED
@@ -1,5 +1,6 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
+ /.idea/
3
4
  /Gemfile.lock
4
5
  /_yardoc/
5
6
  /coverage/
data/.rubocop.yml CHANGED
@@ -1,11 +1,17 @@
1
+ AllCops:
2
+ NewCops: enable
3
+ SuggestExtensions: false
4
+
1
5
  Style/FrozenStringLiteralComment:
2
6
  Enabled: false
3
7
 
4
8
  Metrics/BlockLength:
9
+ Max: 2000
5
10
  Exclude:
11
+ - 'spec/*.rb'
12
+ - 'spec/**/*.rb'
6
13
  - 'Rakefile'
7
14
  - '**/*.rake'
8
- - 'spec/**/*.rb'
9
15
  - '*.gemspec'
10
16
 
11
17
  Metrics/MethodLength:
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
  gem 'simplecov', require: false, group: :test
3
5
 
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rspec/core/rake_task'
3
5
 
data/curlyrest.gemspec CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  lib = File.expand_path('lib', __dir__)
2
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
5
  require 'curlyrest/version'
@@ -7,7 +9,7 @@ Gem::Specification.new do |spec|
7
9
  spec.version = Curlyrest::VERSION
8
10
  spec.authors = ['Keith Williams']
9
11
  spec.email = ['keithrw@comcast.net']
10
-
12
+ spec.required_ruby_version = ['>= 2.5.5', '< 3.0']
11
13
  spec.summary =
12
14
  'gem extending rest-client, allowing use/debug of curl for request'
13
15
  spec.description =
data/lib/curlyrest.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'curlyrest/version'
2
4
  require 'rest-client'
3
5
  require 'byebug'
@@ -8,45 +10,42 @@ module Curlyrest
8
10
  class CurlResponse
9
11
  include Net::HTTPHeader
10
12
  attr_reader :code, :http_version, :message, :headers
11
- attr_accessor :body, :inflate
13
+ attr_accessor :body
14
+
12
15
  def initialize(http_version, status, message = '')
13
16
  @message = message
14
17
  @http_version = http_version
15
18
  @code = status
16
19
  @body = ''
17
- @inflate = Zlib::Inflate.new(32 + Zlib::MAX_WBITS)
18
20
  initialize_http_header nil
19
21
  end
20
-
21
- def unzip_body(gzip)
22
- @body = @inflate.inflate(gzip)
23
- end
24
22
  end
25
23
 
26
24
  # class for parsing curl responses
27
25
  class CurlResponseParser
28
26
  attr_accessor :response
27
+
29
28
  def initialize(response)
30
29
  @state = :read_status
31
30
  @response = nil
32
- @body = ''
31
+ @body_lines = []
32
+ @body = nil
33
33
  parse(response)
34
34
  end
35
35
 
36
+ def body
37
+ @body || @body_lines.join
38
+ end
39
+
36
40
  def parse(response)
37
41
  response.lines.each do |line|
38
42
  parse_line(line)
39
43
  end
40
- ce = @response.to_hash.dig('content-encoding')
41
- if ce&.include?('gzip')
42
- @response.unzip_body(@body)
43
- else
44
- @response.body = @body
45
- end
44
+ @response.body = body
46
45
  end
47
46
 
48
47
  def parse_status(line)
49
- re = %r{^HTTP\/(\d+|\d+\.\d+)\s(\d+)\s*(.*)$}
48
+ re = %r{^HTTP/(\d+|\d+\.\d+)\s(\d+)\s*(.*)$}
50
49
  return unless re.match(line.chop)
51
50
 
52
51
  r = Regexp.last_match(2)
@@ -64,19 +63,19 @@ module Curlyrest
64
63
  return
65
64
  end
66
65
  /^([\w-]+):\s(.*)/ =~ line.chop
66
+ raise "invalid line while parsing headers: #{line}" unless Regexp.last_match
67
+
67
68
  @response.add_field(Regexp.last_match(1), Regexp.last_match(2))
68
69
  end
69
70
 
70
71
  def parse_line(line)
71
72
  case @state
72
73
  when :body
73
- @body << line
74
+ @body_lines << line
74
75
  when :read_status
75
76
  parse_status(line)
76
77
  when :headers
77
78
  parse_headers(line)
78
- else
79
- puts "parser error on #{line}"
80
79
  end
81
80
  end
82
81
  end
@@ -84,6 +83,7 @@ module Curlyrest
84
83
  # class for transmitting curl requests
85
84
  class CurlTransmitter
86
85
  attr_accessor :options, :headers, :line, :timeout
86
+
87
87
  def initialize(uri, method, headers, payload)
88
88
  @payload = payload
89
89
  @method = method
@@ -105,14 +105,13 @@ module Curlyrest
105
105
  headers, options = opts_from_headers(headers)
106
106
  headers.delete('No-Restclient-Headers') ||
107
107
  headers.delete(:no_restclient_headers)
108
- headers.delete('Accept-Encoding') ||
109
- headers.delete('accept_encoding')
110
108
  [headers, options]
111
109
  end
112
110
 
113
111
  def curl_data(payload)
114
112
  return nil unless payload
115
113
  return "-d '#{payload}'" unless payload.include?('\'')
114
+
116
115
  File.write('/tmp/curl_quoted_binary', payload)
117
116
  '--data-binary @/tmp/curl_quoted_binary'
118
117
  end
@@ -124,19 +123,19 @@ module Curlyrest
124
123
  def curl_start
125
124
  timeout = options[:timeout]
126
125
  timeout_str = ''
127
- timeout_str << " --max-time #{timeout}" unless timeout.nil?
128
- "curl -isSL -X #{@method.upcase}#{timeout_str}"
126
+ timeout_str += " --max-time #{timeout}" if timeout
127
+ "curl -isSL -X #{@method.upcase}#{timeout_str} 2>&1"
129
128
  end
130
129
 
131
130
  def curl_headers(headers)
132
- ret_headers = ' '
131
+ ret_headers = [' ']
133
132
  headers.each { |k, v| ret_headers << "-H '#{k}: #{v}' " }
134
- ret_headers
133
+ ret_headers.join
135
134
  end
136
135
 
137
136
  def curl_command
138
137
  "#{curl_start}#{curl_proxy(@options[:proxy])}"\
139
- "#{curl_headers(@headers)}'#{@uri}' #{curl_data(@payload&.to_s)}"
138
+ "#{curl_headers(@headers)}'#{@uri}' #{curl_data(@payload&.to_s)}"
140
139
  end
141
140
 
142
141
  def exec_curl
@@ -151,6 +150,7 @@ module Curlyrest
151
150
  def curl_transmit(uri, method, headers, payload)
152
151
  ct = CurlTransmitter.new(uri, method, headers, payload)
153
152
  r = ct.exec_curl
153
+
154
154
  CurlResponseParser.new(r).response
155
155
  end
156
156
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Curlyrest
2
- VERSION = '0.1.33'.freeze
4
+ VERSION = '0.1.37'
3
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: curlyrest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.33
4
+ version: 0.1.37
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keith Williams
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-20 00:00:00.000000000 Z
11
+ date: 2021-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug
@@ -83,7 +83,6 @@ files:
83
83
  - README.md
84
84
  - Rakefile
85
85
  - curlyrest.gemspec
86
- - failing.txt
87
86
  - lib/curlyrest.rb
88
87
  - lib/curlyrest/version.rb
89
88
  homepage: https://github.com/keithrw54/curlyrest.git
@@ -98,14 +97,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
98
97
  requirements:
99
98
  - - ">="
100
99
  - !ruby/object:Gem::Version
101
- version: '0'
100
+ version: 2.5.5
101
+ - - "<"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
102
104
  required_rubygems_version: !ruby/object:Gem::Requirement
103
105
  requirements:
104
106
  - - ">="
105
107
  - !ruby/object:Gem::Version
106
108
  version: '0'
107
109
  requirements: []
108
- rubygems_version: 3.0.8
110
+ rubygems_version: 3.0.9
109
111
  signing_key:
110
112
  specification_version: 4
111
113
  summary: gem extending rest-client, allowing use/debug of curl for request
data/failing.txt DELETED
@@ -1,2 +0,0 @@
1
- curl -isS -X POST -x http://l5d.us1.dev.cloudhealthtech.com:4140 -H 'content_type: application/json' -H 'l5d-dtab: /hh=>/ng/kwilliams' -H 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IkRkcEFZdHAtWUIwdTNIbGxJOGczSkdUX2hkOTI5aERlRkpOUmR6REU3R1UifQ.eyJzdWIiOiJjcm46MjAxNzp1c2VyLzg5MjIxIiwib3JnIjoiY3JuOjIwMTc6b3JnYW5pemF0aW9uLzg5MzM1MzE5NzYyOSIsInJvbGUiOiJjcm46OnJvbGUvMyIsImlzcyI6ImNybjo6dG9rZW4tc2VydmljZS9wb2QiLCJhdWQiOiJjcm46OmFjY2Vzcy10b2tlbi9wb2QiLCJpYXQiOjE1NDM1ODYzMjQsImV4cCI6MTU0MzU4NzIyNCwianRpIjoiYjA1NmUwMWMtYTc0Ni00NjdjLWEwZmQtMzdlMGI1MmUyOGM5In0.EHjFcOSxfxuH9lFTq9RREP0NMofyAkAf0-czbvxZXvfe_7h6brnRFty6_TkGa3fXa3TK6rpWLrWLo2sIeEF2DW5UXYwXz0eMotObMjJVi30VtlYWQPJX1QpQgL97Wzxjb-OZ5buzBzXTWeV2vinDZPxjUhtqHz-TJHjU6jNSNBrDc6eofg_95rANzNjRXJp9JSd89mFq0qAcmQhtnQOAzvTouLViBcK0cwxzsK3ux4QLxS4_SKRGEdZ24tq2mlM8kNi2SB4T1qCX8hItrnCUaShOurB18SuxKdp6PjQmzyBVnnSPRqIgQJGqRSiGPCmHRuLmsm50lGSLnm95HzLP6ZYe6bxyQdFZp7_WIky7onV_EjkqaiPqeb8PqUIBYlYz-sI95vUs__hV8qe47LV7Yw9mB_d00hoDGruUN2XzMV4DLR-E4KMUnHrBD1mZK5gVOi7mx8nPhDYleFAl9d57oTWHMd-iT2NxSpE56Saq1peF2vKgV84nysWyCRf0XRyWsbwNbLL16mGJr56ZR6IbVKZ2tkHSBOiyJ2UIx-IfnAN2p1Y9GaKGsJoGPcRADy9p_ogbNIakH4j92T9RbXbAAjPluZBD9eVnwvejeiuoNMxZQwtV-D32l2jP8u6ZpRCQO2z5Hk0LKSZdxKsm0RQnT_T1n4G1GAxG5sab9zqbXLg' 'http://query-data/graphql' -d '{"query":"mutation ExecuteChql {executeChql (input: {chql: \"SELECT day, aws_regions, aws_charge_type, aws_billing_account, sum(cost) FROM costusage WHERE aws_regions = 'us-east-1' GROUP BY day, aws_regions, aws_charge_type, aws_billing_account ORDER BY aws_regions asc, aws_charge_type desc\"\n sources: [{crn: \"crn:2017:query-meta/dataset:AWS:CostUsageDaily\"\n alias: \"costusage\"}]\n clientMutationId: \"ignore\"}){ id }}"}'
2
- HT