Sha256: 4cca7b9f6c27a2e6cce906120bd1d4bc79a4f31df61ba2922760393b12e64c44

Contents?: true

Size: 1.1 KB

Versions: 2

Compression:

Stored size: 1.1 KB

Contents

module Transmission
  module Model
    class Session
      class SessionError < StandardError; end

      attr_accessor :attributes, :connector

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

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

      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

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

        def connector
          Transmission::Config.get_connector
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
transmission-rpc-ruby-0.2.1 lib/transmission/model/session.rb
transmission-rpc-ruby-0.2.0 lib/transmission/model/session.rb