eac_rest 0.2.0 → 0.3.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/lib/eac_rest/request.rb +43 -12
- data/lib/eac_rest/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '095a93df0ab8b49d4522e152b864277eeb958ec36263bf20789964fcd7f49811'
|
4
|
+
data.tar.gz: 4d65f2b6391de24e0d13875cbc4c2e85b0eb633613c9263959188b7277ca7893
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2116620e53293a41096f2285b5c417bb99c1ebb6c61071dec0dc9b37e0091cdc67c91fe9c325d303ba86b4263c51aea85f2b6874fef4919b15f4c34bb972241c
|
7
|
+
data.tar.gz: 6f6cb59974843728cf619802b71baa90835d22767e284b45e6768e3362fb08055d69eba5878cf80277aa556567530b437d008a1bd2778feaff15583a58a7cf68
|
data/lib/eac_rest/request.rb
CHANGED
@@ -6,14 +6,25 @@ require 'ostruct'
|
|
6
6
|
|
7
7
|
module EacRest
|
8
8
|
class Request
|
9
|
+
COMMON_MODIFIERS = %w[auth body_data verb].freeze
|
10
|
+
HASH_MODIFIERS = %w[header].freeze
|
11
|
+
MODIFIERS = COMMON_MODIFIERS + HASH_MODIFIERS.map(&:pluralize)
|
12
|
+
|
13
|
+
enable_immutable
|
14
|
+
immutable_accessor(*COMMON_MODIFIERS, type: :common)
|
15
|
+
immutable_accessor(*HASH_MODIFIERS, type: :hash)
|
16
|
+
|
17
|
+
enable_listable
|
18
|
+
lists.add_symbol :verb, :get, :delete, :options, :post, :put
|
19
|
+
|
9
20
|
common_constructor :url, :body_data_proc, default: [nil]
|
10
21
|
|
11
22
|
def autenticate(username, password)
|
12
|
-
|
23
|
+
auth(::OpenStruct.new(username: username, password: password))
|
13
24
|
end
|
14
25
|
|
15
|
-
def
|
16
|
-
|
26
|
+
def immutable_constructor_args
|
27
|
+
[url, body_data_proc]
|
17
28
|
end
|
18
29
|
|
19
30
|
def response
|
@@ -22,21 +33,41 @@ module EacRest
|
|
22
33
|
|
23
34
|
private
|
24
35
|
|
25
|
-
attr_accessor :auth
|
26
|
-
|
27
36
|
def build_curl
|
28
37
|
r = ::Curl::Easy.new(url)
|
38
|
+
MODIFIERS.each { |suffix| send("build_curl_#{suffix}", r) }
|
39
|
+
r
|
40
|
+
end
|
41
|
+
|
42
|
+
def build_curl_auth(curl)
|
29
43
|
auth.if_present do |a|
|
30
|
-
|
31
|
-
|
32
|
-
|
44
|
+
curl.http_auth_types = :basic
|
45
|
+
curl.username = a.username
|
46
|
+
curl.password = a.password
|
33
47
|
end
|
34
|
-
r.headers.merge!(headers)
|
35
|
-
r
|
36
48
|
end
|
37
49
|
|
38
|
-
def
|
39
|
-
|
50
|
+
def build_curl_body_data(curl)
|
51
|
+
www_form_body_data_encoded.if_present { |v| curl.post_body = v }
|
52
|
+
end
|
53
|
+
|
54
|
+
def build_curl_headers(curl)
|
55
|
+
curl.headers.merge!(headers)
|
56
|
+
end
|
57
|
+
|
58
|
+
def build_curl_verb(curl)
|
59
|
+
curl.set(
|
60
|
+
:customrequest,
|
61
|
+
verb.if_present(VERB_GET) { |v| self.class.lists.verb.value_validate!(v) }.to_s.upcase
|
62
|
+
)
|
63
|
+
end
|
64
|
+
|
65
|
+
def www_form_body_data_encoded
|
66
|
+
body_data.if_present do |v|
|
67
|
+
v = v.map { |k, vv| [k, vv] } if v.is_a?(::Hash)
|
68
|
+
v = URI.encode_www_form(v) if v.is_a?(::Array)
|
69
|
+
v.to_s
|
70
|
+
end
|
40
71
|
end
|
41
72
|
end
|
42
73
|
end
|
data/lib/eac_rest/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eac_rest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eduardo H. Bogoni
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: eac_ruby_utils
|