cpro-client 0.2.1 → 0.2.2
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/Gemfile.lock +1 -1
- data/lib/cpro/middleware/json.rb +52 -0
- data/lib/cpro/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: dc05774f720962053cfcd6f9f11b4fd9521f704d9f40d4e5178a439c37b03ffd
|
|
4
|
+
data.tar.gz: 63dc3902ac1d84c6bb49f93a0d90b4f1e5035708c69c0a635deef4475bba63d1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e627c2faa3a057a63fc84c3fe37aca1fd3a2020175a05c0e40a0216958ff28686460d366eeae61476480a191a0f2bfcfb4eb3cf576aec3c8f0743e771f9143a7
|
|
7
|
+
data.tar.gz: 95a17ff0f1069454907f6e415b14fdecdf75acdfd959f5d5f30dfcdf8c7532d6f56f0586d7f7fe258234a7fe28de14f6813cfbbd612201579550cbdeae9a9b3b
|
data/Gemfile.lock
CHANGED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
|
|
5
|
+
module Cpro
|
|
6
|
+
module Middleware
|
|
7
|
+
# JSON middleware added for 0.9 Faraday compatibility
|
|
8
|
+
class EncodeJson < Faraday::Middleware
|
|
9
|
+
CONTENT_TYPE = "Content-Type"
|
|
10
|
+
MIME = "application/json"
|
|
11
|
+
|
|
12
|
+
def call(env)
|
|
13
|
+
encode(env) unless env.body.nil? || env.body.is_a?(String)
|
|
14
|
+
@app.call(env)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
def encode(env)
|
|
20
|
+
env.request_headers[CONTENT_TYPE] ||= MIME
|
|
21
|
+
env.body = JSON.generate(env.body)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
class ParseJson < Faraday::Middleware
|
|
26
|
+
def initialize(app, content_type: /\bjson$/)
|
|
27
|
+
super(app)
|
|
28
|
+
@content_type = content_type
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def call(env)
|
|
32
|
+
@app.call(env).on_complete { |response| response.body = parse(response) }
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
private
|
|
36
|
+
|
|
37
|
+
def parse(env)
|
|
38
|
+
body = env.body
|
|
39
|
+
return body unless json?(env) && body.is_a?(String) && !body.strip.empty?
|
|
40
|
+
|
|
41
|
+
JSON.parse(body)
|
|
42
|
+
rescue JSON::ParserError
|
|
43
|
+
body
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def json?(env)
|
|
47
|
+
type = env.response_headers && env.response_headers["content-type"]
|
|
48
|
+
type.to_s.split(";").first.to_s.strip.match?(@content_type)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
data/lib/cpro/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cpro-client
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Hôtentic
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-08-
|
|
11
|
+
date: 2026-08-30 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: faraday
|
|
@@ -78,6 +78,7 @@ files:
|
|
|
78
78
|
- lib/cpro/errors.rb
|
|
79
79
|
- lib/cpro/facturx.rb
|
|
80
80
|
- lib/cpro/middleware/authentication.rb
|
|
81
|
+
- lib/cpro/middleware/json.rb
|
|
81
82
|
- lib/cpro/middleware/raise_error.rb
|
|
82
83
|
- lib/cpro/resources/annuaire.rb
|
|
83
84
|
- lib/cpro/resources/base.rb
|