composio 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +32 -2
- data/lib/composio/api/connections_api.rb +84 -0
- data/lib/composio/models/additional_info.rb +220 -0
- data/lib/composio/models/data.rb +234 -0
- data/lib/composio/models/get_connection_info_response_dto.rb +250 -0
- data/lib/composio/models/parameter.rb +248 -0
- data/lib/composio/version.rb +1 -1
- data/lib/composio.rb +4 -0
- data/spec/api/connections_api_spec.rb +11 -0
- data/spec/models/additional_info_spec.rb +28 -0
- data/spec/models/data_spec.rb +34 -0
- data/spec/models/get_connection_info_response_dto_spec.rb +40 -0
- data/spec/models/parameter_spec.rb +40 -0
- metadata +140 -128
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 953aa316be770c444ed3e7225b3ce1ce3ab7bb12522d23895c5f5395dd120479
|
4
|
+
data.tar.gz: 2238ce5295754b4004e39507bc11f0ec7e31b939b02fe1cd0aedacb0ab5af664
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9151c65b1ec793c2d1e055f86c3c8c7a21f1f1b5472b692d65867d1de779e033ba2b55003ba4206b39c4e4ee3205f016666a62ac53bf7d03e25d494e6e27345a
|
7
|
+
data.tar.gz: b352e4ec843c6f7add2e991b4074ad63010e1108a60d6016b499e0f95f3bd91c3eedb8ca7bb679cbb7189a4059c3b3a790c2c8b3ff4c046bd62a0461cbf0ec49
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
Composio SDK: Equip your agent with high-quality tools and build your real-world usecase
|
8
8
|
|
9
|
-
[![npm](https://img.shields.io/badge/gem-v0.1.
|
9
|
+
[![npm](https://img.shields.io/badge/gem-v0.1.8-blue)](https://rubygems.org/gems/composio/versions/0.1.8)
|
10
10
|
[![More Info](https://img.shields.io/badge/More%20Info-Click%20Here-orange)](https://composio.dev)
|
11
11
|
|
12
12
|
</div>
|
@@ -40,6 +40,7 @@ Composio SDK: Equip your agent with high-quality tools and build your real-world
|
|
40
40
|
* [`composio.connections.disable`](#composioconnectionsdisable)
|
41
41
|
* [`composio.connections.enable`](#composioconnectionsenable)
|
42
42
|
* [`composio.connections.get`](#composioconnectionsget)
|
43
|
+
* [`composio.connections.get_info`](#composioconnectionsget_info)
|
43
44
|
* [`composio.connections.initiate`](#composioconnectionsinitiate)
|
44
45
|
* [`composio.connections.list`](#composioconnectionslist)
|
45
46
|
* [`composio.event_logs.get_events`](#composioevent_logsget_events)
|
@@ -77,7 +78,7 @@ Composio SDK: Equip your agent with high-quality tools and build your real-world
|
|
77
78
|
Add to Gemfile:
|
78
79
|
|
79
80
|
```ruby
|
80
|
-
gem 'composio', '~> 0.1.
|
81
|
+
gem 'composio', '~> 0.1.8'
|
81
82
|
```
|
82
83
|
|
83
84
|
## Getting Started<a id="getting-started"></a>
|
@@ -738,6 +739,35 @@ p result
|
|
738
739
|
---
|
739
740
|
|
740
741
|
|
742
|
+
### `composio.connections.get_info`<a id="composioconnectionsget_info"></a>
|
743
|
+
|
744
|
+
Get connection info
|
745
|
+
|
746
|
+
#### 🛠️ Usage<a id="🛠️-usage"></a>
|
747
|
+
|
748
|
+
```ruby
|
749
|
+
result = composio.connections.get_info(
|
750
|
+
connected_account_id: "'+j>6",
|
751
|
+
)
|
752
|
+
p result
|
753
|
+
```
|
754
|
+
|
755
|
+
#### ⚙️ Parameters<a id="⚙️-parameters"></a>
|
756
|
+
|
757
|
+
##### connected_account_id: `String`<a id="connected_account_id-string"></a>
|
758
|
+
#### 🔄 Return<a id="🔄-return"></a>
|
759
|
+
|
760
|
+
[GetConnectionInfoResponseDTO](./lib/composio/models/get_connection_info_response_dto.rb)
|
761
|
+
|
762
|
+
#### 🌐 Endpoint<a id="🌐-endpoint"></a>
|
763
|
+
|
764
|
+
`/api/v1/connectedAccounts/{connectedAccountId}/info` `GET`
|
765
|
+
|
766
|
+
[🔙 **Back to Table of Contents**](#table-of-contents)
|
767
|
+
|
768
|
+
---
|
769
|
+
|
770
|
+
|
741
771
|
### `composio.connections.initiate`<a id="composioconnectionsinitiate"></a>
|
742
772
|
|
743
773
|
Initiate connection
|
@@ -352,6 +352,90 @@ module Composio
|
|
352
352
|
end
|
353
353
|
|
354
354
|
|
355
|
+
# Get connection info
|
356
|
+
#
|
357
|
+
# @param connected_account_id [String]
|
358
|
+
# @param [Hash] extra additional parameters to pass along through :header_params, :query_params, or parameter name
|
359
|
+
def get_info(connected_account_id:, extra: {})
|
360
|
+
api_response = get_info_with_http_info_impl(connected_account_id, extra)
|
361
|
+
api_response.data
|
362
|
+
end
|
363
|
+
|
364
|
+
# Get connection info
|
365
|
+
#
|
366
|
+
# @param connected_account_id [String]
|
367
|
+
# @param [Hash] extra additional parameters to pass along through :header_params, :query_params, or parameter name
|
368
|
+
def get_info_with_http_info(connected_account_id:, extra: {})
|
369
|
+
get_info_with_http_info_impl(connected_account_id, extra)
|
370
|
+
end
|
371
|
+
|
372
|
+
# Get connection info
|
373
|
+
# @param connected_account_id [String]
|
374
|
+
# @param [Hash] opts the optional parameters
|
375
|
+
# @return [GetConnectionInfoResponseDTO]
|
376
|
+
private def get_info_impl(connected_account_id, opts = {})
|
377
|
+
data, _status_code, _headers = get_info_with_http_info(connected_account_id, opts)
|
378
|
+
data
|
379
|
+
end
|
380
|
+
|
381
|
+
# Get connection info
|
382
|
+
# @param connected_account_id [String]
|
383
|
+
# @param [Hash] opts the optional parameters
|
384
|
+
# @return [APIResponse] data is GetConnectionInfoResponseDTO, status code, headers and response
|
385
|
+
private def get_info_with_http_info_impl(connected_account_id, opts = {})
|
386
|
+
if @api_client.config.debugging
|
387
|
+
@api_client.config.logger.debug 'Calling API: ConnectionsApi.get_info ...'
|
388
|
+
end
|
389
|
+
# verify the required parameter 'connected_account_id' is set
|
390
|
+
if @api_client.config.client_side_validation && connected_account_id.nil?
|
391
|
+
fail ArgumentError, "Missing the required parameter 'connected_account_id' when calling ConnectionsApi.get_info"
|
392
|
+
end
|
393
|
+
pattern = Regexp.new(/[^\/#\?]+?/)
|
394
|
+
if @api_client.config.client_side_validation && connected_account_id !~ pattern
|
395
|
+
fail ArgumentError, "invalid value for 'connected_account_id' when calling ConnectionsApi.get_info, must conform to the pattern #{pattern}."
|
396
|
+
end
|
397
|
+
|
398
|
+
# resource path
|
399
|
+
local_var_path = '/api/v1/connectedAccounts/{connectedAccountId}/info'.sub('{' + 'connectedAccountId' + '}', CGI.escape(connected_account_id.to_s))
|
400
|
+
|
401
|
+
# query parameters
|
402
|
+
query_params = opts[:query_params] || {}
|
403
|
+
|
404
|
+
# header parameters
|
405
|
+
header_params = opts[:header_params] || {}
|
406
|
+
# HTTP header 'Accept' (if needed)
|
407
|
+
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
|
408
|
+
|
409
|
+
# form parameters
|
410
|
+
form_params = opts[:form_params] || {}
|
411
|
+
|
412
|
+
# http body (model)
|
413
|
+
post_body = opts[:debug_body]
|
414
|
+
|
415
|
+
# return_type
|
416
|
+
return_type = opts[:debug_return_type] || 'GetConnectionInfoResponseDTO'
|
417
|
+
|
418
|
+
# auth_names
|
419
|
+
auth_names = opts[:debug_auth_names] || ['api_key']
|
420
|
+
|
421
|
+
new_options = opts.merge(
|
422
|
+
:operation => :"ConnectionsApi.get_info",
|
423
|
+
:header_params => header_params,
|
424
|
+
:query_params => query_params,
|
425
|
+
:form_params => form_params,
|
426
|
+
:body => post_body,
|
427
|
+
:auth_names => auth_names,
|
428
|
+
:return_type => return_type
|
429
|
+
)
|
430
|
+
|
431
|
+
data, status_code, headers, response = @api_client.call_api(:GET, local_var_path, new_options)
|
432
|
+
if @api_client.config.debugging
|
433
|
+
@api_client.config.logger.debug "API called: ConnectionsApi#get_info\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
434
|
+
end
|
435
|
+
APIResponse::new(data, status_code, headers, response)
|
436
|
+
end
|
437
|
+
|
438
|
+
|
355
439
|
# Initiate connection
|
356
440
|
#
|
357
441
|
# @param integration_id [String]
|
@@ -0,0 +1,220 @@
|
|
1
|
+
=begin
|
2
|
+
#Composio OpenAPI
|
3
|
+
|
4
|
+
#Composio SDK: Equip your agent with high-quality tools and build your real-world usecase
|
5
|
+
|
6
|
+
The version of the OpenAPI document: 1.0.0
|
7
|
+
=end
|
8
|
+
|
9
|
+
require 'date'
|
10
|
+
require 'time'
|
11
|
+
|
12
|
+
module Composio
|
13
|
+
class AdditionalInfo
|
14
|
+
attr_accessor :meta
|
15
|
+
|
16
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
17
|
+
def self.attribute_map
|
18
|
+
{
|
19
|
+
:'meta' => :'meta'
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
# Returns all the JSON keys this model knows about
|
24
|
+
def self.acceptable_attributes
|
25
|
+
attribute_map.values
|
26
|
+
end
|
27
|
+
|
28
|
+
# Attribute type mapping.
|
29
|
+
def self.openapi_types
|
30
|
+
{
|
31
|
+
:'meta' => :'String'
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
# List of attributes with nullable: true
|
36
|
+
def self.openapi_nullable
|
37
|
+
Set.new([
|
38
|
+
])
|
39
|
+
end
|
40
|
+
|
41
|
+
# Initializes the object
|
42
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
43
|
+
def initialize(attributes = {})
|
44
|
+
if (!attributes.is_a?(Hash))
|
45
|
+
fail ArgumentError, "The input argument (attributes) must be a hash in `Composio::AdditionalInfo` initialize method"
|
46
|
+
end
|
47
|
+
|
48
|
+
# check to see if the attribute exists and convert string to symbol for hash key
|
49
|
+
attributes = attributes.each_with_object({}) { |(k, v), h|
|
50
|
+
if (!self.class.attribute_map.key?(k.to_sym))
|
51
|
+
fail ArgumentError, "`#{k}` is not a valid attribute in `Composio::AdditionalInfo`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
|
52
|
+
end
|
53
|
+
h[k.to_sym] = v
|
54
|
+
}
|
55
|
+
|
56
|
+
if attributes.key?(:'meta')
|
57
|
+
self.meta = attributes[:'meta']
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# Show invalid properties with the reasons. Usually used together with valid?
|
62
|
+
# @return Array for valid properties with the reasons
|
63
|
+
def list_invalid_properties
|
64
|
+
invalid_properties = Array.new
|
65
|
+
if @meta.nil?
|
66
|
+
invalid_properties.push('invalid value for "meta", meta cannot be nil.')
|
67
|
+
end
|
68
|
+
|
69
|
+
invalid_properties
|
70
|
+
end
|
71
|
+
|
72
|
+
# Check to see if the all the properties in the model are valid
|
73
|
+
# @return true if the model is valid
|
74
|
+
def valid?
|
75
|
+
return false if @meta.nil?
|
76
|
+
true
|
77
|
+
end
|
78
|
+
|
79
|
+
# Checks equality by comparing each attribute.
|
80
|
+
# @param [Object] Object to be compared
|
81
|
+
def ==(o)
|
82
|
+
return true if self.equal?(o)
|
83
|
+
self.class == o.class &&
|
84
|
+
meta == o.meta
|
85
|
+
end
|
86
|
+
|
87
|
+
# @see the `==` method
|
88
|
+
# @param [Object] Object to be compared
|
89
|
+
def eql?(o)
|
90
|
+
self == o
|
91
|
+
end
|
92
|
+
|
93
|
+
# Calculates hash code according to all attributes.
|
94
|
+
# @return [Integer] Hash code
|
95
|
+
def hash
|
96
|
+
[meta].hash
|
97
|
+
end
|
98
|
+
|
99
|
+
# Builds the object from hash
|
100
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
101
|
+
# @return [Object] Returns the model itself
|
102
|
+
def self.build_from_hash(attributes)
|
103
|
+
new.build_from_hash(attributes)
|
104
|
+
end
|
105
|
+
|
106
|
+
# Builds the object from hash
|
107
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
108
|
+
# @return [Object] Returns the model itself
|
109
|
+
def build_from_hash(attributes)
|
110
|
+
return nil unless attributes.is_a?(Hash)
|
111
|
+
attributes = attributes.transform_keys(&:to_sym)
|
112
|
+
self.class.openapi_types.each_pair do |key, type|
|
113
|
+
if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
|
114
|
+
self.send("#{key}=", nil)
|
115
|
+
elsif type =~ /\AArray<(.*)>/i
|
116
|
+
# check to ensure the input is an array given that the attribute
|
117
|
+
# is documented as an array but the input is not
|
118
|
+
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
119
|
+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
|
120
|
+
end
|
121
|
+
elsif !attributes[self.class.attribute_map[key]].nil?
|
122
|
+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
self
|
127
|
+
end
|
128
|
+
|
129
|
+
# Deserializes the data based on type
|
130
|
+
# @param string type Data type
|
131
|
+
# @param string value Value to be deserialized
|
132
|
+
# @return [Object] Deserialized data
|
133
|
+
def _deserialize(type, value)
|
134
|
+
case type.to_sym
|
135
|
+
when :Time
|
136
|
+
Time.parse(value)
|
137
|
+
when :Date
|
138
|
+
Date.parse(value)
|
139
|
+
when :String
|
140
|
+
value.to_s
|
141
|
+
when :Integer
|
142
|
+
value.to_i
|
143
|
+
when :Float
|
144
|
+
value.to_f
|
145
|
+
when :Boolean
|
146
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
147
|
+
true
|
148
|
+
else
|
149
|
+
false
|
150
|
+
end
|
151
|
+
when :Object
|
152
|
+
# generic object (usually a Hash), return directly
|
153
|
+
value
|
154
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
155
|
+
inner_type = Regexp.last_match[:inner_type]
|
156
|
+
value.map { |v| _deserialize(inner_type, v) }
|
157
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
158
|
+
k_type = Regexp.last_match[:k_type]
|
159
|
+
v_type = Regexp.last_match[:v_type]
|
160
|
+
{}.tap do |hash|
|
161
|
+
value.each do |k, v|
|
162
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
else # model
|
166
|
+
# models (e.g. Pet) or oneOf
|
167
|
+
klass = Composio.const_get(type)
|
168
|
+
klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
# Returns the string representation of the object
|
173
|
+
# @return [String] String presentation of the object
|
174
|
+
def to_s
|
175
|
+
to_hash.to_s
|
176
|
+
end
|
177
|
+
|
178
|
+
# to_body is an alias to to_hash (backward compatibility)
|
179
|
+
# @return [Hash] Returns the object in the form of hash
|
180
|
+
def to_body
|
181
|
+
to_hash
|
182
|
+
end
|
183
|
+
|
184
|
+
# Returns the object in the form of hash
|
185
|
+
# @return [Hash] Returns the object in the form of hash
|
186
|
+
def to_hash
|
187
|
+
hash = {}
|
188
|
+
self.class.attribute_map.each_pair do |attr, param|
|
189
|
+
value = self.send(attr)
|
190
|
+
if value.nil?
|
191
|
+
is_nullable = self.class.openapi_nullable.include?(attr)
|
192
|
+
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
|
193
|
+
end
|
194
|
+
|
195
|
+
hash[param] = _to_hash(value)
|
196
|
+
end
|
197
|
+
hash
|
198
|
+
end
|
199
|
+
|
200
|
+
# Outputs non-array value in the form of hash
|
201
|
+
# For object, use to_hash. Otherwise, just return the value
|
202
|
+
# @param [Object] value Any valid value
|
203
|
+
# @return [Hash] Returns the value in the form of hash
|
204
|
+
def _to_hash(value)
|
205
|
+
if value.is_a?(Array)
|
206
|
+
value.compact.map { |v| _to_hash(v) }
|
207
|
+
elsif value.is_a?(Hash)
|
208
|
+
{}.tap do |hash|
|
209
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
210
|
+
end
|
211
|
+
elsif value.respond_to? :to_hash
|
212
|
+
value.to_hash
|
213
|
+
else
|
214
|
+
value
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
end
|
219
|
+
|
220
|
+
end
|
@@ -0,0 +1,234 @@
|
|
1
|
+
=begin
|
2
|
+
#Composio OpenAPI
|
3
|
+
|
4
|
+
#Composio SDK: Equip your agent with high-quality tools and build your real-world usecase
|
5
|
+
|
6
|
+
The version of the OpenAPI document: 1.0.0
|
7
|
+
=end
|
8
|
+
|
9
|
+
require 'date'
|
10
|
+
require 'time'
|
11
|
+
|
12
|
+
module Composio
|
13
|
+
class Data
|
14
|
+
attr_accessor :field1
|
15
|
+
|
16
|
+
attr_accessor :field2
|
17
|
+
|
18
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
19
|
+
def self.attribute_map
|
20
|
+
{
|
21
|
+
:'field1' => :'field1',
|
22
|
+
:'field2' => :'field2'
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
# Returns all the JSON keys this model knows about
|
27
|
+
def self.acceptable_attributes
|
28
|
+
attribute_map.values
|
29
|
+
end
|
30
|
+
|
31
|
+
# Attribute type mapping.
|
32
|
+
def self.openapi_types
|
33
|
+
{
|
34
|
+
:'field1' => :'String',
|
35
|
+
:'field2' => :'String'
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
# List of attributes with nullable: true
|
40
|
+
def self.openapi_nullable
|
41
|
+
Set.new([
|
42
|
+
])
|
43
|
+
end
|
44
|
+
|
45
|
+
# Initializes the object
|
46
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
47
|
+
def initialize(attributes = {})
|
48
|
+
if (!attributes.is_a?(Hash))
|
49
|
+
fail ArgumentError, "The input argument (attributes) must be a hash in `Composio::Data` initialize method"
|
50
|
+
end
|
51
|
+
|
52
|
+
# check to see if the attribute exists and convert string to symbol for hash key
|
53
|
+
attributes = attributes.each_with_object({}) { |(k, v), h|
|
54
|
+
if (!self.class.attribute_map.key?(k.to_sym))
|
55
|
+
fail ArgumentError, "`#{k}` is not a valid attribute in `Composio::Data`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
|
56
|
+
end
|
57
|
+
h[k.to_sym] = v
|
58
|
+
}
|
59
|
+
|
60
|
+
if attributes.key?(:'field1')
|
61
|
+
self.field1 = attributes[:'field1']
|
62
|
+
end
|
63
|
+
|
64
|
+
if attributes.key?(:'field2')
|
65
|
+
self.field2 = attributes[:'field2']
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# Show invalid properties with the reasons. Usually used together with valid?
|
70
|
+
# @return Array for valid properties with the reasons
|
71
|
+
def list_invalid_properties
|
72
|
+
invalid_properties = Array.new
|
73
|
+
if @field1.nil?
|
74
|
+
invalid_properties.push('invalid value for "field1", field1 cannot be nil.')
|
75
|
+
end
|
76
|
+
|
77
|
+
if @field2.nil?
|
78
|
+
invalid_properties.push('invalid value for "field2", field2 cannot be nil.')
|
79
|
+
end
|
80
|
+
|
81
|
+
invalid_properties
|
82
|
+
end
|
83
|
+
|
84
|
+
# Check to see if the all the properties in the model are valid
|
85
|
+
# @return true if the model is valid
|
86
|
+
def valid?
|
87
|
+
return false if @field1.nil?
|
88
|
+
return false if @field2.nil?
|
89
|
+
true
|
90
|
+
end
|
91
|
+
|
92
|
+
# Checks equality by comparing each attribute.
|
93
|
+
# @param [Object] Object to be compared
|
94
|
+
def ==(o)
|
95
|
+
return true if self.equal?(o)
|
96
|
+
self.class == o.class &&
|
97
|
+
field1 == o.field1 &&
|
98
|
+
field2 == o.field2
|
99
|
+
end
|
100
|
+
|
101
|
+
# @see the `==` method
|
102
|
+
# @param [Object] Object to be compared
|
103
|
+
def eql?(o)
|
104
|
+
self == o
|
105
|
+
end
|
106
|
+
|
107
|
+
# Calculates hash code according to all attributes.
|
108
|
+
# @return [Integer] Hash code
|
109
|
+
def hash
|
110
|
+
[field1, field2].hash
|
111
|
+
end
|
112
|
+
|
113
|
+
# Builds the object from hash
|
114
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
115
|
+
# @return [Object] Returns the model itself
|
116
|
+
def self.build_from_hash(attributes)
|
117
|
+
new.build_from_hash(attributes)
|
118
|
+
end
|
119
|
+
|
120
|
+
# Builds the object from hash
|
121
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
122
|
+
# @return [Object] Returns the model itself
|
123
|
+
def build_from_hash(attributes)
|
124
|
+
return nil unless attributes.is_a?(Hash)
|
125
|
+
attributes = attributes.transform_keys(&:to_sym)
|
126
|
+
self.class.openapi_types.each_pair do |key, type|
|
127
|
+
if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
|
128
|
+
self.send("#{key}=", nil)
|
129
|
+
elsif type =~ /\AArray<(.*)>/i
|
130
|
+
# check to ensure the input is an array given that the attribute
|
131
|
+
# is documented as an array but the input is not
|
132
|
+
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
133
|
+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
|
134
|
+
end
|
135
|
+
elsif !attributes[self.class.attribute_map[key]].nil?
|
136
|
+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
self
|
141
|
+
end
|
142
|
+
|
143
|
+
# Deserializes the data based on type
|
144
|
+
# @param string type Data type
|
145
|
+
# @param string value Value to be deserialized
|
146
|
+
# @return [Object] Deserialized data
|
147
|
+
def _deserialize(type, value)
|
148
|
+
case type.to_sym
|
149
|
+
when :Time
|
150
|
+
Time.parse(value)
|
151
|
+
when :Date
|
152
|
+
Date.parse(value)
|
153
|
+
when :String
|
154
|
+
value.to_s
|
155
|
+
when :Integer
|
156
|
+
value.to_i
|
157
|
+
when :Float
|
158
|
+
value.to_f
|
159
|
+
when :Boolean
|
160
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
161
|
+
true
|
162
|
+
else
|
163
|
+
false
|
164
|
+
end
|
165
|
+
when :Object
|
166
|
+
# generic object (usually a Hash), return directly
|
167
|
+
value
|
168
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
169
|
+
inner_type = Regexp.last_match[:inner_type]
|
170
|
+
value.map { |v| _deserialize(inner_type, v) }
|
171
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
172
|
+
k_type = Regexp.last_match[:k_type]
|
173
|
+
v_type = Regexp.last_match[:v_type]
|
174
|
+
{}.tap do |hash|
|
175
|
+
value.each do |k, v|
|
176
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
else # model
|
180
|
+
# models (e.g. Pet) or oneOf
|
181
|
+
klass = Composio.const_get(type)
|
182
|
+
klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
# Returns the string representation of the object
|
187
|
+
# @return [String] String presentation of the object
|
188
|
+
def to_s
|
189
|
+
to_hash.to_s
|
190
|
+
end
|
191
|
+
|
192
|
+
# to_body is an alias to to_hash (backward compatibility)
|
193
|
+
# @return [Hash] Returns the object in the form of hash
|
194
|
+
def to_body
|
195
|
+
to_hash
|
196
|
+
end
|
197
|
+
|
198
|
+
# Returns the object in the form of hash
|
199
|
+
# @return [Hash] Returns the object in the form of hash
|
200
|
+
def to_hash
|
201
|
+
hash = {}
|
202
|
+
self.class.attribute_map.each_pair do |attr, param|
|
203
|
+
value = self.send(attr)
|
204
|
+
if value.nil?
|
205
|
+
is_nullable = self.class.openapi_nullable.include?(attr)
|
206
|
+
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
|
207
|
+
end
|
208
|
+
|
209
|
+
hash[param] = _to_hash(value)
|
210
|
+
end
|
211
|
+
hash
|
212
|
+
end
|
213
|
+
|
214
|
+
# Outputs non-array value in the form of hash
|
215
|
+
# For object, use to_hash. Otherwise, just return the value
|
216
|
+
# @param [Object] value Any valid value
|
217
|
+
# @return [Hash] Returns the value in the form of hash
|
218
|
+
def _to_hash(value)
|
219
|
+
if value.is_a?(Array)
|
220
|
+
value.compact.map { |v| _to_hash(v) }
|
221
|
+
elsif value.is_a?(Hash)
|
222
|
+
{}.tap do |hash|
|
223
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
224
|
+
end
|
225
|
+
elsif value.respond_to? :to_hash
|
226
|
+
value.to_hash
|
227
|
+
else
|
228
|
+
value
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
end
|
233
|
+
|
234
|
+
end
|