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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 52eedfe432cca2d5b561def4ff250065c6f602038820919c3e4588d3f402e74d
4
- data.tar.gz: 8b286a003e28931db39b589f01d56d4e2b4d08be7bac7c9cdb45ee7da3f2883c
3
+ metadata.gz: '095a93df0ab8b49d4522e152b864277eeb958ec36263bf20789964fcd7f49811'
4
+ data.tar.gz: 4d65f2b6391de24e0d13875cbc4c2e85b0eb633613c9263959188b7277ca7893
5
5
  SHA512:
6
- metadata.gz: 66f581076f08aa0d44eff44dc7c274c7fcac6079b1b0461afa2a9706a052c9d9445088ac9074f2f58db4f5d5db754d6f0d078693f1b6aa54ce14b3d0a8daf2e5
7
- data.tar.gz: 2d87555094fcdfd930573fce8711fc3e38380ae63235a30743f283cabddcb0ec85f0938e468c889f9d5b431c1dec7330e89533412188b3243d6ecea8a574d25e
6
+ metadata.gz: 2116620e53293a41096f2285b5c417bb99c1ebb6c61071dec0dc9b37e0091cdc67c91fe9c325d303ba86b4263c51aea85f2b6874fef4919b15f4c34bb972241c
7
+ data.tar.gz: 6f6cb59974843728cf619802b71baa90835d22767e284b45e6768e3362fb08055d69eba5878cf80277aa556567530b437d008a1bd2778feaff15583a58a7cf68
@@ -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
- self.auth = ::OpenStruct.new(username: username, password: password)
23
+ auth(::OpenStruct.new(username: username, password: password))
13
24
  end
14
25
 
15
- def header(name, value)
16
- headers[name.to_s] = value
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
- r.http_auth_types = :basic
31
- r.username = a.username
32
- r.password = a.password
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 headers
39
- @headers ||= {}
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRest
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  end
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.2.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-03-28 00:00:00.000000000 Z
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