bannerbear 0.1.1 → 0.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6e7af6c8f418095cdd98b0aca144cab75fa95911d926bef172d6c3850274e3c2
4
- data.tar.gz: f9931adef63f70a4c14b9ccee4c04b72be00c55c6c3b9ff16fbf64e764af31bf
3
+ metadata.gz: a63e7f3269afc788dea97a56ba271553cce7ae8ad8c605246321be788bbe5601
4
+ data.tar.gz: 68aa7455b8b4b71ddcf47ee0a59563d0a36f437670822680b9030ff0d41993a2
5
5
  SHA512:
6
- metadata.gz: 6bfc15b798a35ec932f76770f94ebb6c4bf74f3a52fd3de526301e9da9ace91476949f5f54b9b9fed1cade8d887c0cffc24c48180b6f10e62df3634ae114732d
7
- data.tar.gz: 358759f57e2873ae5f8e4c2c5a63a14a9d19144bd2234fc58219018f5882673ae3e73096c8913c3c4a74d92b1687b2f17fb45cee43e318678bb2a9a77137e5e7
6
+ metadata.gz: 2e4cc99311a703073a184a5211bf1c7c14b18df1062b03592558368e4d017d3f5e116f1c7948c63703300bb4af6cc6da5c0b15bdaf5942e4a1465624fc89c0af
7
+ data.tar.gz: a3017ce751ebfac3260bd7f174b61040ac2c0130a28f13ced336f7d77e0944507a195ef28aba8701d706fc4b6bef8d5b428a7ee3e51bfa716ef92fddf33af26a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bannerbear (0.1.0)
4
+ bannerbear (0.1.4)
5
5
  httparty
6
6
 
7
7
  GEM
@@ -12,7 +12,7 @@ GEM
12
12
  multi_xml (>= 0.5.2)
13
13
  mime-types (3.4.1)
14
14
  mime-types-data (~> 3.2015)
15
- mime-types-data (3.2021.1115)
15
+ mime-types-data (3.2022.0105)
16
16
  multi_xml (0.6.0)
17
17
  rake (12.3.3)
18
18
 
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Bannerbear
1
+ # Bannerbear Ruby
2
2
 
3
3
  Ruby wrapper for the [Bannerbear API](https://developers.bannerbear.com) - an image and video generation service.
4
4
 
@@ -20,7 +20,22 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- ### Create the Client
23
+ ### Table of Contents
24
+
25
+ - [Authentication](#authentication)
26
+ - [Account Info](#account-info)
27
+ - [Images](#images)
28
+ - [Videos](#videos)
29
+ - [Collections](#collections)
30
+ - [Animated Gifs](#animated-gifs)
31
+ - [Movies](#movies)
32
+ - [Screenshots](#screenshots)
33
+ - [Templates](#templates)
34
+ - [Template Sets](#template-sets)
35
+ - [Video Templates](#video-templates)
36
+ - [Signed URLs](#signed-urls)
37
+
38
+ ### Authentication
24
39
 
25
40
  Get the API key for your project in Bannerbear and create a client.
26
41
 
@@ -34,7 +49,7 @@ Alternatively you can place your API key in an ENV variable named `BANNERBEAR_AP
34
49
  bb = Bannerbear::Client.new
35
50
  ```
36
51
 
37
- ### Get Account Info
52
+ ### Account Info
38
53
 
39
54
  Return info about the Account / Project associated with this API key.
40
55
 
@@ -42,7 +57,9 @@ Return info about the Account / Project associated with this API key.
42
57
  bb.account
43
58
  ```
44
59
 
45
- ### Create an Image
60
+ ### Images
61
+
62
+ #### Create an Image
46
63
 
47
64
  To create an image you reference a template uid and a list of modifications. The default is async generation meaning the API will respond with a `pending` status and you can use `get_image` to retrieve the final image.
48
65
 
@@ -79,21 +96,22 @@ bb.create_image("template uid",
79
96
  )
80
97
  ```
81
98
 
82
- #### Options
99
+ ##### Options
83
100
 
84
101
  - `modifications`: an array of [modifications](https://developers.bannerbear.com/#post-v2-images) you would like to make (`array`)
85
102
  - `webhook_url`: a webhook url to post the final image object to (`string`)
86
103
  - `transparent`: render image with a transparent background (`boolean`)
104
+ - `synchronous`: generate the image synchronously (`boolean`)
87
105
  - `render_pdf`: render a PDF in addition to an image (`boolean`)
88
106
  - `metadata`: include any metadata to reference at a later point (`string`)
89
107
 
90
- ### Get an Image
108
+ #### Get an Image
91
109
 
92
110
  ```ruby
93
111
  bb.get_image("image uid")
94
112
  ```
95
113
 
96
- ### List all Images
114
+ #### List all Images
97
115
 
98
116
  ```ruby
99
117
  bb.list_images
@@ -103,12 +121,14 @@ bb.list_images
103
121
  bb.list_images(:page => 10)
104
122
  ```
105
123
 
106
- #### Options
124
+ ##### Options
107
125
 
108
126
  - `page`: pagination (`integer`)
109
127
  - `limit`: return n images per page (`integer`)
110
128
 
111
- ### Create a Video
129
+ ### Videos
130
+
131
+ #### Create a Video
112
132
 
113
133
  To create a video you reference a *video template uid*, an input media and a list of modifications. Videos are created async - use `get_video` to retrieve the final video.
114
134
 
@@ -124,7 +144,7 @@ bb.create_video("video template uid",
124
144
  )
125
145
  ```
126
146
 
127
- #### Options
147
+ ##### Options
128
148
 
129
149
  - `input_media_url`: a url to a publicly available video file you want to import (`string`)
130
150
  - `modifications`: an array of modifications you would like to make to the video overlay (`array`)
@@ -139,41 +159,204 @@ If your video is using the "Multi Overlay" build pack then you can pass in a set
139
159
  - `frames`: an array of sets of `modifications` (`array`)
140
160
  - `frame_durations`: specify the duration of each frame (`array`)
141
161
 
142
- ### Get a Video
162
+ #### Get a Video
143
163
 
144
164
  ```ruby
145
165
  bb.get_video("video uid")
146
166
  ```
147
167
 
148
- ### List all Videos
168
+ #### Update a Video
169
+
170
+ Updating a video is only relevant under specific conditions. Video Templates using the build pack `transcribe` and set to manual approval (via the dashboard) will result in videos that enter a `pending_approval` status. At this point, the video is waiting for approval before final rendering. The purpose of this is to check the transcript is correct, make any changes, and approve the video for rendering.
171
+
172
+ ```ruby
173
+ bb.update_video("video uid",
174
+ :approved => true,
175
+ :transcription => [
176
+ "This is a new transcription",
177
+ "It must contain the same number of lines",
178
+ "As the previous transcription"
179
+ ]
180
+ )
181
+ ```
182
+
183
+ ##### Options
184
+
185
+ - `approved`: approve the video for rendering (`boolean`)
186
+ - `transcription`: an array of strings to represent the new transcription (will overwrite the existing one) (`array`)
187
+
188
+ #### List all Videos
149
189
 
150
190
  ```ruby
151
191
  bb.list_videos
152
192
  ```
153
193
 
154
- #### Options
194
+ ##### Options
155
195
 
156
196
  - `page`: pagination (`integer`)
157
197
 
158
- ### Templates, Template Sets and Video Templates
198
+ ### Collections
199
+
200
+ Create multiple images in one API request.
201
+
202
+ ```ruby
203
+ bb.get_collection("collection uid")
204
+ bb.list_collections(:page => 3)
205
+ bb.create_collection("template set uid",
206
+ :synchronous => true,
207
+ :modifications => [
208
+ {
209
+ :name => "headline",
210
+ :text => "Hello World!"
211
+ }
212
+ ]
213
+ )
214
+ ```
215
+
216
+ ##### Options for `create_collection`
217
+
218
+ - `modifications`: an array of [modifications](https://developers.bannerbear.com/#post-v2-images) you would like to make (`array`)
219
+ - `webhook_url`: a webhook url to post the final collection object to (`string`)
220
+ - `transparent`: render image with a transparent background (`boolean`)
221
+ - `synchronous`: generate the images synchronously (`boolean`)
222
+ - `metadata`: include any metadata to reference at a later point (`string`)
223
+
224
+ ### Animated Gifs
225
+
226
+ Create a slideshow style gif
227
+
228
+ ```ruby
229
+ bb.get_animated_gif("gif uid")
230
+ bb.list_animated_gifs(:page => 3)
231
+ bb.create_animated_gif("template uid",
232
+ :frames => [
233
+ [ #frame 1 starts here
234
+ {
235
+ :name => "layer1",
236
+ :text => "This is my text"
237
+ },
238
+ {
239
+ :name => "photo",
240
+ :image_url => "https://www.pathtomyphoto.com/1.jpg"
241
+ }
242
+ ],
243
+ [ #frame 2 starts here
244
+ {
245
+ :name => "layer1",
246
+ :text => "This is my follow up text"
247
+ },
248
+ {
249
+ :name => "photo",
250
+ :image_url => "https://www.pathtomyphoto.com/2.jpg"
251
+ }
252
+ ]
253
+ ]
254
+ )
255
+ ```
256
+
257
+ ##### Options for `create_animated_gif`
258
+
259
+ - `frames`: an array of arrays of [modifications](https://developers.bannerbear.com/#post-v2-images) you would like to make (`array`)
260
+ - `frame_durations`: an array of times (in seconds) to show each frame (`array`)
261
+ - `input_media_url`: optionally import an external video file to use as part of the gif
262
+ - `fps`: frames per second e.g. 1 (`integer`)
263
+ - `loop`: whether to loop or not (`boolean`)
264
+ - `webhook_url`: a webhook url to post the final gif object to (`string`)
265
+ - `metadata`: include any metadata to reference at a later point (`string`)
266
+
267
+ ### Movies
268
+
269
+ Assemble video clips or still images into a single movie with transitions.
270
+
271
+ ```ruby
272
+ bb.get_movie("movie uid")
273
+ bb.list_movies(:page => 3)
274
+ bb.create_movie(:width => 800, :height => 800, :transition => "pixelize", :inputs => [
275
+ {
276
+ :asset_url => "https://images.unsplash.com/photo-1635910160061-4b688344bd20?w=500&q=60"
277
+ },
278
+ {
279
+ :asset_url => "https://i.imgur.com/fH7a5dO.png"
280
+ }
281
+ ])
282
+ ```
283
+
284
+ ##### Options for `create_movie`
285
+
286
+ - `width`: the movie width in pixels (`integer`)
287
+ - `height`: the movie height in pixels (`integer`)
288
+ - `transition`: the transition style: fade, pixelize, slidedown, slideright, slideup, slideleft (`string`)
289
+ - `inputs`: a list of [inputs](https://developers.bannerbear.com/#post-v2-movies) (`array`)
290
+ - `webhook_url`: a webhook url to post the final movie object to (`string`)
291
+ - `metadata`: include any metadata to reference at a later point (`string`)
159
292
 
160
- Various operations exist for handling templates.
293
+
294
+ ### Screenshots
295
+
296
+ Take screenshots of websites.
297
+
298
+ ```ruby
299
+ bb.get_screenshot("screenshot uid")
300
+ bb.list_screenshots(:page => 3)
301
+ bb.create_screenshot("https://www.bannerbear.com/",
302
+ :synchronous => true,
303
+ :width => 1000
304
+ )
305
+ ```
306
+
307
+ ##### Options for `create_screenshot`
308
+
309
+ - `width`: the desired screenshot width in pixels (`integer`)
310
+ - `height`: the desired screenshot height in pixels (`integer`)
311
+ - `synchronous`: generate the screenshot synchronously (`boolean`)
312
+ - `mobile`: use a mobile user agent
313
+ - `webhook_url`: a webhook url to post the final screenshot object to (`string`)
314
+
315
+ ### Templates
161
316
 
162
317
  ```ruby
163
- # Templates
164
318
  bb.get_template("template uid")
165
319
  bb.update_template("template uid", :name => "New Template Name", :tags => ["portrait", "instagram"])
166
320
  bb.list_templates(:page => 2, :tag => "portrait")
321
+ ```
167
322
 
168
- # Template Sets
323
+ ### Template Sets
324
+
325
+ ```ruby
169
326
  bb.get_template_set("template set uid")
170
327
  bb.list_template_sets(:page => 2)
328
+ ```
171
329
 
172
- # Video Templates
330
+ ### Video Templates
331
+
332
+ ```ruby
173
333
  bb.get_video_template("video template uid")
174
334
  bb.list_video_templates(:page => 2)
175
335
  ```
176
336
 
337
+ ### Signed URLs
338
+
339
+ This gem also includes a convenient utility for generating signed urls. Authenticate as above, then:
340
+
341
+ ```ruby
342
+ bb.generate_signed_url("base uid", :modifications => [])
343
+
344
+ # example
345
+ bb.generate_signed_url("A89wavQyY3Bebk3djP",
346
+ :modifications => [
347
+ {
348
+ :name => "country",
349
+ :text => "testing!"
350
+ },
351
+ {
352
+ :name => "photo",
353
+ :image_url => "https://images.unsplash.com/photo-1638356435991-4c79b00ebef3?w=764&q=80"
354
+ }
355
+ ]
356
+ )
357
+ # https://ondemand.bannerbear.com/signedurl/A89wavQyY3Bebk3djP/image.jpg?modifications=W3sibmFtZSI6ImNvdW50cnkiLCJ0ZXh0IjoidGVzdGluZyEifSx7Im5hbWUiOiJwaG90byIsImltYWdlX3VybCI6Imh0dHBzOi8vaW1hZ2VzLnVuc3BsYXNoLmNvbS9waG90by0xNjM4MzU2NDM1OTkxLTRjNzliMDBlYmVmMz93PTc2NCZxPTgwIn1d&s=40e7c9d4902b86ea83e0c400e57d7cc580534fd527e234d40a0c7ace589a16eb
358
+ ```
359
+
177
360
  ## Contributing
178
361
 
179
362
  Bug reports and pull requests are welcome on GitHub at https://github.com/yongfook/bannerbear-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/yongfook/bannerbear-ruby/blob/master/CODE_OF_CONDUCT.md).
@@ -109,8 +109,8 @@ module Bannerbear
109
109
 
110
110
  # Templates
111
111
 
112
- def get_template(uid)
113
- get_response "/templates/#{uid}"
112
+ def get_template(uid, params = {})
113
+ get_response "/templates/#{uid}?#{URI.encode_www_form(params.slice(:extended))}"
114
114
  end
115
115
 
116
116
  def update_template(uid, payload = {})
@@ -118,17 +118,17 @@ module Bannerbear
118
118
  end
119
119
 
120
120
  def list_templates(params = {})
121
- get_response "/templates?#{URI.encode_www_form(params.slice(:page, :tag, :limit, :name))}"
121
+ get_response "/templates?#{URI.encode_www_form(params.slice(:page, :tag, :limit, :name, :extended))}"
122
122
  end
123
123
 
124
124
  # Template Sets
125
125
 
126
- def get_template_set(uid)
127
- get_response "/template_sets/#{uid}"
126
+ def get_template_set(uid, params = {})
127
+ get_response "/template_sets/#{uid}?#{URI.encode_www_form(params.slice(:extended))}"
128
128
  end
129
129
 
130
130
  def list_template_sets(params = {})
131
- get_response "/template_sets?#{URI.encode_www_form(params.slice(:page))}"
131
+ get_response "/template_sets?#{URI.encode_www_form(params.slice(:page, :extended))}"
132
132
  end
133
133
 
134
134
  # Video Templates
@@ -141,7 +141,14 @@ module Bannerbear
141
141
  get_response "/video_templates?#{URI.encode_www_form(params.slice(:page))}"
142
142
  end
143
143
 
144
+ # Signed URLS
144
145
 
146
+ def generate_signed_url(base_id, params = {})
147
+ base = "https://ondemand.bannerbear.com/signedurl/#{base_id}/image.jpg"
148
+ query = "?modifications=" + Base64.urlsafe_encode64(params[:modifications].to_json, :padding => false)
149
+ signature = OpenSSL::HMAC.hexdigest("SHA256", @api_key, base + query)
150
+ return base + query + "&s=" + signature
151
+ end
145
152
 
146
153
 
147
154
  private
@@ -151,7 +158,9 @@ module Bannerbear
151
158
 
152
159
  def get_response(url)
153
160
  response = HTTParty.get("#{BB_API_ENDPOINT}#{url}", timeout: 3, headers: { 'Authorization' => "Bearer #{@api_key}" })
154
- JSON.parse(response.body)
161
+ body = JSON.parse(response.body)
162
+ return {"error" => body['message'], "code" => response.code} if response.code >= 400
163
+ return body
155
164
  end
156
165
 
157
166
  def patch_response(url, payload)
@@ -163,7 +172,9 @@ module Bannerbear
163
172
  'Content-Type' => 'application/json'
164
173
  }
165
174
  )
166
- JSON.parse(response.body)
175
+ body = JSON.parse(response.body)
176
+ return {"error" => body['message'], "code" => response.code} if response.code >= 400
177
+ return body
167
178
  end
168
179
 
169
180
  def post_response(url, payload, sync = false)
@@ -182,7 +193,7 @@ module Bannerbear
182
193
  }
183
194
  )
184
195
  body = JSON.parse(response.body)
185
- return {"error" => body['message']} if response.code >= 400
196
+ return {"error" => body['message'], "code" => response.code} if response.code >= 400
186
197
  return body
187
198
  end
188
199
 
@@ -1,3 +1,3 @@
1
1
  module Bannerbear
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.4"
3
3
  end
data/lib/bannerbear.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  require "httparty"
2
+ require "openssl"
3
+ require "base64"
2
4
  require "bannerbear/version"
3
5
  require "bannerbear/client"
4
6
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bannerbear
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Yongfook
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-12-01 00:00:00.000000000 Z
11
+ date: 2022-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty