orshot 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +114 -76
- data/lib/orshot/client.rb +80 -0
- data/lib/orshot/constants.rb +1 -1
- data/lib/orshot/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 254db8a10f31a88b94717126e26b0368f9de4959436c4c96dcd53e3f8004b4e0
|
|
4
|
+
data.tar.gz: b34d8bf21f984e93ac7290871c489430fbc9559db1a7b21beaa9e3a76f78f52f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6dfb510c8392bb9b1ea170828d4e0e02f3cea1ce5782e1b85cde1512846383818bc30f7f7d3b45a20f8cd27dde3ccd13d8437afac47aa7b313ed29cec5f0a5f5
|
|
7
|
+
data.tar.gz: 66955622a4fd952e1d4aeb26ddd18c40e4e87672d7d3ad146ad7fb02e171eb6fff0fac5586be245840512223597884ee93cfb905f670e5207d3f9c52e44e74d9
|
data/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Orshot
|
|
1
|
+
# Orshot Ruby API SDK
|
|
2
2
|
|
|
3
3
|
View on Rubygems: rubygems.org/gems/orshot
|
|
4
4
|
|
|
@@ -27,116 +27,154 @@ If you don't have your API key, get one from [orshot.com](https://orshot.com/).
|
|
|
27
27
|
```ruby
|
|
28
28
|
require 'orshot'
|
|
29
29
|
|
|
30
|
-
client = Orshot::Client.new('
|
|
30
|
+
client = Orshot::Client.new('YOUR_ORSHOT_API_KEY')
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
## render_from_studio_template
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
response = client.render_from_template({'template_id' => 'open-graph-image-1', 'modifications' => {'title': 'From ruby sdk new'}, 'response_type' => 'base64', 'response_format' => 'png'})
|
|
37
|
-
puts response['data']
|
|
38
|
-
```
|
|
35
|
+
Render from a custom [Studio template](https://orshot.com/features/orshot-studio). Supports image, PDF, video generation and publishing to social accounts.
|
|
39
36
|
|
|
40
|
-
### Generate
|
|
37
|
+
### Generate Image
|
|
41
38
|
|
|
42
39
|
```ruby
|
|
43
|
-
response = client.
|
|
44
|
-
|
|
40
|
+
response = client.render_from_studio_template({
|
|
41
|
+
'template_id' => 1234,
|
|
42
|
+
'modifications' => {
|
|
43
|
+
'title' => 'Orshot Studio',
|
|
44
|
+
'description' => 'Generate images from custom templates',
|
|
45
|
+
},
|
|
46
|
+
'response' => { 'type' => 'url', 'format' => 'png', 'scale' => 2 },
|
|
47
|
+
})
|
|
45
48
|
```
|
|
46
49
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
### `Base64` response format
|
|
50
|
+
### Generate PDF
|
|
50
51
|
|
|
51
52
|
```ruby
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
response = client.render_from_studio_template({
|
|
54
|
+
'template_id' => 1234,
|
|
55
|
+
'modifications' => { 'title' => 'Invoice #1234' },
|
|
56
|
+
'response' => { 'type' => 'url', 'format' => 'pdf' },
|
|
57
|
+
'pdf_options' => {
|
|
58
|
+
'margin' => '20px',
|
|
59
|
+
'range_from' => 1,
|
|
60
|
+
'range_to' => 2,
|
|
61
|
+
'color_mode' => 'rgb',
|
|
62
|
+
'dpi' => 300,
|
|
63
|
+
},
|
|
64
|
+
})
|
|
58
65
|
```
|
|
59
66
|
|
|
60
|
-
|
|
67
|
+
### Generate Video
|
|
61
68
|
|
|
62
|
-
```
|
|
63
|
-
|
|
69
|
+
```ruby
|
|
70
|
+
response = client.render_from_studio_template({
|
|
71
|
+
'template_id' => 1234,
|
|
72
|
+
'modifications' => {
|
|
73
|
+
'videoElement' => 'https://example.com/custom-video.mp4',
|
|
74
|
+
'videoElement.trimStart' => 0,
|
|
75
|
+
'videoElement.trimEnd' => 10,
|
|
76
|
+
},
|
|
77
|
+
'response' => { 'type' => 'url', 'format' => 'mp4' },
|
|
78
|
+
'video_options' => { 'trim_start' => 0, 'trim_end' => 20, 'muted' => false, 'loop' => true },
|
|
79
|
+
})
|
|
64
80
|
```
|
|
65
81
|
|
|
66
|
-
###
|
|
82
|
+
### Publish to Social Accounts
|
|
67
83
|
|
|
68
84
|
```ruby
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
85
|
+
response = client.render_from_studio_template({
|
|
86
|
+
'template_id' => 1234,
|
|
87
|
+
'modifications' => { 'title' => 'Check out our latest update!' },
|
|
88
|
+
'response' => { 'type' => 'url', 'format' => 'png' },
|
|
89
|
+
'publish' => {
|
|
90
|
+
'accounts' => [1, 2],
|
|
91
|
+
'content' => 'Check out our latest design!',
|
|
92
|
+
},
|
|
93
|
+
})
|
|
94
|
+
# response['publish'] => [{'platform' => 'twitter', 'username' => 'acmehq', 'status' => 'published'}, ...]
|
|
78
95
|
```
|
|
79
96
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
### `URL` response format
|
|
97
|
+
### Schedule a Post
|
|
83
98
|
|
|
84
99
|
```ruby
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
100
|
+
response = client.render_from_studio_template({
|
|
101
|
+
'template_id' => 1234,
|
|
102
|
+
'modifications' => { 'title' => 'Scheduled post' },
|
|
103
|
+
'response' => { 'type' => 'url', 'format' => 'png' },
|
|
104
|
+
'publish' => {
|
|
105
|
+
'accounts' => [1],
|
|
106
|
+
'content' => 'This will be posted later!',
|
|
107
|
+
'schedule' => { 'scheduled_for' => '2026-04-01T10:00:00Z' },
|
|
108
|
+
'timezone' => 'America/New_York',
|
|
109
|
+
},
|
|
110
|
+
})
|
|
91
111
|
```
|
|
92
112
|
|
|
93
|
-
|
|
113
|
+
### Parameters
|
|
114
|
+
|
|
115
|
+
| key | required | description |
|
|
116
|
+
| -------------------------------- | -------- | ------------------------------------------------------------------------------ |
|
|
117
|
+
| `template_id` | Yes | ID of the Studio template (integer). |
|
|
118
|
+
| `modifications` | No | Hash of dynamic modifications for the template. |
|
|
119
|
+
| `response.type` | No | `base64`, `binary`, `url` (Defaults to `url`). |
|
|
120
|
+
| `response.format` | No | `png`, `webp`, `jpg`, `jpeg`, `pdf`, `mp4`, `webm`, `gif` (Defaults to `png`). |
|
|
121
|
+
| `response.scale` | No | Scale of the output (`1` = original, `2` = double). Defaults to `1`. |
|
|
122
|
+
| `response.include_pages` | No | Page numbers to render for multi-page templates (e.g. `[1, 3]`). |
|
|
123
|
+
| `response.file_name` | No | Custom file name (without extension). Works with `url` and `binary` types. |
|
|
124
|
+
| `pdf_options` | No | `{ margin, range_from, range_to, color_mode, dpi }` |
|
|
125
|
+
| `video_options` | No | `{ trim_start, trim_end, muted, loop }` |
|
|
126
|
+
| `publish.accounts` | No | Array of social account IDs from your workspace. |
|
|
127
|
+
| `publish.content` | No | Caption/text for the social post. |
|
|
128
|
+
| `publish.is_draft` | No | `true` to save as draft instead of publishing. |
|
|
129
|
+
| `publish.schedule.scheduled_for` | No | ISO date string to schedule the post. |
|
|
130
|
+
| `publish.timezone` | No | Timezone string (e.g. `"America/New_York"`). |
|
|
131
|
+
| `publish.platform_options` | No | Per-account options keyed by account ID. |
|
|
132
|
+
|
|
133
|
+
---
|
|
94
134
|
|
|
95
|
-
|
|
96
|
-
{"content"=>"https://storage.orshot.com/00632982-fd46-44ff-9a61-f52cdf1b8e62/images/nNSTZlMHFkr.png", "type"=>"url", "format"=>"png", "responseTime"=>3950.87}
|
|
97
|
-
```
|
|
135
|
+
## render_from_template
|
|
98
136
|
|
|
99
|
-
|
|
137
|
+
Render from a pre-built Orshot template.
|
|
100
138
|
|
|
101
139
|
```ruby
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
140
|
+
response = client.render_from_template({
|
|
141
|
+
'template_id' => 'open-graph-image-1',
|
|
142
|
+
'modifications' => { 'title' => 'Hello World' },
|
|
143
|
+
'response_type' => 'url',
|
|
144
|
+
'response_format' => 'png',
|
|
145
|
+
})
|
|
108
146
|
```
|
|
109
147
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
## render_from_template
|
|
117
|
-
|
|
118
|
-
Use this function to render an image/pdf. This method accepts a hash with the following keys
|
|
119
|
-
|
|
120
|
-
| key | required | description |
|
|
121
|
-
|----------|----------|-------------|
|
|
122
|
-
| `template_id` | Yes | ID of the template (`open-graph-image-1`, `tweet-image-1`, `beautify-screenshot-1`, ...) |
|
|
123
|
-
| `modifications` | Yes | Modifications for the selected template. |
|
|
124
|
-
| `response_type` | No | `base64`, `binary`, `url` (Defaults to `base64`). |
|
|
125
|
-
| `response_format` | No | `png`, `webp`, `pdf`, `jpg`, `jpeg` (Defaults to `png`). |
|
|
148
|
+
| key | required | description |
|
|
149
|
+
| ----------------- | -------- | ---------------------------------------------------------------- |
|
|
150
|
+
| `template_id` | Yes | ID of the template (`open-graph-image-1`, `tweet-image-1`, etc.) |
|
|
151
|
+
| `modifications` | Yes | Modifications for the selected template. |
|
|
152
|
+
| `response_type` | No | `base64`, `binary`, `url` (Defaults to `url`). |
|
|
153
|
+
| `response_format` | No | `png`, `webp`, `pdf`, `jpg`, `jpeg` (Defaults to `png`). |
|
|
126
154
|
|
|
127
155
|
For available templates and their modifications refer [Orshot Templates Page](https://orshot.com/templates)
|
|
128
156
|
|
|
129
157
|
## generate_signed_url
|
|
130
158
|
|
|
131
|
-
|
|
159
|
+
Generate a signed URL for a template.
|
|
160
|
+
|
|
161
|
+
```ruby
|
|
162
|
+
response = client.generate_signed_url({
|
|
163
|
+
'template_id' => 'open-graph-image-1',
|
|
164
|
+
'modifications' => { 'title' => 'Hello World' },
|
|
165
|
+
'expires_at' => 1744276943,
|
|
166
|
+
'render_type' => 'images',
|
|
167
|
+
'response_format' => 'png',
|
|
168
|
+
})
|
|
169
|
+
```
|
|
132
170
|
|
|
133
|
-
| key
|
|
134
|
-
|
|
135
|
-
| `template_id`
|
|
136
|
-
| `modifications`
|
|
137
|
-
| `expires_at`
|
|
138
|
-
| `render_type`
|
|
139
|
-
| `response_format` | No
|
|
171
|
+
| key | required | description |
|
|
172
|
+
| ----------------- | -------- | -------------------------------------------------------- |
|
|
173
|
+
| `template_id` | Yes | ID of the template. |
|
|
174
|
+
| `modifications` | Yes | Modifications for the selected template. |
|
|
175
|
+
| `expires_at` | Yes | Expires at in unix timestamp (Number). |
|
|
176
|
+
| `render_type` | No | `images`, `pdfs` (Defaults to `images`). |
|
|
177
|
+
| `response_format` | No | `png`, `webp`, `pdf`, `jpg`, `jpeg` (Defaults to `png`). |
|
|
140
178
|
|
|
141
179
|
## Development
|
|
142
180
|
|
data/lib/orshot/client.rb
CHANGED
|
@@ -53,6 +53,31 @@ module Orshot
|
|
|
53
53
|
end
|
|
54
54
|
end
|
|
55
55
|
|
|
56
|
+
def render_from_studio_template(options)
|
|
57
|
+
endpoint_url = "#{base_url}/studio/render"
|
|
58
|
+
|
|
59
|
+
response = HTTParty.post(endpoint_url.to_s,
|
|
60
|
+
body: prepare_studio_render_data(options).to_json,
|
|
61
|
+
headers: {
|
|
62
|
+
'Authorization' => "Bearer #{@api_key}",
|
|
63
|
+
'Content-Type' => 'application/json'
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
if response.code == 200
|
|
67
|
+
response_opts = options['response'] || {}
|
|
68
|
+
response_type = response_opts['type'] || DEFAULT_RESPONSE_TYPE
|
|
69
|
+
|
|
70
|
+
if %w[base64 url].include?(response_type)
|
|
71
|
+
JSON.parse(response.body)
|
|
72
|
+
else
|
|
73
|
+
response
|
|
74
|
+
end
|
|
75
|
+
else
|
|
76
|
+
response_body = JSON.parse(response.body)
|
|
77
|
+
raise Error, response_body['error']
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
56
81
|
private
|
|
57
82
|
|
|
58
83
|
def base_url
|
|
@@ -83,5 +108,60 @@ module Orshot
|
|
|
83
108
|
'source' => ORSHOT_SOURCE
|
|
84
109
|
}
|
|
85
110
|
end
|
|
111
|
+
|
|
112
|
+
def prepare_studio_render_data(options)
|
|
113
|
+
response_opts = options['response'] || {}
|
|
114
|
+
response_type = response_opts['type'] || DEFAULT_RESPONSE_TYPE
|
|
115
|
+
response_format = response_opts['format'] || DEFAULT_RESPONSE_FORMAT
|
|
116
|
+
|
|
117
|
+
data = {
|
|
118
|
+
'templateId' => options['template_id'],
|
|
119
|
+
'source' => ORSHOT_SOURCE,
|
|
120
|
+
'response' => {
|
|
121
|
+
'type' => response_type,
|
|
122
|
+
'format' => response_format
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
data['modifications'] = options['modifications'] if options['modifications']
|
|
127
|
+
|
|
128
|
+
data['response']['scale'] = response_opts['scale'] if response_opts.key?('scale')
|
|
129
|
+
data['response']['includePages'] = response_opts['include_pages'] if response_opts['include_pages']
|
|
130
|
+
data['response']['fileName'] = response_opts['file_name'] if response_opts['file_name']
|
|
131
|
+
|
|
132
|
+
if options['pdf_options']
|
|
133
|
+
pdf = options['pdf_options']
|
|
134
|
+
data['pdfOptions'] = {}
|
|
135
|
+
data['pdfOptions']['margin'] = pdf['margin'] if pdf.key?('margin')
|
|
136
|
+
data['pdfOptions']['rangeFrom'] = pdf['range_from'] if pdf.key?('range_from')
|
|
137
|
+
data['pdfOptions']['rangeTo'] = pdf['range_to'] if pdf.key?('range_to')
|
|
138
|
+
data['pdfOptions']['colorMode'] = pdf['color_mode'] if pdf.key?('color_mode')
|
|
139
|
+
data['pdfOptions']['dpi'] = pdf['dpi'] if pdf.key?('dpi')
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
if options['video_options']
|
|
143
|
+
vid = options['video_options']
|
|
144
|
+
data['videoOptions'] = {}
|
|
145
|
+
data['videoOptions']['trimStart'] = vid['trim_start'] if vid.key?('trim_start')
|
|
146
|
+
data['videoOptions']['trimEnd'] = vid['trim_end'] if vid.key?('trim_end')
|
|
147
|
+
data['videoOptions']['muted'] = vid['muted'] if vid.key?('muted')
|
|
148
|
+
data['videoOptions']['loop'] = vid['loop'] if vid.key?('loop')
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
if options['publish']
|
|
152
|
+
pub = options['publish']
|
|
153
|
+
data['publish'] = { 'accounts' => pub['accounts'] }
|
|
154
|
+
data['publish']['content'] = pub['content'] if pub.key?('content')
|
|
155
|
+
data['publish']['isDraft'] = pub['is_draft'] if pub.key?('is_draft')
|
|
156
|
+
data['publish']['timezone'] = pub['timezone'] if pub.key?('timezone')
|
|
157
|
+
data['publish']['platformOptions'] = pub['platform_options'] if pub.key?('platform_options')
|
|
158
|
+
if pub['schedule']
|
|
159
|
+
data['publish']['schedule'] = {}
|
|
160
|
+
data['publish']['schedule']['scheduledFor'] = pub['schedule']['scheduled_for'] if pub['schedule']['scheduled_for']
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
data
|
|
165
|
+
end
|
|
86
166
|
end
|
|
87
167
|
end
|
data/lib/orshot/constants.rb
CHANGED
data/lib/orshot/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: orshot
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- rishimohan
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-03-12 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -96,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
96
96
|
- !ruby/object:Gem::Version
|
|
97
97
|
version: '0'
|
|
98
98
|
requirements: []
|
|
99
|
-
rubygems_version: 3.
|
|
99
|
+
rubygems_version: 3.1.4
|
|
100
100
|
signing_key:
|
|
101
101
|
specification_version: 4
|
|
102
102
|
summary: Orshot API sdk for ruby
|