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 +4 -4
- data/README.md +44 -0
- data/lib/purple/boolean.rb +2 -0
- data/lib/purple/client.rb +2 -2
- data/lib/purple/path.rb +6 -0
- data/lib/purple/response.rb +1 -0
- data/lib/purple/responses/body.rb +2 -0
- data/lib/purple/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39f3cee0069620b8f540e7103eb4aa27fa0b7384a0b473c586dde47f6cebd62d
|
4
|
+
data.tar.gz: fe5c9ac61f1795b3994124c53ce1c5a31657a6e429e42e60c016b1c32a1909df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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 =
|
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 }
|
data/lib/purple/response.rb
CHANGED
@@ -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)
|
data/lib/purple/version.rb
CHANGED
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.
|
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-
|
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
|