Sha256: e0fddafbc5b9dc1f656e8a49fd9b907411a1608776806080cfea16aa3bbcc341

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

require 'triviacrack/session'
require 'triviacrack/parsers/time_parser'

# Internal: This module is used to parse data returned from the Trivia Crack API
# into a ruby object that represents a Trivia Crack session.
module TriviaCrack
  module Parsers
    module SessionParser
      # Internal: Parses data returned from the Trivia Crack API to create a
      # TriviaCrack::Session object.
      #
      # raw_data  - A hash of the raw data returned by the Trivia Crack API.
      #
      # Examples
      #
      #   raw_data = get_raw_data_from_API
      #   ...
      #   session = TriviaCrack::Parsers::SessionParser.parse raw_data
      #
      # Returns a TriviaCrack::Session.
      def self.parse(raw_data)
        expiration = TimeParser.parse raw_data['session']['expirationTime']

        TriviaCrack::Session.new(
          session_id: raw_data['session']['session'],
          user_id: raw_data['id'],
          username: raw_data['username'],
          device_key: raw_data['session']['deviceKey'],
          expiration: expiration
        )
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
triviacrack-0.8.0 lib/triviacrack/parsers/session_parser.rb
triviacrack-0.7.0 lib/triviacrack/parsers/session_parser.rb