petail 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: f8b4586f6ff3956d439fa35a0aaa64753b3839261a55df4cc9ce83b0bbdd277f
4
- data.tar.gz: 4b20c15bc80355c4d55dd83d365ca3ed8806775385623b005e53aaa61cf9b260
3
+ metadata.gz: e974c64e0259b3561130ac6d4ea4a7bae80fa381e9ab7ee7cb3ab0338d9fe2c4
4
+ data.tar.gz: 6e99b146485fd8da57711ed81512ee599b10797fbc5cfb2072941927f78bd640
5
5
  SHA512:
6
- metadata.gz: 1e7a2e97589c26880828fda50953a8cf542b0eb6c1c285bed3e4889d091c8486a5c1e6998e5efae59dc0a5a013e3f30859366d08773155cc3ae96c95beffdbd1
7
- data.tar.gz: 8f69aaadab1e77609b51824528b22e896c6e3c5a7c3b963e9fadd7edb098f232ba6f1cc64f07a3fcf746c0a9e1e16173a5e5bd8dfd7b059fc179e67786f4d608
6
+ metadata.gz: 4f6aa6a580106976c75f5f7db20362ffad7be1c6d25c1c55ed19dafe8c7ea7b50387213dcac51395d8cb9f6fe9aa5160bd1879fb20b9cbde9b48dedfdbe63822
7
+ data.tar.gz: a51c4609448bc36218c226c4f71a1b3fd99d46d4d16c666c4b009d76f1020ec2ee2634f156fbbaecd6012c9f4149409d45d44d00e378e5ecbc1eef1037db9bb9
checksums.yaml.gz.sig CHANGED
Binary file
data/README.adoc CHANGED
@@ -55,10 +55,12 @@ The quickest way to get started is to create a new instance and then cast as JSO
55
55
 
56
56
  [source,ruby]
57
57
  ----
58
- payload = Petail.new type: "https://demo.io/problem_details/timeout",
59
- status: 413,
60
- detail: "You've exceeded the 5MB upload limit.",
61
- instance: "/profile/3a1bfd54-ae6c-4a61-8d0d-90c132428dc3"
58
+ payload = Petail[
59
+ type: "https://demo.io/problem_details/timeout",
60
+ status: 413,
61
+ detail: "You've exceeded the 5MB upload limit.",
62
+ instance: "/profile/3a1bfd54-ae6c-4a61-8d0d-90c132428dc3"
63
+ ]
62
64
 
63
65
  payload.to_json
64
66
 
@@ -82,6 +84,8 @@ payload.to_xml
82
84
  # </problem>
83
85
  ----
84
86
 
87
+ 💡 You can also use `Petail.new` to create instances if you don't like `Petail.[]`, as shown above, but `.[]` is preferred.
88
+
85
89
  === Media Types
86
90
 
87
91
  For convenience, you can obtain the necessary media types for your HTTP headers as follows:
@@ -97,11 +101,11 @@ Petail.media_type_for :xml # "application/problem+xml"
97
101
 
98
102
  === Payload
99
103
 
100
- You'll always get a `Petail::Payload` object answered back when using `Petail.new` for which you can cast to JSON, XML, and other types. There are few conveniences provided for you when constructing a new payload. For instance, you can also use status to set default title:
104
+ You'll always get a `Petail::Payload` object answered back when using `Petail.[]` or `Petail.new` for which you can cast to JSON, XML, and other types. There are few conveniences provided for you when constructing a new payload. For instance, you can also use status to set default title:
101
105
 
102
106
  [source,ruby]
103
107
  ----
104
- Petail.new status: 413
108
+ Petail[status: 413]
105
109
  # #<Struct:Petail::Payload:0x0000ec80
106
110
  # detail = nil,
107
111
  # extensions = {},
@@ -116,7 +120,7 @@ Notice that standard HTTP 413 title of "Content Too Large" is provided for you b
116
120
 
117
121
  [source,ruby]
118
122
  ----
119
- Petail.new status: :bad_request
123
+ Petail[status: :bad_request]
120
124
  # #<Struct:Petail::Payload:0x0000f280
121
125
  # detail = nil,
122
126
  # extensions = {},
@@ -133,7 +137,7 @@ Due to the payload being a `Struct`, you have all of the standard methods availa
133
137
 
134
138
  [source,]
135
139
  ----
136
- payload = Petail.new status: :forbidden
140
+ payload = Petail[status: :forbidden]
137
141
 
138
142
  payload.add_extension(:account, "/accounts/1")
139
143
  .add_extension(:balance, 50)
@@ -165,7 +169,7 @@ Both serialization and deserialization of JSON is supported. For example, given
165
169
 
166
170
  [source,ruby]
167
171
  ----
168
- payload = Petail.new(
172
+ payload = Petail[
169
173
  type: "https://test.io/problem_details/out_of_credit",
170
174
  title: "You do not have enough credit.",
171
175
  status: 403,
@@ -175,7 +179,7 @@ payload = Petail.new(
175
179
  balance: 30,
176
180
  accounts: %w[/accounts/1 /accounts/10]
177
181
  }
178
- )
182
+ ]
179
183
  ----
180
184
 
181
185
  This means you can serialize as follows:
@@ -232,7 +236,7 @@ XML is supported too but isn't as robust as JSON support, at the moment. This is
232
236
 
233
237
  [source,ruby]
234
238
  ----
235
- payload = Petail.new(
239
+ payload = Petail[
236
240
  type: "https://test.io/problem_details/out_of_credit",
237
241
  title: "You do not have enough credit.",
238
242
  status: 403,
@@ -242,7 +246,7 @@ payload = Petail.new(
242
246
  balance: 30,
243
247
  accounts: %w[/accounts/1 /accounts/10]
244
248
  }
245
- )
249
+ ]
246
250
  ----
247
251
 
248
252
  This means you can serialize as follows:
data/lib/petail.rb CHANGED
@@ -10,6 +10,10 @@ module Petail
10
10
  MEDIA_TYPE_XML = "application/problem+xml"
11
11
  TYPES = %i[json xml].freeze
12
12
 
13
+ def self.[](**) = Payload.for(**)
14
+
15
+ def self.new(**) = Payload.for(**)
16
+
13
17
  def self.from_json(...) = Payload.from_json(...)
14
18
 
15
19
  def self.from_xml(...) = Payload.from_xml(...)
@@ -17,6 +21,4 @@ module Petail
17
21
  def self.media_type_for key, types: TYPES
18
22
  types.include?(key) ? const_get("MEDIA_TYPE_#{key.upcase}") : ""
19
23
  end
20
-
21
- def self.new(**) = Payload.for(**)
22
24
  end
data/petail.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "petail"
5
- spec.version = "0.2.0"
5
+ spec.version = "0.3.0"
6
6
  spec.authors = ["Brooke Kuhlmann"]
7
7
  spec.email = ["brooke@alchemists.io"]
8
8
  spec.homepage = "https://alchemists.io/projects/petail"
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
24
24
 
25
25
  spec.required_ruby_version = "~> 3.4"
26
26
  spec.add_dependency "rack", ">= 2.2", "< 4.0"
27
+ spec.add_dependency "rexml", "~> 3.4"
27
28
 
28
29
  spec.extra_rdoc_files = Dir["README*", "LICENSE*"]
29
30
  spec.files = Dir["*.gemspec", "lib/**/*"]
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: petail
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
  - Brooke Kuhlmann
@@ -55,6 +55,20 @@ dependencies:
55
55
  - - "<"
56
56
  - !ruby/object:Gem::Version
57
57
  version: '4.0'
58
+ - !ruby/object:Gem::Dependency
59
+ name: rexml
60
+ requirement: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - "~>"
63
+ - !ruby/object:Gem::Version
64
+ version: '3.4'
65
+ type: :runtime
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - "~>"
70
+ - !ruby/object:Gem::Version
71
+ version: '3.4'
58
72
  email:
59
73
  - brooke@alchemists.io
60
74
  executables: []
@@ -95,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
109
  - !ruby/object:Gem::Version
96
110
  version: '0'
97
111
  requirements: []
98
- rubygems_version: 3.6.7
112
+ rubygems_version: 3.6.9
99
113
  specification_version: 4
100
114
  summary: A RFC 9457 Problem Details for HTTP APIs implementation.
101
115
  test_files: []
metadata.gz.sig CHANGED
Binary file