Class: GenerateImage::Response
- Inherits:
-
Object
- Object
- GenerateImage::Response
- Defined in:
- lib/generate_image/response.rb
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
Instance Method Summary collapse
- #b64 ⇒ Object
- #created ⇒ Object
- #data_items ⇒ Object
- #images ⇒ Object
-
#initialize(parsed_json, model: nil) ⇒ Response
constructor
A new instance of Response.
- #to_h ⇒ Object
- #url ⇒ Object
- #usage ⇒ Object
Constructor Details
#initialize(parsed_json, model: nil) ⇒ Response
Returns a new instance of Response.
7 8 9 10 |
# File 'lib/generate_image/response.rb', line 7 def initialize(parsed_json, model: nil) @raw = parsed_json @model = model end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
5 6 7 |
# File 'lib/generate_image/response.rb', line 5 def model @model end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
5 6 7 |
# File 'lib/generate_image/response.rb', line 5 def raw @raw end |
Instance Method Details
#b64 ⇒ Object
32 33 34 |
# File 'lib/generate_image/response.rb', line 32 def b64 data_items.find { |d| d["b64_json"] }&.fetch("b64_json", nil) end |
#created ⇒ Object
40 41 42 |
# File 'lib/generate_image/response.rb', line 40 def created raw["created"] end |
#data_items ⇒ Object
12 13 14 |
# File 'lib/generate_image/response.rb', line 12 def data_items Array(raw["data"]) end |
#images ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/generate_image/response.rb', line 16 def images data_items.map do |item| if item["url"] { url: item["url"] } elsif item["b64_json"] { b64_json: item["b64_json"] } else {} end end end |
#to_h ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/generate_image/response.rb', line 44 def to_h if url { image_url: url } elsif b64 { image_base64: b64 } else {} end end |
#url ⇒ Object
28 29 30 |
# File 'lib/generate_image/response.rb', line 28 def url data_items.find { |d| d["url"] }&.fetch("url", nil) end |
#usage ⇒ Object
36 37 38 |
# File 'lib/generate_image/response.rb', line 36 def usage raw["usage"] end |