lib/shiprocket_api/resources/base.rb in shiprocket_api-0.2.0 vs lib/shiprocket_api/resources/base.rb in shiprocket_api-0.3.0
- old
+ new
@@ -19,9 +19,17 @@
def clear_session
self.session = nil
self.connection.bearer_token = nil
end
+ def with_temp_session(email:, password:, &block)
+ raise ArgumentError, "A block must be given" unless block
+
+ create_session(email: email, password: password)
+ yield
+ clear_session
+ end
+
def set_resource(resource)
ori_prefix = self.prefix
self.prefix = self.prefix.split("/")[0..-2].append(resource).join("/")
result = yield
self.prefix = ori_prefix
\ No newline at end of file