Sha256: f03f92449db8190f9d23b6e85c4d3ad388bd621818d8a1ae89684b3292115f2f

Contents?: true

Size: 1.22 KB

Versions: 22

Compression:

Stored size: 1.22 KB

Contents

# extract each record from request contents
# and stream it to output
class TwitterRequestParser < Wukong::Streamer::StructStreamer
  def process request
    request.parse do |obj|
      yield obj
    end
  end
end

# Incoming Request:
class TwitterFollowersRequest < Struct.new(
    :url, :scraped_at, :response_code, :response_message, :moreinfo, :contents)
  include Monkeyshines::ScrapeRequest
end

# Outgoing classes:
class TwitterUser < TypedStruct.new( :id, :scraped_at, :screen_name, :protected, :created_at,
    :followers_count, :friends_count, :statuses_count, :favourites_count )
end
class Tweet < TypedStruct.new(:id, :created_at, :twitter_user_id, :favorited, :truncated,
    :text, :source, :in_reply_to_user_id, :in_reply_to_status_id, :in_reply_to_screen_name)
end

# Parsing code:
TwitterFollowersRequest.class_eval do
  include Monkeyshines::RawJsonContents
  def parse &block
    parsed_contents.each do |user_tweet_hash|
      yield AFollowsB.new         user_tweet_hash["id"], self.moreinfo[:request_user_id]
      yield TwitterUser.from_hash user_tweet_hash
      yield Tweet.from_hash       user_tweet_hash
    end
  end
end

# This makes the script go.
Wukong::Script.new(TwitterRequestParser, TwitterRequestUniqer).run

Version data entries

22 entries across 22 versions & 2 rubygems

Version Path
mrflip-wukong-0.1.0 doc/code/parser_skeleton.rb
wukong-3.0.0.pre docpages/code/parser_skeleton.rb
wukong-2.0.2 docpages/code/parser_skeleton.rb
wukong-2.0.1 docpages/code/parser_skeleton.rb
wukong-2.0.0 docpages/code/parser_skeleton.rb
wukong-1.5.4 docpages/code/parser_skeleton.rb
wukong-1.5.3 docpages/code/parser_skeleton.rb
wukong-1.5.2 docpages/code/parser_skeleton.rb
wukong-1.5.1 docpages/code/parser_skeleton.rb
wukong-1.5.0 docpages/code/parser_skeleton.rb
wukong-1.4.12 docpages/code/parser_skeleton.rb
wukong-1.4.11 docpages/code/parser_skeleton.rb
wukong-1.4.10 docpages/code/parser_skeleton.rb
wukong-1.4.9 docpages/code/parser_skeleton.rb
wukong-1.4.7 docpages/code/parser_skeleton.rb
wukong-1.4.6 docpages/code/parser_skeleton.rb
wukong-1.4.5 docpages/code/parser_skeleton.rb
wukong-1.4.2 docpages/code/parser_skeleton.rb
wukong-1.4.1 docpages/code/parser_skeleton.rb
wukong-1.4.0 docpages/code/parser_skeleton.rb