Sha256: 996a32f5b9d89691793949dca7a1a6a66f45a4fbe9ce41bf6dff157c7b4cb0c1
Contents?: true
Size: 1.31 KB
Versions: 1
Compression:
Stored size: 1.31 KB
Contents
# frozen_string_literal: true module Redd module Utilities # Unmarshals hashes into objects. class Unmarshaller # Contains the mapping from 'kind' strings to classes. # TODO: UserList type! MAPPING = { 't1' => Models::Comment, 't2' => Models::User, 't3' => Models::Submission, 't4' => Models::PrivateMessage, 't5' => Models::Subreddit, 'more' => Models::MoreComments, 'wikipage' => Models::WikiPage, 'Listing' => Models::Listing, 'LabeledMulti' => Models::Multireddit, 'LiveUpdate' => Models::LiveThread::LiveUpdate }.freeze def initialize(client) @client = client end def unmarshal(response) if response[:json] && response[:json][:data] if response[:json][:data][:things] Models::Listing.from_response(@client, children: response[:json][:data][:things]) else Models::BasicModel.new(@client, response[:json][:data]) end elsif MAPPING.key?(response[:kind]) MAPPING[response[:kind]].from_response(@client, response[:data]) else raise "unknown type to unmarshal: #{response[:kind].inspect}" end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
redd-0.8.1 | lib/redd/utilities/unmarshaller.rb |