lib/shiprocket_api/resources/base.rb in shiprocket_api-0.5.3 vs lib/shiprocket_api/resources/base.rb in shiprocket_api-0.6.0

- old
+ new

@@ -3,46 +3,45 @@ cattr_accessor :session self.connection_class = ShiprocketAPI::Connection self.include_root_in_json = false self.include_format_in_path = false - self.site = "https://apiv2.shiprocket.in" - self.connection.auth_type = :bearer + self.site = 'https://apiv2.shiprocket.in' + connection.auth_type = :bearer self.prefix = '/v1/external' self.session = nil class << self def create_session(email: ShiprocketAPI.config.email, password: ShiprocketAPI.config.password) self.session = Session.create(email: email, password: password) - self.connection.bearer_token = session.token + connection.bearer_token = session.token end - + def clear_session self.session = nil - self.connection.bearer_token = nil + connection.bearer_token = nil end def with_temp_session(email:, password:, &block) - raise ArgumentError, "A block must be given" unless block + raise ArgumentError, 'A block must be given' unless block create_session(email: email, password: password) yield clear_session end def set_prefix(prefix) ori_prefix = self.prefix self.prefix = prefix result = yield - self.prefix = ori_prefix result + ensure + self.prefix = ori_prefix end end def initialize(attributes = {}, persisted = false) - if defined?(self.class::DEFAULT_ATTRS) - attributes = self.class::DEFAULT_ATTRS.merge(attributes) - end + attributes = self.class::DEFAULT_ATTRS.merge(attributes) if defined?(self.class::DEFAULT_ATTRS) super end end -end \ No newline at end of file +end