Search code examples
ruby-on-rails-3.1twitterprivate-methods

Private method error using object.entities in Twitter API


I am getting the following error when trying to call tweet.entities in my twitter feed controller.

private method `entities' called for #Twitter::Status:0x94d4bf4

I have no methods called entities in the code, I even did a full file search to check.

I either need to rename the entities part of the object or somehow find where this so called private method is or circumnavigate it somehow. My method within my twitter_feeds controller is as follows:

  def hometimeline
@user = User.find(current_user.id)

tweets = @user.tweeting.user_timeline(count: '10', include_entities: true)


parsed_tweets = []
i = 0

tweets.each do |tweet| 

  more = Hash.new
  more['test'] = tweet
  internal_hash = Hash.new
  mappings = {"source" => "fixed"}

  another = more['test']

  boo = Array(tweet)


  #newhash = Hash[twee.map {|k, v| [mapping[k], v] }]
  #newhash = Hash[more.map {|k, v| [mappings[k], v] }]
  #newhash = Hash[tweet.map {|k, v| [mappings[k] || k, v] }]

  internal_hash['parsed_text'] = tweet.entities

  internal_hash['id'] = tweet.id
  internal_hash['raw_text'] = tweet.text

  internal_hash['name'] = tweet.user.name
  internal_hash['screen_name'] = tweet.user.screen_name
  internal_hash['user_id'] = tweet.user.id
  internal_hash['user_image_url'] = tweet.user.profile_image_url
  parsed_tweets << internal_hash
  i = i + 1
end

respond_to do |format|
  format.json { render json: parsed_tweets }
end

end

Essentially I am sending a set of parsed tweets to the client and want to achieve link wrapping etc. on the server.

Is there any way I can find where the code thinks this method is or is there a way to make it not private or ignore it so I can call tweet.entities.

EDIT: One extra point to note is that I did have an entity model and entities controller but have deleted them and still get this.

Thanks


Solution

  • Turns out this error is caused by the Twitter gem and they have methods for calling the entities object namely, tweet.urls, tweet.user_mentions etc. rather than tweet.entities.user_mentions as I would have thought.

    Docs are here http://rdoc.info/gems/twitter/Twitter/Tweet