Class: Transmission::Model::Session

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

Defined Under Namespace

Classes: SessionError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session_object, connector) ⇒ Session

Returns a new instance of Session.



8
9
10
11
# File 'lib/transmission/model/session.rb', line 8

def initialize(session_object, connector)
  @attributes = session_object
  @connector = connector
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *args) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/transmission/model/session.rb', line 22

def method_missing(symbol, *args)
  string = symbol.to_s
  if string[-1] == '='
    string = string[0..-2]
    key = Transmission::Arguments::SessionSet.real_key string
    return @attributes[key] = args.first if !!key
  else
    key = Transmission::Fields::SessionGet.real_key string
    return @attributes[key] if !!key
  end
  super
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



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

def attributes
  @attributes
end

#connectorObject

Returns the value of attribute connector.



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

def connector
  @connector
end

Class Method Details

.connectorObject



42
43
44
# File 'lib/transmission/model/session.rb', line 42

def connector
  Transmission::Config.get_connector
end

.get(options = {}) ⇒ Object



36
37
38
39
40
# File 'lib/transmission/model/session.rb', line 36

def get(options = {})
  rpc = options[:connector] || connector
  body = rpc.get_session options[:fields]
  Session.new body, rpc
end

Instance Method Details

#save!Object



13
14
15
16
# File 'lib/transmission/model/session.rb', line 13

def save!
  filtered = Transmission::Arguments::SessionSet.filter @attributes
  connector.set_session filtered
end

#to_jsonObject



18
19
20
# File 'lib/transmission/model/session.rb', line 18

def to_json
  @attributes
end