Created
September 19, 2010 01:46
-
-
Save ajturner/586266 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Arel | |
class TwitterArray | |
include Relation | |
attr_reader :array, :attribute_names_and_types | |
include Recursion::BaseCase | |
ATTR_MAP = { | |
:twitter_name => Attributes::String, | |
:id => Attributes::Integer, | |
:text => Attributes::String, | |
:from_user => Attributes::String, | |
:from_user_id => Attributes::Integer, | |
:to_user => Attributes::String, | |
:to_user_id => Attributes::Integer, | |
:profile_image_url => Attributes::String, | |
:created_at => Attributes::String | |
} | |
# Creates a new Twitter client array | |
# | |
# @params twitter_auth: { | |
# :type=>:oauth, | |
# :consumer_key=>'SOMECONSUMERKEYFROMTWITTER', :consumer_secret=>'SOMECONSUMERTOKENFROMTWITTER', | |
# :token=>'ACCESSTOKENACQUIREDONUSERSBEHALF', :token_secret=>'SUPERSECRETACCESSTOKENSECRET' | |
# } | |
def initialize(username, twitter_auth = nil) | |
@username = username | |
@auth = twitter_auth | |
@array = [] | |
@attribute_names_and_types = ATTR_MAP.collect do |key, value| | |
[key,value] | |
end | |
@engine = nil | |
@attributes = nil | |
end | |
def engine | |
@engine ||= Memory::Engine.new | |
end | |
def attributes | |
@attributes ||= begin | |
attrs = @attribute_names_and_types.collect do |attribute, type| | |
attribute = type.new(self, attribute) if Symbol === attribute | |
attribute | |
end | |
Header.new(attrs) | |
end | |
end | |
def format(attribute, value) | |
value | |
end | |
def create_from_twitter(status_data) | |
ATTR_MAP.collect { |k,v| status_data.send(k) } | |
end | |
def eval | |
# Twitter from Nunemaker | |
Twitter::Search.new.from(@username).fetch().results.collect do |s| | |
Row.new(self, create_from_twitter(s)) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment