Class: Datarobot::AiApi::Dataset
- Inherits:
-
Object
- Object
- Datarobot::AiApi::Dataset
- Includes:
- Refreshable
- Defined in:
- lib/datarobot/ai_api/dataset.rb
Instance Attribute Summary collapse
-
#ai_id ⇒ Object
readonly
Returns the value of attribute ai_id.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#task ⇒ Object
readonly
Returns the value of attribute task.
Class Method Summary collapse
-
.all(limit: 50, offset: 0) ⇒ Datarobot::AiApi::Page(Datarobot::AiApi::Dataset)
Retrieves all datasets as a paginated resource.
-
.create_from_file(file_path) ⇒ Datarobot::AiApi::Dataset
Creates a dataset from the file at the given (local) path.
-
.create_from_url(url) ⇒ Datarobot::AiApi::Dataset
Creates a dataset from the file at the given (publicly accessible) url.
-
.delete(id) ⇒ nil
Deletes a dataset.
-
.find(id, &block) ⇒ Datarobot::AiApi::Dataset
Retrieves an dataset given an ID.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Dataset
constructor
Given a parsed response body from the API, will create a new Dataset object.
-
#set_from_options(options = {}) ⇒ void
Takes a response body from the API.
Methods included from Refreshable
Constructor Details
#initialize(options = {}) ⇒ Dataset
Given a parsed response body from the API, will create a new Dataset object
74 75 76 77 78 79 80 81 |
# File 'lib/datarobot/ai_api/dataset.rb', line 74 def initialize( = {}) # Suppresses warnings about uninitialized variables @ai_id = nil @name = nil @created_at = nil () end |
Instance Attribute Details
#ai_id ⇒ Object (readonly)
Returns the value of attribute ai_id.
6 7 8 |
# File 'lib/datarobot/ai_api/dataset.rb', line 6 def ai_id @ai_id end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
6 7 8 |
# File 'lib/datarobot/ai_api/dataset.rb', line 6 def created_at @created_at end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/datarobot/ai_api/dataset.rb', line 6 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/datarobot/ai_api/dataset.rb', line 5 def name @name end |
#task ⇒ Object (readonly)
Returns the value of attribute task.
6 7 8 |
# File 'lib/datarobot/ai_api/dataset.rb', line 6 def task @task end |
Class Method Details
.all(limit: 50, offset: 0) ⇒ Datarobot::AiApi::Page(Datarobot::AiApi::Dataset)
Retrieves all datasets as a paginated resource.
14 15 16 17 18 |
# File 'lib/datarobot/ai_api/dataset.rb', line 14 def self.all(limit: 50, offset: 0) Datarobot::AiApi.request_endpoint('/aiapi/datasets/', params: {limit: limit, offset: offset}) do |data| Datarobot::AiApi::Page.new(self, data) end end |
.create_from_file(file_path) ⇒ Datarobot::AiApi::Dataset
Creates a dataset from the file at the given (local) path
51 52 53 54 55 56 |
# File 'lib/datarobot/ai_api/dataset.rb', line 51 def self.create_from_file(file_path) Datarobot::AiApi.upload_to_endpoint('/aiapi/datasets/fileImports', file_path) do |data| task = Datarobot::AiApi::Task.new(data) task.wait_until_complete end end |
.create_from_url(url) ⇒ Datarobot::AiApi::Dataset
Creates a dataset from the file at the given (publicly accessible) url
63 64 65 66 67 68 69 70 71 |
# File 'lib/datarobot/ai_api/dataset.rb', line 63 def self.create_from_url(url) uri = URI.parse(url) name = File.basename(uri.path) Datarobot::AiApi.request_endpoint("/aiapi/datasets/urlImports/", method: "post", body: {url: url}) do |data| dataset = new(data) dataset.name = name dataset end end |
.delete(id) ⇒ nil
Deletes a dataset. Returns ‘nil` if the action was successful. Will raise an error if the action was unsuccessful
42 43 44 |
# File 'lib/datarobot/ai_api/dataset.rb', line 42 def self.delete(id) Datarobot::AiApi.request_endpoint("/aiapi/datasets/#{id}", method: "delete") end |
.find(id, &block) ⇒ Datarobot::AiApi::Dataset
Retrieves an dataset given an ID.
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/datarobot/ai_api/dataset.rb', line 25 def self.find(id, &block) raise Datarobot::AiApi::NotFoundError, "Cannot find Dataset with id: nil" if id.nil? Datarobot::AiApi.request_endpoint("/aiapi/datasets/#{id}") do |data| if block_given? yield data else self.new(data) end end end |
Instance Method Details
#set_from_options(options = {}) ⇒ void
This method returns an undefined value.
Takes a response body from the API. Will set all Dataset attributes from the response body
88 89 90 91 92 93 94 95 96 |
# File 'lib/datarobot/ai_api/dataset.rb', line 88 def ( = {}) # one-liner replacement for `stringify_keys` = .collect{|k,v| [k.to_s, v]}.to_h @created_at = .dig("createdOn") || @created_at @name = .dig("datasetName") || .dig("name") || @name @id = .dig("id") || .dig("datasetId") || @id @ai_id = .dig("aiId") || @ai_id end |