File tree 3 files changed +48
-2
lines changed 3 files changed +48
-2
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
16
16
17
17
spec . required_ruby_version = ">= 2.5"
18
18
19
- spec . add_dependency "async-rest" , "~> 0.10.0 "
19
+ spec . add_dependency "async-rest" , "~> 0.12.3 "
20
20
21
21
spec . add_development_dependency "async-rspec"
22
22
spec . add_development_dependency "bundler"
Original file line number Diff line number Diff line change 5
5
6
6
require_relative '../paginate'
7
7
require_relative '../representation'
8
+ require_relative 'rest_wrapper'
8
9
9
10
module Cloudflare
10
11
module KV
@@ -55,7 +56,8 @@ def write_value(name, value)
55
56
private
56
57
57
58
def value_representation ( name )
58
- self . with ( Representation , path : "values/#{ name } " )
59
+ @representation_class ||= Representation [ RESTWrapper ]
60
+ self . with ( @representation_class , path : "values/#{ name } " )
59
61
end
60
62
end
61
63
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+
5
+ module Cloudflare
6
+ module KV
7
+ class RESTWrapper < Async ::REST ::Wrapper ::Generic
8
+ APPLICATION_OCTET_STREAM = 'application/octet-stream'
9
+ APPLICATION_JSON = 'application/json'
10
+ ACCEPT_HEADER = "#{ APPLICATION_JSON } , #{ APPLICATION_OCTET_STREAM } "
11
+
12
+ def prepare_request ( payload , headers )
13
+ headers [ 'accept' ] ||= ACCEPT_HEADER
14
+
15
+ if payload
16
+ headers [ 'content-type' ] = APPLICATION_OCTET_STREAM
17
+ ::Protocol ::HTTP ::Body ::Buffered . new ( [ payload . to_s ] )
18
+ end
19
+ end
20
+
21
+ def parser_for ( response )
22
+ if response . headers [ 'content-type' ] . start_with? ( APPLICATION_OCTET_STREAM )
23
+ OctetParser
24
+ elsif response . headers [ 'content-type' ] . start_with? ( APPLICATION_JSON )
25
+ JsonParser
26
+ else
27
+ Async ::REST ::Wrapper ::Generic ::Unsupported
28
+ end
29
+ end
30
+
31
+ class OctetParser < ::Protocol ::HTTP ::Body ::Wrapper
32
+ def join
33
+ super
34
+ end
35
+ end
36
+
37
+ class JsonParser < ::Protocol ::HTTP ::Body ::Wrapper
38
+ def join
39
+ JSON . parse ( super , symbolize_names : true )
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
You can’t perform that action at this time.
0 commit comments