Module: ShopExpress::Connection
- Included in:
- Base
- Defined in:
- lib/shop_express/connection.rb
Overview
Module for check connection
Constant Summary collapse
- ERROR =
{ 'status' => 'HTTP_ERROR', 'response' => { 'message' => 'UNKNOWN SERVER ERROR' } }.freeze
Instance Method Summary collapse
- #connection(shop_express) ⇒ Object
- #mixin_token!(shop_express, body) ⇒ Object
- #post(shop_express:, url:, body:, add_token: false) ⇒ Object
Instance Method Details
#connection(shop_express) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/shop_express/connection.rb', line 17 def connection(shop_express) @connection ||= Faraday.new(url: shop_express.url) do |faraday| faraday.request :json faraday.response :raise_error faraday.response :json faraday.adapter Faraday.default_adapter end end |
#mixin_token!(shop_express, body) ⇒ Object
26 27 28 29 |
# File 'lib/shop_express/connection.rb', line 26 def mixin_token!(shop_express, body) shop_express.refresh_token! unless shop_express.token_valid? body[:token] = shop_express.token end |
#post(shop_express:, url:, body:, add_token: false) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/shop_express/connection.rb', line 9 def post(shop_express:, url:, body:, add_token: false) mixin_token!(shop_express, body) if add_token connection(shop_express).post(url, body).body rescue Faraday::Error => e Rails.logger.error(e) if defined?(Rails) ERROR end |