Class: Blockmason::Link::ManagedSession

Inherits:
Object
  • Object
show all
Defined in:
lib/blockmason/link/managed_session.rb

Instance Method Summary collapse

Constructor Details

#initialize(session:) ⇒ ManagedSession

Returns a new instance of ManagedSession.



6
7
8
# File 'lib/blockmason/link/managed_session.rb', line 6

def initialize(session:)
  @session = session
end

Instance Method Details

#get(path, inputs) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/blockmason/link/managed_session.rb', line 23

def get(path, inputs)
  begin
    @session.get(path, inputs)
  rescue error
    if error["errors"].any? { |it| it['detail'] =~ /Authentication failed/ }
      @session = @session.refresh!
      @session.get(path, inputs)
    else
      raise error
    end
  end
end

#post(path, inputs) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/blockmason/link/managed_session.rb', line 10

def post(path, inputs)
  begin
    @session.post(path, inputs)
  rescue error
    if error["errors"].any? { |it| it['detail'] =~ /Authentication failed/ }
      @session = @session.refresh!
      @session.post(path, inputs)
    else
      raise error
    end
  end
end