Class: Bannerbear::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/bannerbear/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(api_key = nil) ⇒ Client

Returns a new instance of Client.



5
6
7
# File 'lib/bannerbear/client.rb', line 5

def initialize(api_key = nil)
  @api_key = api_key || ENV["BANNERBEAR_API_KEY"]
end

Instance Method Details

#accountObject



9
10
11
# File 'lib/bannerbear/client.rb', line 9

def 
  get_response "/account"
end

#create_animated_gif(uid, payload = {}) ⇒ Object



91
92
93
# File 'lib/bannerbear/client.rb', line 91

def create_animated_gif(uid, payload = {})
  post_response "/animated_gifs", payload.slice(:frames, :input_media_url, :webhook_url, :metadata, :loop, :frame_durations, :fps).merge({:template => uid})
end

#create_collection(uid, payload = {}) ⇒ Object



63
64
65
# File 'lib/bannerbear/client.rb', line 63

def create_collection(uid, payload = {})
  post_response "/collections", payload.slice(:modifications, :webhook_url, :transparent, :metadata).merge({:template_set => uid}), payload[:synchronous]
end

#create_image(uid, payload = {}) ⇒ Object



31
32
33
# File 'lib/bannerbear/client.rb', line 31

def create_image(uid, payload = {})
	post_response "/images", payload.slice(:modifications, :webhook_url, :transparent, :render_pdf, :metadata).merge({:template => uid}), payload[:synchronous]
end

#create_movie(payload = {}) ⇒ Object



105
106
107
# File 'lib/bannerbear/client.rb', line 105

def create_movie(payload = {})
  post_response "/movies", payload.slice(:width, :height, :inputs, :transition, :soundtrack_url, :webhook_url, :metadata)
end

#create_screenshot(url, payload = {}) ⇒ Object



77
78
79
# File 'lib/bannerbear/client.rb', line 77

def create_screenshot(url, payload = {})
  post_response "/screenshots", payload.slice(:width, :height, :mobile, :webhook_url).merge({:url => url}), payload[:synchronous]
end

#create_video(uid, payload = {}) ⇒ Object



45
46
47
# File 'lib/bannerbear/client.rb', line 45

def create_video(uid, payload = {})
	post_response "/videos", payload.slice(:input_media_url, :modifications, :blur, :trim_to_length_in_seconds, :webhook_url, :metadata, :frames, :frame_durations, :create_gif_preview).merge({:video_template => uid})
end

#effectsObject



17
18
19
# File 'lib/bannerbear/client.rb', line 17

def effects
  get_response "/effects"
end

#fontsObject



13
14
15
# File 'lib/bannerbear/client.rb', line 13

def fonts
  get_response "/fonts"
end

#generate_signed_url(base_id, params = {}) ⇒ Object

Signed URLS



146
147
148
149
150
151
# File 'lib/bannerbear/client.rb', line 146

def generate_signed_url(base_id, params = {})
  base = "https://ondemand.bannerbear.com/signedurl/#{base_id}/image.jpg"
  query = "?modifications=" + Base64.urlsafe_encode64(params[:modifications].to_json, :padding => false)
  signature = OpenSSL::HMAC.hexdigest("SHA256", @api_key, base + query)
  return base + query + "&s=" + signature
end

#get_animated_gif(uid) ⇒ Object

Animated Gifs



83
84
85
# File 'lib/bannerbear/client.rb', line 83

def get_animated_gif(uid)
  get_response "/animated_gifs/#{uid}"
end

#get_collection(uid) ⇒ Object

Collections



55
56
57
# File 'lib/bannerbear/client.rb', line 55

def get_collection(uid)
  get_response "/collections/#{uid}"
end

#get_image(uid) ⇒ Object

Images



23
24
25
# File 'lib/bannerbear/client.rb', line 23

def get_image(uid)
	get_response "/images/#{uid}"
end

#get_movie(uid) ⇒ Object

Movies



97
98
99
# File 'lib/bannerbear/client.rb', line 97

def get_movie(uid)
  get_response "/movies/#{uid}"
end

#get_screenshot(uid) ⇒ Object

Screenshots



69
70
71
# File 'lib/bannerbear/client.rb', line 69

def get_screenshot(uid)
  get_response "/screenshots/#{uid}"
end

#get_template(uid, params = {}) ⇒ Object

Templates



112
113
114
# File 'lib/bannerbear/client.rb', line 112

def get_template(uid, params = {})
	get_response "/templates/#{uid}?#{URI.encode_www_form(params.slice(:extended))}"
end

#get_template_set(uid, params = {}) ⇒ Object

Template Sets



126
127
128
# File 'lib/bannerbear/client.rb', line 126

def get_template_set(uid, params = {})
	get_response "/template_sets/#{uid}?#{URI.encode_www_form(params.slice(:extended))}"
end

#get_video(uid) ⇒ Object

Videos



37
38
39
# File 'lib/bannerbear/client.rb', line 37

def get_video(uid)
	get_response "/videos/#{uid}"
end

#get_video_template(uid) ⇒ Object

Video Templates



136
137
138
# File 'lib/bannerbear/client.rb', line 136

def get_video_template(uid)
	get_response "/video_templates/#{uid}"
end

#list_animated_gifs(params = {}) ⇒ Object



87
88
89
# File 'lib/bannerbear/client.rb', line 87

def list_animated_gifs(params = {})
  get_response "/animated_gifs?#{URI.encode_www_form(params.slice(:page))}"
end

#list_collections(params = {}) ⇒ Object



59
60
61
# File 'lib/bannerbear/client.rb', line 59

def list_collections(params = {})
  get_response "/collections?#{URI.encode_www_form(params.slice(:page))}"
end

#list_images(params = {}) ⇒ Object



27
28
29
# File 'lib/bannerbear/client.rb', line 27

def list_images(params = {})
	get_response "/images?#{URI.encode_www_form(params.slice(:page, :limit))}"
end

#list_movies(params = {}) ⇒ Object



101
102
103
# File 'lib/bannerbear/client.rb', line 101

def list_movies(params = {})
  get_response "/movies?#{URI.encode_www_form(params.slice(:page))}"
end

#list_screenshots(params = {}) ⇒ Object



73
74
75
# File 'lib/bannerbear/client.rb', line 73

def list_screenshots(params = {})
  get_response "/screenshots?#{URI.encode_www_form(params.slice(:page))}"
end

#list_template_sets(params = {}) ⇒ Object



130
131
132
# File 'lib/bannerbear/client.rb', line 130

def list_template_sets(params = {})
	get_response "/template_sets?#{URI.encode_www_form(params.slice(:page, :extended))}"
end

#list_templates(params = {}) ⇒ Object



120
121
122
# File 'lib/bannerbear/client.rb', line 120

def list_templates(params = {})
	get_response "/templates?#{URI.encode_www_form(params.slice(:page, :tag, :limit, :name, :extended))}"
end

#list_video_templates(params = {}) ⇒ Object



140
141
142
# File 'lib/bannerbear/client.rb', line 140

def list_video_templates(params = {})
	get_response "/video_templates?#{URI.encode_www_form(params.slice(:page))}"
end

#list_videos(params = {}) ⇒ Object



41
42
43
# File 'lib/bannerbear/client.rb', line 41

def list_videos(params = {})
	get_response "/videos?#{URI.encode_www_form(params.slice(:page))}"
end

#update_template(uid, payload = {}) ⇒ Object



116
117
118
# File 'lib/bannerbear/client.rb', line 116

def update_template(uid, payload = {})
	patch_response "/templates/#{uid}", payload.slice(:name, :metadata, :tags)
end

#update_video(uid, payload = {}) ⇒ Object



49
50
51
# File 'lib/bannerbear/client.rb', line 49

def update_video(uid, payload = {})
  patch_response "/videos", payload.slice(:transcription, :approved).merge({:uid => uid})
end