purple-client 0.1.5.2 → 0.1.7.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: 75b0112e7f0757f456ca2580565433282b7ed33ac1e5c0e1a5cde5dadcb25eb7
4
- data.tar.gz: e5738ee82c58c3ac8e5ae184f387045efbad92cecaf9102718f567516c75ddb9
3
+ metadata.gz: 39f3cee0069620b8f540e7103eb4aa27fa0b7384a0b473c586dde47f6cebd62d
4
+ data.tar.gz: fe5c9ac61f1795b3994124c53ce1c5a31657a6e429e42e60c016b1c32a1909df
5
5
  SHA512:
6
- metadata.gz: 8b343906b6609c8a0bc38de841353f97a5f1a4dba5cf6cc5e89eee1dfcc7f7a6d4b693a9d3cad02cfdccdf6393d8857fef5a880ff5afbbca91707c5bac57c385
7
- data.tar.gz: a3d193575c7eed275005303ef90a0fa6ac4512a04b2cbaf87d71310c1a877e4fafbfe647b8281edc1c184ccf164aca8db42648e7b110cba2c5852e51d028b4b8
6
+ metadata.gz: 3bf2ea0e3cd4aca1b327ad57da1711775a1bb14208163f41a8d6632232c1e45b5abba8a70c2b2953acd10288f5ad111ac83bf315e5056496801c8942d4163636
7
+ data.tar.gz: 5e544d9b54f7938fdca2f71ae58a6ce9e11815eae8d545511bab5afc7e5a4e93edb4dbdc30da572dd57e4a8fc9e412b8001533f303ebed7dfb667185c055fa64
data/README.md CHANGED
@@ -78,6 +78,27 @@ end
78
78
  ProfileClient.profile
79
79
  ```
80
80
 
81
+ ### Using custom headers
82
+
83
+ ```ruby
84
+ class CustomHeadersClient < Purple::Client
85
+ domain 'https://api.example.com'
86
+ authorization :custom_headers,
87
+ 'X-API-KEY' => 'your-api-key',
88
+ 'X-Secret' => 'your-api-secret'
89
+
90
+ path :widgets do
91
+ response :ok do
92
+ body :default
93
+ end
94
+ root_method :widgets
95
+ end
96
+ end
97
+
98
+ # Custom headers will be sent automatically
99
+ CustomHeadersClient.widgets
100
+ ```
101
+
81
102
  ### Nested paths
82
103
 
83
104
  ```ruby
@@ -130,6 +151,29 @@ extracted from the call and passed to your callback. In the example above the
130
151
  available inside the callback so you can associate the stored event with a
131
152
  record of your choice.
132
153
 
154
+ ### Boolean response types
155
+
156
+ If you have boolean types `true` or `false` in your response, use
157
+ `Purple::Boolean` in the response configuration.
158
+
159
+ ```ruby
160
+ class AccountsClient < Purple::Client
161
+ domain 'https://api.example.com'
162
+
163
+ path :accounts do
164
+ response :ok do
165
+ body(
166
+ last_name: String,
167
+ first_name: String,
168
+ is_creator: Purple::Boolean,
169
+ is_premium: Purple::Boolean,
170
+ )
171
+ end
172
+ root_method :accounts
173
+ end
174
+ end
175
+ ```
176
+
133
177
  ## Development
134
178
 
135
179
  After checking out the repo, run `bin/setup` to install dependencies. Then run
@@ -0,0 +1,2 @@
1
+ class Purple::Boolean
2
+ end
data/lib/purple/client.rb CHANGED
@@ -5,6 +5,7 @@ require 'purple/request'
5
5
  require 'purple/requests/authorization'
6
6
  require 'purple/response'
7
7
  require 'purple/responses/body'
8
+ require 'purple/boolean'
8
9
  require_relative "version"
9
10
 
10
11
  module Purple
@@ -64,9 +65,8 @@ module Purple
64
65
 
65
66
  define_singleton_method method_name do |*call_args, **kw_args, &block|
66
67
  if current_path.is_param
67
- value = kw_args[current_path.name] || call_args.first
68
+ value = call_args.first
68
69
  current_path.with(value)
69
- kw_args[current_path.name] = value
70
70
  end
71
71
 
72
72
  callback_arguments = additional_callback_arguments.map do |arg|
data/lib/purple/path.rb CHANGED
@@ -74,6 +74,12 @@ module Purple
74
74
  connection.get(url, params)
75
75
  when :post
76
76
  connection.post(url, params.to_json)
77
+ when :put
78
+ connection.put(url, params.to_json)
79
+ when :delete
80
+ connection.delete(url, params)
81
+ when :patch
82
+ connection.patch(url, params.to_json)
77
83
  end
78
84
 
79
85
  resp_structure = responses.find { |resp| resp.status_code == response.status }
@@ -13,6 +13,7 @@ class Purple::Response
13
13
  ok: 200,
14
14
  bad_request: 400,
15
15
  unauthorized: 401,
16
+ unprocessable_entity: 422,
16
17
  forbidden: 403,
17
18
  not_found: 404,
18
19
  too_many_requests: 429,
@@ -98,6 +98,8 @@ class Purple::Responses::Body
98
98
  "Missing field '#{key}' in response body. Body: #{object}"
99
99
  end
100
100
 
101
+ return if expected_type == Purple::Boolean && (object[key] == true || object[key] == false)
102
+
101
103
  return if object[key].is_a?(expected_type)
102
104
 
103
105
  raise BodyStructureMismatchError.new(key, expected_type, object[key], object)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Purple
4
- VERSION = "0.1.5.2"
4
+ VERSION = "0.1.7.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.5.2
4
+ version: 0.1.7.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: 2025-07-07 00:00:00.000000000 Z
11
+ date: 2025-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-initializer
@@ -38,6 +38,7 @@ files:
38
38
  - LICENSE.txt
39
39
  - README.md
40
40
  - Rakefile
41
+ - lib/purple/boolean.rb
41
42
  - lib/purple/client.rb
42
43
  - lib/purple/path.rb
43
44
  - lib/purple/request.rb