Sha256: d8db286b8a4e1450aeb11d0aeef4a6a25ca6379203ecf56de600380cd3613698

Contents?: true

Size: 1.68 KB

Versions: 3

Compression:

Stored size: 1.68 KB

Contents

require 'rexml/document'
require 'cgi'

module Soba
  class Mieruka

    class Session
      def initialize(params)
        @id = params['id']
        @title = params['title']
        @description = params['description']
        @creator_id = params['creator-id']
        @created_time = params['created-time']
        @deleted_time = params['deleted-time']
        @soba_session_id = params['soba-session-id']
        @scope = params['scope']
        @participants = params['participants']
      end

      attr_reader :id, :title, :description, :creator_id, :created_time, :deleted_time, :soba_session_id, :scope
    
      def self.create(http_res)
        doc = REXML::Document.new(http_res.body)
        ret = []
        doc.elements.each('session-list-response/session-list/session') do |elm|
          ret << Session.elm_to_session(elm)
        end
        ret
      end
    
      def self.create_from_session_element(elm)
        return Session.new(parse_session_elm(elm))
      end
    
   
      private
    
      def self.elm_to_session(elm)
        Session.new(parse_session_elm(elm))
      end

      ATTRS = ['id', 'title', 'description', 'creator-id', 'created-time', 'deleted-time', 'soba-session-id', 'scope']

      def self.parse_session_elm(elm)
        params = {}
        ATTRS.each do |a|
          begin
            params[a] = CGI.unescapeHTML(elm.elements[a].get_text.to_s )
          rescue
          end
        end
        params['participants'] = []
        elm.elements.each('participants/participant') do |partElm|
          params['participants'] << partElm.get_text.to_s
        end
        params
      end
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
soba-mieruka-0.0.4 lib/soba/mieruka/session.rb
soba-mieruka-0.0.3 lib/soba/mieruka/session.rb
soba-mieruka-0.0.2 lib/soba/mieruka/session.rb