purple-client 0.1.0.1 → 0.1.1

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: 066bed26b96e48e935797201e73754b1e04db86788fdca81935c412daed48e8f
4
- data.tar.gz: 47106e21ab8fc4607a84a4ea89e85653c83c5c182aa42192228ff6164e5eaef3
3
+ metadata.gz: 52d949ade3816a9c300a86183d10aadf41052ce9b5532651bbb45824f6e731ca
4
+ data.tar.gz: 0a0b9f5bf1ff5f4f8acbd45a813d0c79251422c133bc11566b40fca97f51ed61
5
5
  SHA512:
6
- metadata.gz: 3e188539cd06534badf64c79abb833756e410ff42576804e7f1f86f34c6b44332766804496d903b9ba7cb25f6cb6f2e690e07eda1ee0f03dcb8d2af39d4ae436
7
- data.tar.gz: c461496af7c52405b2c2251201b3ad57a5add4c06e2f94fd0be2d80951933a942e753e06d03b8be5d4dcca15741d4c72b11a7f72bc58b21bc815f03f14f00ac6
6
+ metadata.gz: b2b509535d9dac1de4611d17a8eee8a51d16c6621762d59212fbde9aa1c0b99197349e2fed2b829f3335f04e1da88485618730f922aef7be8b086bfc38ded3e2
7
+ data.tar.gz: 24ef0a418979210df30bd2fc3c8e33bc5d6b3d9899b6d2dd72c44683689553b0a1b1e59dba8a77645b57295455d9cc71cb937ac4f2bb0ef9d7867d2f779a0885
data/lib/purple/client.rb CHANGED
@@ -90,8 +90,13 @@ module Purple
90
90
  yield if block_given?
91
91
  end
92
92
 
93
- def body(_type = nil, **structure, &block)
94
- @current_resp.body = Responses::Body.new(structure:, response: @current_resp, transform: block)
93
+ def body(type = nil, **structure, &block)
94
+ case type
95
+ when :default
96
+ @current_resp.body = :default
97
+ else
98
+ @current_resp.body = Responses::Body.new(structure:, response: @current_resp, transform: block)
99
+ end
95
100
  end
96
101
 
97
102
  def method_missing(method_name, *args, &)
data/lib/purple/path.rb CHANGED
@@ -53,7 +53,13 @@ module Purple
53
53
 
54
54
  resp_structure = responses.find { |resp| resp.status_code == response.status }
55
55
 
56
- object = resp_structure.body.validate!(response.body, args) if resp_structure
56
+ object = if resp_structure.body.is_a?(Purple::Responses::Body)
57
+ resp_structure.body.validate!(response.body, args)
58
+ elsif resp_structure.body == :default
59
+ response.body
60
+ else
61
+ {}
62
+ end
57
63
 
58
64
  client.callback&.call(url, params, headers, JSON.parse(response.body))
59
65
 
@@ -69,13 +69,18 @@ class Purple::Responses::Body
69
69
  def check_structure!(object, substructure = structure)
70
70
  substructure.each do |key, value|
71
71
  if value.is_a?(Hash)
72
- if value.key?(:optional) && value.key?(:type)
72
+ if options?(value)
73
73
  next if value[:optional]
74
+ next if value[:allow_blank] && object[key].blank?
74
75
 
75
76
  check_type!(object, key, value[:type])
76
77
  else
77
78
  check_structure!(object[key], substructure[key])
78
79
  end
80
+ elsif value.is_a?(Array)
81
+ object[key].each do |item|
82
+ check_structure!(item, value[0])
83
+ end
79
84
  else
80
85
  check_type!(object, key, value)
81
86
  end
@@ -85,11 +90,15 @@ class Purple::Responses::Body
85
90
  def check_type!(object, key, expected_type)
86
91
  unless object.key?(key)
87
92
  raise BodyStructureMismatchError.new(key, expected_type, object[key], object),
88
- "Missing field '#{key}' in response body. Body: #{object}"
93
+ "Missing field '#{key}' in response body. Body: #{object}"
89
94
  end
90
95
 
91
96
  return if object[key].is_a?(expected_type)
92
97
 
93
98
  raise BodyStructureMismatchError.new(key, expected_type, object[key], object)
94
99
  end
100
+
101
+ def options?(hash)
102
+ hash.key?(:type) && (hash.key?(:optional) || hash.key?(:allow_blank))
103
+ end
95
104
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Purple
4
- VERSION = "0.1.0.1"
4
+ VERSION = "0.1.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: purple-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.1
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Kalashnikov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-12-01 00:00:00.000000000 Z
11
+ date: 2024-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-initializer