Sha256: 2872f25c2c57cd7c690ea5ce48612a92cd9855af4f0da05cfe705699ad93255e

Contents?: true

Size: 910 Bytes

Versions: 4

Compression:

Stored size: 910 Bytes

Contents

require "twitter/creatable"
require "twitter/identity"

module Twitter
  module DirectMessages
    class WelcomeMessageRuleWrapper < Twitter::Identity
      attr_reader :created_timestamp

      object_attr_reader "DirectMessages::WelcomeMessageRule", :welcome_message_rule

      def initialize(attrs)
        attrs = read_from_response(attrs)

        attrs[:welcome_message_rule] = build_welcome_message_rule(attrs)
        super
      end

    private

      # @return [Hash] Normalized hash of attrs
      def read_from_response(attrs)
        return attrs[:welcome_message_rule] unless attrs[:welcome_message_rule].nil?

        attrs
      end

      def build_welcome_message_rule(attrs)
        {
          id: attrs[:id].to_i,
          created_at: Time.at(attrs[:created_timestamp].to_i / 1000.0),
          welcome_message_id: attrs[:welcome_message_id].to_i,
        }
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
twitter-8.1.0 lib/twitter/direct_messages/welcome_message_rule_wrapper.rb
twitter-8.0.1 lib/twitter/direct_messages/welcome_message_rule_wrapper.rb
twitter-8.0.0 lib/twitter/direct_messages/welcome_message_rule_wrapper.rb
twitter-8.0.0.rc.1 lib/twitter/direct_messages/welcome_message_rule_wrapper.rb