Class: ShortPixel::Client
- Inherits:
-
Object
- Object
- ShortPixel::Client
- Defined in:
- lib/shortpixel/client.rb
Constant Summary collapse
- BASE_URL =
'https://api.shortpixel.com/v2/'
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
Instance Method Summary collapse
- #connection ⇒ Object
-
#initialize(api_key:, adapter: Faraday.default_adapter, stubs: nil) ⇒ Client
constructor
A new instance of Client.
- #post_reducer ⇒ Object
-
#reducer ⇒ Object
pngs = [“”] reducer = client.reducer.info(lossy: 1, urllist: pngs) result = reducer.results.first result.lossy_url result.lossy_size.
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
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
12 13 14 |
# File 'lib/shortpixel/client.rb', line 12 def adapter @adapter end |
#api_key ⇒ Object (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
#connection ⇒ Object
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_reducer ⇒ Object
20 21 22 |
# File 'lib/shortpixel/client.rb', line 20 def post_reducer PostReducerResource.new(self) end |
#reducer ⇒ Object
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 |