apimatic_core_interfaces 0.1.2 → 0.2.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: 90e066016582514a809448dcd2268022b4a9876641ef77dfd5ae88915bd605a0
4
- data.tar.gz: fc00d445cfd4e983cf3fecd034834bbac9ec649c10e18d7f245501959baa6446
3
+ metadata.gz: aaf47cc9c42b3a20af7fa3b74bdabd33852f43d29e7f2fe426ee17f51fb0ff42
4
+ data.tar.gz: 4d9200846000fa6492e05d04d4dbc51b27ff7a3e077b583f96af5e9d89c8a420
5
5
  SHA512:
6
- metadata.gz: a1d9b6e320aa1b921f1018a5017595476574977fdb34233db073c64f1a6e8107b9ea8b3a8b961cfbc89b5223e419e7b0645d14d8ec1e57367d26dd0e1bd5480b
7
- data.tar.gz: ae062e11518bc9a72b0374f52556af263e3b5e32419cd0a6ab18519ee1a2fc5aa81a1de8bcbad308ffaf6e4ab53b4571f7872407cd123bbc4deb9bc67a2e575e
6
+ metadata.gz: b9a7ca20453fd54f0342271f1a4173fe3165c0cb53a45e1bbdff5e8379d0c9edd6a7b5135cb960ecb23ec97543d7d4f196290645ca11bafe23bf36c4490099bc
7
+ data.tar.gz: be574e6033423b730fe3e8a4e5f5c3d9b5167e0e4bfa376645cdee46310ea692a15cb297c82d42894bcd790647d2517d735afc0b630b45d601ba23aed08fa1bf
data/README.md CHANGED
@@ -24,12 +24,13 @@ gem 'apimatic_core_interfaces'
24
24
  ```
25
25
 
26
26
  ## Interfaces
27
- | Name | Description |
28
- |--------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------|
29
- | [`HttpClient`](lib/apimatic-core-interfaces/client/http_client.rb) | To save both Request and Response after the completion of response |
30
- | [`ResponseFactory`](lib/apimatic-core-interfaces/factories/response_factory.rb) | To convert the client-adapter response into a custom HTTP response |
31
- | [`Authentication`](lib/apimatic-core-interfaces/types/authentication.rb) | To setup methods for the validation and application of the required authentication scheme |
32
- | [`ClientConfiguration`](lib/apimatic-core-interfaces/client/client_configuration.rb) | To setup the http client configurations including retries, timeouts and connections etc. |
27
+ | Name | Description |
28
+ |--------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------|
29
+ | [`HttpClient`](lib/apimatic-core-interfaces/client/http_client.rb) | To save both Request and Response after the completion of response |
30
+ | [`ResponseFactory`](lib/apimatic-core-interfaces/factories/response_factory.rb) | To convert the client-adapter response into a custom HTTP response |
31
+ | [`Authentication`](lib/apimatic-core-interfaces/types/authentication.rb) | To setup methods for the validation and application of the required authentication scheme |
32
+ | [`UnionType`](lib/apimatic-core-interfaces/types/union_type.rb) | To setup methods for the validation, serialization and deserialization of OneOf/AnyOf union types |
33
+ | [`ClientConfiguration`](lib/apimatic-core-interfaces/client/client_configuration.rb) | To setup the http client configurations including retries, timeouts and connections etc. |
33
34
 
34
35
 
35
36
  ## Enumerations
@@ -0,0 +1,55 @@
1
+ module CoreLibrary
2
+ # Represents a union type that can validate, serialize and deserialize values based on a set of allowed types.
3
+ class UnionType
4
+ # NATIVE_TYPES represents the list of native types in Ruby.
5
+ # These types are commonly used and built-in to the Ruby language.
6
+ # The constant contains the following types:
7
+ # - Integer: Represents whole numbers without a decimal point.
8
+ # - String: Represents a sequence of characters.
9
+ # - Float: Represents floating-point numbers with a decimal point.
10
+ # - TrueClass: Represents the boolean value `true`.
11
+ # - FalseClass: Represents the boolean value `false`.
12
+ # This constant is used within the UnionType class to define the allowed native types.
13
+ NATIVE_TYPES = [Integer, String, Float, TrueClass, FalseClass].freeze
14
+
15
+ attr_accessor :is_valid, :error_messages, :union_type_context, :union_types
16
+
17
+ # Initializes a new instance of UnionType.
18
+ # @param union_types [Array<Class>] An array of allowed types for the union.
19
+ # @param union_type_context [Object] The context of the union type.
20
+ def initialize(union_types, union_type_context)
21
+ @union_types = union_types
22
+ @union_type_context = union_type_context
23
+ @is_valid = false
24
+ @error_messages = Set.new
25
+ end
26
+
27
+ # Validates a value against the union type.
28
+ # This method should be implemented by subclasses.
29
+ # @param value [Object] The value to validate.
30
+ # @raise [NotImplementedError] If the method is not implemented in a subclass.
31
+ def validate(value)
32
+ raise NotImplementedError, 'This method needs
33
+ to be implemented in a child class.'
34
+ end
35
+
36
+ # Serializes a given value.
37
+ # @param value [Object] The value to be serialized.
38
+ # @raise [NotImplementedError] If the method is not implemented in the child class.
39
+ # @return [String] The serialized representation of the value.
40
+ def serialize(value)
41
+ raise NotImplementedError, 'This method needs
42
+ to be implemented in a child class.'
43
+ end
44
+
45
+ # Deserializes a value based on the union type.
46
+ # This method should be implemented by subclasses.
47
+ # @param value [Object] The value to deserialize.
48
+ # @param should_symbolize [Boolean] Indicates whether the deserialized value should be symbolized.
49
+ # @raise [NotImplementedError] If the method is not implemented in a subclass.
50
+ def deserialize(value, should_symbolize: false)
51
+ raise NotImplementedError, 'This method needs
52
+ to be implemented in a child class.'
53
+ end
54
+ end
55
+ end
@@ -4,6 +4,7 @@ require_relative 'apimatic-core-interfaces/client/client_configuration'
4
4
  require_relative 'apimatic-core-interfaces/factories/response_factory'
5
5
 
6
6
  require_relative 'apimatic-core-interfaces/types/authentication'
7
+ require_relative 'apimatic-core-interfaces/types/union_type'
7
8
  require_relative 'apimatic-core-interfaces/types/http_callback'
8
9
  require_relative 'apimatic-core-interfaces/types/http_method'
9
10
  require_relative 'apimatic-core-interfaces/types/array_serialization_format'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apimatic_core_interfaces
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - APIMatic Ltd.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-04 00:00:00.000000000 Z
11
+ date: 2023-07-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: This project contains the abstract layer for APIMatic's core library.
14
14
  The purpose of creating interfaces is to separate out the functionalities needed
@@ -30,6 +30,7 @@ files:
30
30
  - lib/apimatic-core-interfaces/types/datetime_format.rb
31
31
  - lib/apimatic-core-interfaces/types/http_callback.rb
32
32
  - lib/apimatic-core-interfaces/types/http_method.rb
33
+ - lib/apimatic-core-interfaces/types/union_type.rb
33
34
  - lib/apimatic_core_interfaces.rb
34
35
  homepage: https://apimatic.io
35
36
  licenses: