Class: ShortPixel::Client

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

Constant Summary collapse

BASE_URL =
'https://api.shortpixel.com/v2/'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key:, adapter: Faraday.default_adapter, stubs: nil) ⇒ Client

Returns a new instance of Client.



14
15
16
17
18
# File 'lib/shortpixel/client.rb', line 14

def initialize(api_key:, adapter: Faraday.default_adapter, stubs: nil)
  @api_key = api_key
  @adapter = adapter
  @stubs = stubs
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



12
13
14
# File 'lib/shortpixel/client.rb', line 12

def adapter
  @adapter
end

#api_keyObject (readonly)

Returns the value of attribute api_key.



12
13
14
# File 'lib/shortpixel/client.rb', line 12

def api_key
  @api_key
end

Instance Method Details

#connectionObject



33
34
35
36
37
38
39
40
41
42
# File 'lib/shortpixel/client.rb', line 33

def connection
  @connection ||= Faraday.new do |conn|
    conn.url_prefix = BASE_URL
    conn.request :json

    conn.response :json, content_type: "application/json"

    conn.adapter adapter, @stubs
  end
end

#post_reducerObject



20
21
22
# File 'lib/shortpixel/client.rb', line 20

def post_reducer
  PostReducerResource.new(self)
end

#reducerObject

pngs = [“”] reducer = client.reducer.info(lossy: 1, urllist: pngs) result = reducer.results.first result.lossy_url result.lossy_size



29
30
31
# File 'lib/shortpixel/client.rb', line 29

def reducer
  ReducerResource.new(self)
end