Sha256: c29f4474a61bc32ee332678eab742ac8e8e7ca2d28acf99faba390b47dd3f5d7

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

require 'strongly_typed'

require 'date'

module Twitter
  # @note Inspired from twitter-4.5.0/lib/twitter/api/timelines.rb
  class Tweet
    # Class Methods
    class << self
      # Transform a json array into a collection of tweets
      #
      # @param [Array<Hash>] ary the json twitter results turned into an array of hashes
      #
      # @return [Array<Tweet>] the array of Tweets normalized objects
      #
      # @example
      #   ary = [{'created_at'=>'2013-02-28', 'id'=>3, 'text'=>'hello world'}]
      #   Twitter::Tweet.build_tweets(ary)
      #   #=> [#<Twitter::Tweet:0x07.. @id="3", @text="hello world", @created_at=#<DateTime: 2013-02-27>>]
      def build_tweets(ary)
        tweets = ary.map do |tweet|
          args = { id:         tweet['id'],
                   text:       tweet['text'],
                   created_at: tweet['created_at'] }
          new(args)
        end
      end
    end

    # Instance Methods
    include StronglyTyped::Model

    attribute :id, String
    attribute :text, String
    attribute :created_at, DateTime
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
twitter_anonymous_client-1.0.0.0 lib/twitter/tweet.rb