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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7f1cf824802fe7b24c8df963fcf6598e650d4bcf8393f4d685cab9f4825838ca
4
- data.tar.gz: 4f7b2f485cdbbcf3e2f10aa64fa0d562d789bb23aa2e6c47611bb7ff5a86db29
3
+ metadata.gz: 1d7d0d197548b78702536dcb3ffd582f1a637ba7c4563b678b682702a55f1f92
4
+ data.tar.gz: 944dd3cb645f422900a45ff8728a08f47472abb98c64e7c3c34a3a8e696ad0d0
5
5
  SHA512:
6
- metadata.gz: d601f302816a8e521bfd00985f04391a939c4f416a06e7b5accb0701a6c02109f7653b4be0ea8d7b12b191f867284959e0068a1b84495c082dd600c094636e2e
7
- data.tar.gz: 16c72f9028b2060dc39b28a9c7037e3d2fba2ebe2a1079a2dbfe3eef2f9ed198ecc60c7dd4ae0c61a1cf79ddefe4638789b4e5072e07da36236b0cf4d3fc92f6
6
+ metadata.gz: 51854938895ac5cfdcb616fd9a6a6de72ed0e4a7544bea9eca525b64b8c370b2dbc9b0ca2b596fcbd1838f7b4eaec0a4fa476666e1bca79436f448c647d358cb
7
+ data.tar.gz: fe27c57580cf3d50d49830d0b1449d177f0de21cb077eb12a3cc953351c1f3d9dc898de8cf4391130dea6f5e549cf9b6530928094cf5866482fefb5e1d795cca
data/CHANGELOG.md CHANGED
@@ -15,3 +15,6 @@
15
15
  ## [0.2.0] - 2024-02-8
16
16
  - implement json pagination
17
17
 
18
+ ## [0.2.0] - 2024-02-13
19
+ - implement option to manipulate request
20
+
data/Gemfile CHANGED
@@ -6,4 +6,4 @@ source 'https://rubygems.org'
6
6
  gemspec
7
7
 
8
8
  gem 'rake', '~> 13.0'
9
- gem 'rubocop', "~> 1.7'
9
+ gem 'rubocop', '~> 1.7'
@@ -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(/("accessToken":")(.+?)(".*)/, '\1[REMOVED]\3')
55
+ l.filter(/("[Aa]ccess_?[Tt]oken":")(.+?)(".*)/, '\1[REMOVED]\3')
56
56
  # filter header content
57
- l.filter(/(client-secret:.)([^&]+)/, '\1[REMOVED]')
57
+ l.filter(/(client[-_]secret[:=].)([^&]+)/, '\1[REMOVED]')
58
58
  l.filter(/(Authorization:.)([^&]+)/, '\1[REMOVED]')
59
59
  end
60
60
  end
@@ -6,7 +6,7 @@ module WrAPI
6
6
  # required attributes format
7
7
  module RequestPagination
8
8
 
9
- # Defaut pages asumes all sdata retrieved in a single go.
9
+ # Defaut pages asumes all data retrieved in a single go.
10
10
  class DefaultPager
11
11
 
12
12
  # initialize with page size
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
- def get_paged(path, options = {}, &block)
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
- #data = response.body
25
- d = pager.class.data(response.body).map { |e| Entity.new(e) }
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
- result += d
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WrAPI
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  end
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.2.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-08 00:00:00.000000000 Z
11
+ date: 2024-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday