wrapi 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/Gemfile +1 -1
- data/lib/wrapi/connection.rb +2 -2
- data/lib/wrapi/pagination.rb +1 -1
- data/lib/wrapi/request.rb +34 -10
- data/lib/wrapi/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d7d0d197548b78702536dcb3ffd582f1a637ba7c4563b678b682702a55f1f92
|
4
|
+
data.tar.gz: 944dd3cb645f422900a45ff8728a08f47472abb98c64e7c3c34a3a8e696ad0d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51854938895ac5cfdcb616fd9a6a6de72ed0e4a7544bea9eca525b64b8c370b2dbc9b0ca2b596fcbd1838f7b4eaec0a4fa476666e1bca79436f448c647d358cb
|
7
|
+
data.tar.gz: fe27c57580cf3d50d49830d0b1449d177f0de21cb077eb12a3cc953351c1f3d9dc898de8cf4391130dea6f5e549cf9b6530928094cf5866482fefb5e1d795cca
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/lib/wrapi/connection.rb
CHANGED
@@ -52,9 +52,9 @@ module WrAPI
|
|
52
52
|
connection.response :logger, logger, { headers: true, bodies: true } do |l|
|
53
53
|
# filter json content
|
54
54
|
l.filter(/("password":")(.+?)(".*)/, '\1[REMOVED]\3')
|
55
|
-
l.filter(/("
|
55
|
+
l.filter(/("[Aa]ccess_?[Tt]oken":")(.+?)(".*)/, '\1[REMOVED]\3')
|
56
56
|
# filter header content
|
57
|
-
l.filter(/(client-secret
|
57
|
+
l.filter(/(client[-_]secret[:=].)([^&]+)/, '\1[REMOVED]')
|
58
58
|
l.filter(/(Authorization:.)([^&]+)/, '\1[REMOVED]')
|
59
59
|
end
|
60
60
|
end
|
data/lib/wrapi/pagination.rb
CHANGED
data/lib/wrapi/request.rb
CHANGED
@@ -7,26 +7,40 @@ module WrAPI
|
|
7
7
|
module Request
|
8
8
|
|
9
9
|
# Perform an HTTP GET request and return entity incase format is :json
|
10
|
+
# @return if format is :json an [Entity] is returned, otherwhise the response body
|
10
11
|
def get(path, options = {})
|
11
|
-
response = request(:get, path, options)
|
12
|
+
response = request(:get, path, options) do |request|
|
13
|
+
yield(request) if block_given?
|
14
|
+
end
|
12
15
|
:json.eql?(format) ? Entity.new(pagination_class.data(response.body)) : response.body
|
13
16
|
end
|
14
17
|
|
15
18
|
# Perform an HTTP GET request for paged date sets response
|
16
|
-
|
19
|
+
# @return nil if block given, otherwise complete concatenated json result set
|
20
|
+
def get_paged(path, options = {}, request_labda = nil)
|
17
21
|
raise ArgumentError,
|
18
22
|
"Pages requests should be json formatted (given format '#{format}')" unless :json.eql? format
|
19
23
|
|
20
24
|
result = []
|
21
25
|
pager = create_pager
|
22
26
|
while pager.more_pages?
|
23
|
-
response = request(:get, path, options.merge(pager.page_options))
|
24
|
-
|
25
|
-
|
27
|
+
response = request(:get, path, options.merge(pager.page_options)) do |req|
|
28
|
+
request_labda.call(req) if request_labda
|
29
|
+
end
|
30
|
+
d = pager.class.data(response.body)
|
31
|
+
if d.is_a? Array
|
32
|
+
d = pager.class.data(response.body).map { |e| Entity.new(e) }
|
33
|
+
else
|
34
|
+
d = Entity.new(d)
|
35
|
+
end
|
26
36
|
if block_given?
|
27
37
|
yield(d)
|
28
38
|
else
|
29
|
-
|
39
|
+
if d.is_a? Array
|
40
|
+
result += d
|
41
|
+
else
|
42
|
+
result << d
|
43
|
+
end
|
30
44
|
end
|
31
45
|
pager.next_page!(response.body)
|
32
46
|
end
|
@@ -34,29 +48,39 @@ module WrAPI
|
|
34
48
|
end
|
35
49
|
|
36
50
|
# Perform an HTTP POST request
|
51
|
+
# @return response is returned in json if format is :json
|
37
52
|
def post(path, options = {})
|
38
|
-
request(:post, path, options)
|
53
|
+
response = request(:post, path, options) do |request|
|
54
|
+
yield(request) if block_given?
|
55
|
+
end
|
39
56
|
end
|
40
57
|
|
41
58
|
# Perform an HTTP PUT request
|
59
|
+
# @return response is returned in json if format is :json
|
42
60
|
def put(path, options = {})
|
43
|
-
request(:put, path, options)
|
61
|
+
response = request(:put, path, options) do |request|
|
62
|
+
yield(request) if block_given?
|
63
|
+
end
|
44
64
|
end
|
45
65
|
|
46
66
|
# Perform an HTTP DELETE request
|
67
|
+
# @return response is returened
|
47
68
|
def delete(path, options = {})
|
48
|
-
request(:delete, path, options)
|
69
|
+
response = request(:delete, path, options) do |request|
|
70
|
+
yield(request) if block_given?
|
71
|
+
end
|
49
72
|
end
|
50
73
|
|
51
74
|
private
|
52
75
|
|
53
76
|
def create_pager
|
54
|
-
pagination_class.new(page_size)
|
77
|
+
pagination_class ? pagination_class.new(page_size) : WrAPI::RequestPagination::DefaultPager
|
55
78
|
end
|
56
79
|
|
57
80
|
# Perform an HTTP request
|
58
81
|
def request(method, path, options)
|
59
82
|
response = connection.send(method) do |request|
|
83
|
+
yield(request) if block_given?
|
60
84
|
uri = URI::Parser.new
|
61
85
|
case method
|
62
86
|
when :get, :delete
|
data/lib/wrapi/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wrapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Janco Tanis
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-02-
|
11
|
+
date: 2024-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|