virtuous 0.0.2 → 0.0.4

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: f9f937cdf43802f0f1a11389e495f22a8dcbbce4899bab8489305b2cd33f70f6
4
- data.tar.gz: 76d4f355d36fb2ed6e5bb9cfbc4e4f4fa89b6bb3cc03666fe12ef7699b5784d8
3
+ metadata.gz: dde636ea3b588b861eb1571600585b5a92f221c427b1de5d0dd5da6019f19906
4
+ data.tar.gz: c82140d46fe427a713015074ae28c81fa2ef7494cc9a527cd1dac9f129525b69
5
5
  SHA512:
6
- metadata.gz: eb33edfcd401c81370d6079b9d85d67036e2c27e40cd1d441ae94bc34de34c50b6609e73ccfe6bc323d38bd224d98f4420996e83a85b387956517e20256ba9c9
7
- data.tar.gz: f3021bf9fc25965c14e902f68678e41faffb3bad502ff25dd23c06504147aee5ebaa3edc5de33a07a6baf2d09665320b00c4a1c5cdcb2217b922128033483ed4
6
+ metadata.gz: 408bdd4c97d63495fca22af299e1878ef70ca601428bde15ecc684c59f8d01cb0d3340389de1b4adb77958d6fc9972f2864338d31b729ef1e8db2a3951b3c180
7
+ data.tar.gz: a917e9353ad30d8ac5f4626dedf67890fa5cbc3123d9559aa0a61475034e7e98faf2e0e45644428326326529392c215c1fb0a91beb3955cdac3ef0ff46c33179
data/.reek.yml CHANGED
@@ -8,7 +8,7 @@ detectors:
8
8
  - "Virtuous::Client#connection"
9
9
  - "Virtuous::Client#unauthorized_connection"
10
10
  - "Virtuous::HashHelper#self.deep_transform_keys"
11
- - "FaradayMiddleware::ParseOj#on_complete"
11
+ - "Virtuous::FaradayMiddleware::ParseOj#on_complete"
12
12
  NilCheck:
13
13
  exclude:
14
14
  - "Virtuous::Client#initialize"
@@ -22,7 +22,7 @@ detectors:
22
22
  - "Virtuous::HashHelper#self.deep_transform_keys"
23
23
  - "Virtuous::Client#connection"
24
24
  - "Virtuous::Client#unauthorized_connection"
25
- - "FaradayMiddleware::VirtuousErrorHandler#on_complete"
25
+ - "Virtuous::FaradayMiddleware::VirtuousErrorHandler#on_complete"
26
26
  ControlParameter:
27
27
  exclude:
28
28
  - "Virtuous::Client#initialize"
data/CHANGELOG.md CHANGED
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ### Added
11
+
12
+ - Method to query projects
13
+
10
14
  ## [0.0.2] - 2024-01-04
11
15
 
12
16
  ### Added
@@ -0,0 +1,58 @@
1
+ module Virtuous
2
+ class Client
3
+ module Project
4
+ ##
5
+ # Queries a list of available project query options.
6
+ # @return [Hash] A list of available project query options.
7
+ def project_query_options
8
+ parse(get('api/Project/QueryOptions'))
9
+ end
10
+
11
+ ##
12
+ # Queries projects.
13
+ #
14
+ # @example
15
+ # client.query_projects(
16
+ # take: 5, skip: 0, sort_by: 'Id',
17
+ # conditions: [{ parameter: 'Project Code', operator: 'Is', value: 102 }]
18
+ # )
19
+ #
20
+ # @option options [Integer] :take The maximum amount of projects to query. Default: 10.
21
+ # Max is 1000.
22
+ # @option options [Integer] :skip The number of projects to skip. Default: 0.
23
+ # @option options [String] :sort_by The value to sort records by.
24
+ # @option options [Boolean] :descending If true the records will be sorted in descending
25
+ # order.
26
+ # @option options [Array] :conditions An array of conditions to filter the project.
27
+ # Use {project_query_options} to see
28
+ # a full list of available conditions.
29
+ #
30
+ # @return [Hash] A hash with a list and the total amount of projects that satisfy
31
+ # the conditions.
32
+ # @example Output
33
+ # { list: [...], total: n }
34
+ #
35
+ def query_projects(**options)
36
+ uri = URI('api/Project/Query')
37
+ query_params = options.slice(:take, :skip)
38
+ uri.query = URI.encode_www_form(query_params) unless query_params.empty?
39
+
40
+ parse(post(uri, format(query_projects_body(options))))
41
+ end
42
+
43
+ private
44
+
45
+ def query_projects_body(options)
46
+ conditions = options[:conditions]
47
+ body = options.slice(:sort_by, :descending)
48
+ return body if conditions.nil?
49
+
50
+ body.merge({
51
+ groups: [{
52
+ conditions: conditions
53
+ }]
54
+ })
55
+ end
56
+ end
57
+ end
58
+ end
@@ -75,6 +75,7 @@ module Virtuous
75
75
  include Gift
76
76
  include RecurringGift
77
77
  include GiftDesignation
78
+ include Project
78
79
 
79
80
  ##
80
81
  # Access token used for OAuth authentication.
@@ -263,7 +264,7 @@ module Virtuous
263
264
  conn.request :json
264
265
  conn.response :oj
265
266
  conn.response :logger, @logger if @logger
266
- conn.use FaradayMiddleware::VirtuousErrorHandler
267
+ conn.use Virtuous::FaradayMiddleware::VirtuousErrorHandler
267
268
  conn.adapter @adapter
268
269
  yield(conn) if block_given?
269
270
  end
@@ -1,3 +1,5 @@
1
+ require 'faraday'
2
+
1
3
  module Virtuous # :nodoc: all
2
4
  class Error < StandardError; end
3
5
  class BadGateway < Error; end
@@ -9,46 +11,45 @@ module Virtuous # :nodoc: all
9
11
  class NotFound < Error; end
10
12
  class ServiceUnavailable < Error; end
11
13
  class Unauthorized < Error; end
12
- end
13
14
 
14
- require 'faraday'
15
- module FaradayMiddleware
16
- class VirtuousErrorHandler < Faraday::Middleware
17
- ERROR_STATUSES = (400..600).freeze
15
+ module FaradayMiddleware
16
+ class VirtuousErrorHandler < Faraday::Middleware
17
+ ERROR_STATUSES = (400..600).freeze
18
18
 
19
- ##
20
- # Throws an exception for responses with an HTTP error code.
21
- def on_complete(env)
22
- message = error_message(env)
19
+ ##
20
+ # Throws an exception for responses with an HTTP error code.
21
+ def on_complete(env)
22
+ message = error_message(env)
23
23
 
24
- case env[:status]
25
- when 400
26
- raise Virtuous::BadRequest, message
27
- when 401
28
- raise Virtuous::Unauthorized, message
29
- when 403
30
- raise Virtuous::Forbidden, message
31
- when 404
32
- raise Virtuous::NotFound, message
33
- when 500
34
- raise Virtuous::InternalServerError, message
35
- when 502
36
- raise Virtuous::BadGateway, message
37
- when 503
38
- raise Virtuous::ServiceUnavailable, message
39
- when 504
40
- raise Virtuous::GatewayTimeout, message
41
- when 520
42
- raise Virtuous::CloudflareError, message
43
- when ERROR_STATUSES
44
- raise Virtuous::Error, message
24
+ case env[:status]
25
+ when 400
26
+ raise Virtuous::BadRequest, message
27
+ when 401
28
+ raise Virtuous::Unauthorized, message
29
+ when 403
30
+ raise Virtuous::Forbidden, message
31
+ when 404
32
+ raise Virtuous::NotFound, message
33
+ when 500
34
+ raise Virtuous::InternalServerError, message
35
+ when 502
36
+ raise Virtuous::BadGateway, message
37
+ when 503
38
+ raise Virtuous::ServiceUnavailable, message
39
+ when 504
40
+ raise Virtuous::GatewayTimeout, message
41
+ when 520
42
+ raise Virtuous::CloudflareError, message
43
+ when ERROR_STATUSES
44
+ raise Virtuous::Error, message
45
+ end
45
46
  end
46
- end
47
47
 
48
- private
48
+ private
49
49
 
50
- def error_message(env)
51
- "#{env[:status]}: #{env[:url]} #{env[:body]}"
50
+ def error_message(env)
51
+ "#{env[:status]}: #{env[:url]} #{env[:body]}"
52
+ end
52
53
  end
53
54
  end
54
55
  end
@@ -1,24 +1,26 @@
1
1
  require 'oj'
2
2
 
3
- module FaradayMiddleware
4
- class ParseOj < Faraday::Middleware
5
- ##
6
- # Parses JSON responses.
7
- def on_complete(env)
8
- body = env[:body]
9
- env[:body] = if empty_body?(body.strip)
10
- nil
11
- else
12
- Oj.load(body, mode: :compat)
13
- end
14
- end
3
+ module Virtuous
4
+ module FaradayMiddleware
5
+ class ParseOj < Faraday::Middleware
6
+ ##
7
+ # Parses JSON responses.
8
+ def on_complete(env)
9
+ body = env[:body]
10
+ env[:body] = if empty_body?(body.strip)
11
+ nil
12
+ else
13
+ Oj.load(body, mode: :compat)
14
+ end
15
+ end
15
16
 
16
- private
17
+ private
17
18
 
18
- def empty_body?(body)
19
- body.empty? && body == ''
19
+ def empty_body?(body)
20
+ body.empty? && body == ''
21
+ end
20
22
  end
21
23
  end
22
24
  end
23
25
 
24
- Faraday::Response.register_middleware(oj: FaradayMiddleware::ParseOj)
26
+ Faraday::Response.register_middleware(oj: Virtuous::FaradayMiddleware::ParseOj)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Virtuous
4
- VERSION = '0.0.2'
4
+ VERSION = '0.0.4'
5
5
  end