Class: Orshot::Client
- Inherits:
-
Object
- Object
- Orshot::Client
- Defined in:
- lib/orshot/client.rb
Overview
Client for interacting with the Orshot API
Instance Method Summary collapse
- #generate_signed_url(signed_url_options) ⇒ Object
-
#initialize(api_key) ⇒ Client
constructor
A new instance of Client.
- #render_from_template(render_options) ⇒ Object
Constructor Details
#initialize(api_key) ⇒ Client
Returns a new instance of Client.
12 13 14 |
# File 'lib/orshot/client.rb', line 12 def initialize(api_key) @api_key = api_key end |
Instance Method Details
#generate_signed_url(signed_url_options) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/orshot/client.rb', line 38 def generate_signed_url() endpoint_url = "#{base_url}/signed-url/create" response = HTTParty.post(endpoint_url.to_s, body: prepare_signed_url_data().to_json, headers: { 'Authorization' => "Bearer #{@api_key}", 'Content-Type' => 'application/json' }) if response.code == 200 JSON.parse(response.body) else response_body = JSON.parse(response.body) raise Error, response_body['error'] end end |
#render_from_template(render_options) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/orshot/client.rb', line 16 def render_from_template() endpoint_url = "#{base_url}/generate/images/#{render_options['template_id']}" response = HTTParty.post(endpoint_url.to_s, body: prepare_render_data().to_json, headers: { 'Authorization' => "Bearer #{@api_key}", 'Content-Type' => 'application/json' }) if response.code == 200 if %w[base64 url].include?(['response_format']) JSON.parse(response.body) else response end else response_body = JSON.parse(response.body) raise Error, response_body['error'] end end |