sinew 3.0.1 → 4.0.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.
- checksums.yaml +4 -4
- data/.gitignore +3 -5
- data/.rubocop.yml +30 -48
- data/Gemfile +4 -4
- data/Gemfile.lock +124 -0
- data/README.md +108 -47
- data/Rakefile +16 -15
- data/bin/sinew +13 -41
- data/lib/sinew.rb +23 -9
- data/lib/sinew/args.rb +53 -0
- data/lib/sinew/base.rb +251 -0
- data/lib/sinew/csv.rb +89 -0
- data/lib/sinew/main.rb +46 -72
- data/lib/sinew/{connection → middleware}/log_formatter.rb +2 -1
- data/lib/sinew/nokogiri_ext.rb +12 -21
- data/lib/sinew/response.rb +41 -52
- data/lib/sinew/version.rb +1 -1
- data/sample.rb +13 -0
- data/sample.sinew +4 -4
- data/sinew.gemspec +19 -16
- metadata +31 -21
- data/.vscode/extensions.json +0 -3
- data/.vscode/settings.json +0 -5
- data/lib/sinew/connection.rb +0 -52
- data/lib/sinew/connection/rate_limit.rb +0 -29
- data/lib/sinew/core_ext.rb +0 -59
- data/lib/sinew/dsl.rb +0 -115
- data/lib/sinew/output.rb +0 -133
- data/lib/sinew/request.rb +0 -86
- data/lib/sinew/runtime_options.rb +0 -28
data/lib/sinew/request.rb
DELETED
@@ -1,86 +0,0 @@
|
|
1
|
-
require 'sterile'
|
2
|
-
|
3
|
-
#
|
4
|
-
# Process a single HTTP request.
|
5
|
-
#
|
6
|
-
|
7
|
-
module Sinew
|
8
|
-
class Error < StandardError; end
|
9
|
-
|
10
|
-
class Request
|
11
|
-
VALID_METHODS = %w[get post patch put delete head options].freeze
|
12
|
-
METHODS_WITH_BODY = %w[patch post put].freeze
|
13
|
-
|
14
|
-
attr_reader :method, :options, :uri
|
15
|
-
|
16
|
-
# Supported options:
|
17
|
-
# body: Body of http post
|
18
|
-
# headers: Hash of HTTP headers (combined with runtime_options.headers)
|
19
|
-
# query: Hash of query parameters to add to url
|
20
|
-
def initialize(method, url, options = {})
|
21
|
-
@method = method
|
22
|
-
@options = options.dup
|
23
|
-
@uri = parse_url(url)
|
24
|
-
end
|
25
|
-
|
26
|
-
# run the request, return the result
|
27
|
-
def perform(connection)
|
28
|
-
validate!
|
29
|
-
|
30
|
-
body = options.delete(:body)
|
31
|
-
fday_response = connection.send(method, uri, body) do
|
32
|
-
_1.headers.update(options[:headers]) if options[:headers]
|
33
|
-
_1.options[:proxy] = options[:proxy]
|
34
|
-
end
|
35
|
-
|
36
|
-
Response.from_network(self, fday_response)
|
37
|
-
end
|
38
|
-
|
39
|
-
# We accept sloppy urls and attempt to clean them up
|
40
|
-
def parse_url(url)
|
41
|
-
s = url.to_s
|
42
|
-
|
43
|
-
# remove entities
|
44
|
-
s = Sterile.decode_entities(s)
|
45
|
-
|
46
|
-
# fix a couple of common encoding bugs
|
47
|
-
s = s.gsub(' ', '%20')
|
48
|
-
s = s.gsub("'", '%27')
|
49
|
-
|
50
|
-
# append query manually (instead of letting Faraday handle it) for consistent
|
51
|
-
# Request#uri and Response#uri
|
52
|
-
query = options.delete(:query)
|
53
|
-
if query.present?
|
54
|
-
q = Faraday::Utils.default_params_encoder.encode(query)
|
55
|
-
separator = s.include?('?') ? '&' : '?'
|
56
|
-
s = "#{s}#{separator}#{q}"
|
57
|
-
end
|
58
|
-
|
59
|
-
URI.parse(s)
|
60
|
-
end
|
61
|
-
protected :parse_url
|
62
|
-
|
63
|
-
def validate!
|
64
|
-
raise "invalid method #{method}" if !VALID_METHODS.include?(method)
|
65
|
-
raise "invalid url #{uri}" if uri.scheme !~ /^http/
|
66
|
-
raise "can't #{method} with a body" if body && !METHODS_WITH_BODY.include?(method)
|
67
|
-
raise "Content-Type doesn't make sense without a body" if content_type && !body
|
68
|
-
end
|
69
|
-
protected :validate!
|
70
|
-
|
71
|
-
def body
|
72
|
-
options[:body]
|
73
|
-
end
|
74
|
-
protected :body
|
75
|
-
|
76
|
-
def headers
|
77
|
-
options[:headers]
|
78
|
-
end
|
79
|
-
protected :headers
|
80
|
-
|
81
|
-
def content_type
|
82
|
-
headers && headers['Content-Type']
|
83
|
-
end
|
84
|
-
protected :content_type
|
85
|
-
end
|
86
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Runtime options that sinew files can modify.
|
3
|
-
#
|
4
|
-
|
5
|
-
module Sinew
|
6
|
-
class RuntimeOptions
|
7
|
-
attr_accessor :retries
|
8
|
-
attr_accessor :rate_limit
|
9
|
-
attr_accessor :headers
|
10
|
-
attr_accessor :httpdisk_options
|
11
|
-
attr_accessor :insecure
|
12
|
-
|
13
|
-
def initialize
|
14
|
-
self.retries = 3
|
15
|
-
self.rate_limit = 1
|
16
|
-
self.headers = {
|
17
|
-
'User-Agent' => "sinew/#{VERSION}",
|
18
|
-
}
|
19
|
-
self.httpdisk_options = {}
|
20
|
-
self.insecure = false
|
21
|
-
|
22
|
-
# for testing
|
23
|
-
if ENV['SINEW_TEST']
|
24
|
-
self.rate_limit = 0
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|