microsoft_kiota_serialization_text 0.25.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0b3c4ccf35a126e8f4efcb4660abe9b8bb77aff722dc7da29fb11fd87ed2183c
4
+ data.tar.gz: 15d90adcf5d3ff5fd0bbf427a3dd4942aa8f5d63734fccdb1546b1d1d4e36c79
5
+ SHA512:
6
+ metadata.gz: 507035c41b383628515e5c00a36f1df458dc4d22a11fa6b2c47e7b3a1f9f97ab2455261b972e874392e1fca37079c632e749e62ebce3493ecfc7c481255e481b
7
+ data.tar.gz: 2f60bd6fff2b8ae402ab6940bf5ebff31ece25153e1269ea5968cfdeeea3d255cd8d3c93e8e5cfedd33f71f2522d3fdecfb4b3f0c65d50d2b6a7226401834854
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ ruby '>= 3.3.0'
6
+
7
+ gem 'microsoft_kiota_abstractions', path: '../../abstractions'
8
+ gem 'rake', '~> 13.0'
9
+ gem 'rspec', '~> 3.0'
10
+
11
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MicrosoftKiotaSerializationText
4
+ # bytes are read as UTF-8; a string Faraday tagged with its charset is converted
5
+ def self.to_utf8(text)
6
+ text.encoding == Encoding::BINARY ? text.dup.force_encoding(Encoding::UTF_8) : text.encode(Encoding::UTF_8)
7
+ end
8
+ end
@@ -0,0 +1,117 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'time'
4
+ require 'date'
5
+ require 'uuidtools'
6
+ require 'microsoft_kiota_abstractions'
7
+
8
+ module MicrosoftKiotaSerializationText
9
+ class TextParseNode
10
+ include MicrosoftKiotaAbstractions::ParseNode
11
+
12
+ NO_STRUCTURED_DATA_MESSAGE = 'Text does not support structured data'
13
+
14
+ # temporal readers take only their own shape, as in the form gem, so a union picks the right member
15
+ DATE = /\A\d{4}-\d{2}-\d{2}\z/
16
+ TIME = /\A\d{2}:\d{2}(:\d{2}(\.\d+)?)?\z/
17
+ DATE_TIME = /\A\d{4}-\d{2}-\d{2}[Tt ]\d{2}:\d{2}(:\d{2}(\.\d+)?)?([Zz]|[+-]\d{2}(:?\d{2})?)?\z/
18
+
19
+ def initialize(text)
20
+ @text = text
21
+ end
22
+
23
+ def get_string_value
24
+ @text unless @text.nil? || @text.empty?
25
+ end
26
+
27
+ def get_boolean_value
28
+ case scalar_text&.downcase
29
+ when 'true' then true
30
+ when 'false' then false
31
+ end
32
+ end
33
+
34
+ def get_number_value
35
+ text = scalar_text
36
+ Integer(text, 10, exception: false) if text
37
+ end
38
+
39
+ def get_float_value
40
+ text = scalar_text
41
+ Float(text, exception: false) if text
42
+ end
43
+
44
+ def get_guid_value
45
+ parsed { |text| UUIDTools::UUID.parse(text) }
46
+ end
47
+
48
+ def get_date_value
49
+ parsed { |text| Date.parse(text) if DATE.match?(text) }
50
+ end
51
+
52
+ def get_time_value
53
+ parsed { |text| Time.parse(text) if TIME.match?(text) }
54
+ end
55
+
56
+ def get_date_time_value
57
+ parsed { |text| DateTime.parse(text) if DATE_TIME.match?(text) }
58
+ end
59
+
60
+ def get_duration_value
61
+ parsed { |text| MicrosoftKiotaAbstractions::ISODuration.new(text) }
62
+ end
63
+
64
+ def get_byte_array_value
65
+ scalar_text&.unpack1('m')
66
+ end
67
+
68
+ def get_enum_value(type)
69
+ text = scalar_text
70
+ resolve_enum_member(type, text) if text
71
+ end
72
+
73
+ def get_child_node(_name)
74
+ raise StandardError, NO_STRUCTURED_DATA_MESSAGE
75
+ end
76
+
77
+ def get_collection_of_primitive_values(_type)
78
+ raise StandardError, NO_STRUCTURED_DATA_MESSAGE
79
+ end
80
+
81
+ def get_collection_of_object_values(_factory)
82
+ raise StandardError, NO_STRUCTURED_DATA_MESSAGE
83
+ end
84
+
85
+ def get_collection_of_enum_values(_type)
86
+ raise StandardError, NO_STRUCTURED_DATA_MESSAGE
87
+ end
88
+
89
+ def get_object_value(_factory)
90
+ raise StandardError, NO_STRUCTURED_DATA_MESSAGE
91
+ end
92
+
93
+ private
94
+
95
+ # text that does not parse reads as nil, as .NET's TryParse and the form gem do
96
+ def parsed
97
+ text = scalar_text
98
+ yield text if text
99
+ rescue StandardError
100
+ nil
101
+ end
102
+
103
+ # typed values ignore surrounding whitespace, as .NET's TryParse does
104
+ def scalar_text
105
+ text = get_string_value&.strip
106
+ text unless text.nil? || text.empty?
107
+ end
108
+
109
+ # same resolution as JsonParseNode: the wire value first, then the member name
110
+ def resolve_enum_member(type, raw)
111
+ return raw.to_sym unless type.is_a?(Hash)
112
+
113
+ type.each_value { |value| return value if value.to_s == raw }
114
+ type[raw.to_sym] || type[(raw[0].to_s.upcase + raw[1..].to_s).to_sym]
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'microsoft_kiota_abstractions'
4
+ require_relative 'encoding'
5
+
6
+ module MicrosoftKiotaSerializationText
7
+ class TextParseNodeFactory
8
+ include MicrosoftKiotaAbstractions::ParseNodeFactory
9
+
10
+ def get_valid_content_type
11
+ 'text/plain'
12
+ end
13
+
14
+ def get_parse_node(content_type, content)
15
+ raise ArgumentError, 'content type cannot be undefined or empty' if content_type.nil? || content_type.empty?
16
+ raise ArgumentError, "expected a #{get_valid_content_type} content type" unless get_valid_content_type.casecmp?(content_type)
17
+ raise ArgumentError, 'content cannot be undefined or empty' if content.nil? || content.empty?
18
+
19
+ TextParseNode.new(MicrosoftKiotaSerializationText.to_utf8(content).delete_prefix("\uFEFF"))
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,125 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'time'
4
+ require 'date'
5
+ require 'uuidtools'
6
+ require 'microsoft_kiota_abstractions'
7
+ require_relative 'encoding'
8
+ require_relative 'text_parse_node'
9
+
10
+ module MicrosoftKiotaSerializationText
11
+ class TextSerializationWriter
12
+ include MicrosoftKiotaAbstractions::SerializationWriter
13
+
14
+ NO_STRUCTURED_DATA_MESSAGE = TextParseNode::NO_STRUCTURED_DATA_MESSAGE
15
+ VALUE_ALREADY_WRITTEN_MESSAGE =
16
+ 'a value was already written for this serialization writer, text content only supports a single value'
17
+
18
+ def initialize
19
+ @content = nil
20
+ end
21
+
22
+ def write_string_value(key, value)
23
+ return if value.nil?
24
+ raise StandardError, NO_STRUCTURED_DATA_MESSAGE unless key.nil? || key.empty?
25
+ raise StandardError, VALUE_ALREADY_WRITTEN_MESSAGE unless @content.nil?
26
+
27
+ @content = value
28
+ end
29
+
30
+ def write_boolean_value(key, value)
31
+ write_string_value(key, value&.to_s)
32
+ end
33
+
34
+ def write_number_value(key, value)
35
+ write_string_value(key, value&.to_s)
36
+ end
37
+
38
+ def write_float_value(key, value)
39
+ write_string_value(key, value&.to_s)
40
+ end
41
+
42
+ def write_guid_value(key, value)
43
+ write_string_value(key, value&.to_s)
44
+ end
45
+
46
+ def write_date_value(key, value)
47
+ write_string_value(key, value&.strftime('%Y-%m-%d'))
48
+ end
49
+
50
+ def write_time_value(key, value)
51
+ return if value.nil?
52
+
53
+ digits = fraction_digits(value)
54
+ write_string_value(key, value.strftime(digits.zero? ? '%H:%M:%S' : "%H:%M:%S.%#{digits}N"))
55
+ end
56
+
57
+ def write_date_time_value(key, value)
58
+ write_string_value(key, value&.iso8601(fraction_digits(value)))
59
+ end
60
+
61
+ def write_duration_value(key, value)
62
+ write_string_value(key, value&.string)
63
+ end
64
+
65
+ def write_enum_value(key, value)
66
+ write_string_value(key, value&.to_s)
67
+ end
68
+
69
+ def write_byte_array_value(key, value)
70
+ write_string_value(key, value && [value].pack('m0'))
71
+ end
72
+
73
+ def write_null_value(key)
74
+ write_string_value(key, 'null')
75
+ end
76
+
77
+ def write_any_value(key, value)
78
+ case value
79
+ when nil then nil
80
+ when String then write_string_value(key, value)
81
+ when true, false then write_boolean_value(key, value)
82
+ when Integer then write_number_value(key, value)
83
+ when Float then write_float_value(key, value)
84
+ when DateTime then write_date_time_value(key, value)
85
+ when Date then write_date_value(key, value)
86
+ when Time then write_time_value(key, value)
87
+ when MicrosoftKiotaAbstractions::ISODuration then write_duration_value(key, value)
88
+ when UUIDTools::UUID then write_guid_value(key, value)
89
+ when Symbol then write_enum_value(key, value)
90
+ when Array, Hash, MicrosoftKiotaAbstractions::Parsable then raise StandardError, NO_STRUCTURED_DATA_MESSAGE
91
+ else raise StandardError, "encountered unknown value type during serialization #{value}"
92
+ end
93
+ end
94
+
95
+ def write_collection_of_primitive_values(_key, _values)
96
+ raise StandardError, NO_STRUCTURED_DATA_MESSAGE
97
+ end
98
+
99
+ def write_collection_of_object_values(_key, _values)
100
+ raise StandardError, NO_STRUCTURED_DATA_MESSAGE
101
+ end
102
+
103
+ def write_collection_of_enum_values(_key, _values)
104
+ raise StandardError, NO_STRUCTURED_DATA_MESSAGE
105
+ end
106
+
107
+ def write_object_value(_key, _value, *_additional_values_to_merge)
108
+ raise StandardError, NO_STRUCTURED_DATA_MESSAGE
109
+ end
110
+
111
+ def write_additional_data(_value)
112
+ raise StandardError, NO_STRUCTURED_DATA_MESSAGE
113
+ end
114
+
115
+ def get_serialized_content
116
+ @content.nil? ? '' : MicrosoftKiotaSerializationText.to_utf8(@content)
117
+ end
118
+
119
+ private
120
+
121
+ def fraction_digits(value)
122
+ value.strftime('%N').sub(/0+\z/, '').length
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'microsoft_kiota_abstractions'
4
+
5
+ module MicrosoftKiotaSerializationText
6
+ class TextSerializationWriterFactory
7
+ include MicrosoftKiotaAbstractions::SerializationWriterFactory
8
+
9
+ def get_valid_content_type
10
+ 'text/plain'
11
+ end
12
+
13
+ def get_serialization_writer(content_type)
14
+ raise ArgumentError, 'content type cannot be undefined or empty' if content_type.nil? || content_type.empty?
15
+ raise ArgumentError, "expected a #{get_valid_content_type} content type" unless get_valid_content_type.casecmp?(content_type)
16
+
17
+ TextSerializationWriter.new
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MicrosoftKiotaSerializationText
4
+ VERSION = '0.25.0' # x-release-please-version
5
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'microsoft_kiota_serialization_text/text_parse_node'
4
+ require_relative 'microsoft_kiota_serialization_text/text_parse_node_factory'
5
+ require_relative 'microsoft_kiota_serialization_text/text_serialization_writer'
6
+ require_relative 'microsoft_kiota_serialization_text/text_serialization_writer_factory'
7
+ require_relative 'microsoft_kiota_serialization_text/version'
8
+
9
+ module MicrosoftKiotaSerializationText
10
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/microsoft_kiota_serialization_text/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'microsoft_kiota_serialization_text'
7
+ spec.version = MicrosoftKiotaSerializationText::VERSION
8
+ spec.authors = 'Microsoft Corporation'
9
+ spec.email = 'graphsdkpub+ruby@microsoft.com'
10
+ spec.description = 'Implementation of Kiota Serialization interfaces for text'
11
+ spec.summary = 'Microsoft Kiota Serialization - Ruby serialization for building library agnostic http client'
12
+ spec.homepage = 'https://learn.microsoft.com/openapi/kiota/'
13
+ spec.license = 'MIT'
14
+ spec.metadata = {
15
+ 'bug_tracker_uri' => 'https://github.com/microsoft/kiota-ruby/issues',
16
+ 'changelog_uri' => 'https://github.com/microsoft/kiota-ruby/blob/main/CHANGELOG.md',
17
+ 'homepage_uri' => spec.homepage,
18
+ 'source_code_uri' => 'https://github.com/microsoft/kiota-ruby/tree/main/components/serialization/text',
19
+ 'github_repo' => 'ssh://github.com/microsoft/kiota-ruby',
20
+ 'rubygems_mfa_required' => 'true'
21
+ }
22
+ spec.required_ruby_version = '>= 3.3.0'
23
+
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
26
+ end
27
+ spec.bindir = 'bin'
28
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ['lib']
30
+ spec.add_dependency 'microsoft_kiota_abstractions', MicrosoftKiotaSerializationText::VERSION
31
+ spec.add_dependency 'uuidtools', '>= 2.2', '< 3.1'
32
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: microsoft_kiota_serialization_text
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.25.0
5
+ platform: ruby
6
+ authors:
7
+ - Microsoft Corporation
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: microsoft_kiota_abstractions
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - '='
17
+ - !ruby/object:Gem::Version
18
+ version: 0.25.0
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - '='
24
+ - !ruby/object:Gem::Version
25
+ version: 0.25.0
26
+ - !ruby/object:Gem::Dependency
27
+ name: uuidtools
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '2.2'
33
+ - - "<"
34
+ - !ruby/object:Gem::Version
35
+ version: '3.1'
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '2.2'
43
+ - - "<"
44
+ - !ruby/object:Gem::Version
45
+ version: '3.1'
46
+ description: Implementation of Kiota Serialization interfaces for text
47
+ email: graphsdkpub+ruby@microsoft.com
48
+ executables: []
49
+ extensions: []
50
+ extra_rdoc_files: []
51
+ files:
52
+ - Gemfile
53
+ - Rakefile
54
+ - lib/microsoft_kiota_serialization_text.rb
55
+ - lib/microsoft_kiota_serialization_text/encoding.rb
56
+ - lib/microsoft_kiota_serialization_text/text_parse_node.rb
57
+ - lib/microsoft_kiota_serialization_text/text_parse_node_factory.rb
58
+ - lib/microsoft_kiota_serialization_text/text_serialization_writer.rb
59
+ - lib/microsoft_kiota_serialization_text/text_serialization_writer_factory.rb
60
+ - lib/microsoft_kiota_serialization_text/version.rb
61
+ - microsoft_kiota_serialization_text.gemspec
62
+ homepage: https://learn.microsoft.com/openapi/kiota/
63
+ licenses:
64
+ - MIT
65
+ metadata:
66
+ bug_tracker_uri: https://github.com/microsoft/kiota-ruby/issues
67
+ changelog_uri: https://github.com/microsoft/kiota-ruby/blob/main/CHANGELOG.md
68
+ homepage_uri: https://learn.microsoft.com/openapi/kiota/
69
+ source_code_uri: https://github.com/microsoft/kiota-ruby/tree/main/components/serialization/text
70
+ github_repo: ssh://github.com/microsoft/kiota-ruby
71
+ rubygems_mfa_required: 'true'
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: 3.3.0
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubygems_version: 3.6.9
87
+ specification_version: 4
88
+ summary: Microsoft Kiota Serialization - Ruby serialization for building library agnostic
89
+ http client
90
+ test_files: []