Skip to content

Commit be6aa4c

Browse files
committed
feat(VisualRecognitionV4): add support for object metadata
1 parent 2aa4a78 commit be6aa4c

File tree

1 file changed

+145
-1
lines changed

1 file changed

+145
-1
lines changed

lib/ibm_watson/visual_recognition_v4.rb

Lines changed: 145 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,150 @@ def get_jpeg_image(collection_id:, image_id:, size: nil)
529529
response
530530
end
531531
#########################
532+
# Objects
533+
#########################
534+
535+
##
536+
# @!method list_object_metadata(collection_id:)
537+
# List object metadata.
538+
# Retrieves a list of object names in a collection.
539+
# @param collection_id [String] The identifier of the collection.
540+
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
541+
def list_object_metadata(collection_id:)
542+
raise ArgumentError.new("collection_id must be provided") if collection_id.nil?
543+
544+
headers = {
545+
}
546+
sdk_headers = Common.new.get_sdk_headers("watson_vision_combined", "V4", "list_object_metadata")
547+
headers.merge!(sdk_headers)
548+
549+
params = {
550+
"version" => @version
551+
}
552+
553+
method_url = "/v4/collections/%s/objects" % [ERB::Util.url_encode(collection_id)]
554+
555+
response = request(
556+
method: "GET",
557+
url: method_url,
558+
headers: headers,
559+
params: params,
560+
accept_json: true
561+
)
562+
response
563+
end
564+
565+
##
566+
# @!method update_object_metadata(collection_id:, object:, new_object:)
567+
# Update an object name.
568+
# Update the name of an object. A successful request updates the training data for
569+
# all images that use the object.
570+
# @param collection_id [String] The identifier of the collection.
571+
# @param object [String] The name of the object.
572+
# @param new_object [String] The updated name of the object. The name can contain alphanumeric, underscore,
573+
# hyphen, space, and dot characters. It cannot begin with the reserved prefix
574+
# `sys-`.
575+
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
576+
def update_object_metadata(collection_id:, object:, new_object:)
577+
raise ArgumentError.new("collection_id must be provided") if collection_id.nil?
578+
579+
raise ArgumentError.new("object must be provided") if object.nil?
580+
581+
raise ArgumentError.new("new_object must be provided") if new_object.nil?
582+
583+
headers = {
584+
}
585+
sdk_headers = Common.new.get_sdk_headers("watson_vision_combined", "V4", "update_object_metadata")
586+
headers.merge!(sdk_headers)
587+
588+
params = {
589+
"version" => @version
590+
}
591+
592+
data = {
593+
"object" => new_object
594+
}
595+
596+
method_url = "/v4/collections/%s/objects/%s" % [ERB::Util.url_encode(collection_id), ERB::Util.url_encode(object)]
597+
598+
response = request(
599+
method: "POST",
600+
url: method_url,
601+
headers: headers,
602+
params: params,
603+
json: data,
604+
accept_json: true
605+
)
606+
response
607+
end
608+
609+
##
610+
# @!method get_object_metadata(collection_id:, object:)
611+
# Get object metadata.
612+
# Get the number of bounding boxes for a single object in a collection.
613+
# @param collection_id [String] The identifier of the collection.
614+
# @param object [String] The name of the object.
615+
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
616+
def get_object_metadata(collection_id:, object:)
617+
raise ArgumentError.new("collection_id must be provided") if collection_id.nil?
618+
619+
raise ArgumentError.new("object must be provided") if object.nil?
620+
621+
headers = {
622+
}
623+
sdk_headers = Common.new.get_sdk_headers("watson_vision_combined", "V4", "get_object_metadata")
624+
headers.merge!(sdk_headers)
625+
626+
params = {
627+
"version" => @version
628+
}
629+
630+
method_url = "/v4/collections/%s/objects/%s" % [ERB::Util.url_encode(collection_id), ERB::Util.url_encode(object)]
631+
632+
response = request(
633+
method: "GET",
634+
url: method_url,
635+
headers: headers,
636+
params: params,
637+
accept_json: true
638+
)
639+
response
640+
end
641+
642+
##
643+
# @!method delete_object(collection_id:, object:)
644+
# Delete an object.
645+
# Delete one object from a collection. A successful request deletes the training
646+
# data from all images that use the object.
647+
# @param collection_id [String] The identifier of the collection.
648+
# @param object [String] The name of the object.
649+
# @return [nil]
650+
def delete_object(collection_id:, object:)
651+
raise ArgumentError.new("collection_id must be provided") if collection_id.nil?
652+
653+
raise ArgumentError.new("object must be provided") if object.nil?
654+
655+
headers = {
656+
}
657+
sdk_headers = Common.new.get_sdk_headers("watson_vision_combined", "V4", "delete_object")
658+
headers.merge!(sdk_headers)
659+
660+
params = {
661+
"version" => @version
662+
}
663+
664+
method_url = "/v4/collections/%s/objects/%s" % [ERB::Util.url_encode(collection_id), ERB::Util.url_encode(object)]
665+
666+
request(
667+
method: "DELETE",
668+
url: method_url,
669+
headers: headers,
670+
params: params,
671+
accept_json: true
672+
)
673+
nil
674+
end
675+
#########################
532676
# Training
533677
#########################
534678

@@ -660,7 +804,7 @@ def get_training_usage(start_time: nil, end_time: nil)
660804
# You associate a customer ID with data by passing the `X-Watson-Metadata` header
661805
# with a request that passes data. For more information about personal data and
662806
# customer IDs, see [Information
663-
# security](https://cloud.ibm.com/docs/services/visual-recognition?topic=visual-recognition-information-security).
807+
# security](https://cloud.ibm.com/docs/visual-recognition?topic=visual-recognition-information-security).
664808
# @param customer_id [String] The customer ID for which all data is to be deleted.
665809
# @return [nil]
666810
def delete_user_data(customer_id:)

0 commit comments

Comments
 (0)