Module: Tinify

Defined in:
lib/tinify.rb,
lib/tinify/error.rb,
lib/tinify/client.rb,
lib/tinify/result.rb,
lib/tinify/source.rb,
lib/tinify/version.rb,
lib/tinify/result_meta.rb

Defined Under Namespace

Classes: AccountError, Client, ClientError, ConnectionError, Error, Result, ResultMeta, ServerError, Source

Constant Summary collapse

VERSION =
"1.8.0"
@@mutex =
Mutex.new

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.app_identifier ⇒ Object

Returns the value of attribute app_identifier.



14
15
16
# File 'lib/tinify.rb', line 14

def app_identifier
  @app_identifier
end

.compression_count ⇒ Object

Returns the value of attribute compression_count.



16
17
18
# File 'lib/tinify.rb', line 16

def compression_count
  @compression_count
end

.key ⇒ Object

Returns the value of attribute key.



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

def key
  @key
end

.proxy ⇒ Object

Returns the value of attribute proxy.



15
16
17
# File 'lib/tinify.rb', line 15

def proxy
  @proxy
end

Class Method Details

.client ⇒ Object

Raises:



56
57
58
59
60
61
62
# File 'lib/tinify.rb', line 56

def client
  raise AccountError.new("Provide an API key with Tinify.key = ...") unless key
  return @client if @client
  @@mutex.synchronize do
    @client ||= Client.new(key, app_identifier, proxy).freeze
  end
end

.from_buffer(string) ⇒ Object



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

def from_buffer(string)
  Source.from_buffer(string)
end

.from_file(path) ⇒ Object



33
34
35
# File 'lib/tinify.rb', line 33

def from_file(path)
  Source.from_file(path)
end

.from_url(string) ⇒ Object



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

def from_url(string)
  Source.from_url(string)
end

.validate! ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/tinify.rb', line 45

def validate!
  client.request(:post, "/shrink")
rescue AccountError => err
  return true if err.status == 429
  raise err
rescue ClientError
  true
end