class Tinify::Source

Public Class Methods

from_buffer(string) click to toggle source
# File lib/tinify/source.rb, line 8
def from_buffer(string)
  response = Tinify.client.request(:post, "/shrink", string)
  new(response.headers["Location"]).freeze
end
from_file(path) click to toggle source
# File lib/tinify/source.rb, line 4
def from_file(path)
  from_buffer(File.open(path, "rb") { |file| file.read })
end
from_url(url) click to toggle source
# File lib/tinify/source.rb, line 13
def from_url(url)
  response = Tinify.client.request(:post, "/shrink", source: { url: url })
  new(response.headers["Location"]).freeze
end
new(url, commands = {}) click to toggle source
# File lib/tinify/source.rb, line 19
def initialize(url, commands = {})
  @url, @commands = url.freeze, commands.freeze
end

Public Instance Methods

preserve(*options) click to toggle source
# File lib/tinify/source.rb, line 23
def preserve(*options)
  options = Array(options).flatten
  self.class.new(@url, @commands.merge(preserve: options))
end
resize(options) click to toggle source
# File lib/tinify/source.rb, line 28
def resize(options)
  self.class.new(@url, @commands.merge(resize: options))
end
result() click to toggle source
# File lib/tinify/source.rb, line 37
def result
  response = Tinify.client.request(:get, @url, @commands)
  Result.new(response.headers, response.body).freeze
end
store(options) click to toggle source
# File lib/tinify/source.rb, line 32
def store(options)
  response = Tinify.client.request(:post, @url, @commands.merge(store: options))
  ResultMeta.new(response.headers).freeze
end
to_buffer() click to toggle source
# File lib/tinify/source.rb, line 46
def to_buffer
  result.to_buffer
end
to_file(path) click to toggle source
# File lib/tinify/source.rb, line 42
def to_file(path)
  result.to_file(path)
end