Class: Broker::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/broker/session.rb

Direct Known Subclasses

Export, Import

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opt = {}) ⇒ Session

Returns a new instance of Session.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/broker/session.rb', line 8

def initialize(opt={})
  @app = Broker.lookup_appname(opt[:app])
  @ext = Broker.options[:file_ext]

  credentials = {
    "username" => Broker.secrets['USERNAME'],
    "password" => Broker.secrets['PASSWORD'],
    "appname"  => @app,
    "org"      => Broker.secrets['ORG'],
    "apptoken" => opt[:token] || Broker.secrets['TOKEN']
  }
  
  begin
    @client = QuickBase::Client.init(credentials)
  rescue => e
    puts e.message
    #raise ArgumentError
  ensure
    # We successfully logged into quickbase, but supplied an invalid app name
    if @client && @client.errcode == "32"
      @client.signOut
      raise ArgumentError
    end
  end
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



6
7
8
# File 'lib/broker/session.rb', line 6

def app
  @app
end

#clientObject (readonly)

Returns the value of attribute client.



6
7
8
# File 'lib/broker/session.rb', line 6

def client
  @client
end

#extObject (readonly)

Returns the value of attribute ext.



6
7
8
# File 'lib/broker/session.rb', line 6

def ext
  @ext
end

Instance Method Details

#field_names(table) ⇒ Object



50
51
52
53
54
# File 'lib/broker/session.rb', line 50

def field_names(table)
  table &&= table.to_s
  db = Broker.tables[@app]['tables'][table]
  db && @client.getFieldNames(db, "", true)
end

#fire_eventObject

Raises:

  • (NotImplementedError)


34
35
36
# File 'lib/broker/session.rb', line 34

def fire_event
  raise NotImplementedError
end

#qb_ready?(name) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
45
46
47
48
# File 'lib/broker/session.rb', line 42

def qb_ready?(name)
  app_name = Broker.lookup_appname(name)
  unless app_name == @client.dbname
    return app_name && change_app(app_name, name)
  end
  true
end

#sign_outObject



38
39
40
# File 'lib/broker/session.rb', line 38

def sign_out
  @client.signOut
end