Skip to content

Commit 6308207

Browse files
feat(specs): add put task endpoint to ingestion api (generated)
algolia/api-clients-automation#5281 Co-authored-by: algolia-bot <[email protected]> Co-authored-by: Clément Vannicatte <[email protected]>
1 parent d09d267 commit 6308207

File tree

3 files changed

+359
-3
lines changed

3 files changed

+359
-3
lines changed

lib/algolia/api/ingestion_client.rb

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2265,6 +2265,52 @@ def push_task(task_id, push_task_payload, watch = nil, request_options = {})
22652265
@api_client.deserialize(response.body, request_options[:debug_return_type] || "Ingestion::WatchResponse")
22662266
end
22672267

2268+
# Fully updates a task by its ID, use partialUpdateTask if you only want to update a subset of fields.
2269+
2270+
# @param task_id [String] Unique identifier of a task. (required)
2271+
# @param task_replace [TaskReplace] (required)
2272+
# @param request_options: The request options to send along with the query, they will be merged with the transporter base parameters (headers, query params, timeouts, etc.). (optional)
2273+
# @return [Http::Response] the response
2274+
def replace_task_with_http_info(task_id, task_replace, request_options = {})
2275+
# verify the required parameter 'task_id' is set
2276+
if @api_client.config.client_side_validation && task_id.nil?
2277+
raise ArgumentError, "Parameter `task_id` is required when calling `replace_task`."
2278+
end
2279+
# verify the required parameter 'task_replace' is set
2280+
if @api_client.config.client_side_validation && task_replace.nil?
2281+
raise ArgumentError, "Parameter `task_replace` is required when calling `replace_task`."
2282+
end
2283+
2284+
path = "/2/tasks/{taskID}".sub("{" + "taskID" + "}", Transport.encode_uri(task_id.to_s))
2285+
query_params = {}
2286+
query_params = query_params.merge(request_options[:query_params]) unless request_options[:query_params].nil?
2287+
header_params = {}
2288+
header_params = header_params.merge(request_options[:header_params]) unless request_options[:header_params].nil?
2289+
2290+
post_body = request_options[:debug_body] || @api_client.object_to_http_body(task_replace)
2291+
2292+
new_options = request_options.merge(
2293+
:operation => :"IngestionClient.replace_task",
2294+
:header_params => header_params,
2295+
:query_params => query_params,
2296+
:body => post_body,
2297+
:use_read_transporter => false
2298+
)
2299+
2300+
@api_client.call_api(:PUT, path, new_options)
2301+
end
2302+
2303+
# Fully updates a task by its ID, use partialUpdateTask if you only want to update a subset of fields.
2304+
2305+
# @param task_id [String] Unique identifier of a task. (required)
2306+
# @param task_replace [TaskReplace] (required)
2307+
# @param request_options: The request options to send along with the query, they will be merged with the transporter base parameters (headers, query params, timeouts, etc.). (optional)
2308+
# @return [TaskUpdateResponse]
2309+
def replace_task(task_id, task_replace, request_options = {})
2310+
response = replace_task_with_http_info(task_id, task_replace, request_options)
2311+
@api_client.deserialize(response.body, request_options[:debug_return_type] || "Ingestion::TaskUpdateResponse")
2312+
end
2313+
22682314
# Runs all tasks linked to a source, only available for Shopify, BigCommerce and commercetools sources. Creates one run per task.
22692315
#
22702316
# Required API Key ACLs:
@@ -3046,7 +3092,7 @@ def update_source(source_id, source_update, request_options = {})
30463092
@api_client.deserialize(response.body, request_options[:debug_return_type] || "Ingestion::SourceUpdateResponse")
30473093
end
30483094

3049-
# Updates a task by its ID.
3095+
# Partially updates a task by its ID.
30503096

30513097
# @param task_id [String] Unique identifier of a task. (required)
30523098
# @param task_update [TaskUpdate] (required)
@@ -3081,7 +3127,7 @@ def update_task_with_http_info(task_id, task_update, request_options = {})
30813127
@api_client.call_api(:PATCH, path, new_options)
30823128
end
30833129

3084-
# Updates a task by its ID.
3130+
# Partially updates a task by its ID.
30853131

30863132
# @param task_id [String] Unique identifier of a task. (required)
30873133
# @param task_update [TaskUpdate] (required)
Lines changed: 310 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,310 @@
1+
# frozen_string_literal: true
2+
3+
# Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.
4+
5+
require "date"
6+
require "time"
7+
8+
module Algolia
9+
module Ingestion
10+
# API request body for updating a task.
11+
class TaskReplace
12+
# Universally unique identifier (UUID) of a destination resource.
13+
attr_accessor :destination_id
14+
15+
attr_accessor :action
16+
17+
attr_accessor :subscription_action
18+
19+
# Cron expression for the task's schedule.
20+
attr_accessor :cron
21+
22+
# Whether the task is enabled.
23+
attr_accessor :enabled
24+
25+
# Maximum accepted percentage of failures for a task run to finish successfully.
26+
attr_accessor :failure_threshold
27+
28+
attr_accessor :input
29+
30+
# Date of the last cursor in RFC 3339 format.
31+
attr_accessor :cursor
32+
33+
attr_accessor :notifications
34+
35+
attr_accessor :policies
36+
37+
# Attribute mapping from ruby-style variable name to JSON key.
38+
def self.attribute_map
39+
{
40+
:destination_id => :destinationID,
41+
:action => :action,
42+
:subscription_action => :subscriptionAction,
43+
:cron => :cron,
44+
:enabled => :enabled,
45+
:failure_threshold => :failureThreshold,
46+
:input => :input,
47+
:cursor => :cursor,
48+
:notifications => :notifications,
49+
:policies => :policies
50+
}
51+
end
52+
53+
# Attribute type mapping.
54+
def self.types_mapping
55+
{
56+
:destination_id => :"String",
57+
:action => :"ActionType",
58+
:subscription_action => :"ActionType",
59+
:cron => :"String",
60+
:enabled => :"Boolean",
61+
:failure_threshold => :"Integer",
62+
:input => :"TaskInput",
63+
:cursor => :"String",
64+
:notifications => :"Notifications",
65+
:policies => :"Policies"
66+
}
67+
end
68+
69+
# List of attributes with nullable: true
70+
def self.openapi_nullable
71+
Set.new(
72+
[]
73+
)
74+
end
75+
76+
# Initializes the object
77+
# @param [Hash] attributes Model attributes in the form of hash
78+
def initialize(attributes = {})
79+
if (!attributes.is_a?(Hash))
80+
raise(
81+
ArgumentError,
82+
"The input argument (attributes) must be a hash in `Algolia::TaskReplace` initialize method"
83+
)
84+
end
85+
86+
# check to see if the attribute exists and convert string to symbol for hash key
87+
attributes = attributes.each_with_object({}) { |(k, v), h|
88+
if (!self.class.attribute_map.key?(k.to_sym))
89+
raise(
90+
ArgumentError,
91+
"`#{k}` is not a valid attribute in `Algolia::TaskReplace`. Please check the name to make sure it's valid. List of attributes: " +
92+
self.class.attribute_map.keys.inspect
93+
)
94+
end
95+
96+
h[k.to_sym] = v
97+
}
98+
99+
if attributes.key?(:destination_id)
100+
self.destination_id = attributes[:destination_id]
101+
else
102+
self.destination_id = nil
103+
end
104+
105+
if attributes.key?(:action)
106+
self.action = attributes[:action]
107+
else
108+
self.action = nil
109+
end
110+
111+
if attributes.key?(:subscription_action)
112+
self.subscription_action = attributes[:subscription_action]
113+
end
114+
115+
if attributes.key?(:cron)
116+
self.cron = attributes[:cron]
117+
end
118+
119+
if attributes.key?(:enabled)
120+
self.enabled = attributes[:enabled]
121+
end
122+
123+
if attributes.key?(:failure_threshold)
124+
self.failure_threshold = attributes[:failure_threshold]
125+
end
126+
127+
if attributes.key?(:input)
128+
self.input = attributes[:input]
129+
end
130+
131+
if attributes.key?(:cursor)
132+
self.cursor = attributes[:cursor]
133+
end
134+
135+
if attributes.key?(:notifications)
136+
self.notifications = attributes[:notifications]
137+
end
138+
139+
if attributes.key?(:policies)
140+
self.policies = attributes[:policies]
141+
end
142+
end
143+
144+
# Checks equality by comparing each attribute.
145+
# @param [Object] Object to be compared
146+
def ==(other)
147+
return true if self.equal?(other)
148+
self.class == other.class &&
149+
destination_id == other.destination_id &&
150+
action == other.action &&
151+
subscription_action == other.subscription_action &&
152+
cron == other.cron &&
153+
enabled == other.enabled &&
154+
failure_threshold == other.failure_threshold &&
155+
input == other.input &&
156+
cursor == other.cursor &&
157+
notifications == other.notifications &&
158+
policies == other.policies
159+
end
160+
161+
# @see the `==` method
162+
# @param [Object] Object to be compared
163+
def eql?(other)
164+
self == other
165+
end
166+
167+
# Calculates hash code according to all attributes.
168+
# @return [Integer] Hash code
169+
def hash
170+
[
171+
destination_id,
172+
action,
173+
subscription_action,
174+
cron,
175+
enabled,
176+
failure_threshold,
177+
input,
178+
cursor,
179+
notifications,
180+
policies
181+
].hash
182+
end
183+
184+
# Builds the object from hash
185+
# @param [Hash] attributes Model attributes in the form of hash
186+
# @return [Object] Returns the model itself
187+
def self.build_from_hash(attributes)
188+
return nil unless attributes.is_a?(Hash)
189+
attributes = attributes.transform_keys(&:to_sym)
190+
transformed_hash = {}
191+
types_mapping.each_pair do |key, type|
192+
if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
193+
transformed_hash[key.to_sym] = nil
194+
elsif type =~ /\AArray<(.*)>/i
195+
# check to ensure the input is an array given that the attribute
196+
# is documented as an array but the input is not
197+
if attributes[attribute_map[key]].is_a?(Array)
198+
transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v|
199+
_deserialize(::Regexp.last_match(1), v)
200+
}
201+
end
202+
elsif !attributes[attribute_map[key]].nil?
203+
transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]])
204+
end
205+
end
206+
207+
new(transformed_hash)
208+
end
209+
210+
# Deserializes the data based on type
211+
# @param string type Data type
212+
# @param string value Value to be deserialized
213+
# @return [Object] Deserialized data
214+
def self._deserialize(type, value)
215+
case type.to_sym
216+
when :Time
217+
Time.parse(value)
218+
when :Date
219+
Date.parse(value)
220+
when :String
221+
value.to_s
222+
when :Integer
223+
value.to_i
224+
when :Float
225+
value.to_f
226+
when :Boolean
227+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
228+
true
229+
else
230+
false
231+
end
232+
233+
when :Object
234+
# generic object (usually a Hash), return directly
235+
value
236+
when /\AArray<(?<inner_type>.+)>\z/
237+
inner_type = Regexp.last_match[:inner_type]
238+
value.map { |v| _deserialize(inner_type, v) }
239+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
240+
k_type = Regexp.last_match[:k_type]
241+
v_type = Regexp.last_match[:v_type]
242+
{}.tap do |hash|
243+
value.each do |k, v|
244+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
245+
end
246+
end
247+
# model
248+
else
249+
# models (e.g. Pet) or oneOf
250+
klass = Algolia::Ingestion.const_get(type)
251+
klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass
252+
.build_from_hash(value)
253+
end
254+
end
255+
256+
# Returns the string representation of the object
257+
# @return [String] String presentation of the object
258+
def to_s
259+
to_hash.to_s
260+
end
261+
262+
# to_body is an alias to to_hash (backward compatibility)
263+
# @return [Hash] Returns the object in the form of hash
264+
def to_body
265+
to_hash
266+
end
267+
268+
def to_json(*_args)
269+
to_hash.to_json
270+
end
271+
272+
# Returns the object in the form of hash
273+
# @return [Hash] Returns the object in the form of hash
274+
def to_hash
275+
hash = {}
276+
self.class.attribute_map.each_pair do |attr, param|
277+
value = send(attr)
278+
if value.nil?
279+
is_nullable = self.class.openapi_nullable.include?(attr)
280+
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
281+
end
282+
283+
hash[param] = _to_hash(value)
284+
end
285+
286+
hash
287+
end
288+
289+
# Outputs non-array value in the form of hash
290+
# For object, use to_hash. Otherwise, just return the value
291+
# @param [Object] value Any valid value
292+
# @return [Hash] Returns the value in the form of hash
293+
def _to_hash(value)
294+
if value.is_a?(Array)
295+
value.compact.map { |v| _to_hash(v) }
296+
elsif value.is_a?(Hash)
297+
{}.tap do |hash|
298+
value.each { |k, v| hash[k] = _to_hash(v) }
299+
end
300+
elsif value.respond_to?(:to_hash)
301+
value.to_hash
302+
else
303+
value
304+
end
305+
end
306+
307+
end
308+
309+
end
310+
end

lib/algolia/models/ingestion/task_update.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
module Algolia
99
module Ingestion
10-
# API request body for updating a task.
10+
# API request body for partially updating a task.
1111
class TaskUpdate
1212
# Universally unique identifier (UUID) of a destination resource.
1313
attr_accessor :destination_id

0 commit comments

Comments
 (0)