Class: PikaSdk::Client
- Inherits:
-
Object
- Object
- PikaSdk::Client
- Defined in:
- lib/pika_sdk/client.rb
Instance Method Summary collapse
- #generate_image_from_template(template_id, modifications, response_format = 'base64') ⇒ Object
-
#initialize(api_key) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(api_key) ⇒ Client
Returns a new instance of Client.
8 9 10 |
# File 'lib/pika_sdk/client.rb', line 8 def initialize(api_key) @api_key = api_key end |
Instance Method Details
#generate_image_from_template(template_id, modifications, response_format = 'base64') ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/pika_sdk/client.rb', line 12 def generate_image_from_template(template_id, modifications, response_format = 'base64') endpoint_url = "#{get_base_url()}/templates/#{template_id}/images" data = { "response_format" => response_format, "modifications" => modifications } response = HTTParty.post("#{endpoint_url}", body: data.to_json, headers: { 'Authorization' => "Bearer #{@api_key}", 'Content-Type' => 'application/json' } ) if response.code == 200 if response_format == "base_64" response_body = JSON.parse(response.body) return response_body else return response end else response_body = JSON.parse(response.body) raise Error.new(response_body["error"]) end end |