Class: HtmlCssToImage::Image
- Inherits:
-
Object
- Object
- HtmlCssToImage::Image
- Defined in:
- lib/html_css_to_image/image.rb
Class Method Summary collapse
Class Method Details
.create(html: nil, css: nil) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/html_css_to_image/image.rb', line 4 def create(html: nil, css: nil) raise ArgumentError.new "HTML and CSS are both nil" if html.nil? && css.nil? response = connection.post(resources) do |request| request.body = { html: html.to_s, css: css.to_s }.to_json end raise Error.new( "Failed to create image: #{response.status} #{response.body} " ) if response.status != 200 json = JSON.parse(response.body, symbolize_names: true) Data::Image.from(json) end |
.delete(id) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/html_css_to_image/image.rb', line 20 def delete(id) raise ArgumentError.new "id is nil" if id.nil? response = connection.delete(resource(id)) raise Error.new( "Failed to delete image #{id}: #{response.status} #{response.body}" ) unless [202, 404].include? response.status end |