{"action":"created","comment":{"url":"https://api.github.com/repos/tradegecko/ruby-exercise/pulls/comments/54364044","id":54364044,"diff_hunk":"@@ -0,0 +1,160 @@\n+require 'twitter'\n+\n+class Tweet\n+\n+  def initialize()\n+    @my_quotes = Quote.all\n+    @client = Twitter::REST::Client.new do |config|\n+      config.consumer_key = ENV['consumer_key']\n+      config.consumer_secret = ENV['consumer_secret']\n+      config.access_token = ENV['access_token']\n+      config.access_token_secret = ENV['access_token_secret']\n+    end\n+  end\n+\n+\n+  # tweet with a specific content specified\n+  # Params:\n+  # +tweet_content+:: body of tweet\n+  # @return RequestStatus\n+  def tweet(tweet_content = \"Hola! Nothing to tweet about?\")\n+    response = @client.update(tweet_content)\n+    return RequestStatus.new(true, response.text)\n+\n+  rescue StandardError => e\n+    return RequestStatus.new(false, e.message)\n+  end\n+\n+\n+  # tweet hourly with a random quote from the database\n+  # Params:\n+  # @return RequestStatus\n+  def tweet_random_quote\n+    random_quote = generate_random_quote\n+    tweet random_quote\n+  end\n+\n+\n+  # respond to tweet by translating to a random language\n+  # Params:\n+  # @return RequestStatus\n+  def respond_tweet\n+    # get tweets to respond by retrieve last responded tweet in db and from twitter retrieve more recent tweets\n+    # drawback to possibly enhance: if manually answer via Twitter (not via this twitterbot, duplicate reply)\n+    tweets_to_respond = retrieve_tweets_from_mentions_timeline\n+\n+    # processing tweets_to_respond\n+    if tweets_to_respond.is_a? RequestStatus\n+      # check if return RequestStatus instead then return the status\n+      return tweets_to_respond\n+    elsif tweets_to_respond && tweets_to_respond.empty?\n+      # check if any recent tweets needs responding\n+      return RequestStatus.new(false, \"No tweet to respond!\")\n+    else\n+      # execute respond on retrieved tweets\n+      begin\n+        execute_respond_on_tweets tweets_to_respond\n+      rescue StandardError => e\n+        return RequestStatus.new(false, e.message)\n+      end\n+    end\n+\n+    return RequestStatus.new(true, \"responding to #{tweets_to_respond.size}\")\n+  end\n+\n+\n+  # helper private methods\n+  # generate tweet's body by translating - reuse translator\n+  def generate_respond_tweet x, translator\n+    # regex to remove first tag only\n+    text_removed_tags = x.text.sub(/(@\\w+)/, '')\n+\n+    # try generate 3 times, break if success\n+    translate_response = nil\n+    random_lang = nil\n+    3.times do\n+      random_lang = translator.supported_langs.sample\n+      translate_response = translator.translate_with_yandex(text_removed_tags, random_lang.code)\n+      # puts translate_response\n+      if translate_response.status","path":"app/models/tweet/tweet.rb","position":79,"original_position":79,"commit_id":"5be69bb2dcc53898491bce71898e54cb01258bd2","original_commit_id":"5be69bb2dcc53898491bce71898e54cb01258bd2","user":{"login":"lcpriest","id":735593,"avatar_url":"https://avatars.githubusercontent.com/u/735593?v=3","gravatar_id":"","url":"https://api.github.com/users/lcpriest","html_url":"https://github.com/lcpriest","followers_url":"https://api.github.com/users/lcpriest/followers","following_url":"https://api.github.com/users/lcpriest/following{/other_user}","gists_url":"https://api.github.com/users/lcpriest/gists{/gist_id}","starred_url":"https://api.github.com/users/lcpriest/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lcpriest/subscriptions","organizations_url":"https://api.github.com/users/lcpriest/orgs","repos_url":"https://api.github.com/users/lcpriest/repos","events_url":"https://api.github.com/users/lcpriest/events{/privacy}","received_events_url":"https://api.github.com/users/lcpriest/received_events","type":"User","site_admin":false},"body":"`break if translate_response.status`","created_at":"2016-02-29T02:25:31Z","updated_at":"2016-02-29T02:25:31Z","html_url":"https://github.com/tradegecko/ruby-exercise/pull/15#discussion_r54364044","pull_request_url":"https://api.github.com/repos/tradegecko/ruby-exercise/pulls/15","_links":{"self":{"href":"https://api.github.com/repos/tradegecko/ruby-exercise/pulls/comments/54364044"},"html":{"href":"https://github.com/tradegecko/ruby-exercise/pull/15#discussion_r54364044"},"pull_request":{"href":"https://api.github.com/repos/tradegecko/ruby-exercise/pulls/15"}}},"pull_request":{"url":"https://api.github.com/repos/tradegecko/ruby-exercise/pulls/15","id":60092702,"html_url":"https://github.com/tradegecko/ruby-exercise/pull/15","diff_url":"https://github.com/tradegecko/ruby-exercise/pull/15.diff","patch_url":"https://github.com/tradegecko/ruby-exercise/pull/15.patch","issue_url":"https://api.github.com/repos/tradegecko/ruby-exercise/issues/15","number":15,"state":"open","locked":false,"title":"An Tweetie Bot - anthedung","user":{"login":"anthedung","id":4252704,"avatar_url":"https://avatars.githubusercontent.com/u/4252704?v=3","gravatar_id":"","url":"https://api.github.com/users/anthedung","html_url":"https://github.com/anthedung","followers_url":"https://api.github.com/users/anthedung/followers","following_url":"https://api.github.com/users/anthedung/following{/other_user}","gists_url":"https://api.github.com/users/anthedung/gists{/gist_id}","starred_url":"https://api.github.com/users/anthedung/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anthedung/subscriptions","organizations_url":"https://api.github.com/users/anthedung/orgs","repos_url":"https://api.github.com/users/anthedung/repos","events_url":"https://api.github.com/users/anthedung/events{/privacy}","received_events_url":"https://api.github.com/users/anthedung/received_events","type":"User","site_admin":false},"body":"Task: Write a simple Ruby app that tweets about something of your choice every hour or responds when tweeted at.\r\n\r\n\r\n'An Tweetie Bot' by: anthedung\r\nWebsite https://atweetbot.herokuapp.com\r\n\r\n**Core fuctionalities**\r\n\r\n*Heroku Scheduler*\r\n- Tweet a random inspring quote every 1 hour by @TgkTweetie \r\n- Respond to unresponded tweets (mentioned @TgkTweetie) by translating the text to something else every 10 minutes\r\n\r\n*Web app*\r\n- Browse all the quotes in the database\r\n- Add a new quote of your choice into the DB for future tweet\r\n\r\nThanks for the fun weekend :). Your comments are greatly appreciated!\r\n\r\nContact: anthedung@gmail.com","created_at":"2016-02-21T16:06:19Z","updated_at":"2016-02-29T02:25:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e6f341086555e9e070336f70e069107cca08d0e8","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/tradegecko/ruby-exercise/pulls/15/commits","review_comments_url":"https://api.github.com/repos/tradegecko/ruby-exercise/pulls/15/comments","review_comment_url":"https://api.github.com/repos/tradegecko/ruby-exercise/pulls/comments{/number}","comments_url":"https://api.github.com/repos/tradegecko/ruby-exercise/issues/15/comments","statuses_url":"https://api.github.com/repos/tradegecko/ruby-exercise/statuses/5be69bb2dcc53898491bce71898e54cb01258bd2","head":{"label":"anthedung:master","ref":"master","sha":"5be69bb2dcc53898491bce71898e54cb01258bd2","user":{"login":"anthedung","id":4252704,"avatar_url":"https://avatars.githubusercontent.com/u/4252704?v=3","gravatar_id":"","url":"https://api.github.com/users/anthedung","html_url":"https://github.com/anthedung","followers_url":"https://api.github.com/users/anthedung/followers","following_url":"https://api.github.com/users/anthedung/following{/other_user}","gists_url":"https://api.github.com/users/anthedung/gists{/gist_id}","starred_url":"https://api.github.com/users/anthedung/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anthedung/subscriptions","organizations_url":"https://api.github.com/users/anthedung/orgs","repos_url":"https://api.github.com/users/anthedung/repos","events_url":"https://api.github.com/users/anthedung/events{/privacy}","received_events_url":"https://api.github.com/users/anthedung/received_events","type":"User","site_admin":false},"repo":{"id":52138392,"name":"ruby-exercise","full_name":"anthedung/ruby-exercise","owner":{"login":"anthedung","id":4252704,"avatar_url":"https://avatars.githubusercontent.com/u/4252704?v=3","gravatar_id":"","url":"https://api.github.com/users/anthedung","html_url":"https://github.com/anthedung","followers_url":"https://api.github.com/users/anthedung/followers","following_url":"https://api.github.com/users/anthedung/following{/other_user}","gists_url":"https://api.github.com/users/anthedung/gists{/gist_id}","starred_url":"https://api.github.com/users/anthedung/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anthedung/subscriptions","organizations_url":"https://api.github.com/users/anthedung/orgs","repos_url":"https://api.github.com/users/anthedung/repos","events_url":"https://api.github.com/users/anthedung/events{/privacy}","received_events_url":"https://api.github.com/users/anthedung/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/anthedung/ruby-exercise","description":null,"fork":true,"url":"https://api.github.com/repos/anthedung/ruby-exercise","forks_url":"https://api.github.com/repos/anthedung/ruby-exercise/forks","keys_url":"https://api.github.com/repos/anthedung/ruby-exercise/keys{/key_id}","collaborators_url":"https://api.github.com/repos/anthedung/ruby-exercise/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/anthedung/ruby-exercise/teams","hooks_url":"https://api.github.com/repos/anthedung/ruby-exercise/hooks","issue_events_url":"https://api.github.com/repos/anthedung/ruby-exercise/issues/events{/number}","events_url":"https://api.github.com/repos/anthedung/ruby-exercise/events","assignees_url":"https://api.github.com/repos/anthedung/ruby-exercise/assignees{/user}","branches_url":"https://api.github.com/repos/anthedung/ruby-exercise/branches{/branch}","tags_url":"https://api.github.com/repos/anthedung/ruby-exercise/tags","blobs_url":"https://api.github.com/repos/anthedung/ruby-exercise/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/anthedung/ruby-exercise/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/anthedung/ruby-exercise/git/refs{/sha}","trees_url":"https://api.github.com/repos/anthedung/ruby-exercise/git/trees{/sha}","statuses_url":"https://api.github.com/repos/anthedung/ruby-exercise/statuses/{sha}","languages_url":"https://api.github.com/repos/anthedung/ruby-exercise/languages","stargazers_url":"https://api.github.com/repos/anthedung/ruby-exercise/stargazers","contributors_url":"https://api.github.com/repos/anthedung/ruby-exercise/contributors","subscribers_url":"https://api.github.com/repos/anthedung/ruby-exercise/subscribers","subscription_url":"https://api.github.com/repos/anthedung/ruby-exercise/subscription","commits_url":"https://api.github.com/repos/anthedung/ruby-exercise/commits{/sha}","git_commits_url":"https://api.github.com/repos/anthedung/ruby-exercise/git/commits{/sha}","comments_url":"https://api.github.com/repos/anthedung/ruby-exercise/comments{/number}","issue_comment_url":"https://api.github.com/repos/anthedung/ruby-exercise/issues/comments{/number}","contents_url":"https://api.github.com/repos/anthedung/ruby-exercise/contents/{+path}","compare_url":"https://api.github.com/repos/anthedung/ruby-exercise/compare/{base}...{head}","merges_url":"https://api.github.com/repos/anthedung/ruby-exercise/merges","archive_url":"https://api.github.com/repos/anthedung/ruby-exercise/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/anthedung/ruby-exercise/downloads","issues_url":"https://api.github.com/repos/anthedung/ruby-exercise/issues{/number}","pulls_url":"https://api.github.com/repos/anthedung/ruby-exercise/pulls{/number}","milestones_url":"https://api.github.com/repos/anthedung/ruby-exercise/milestones{/number}","notifications_url":"https://api.github.com/repos/anthedung/ruby-exercise/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/anthedung/ruby-exercise/labels{/name}","releases_url":"https://api.github.com/repos/anthedung/ruby-exercise/releases{/id}","deployments_url":"https://api.github.com/repos/anthedung/ruby-exercise/deployments","created_at":"2016-02-20T05:28:55Z","updated_at":"2016-02-20T05:28:56Z","pushed_at":"2016-02-27T04:48:28Z","git_url":"git://github.com/anthedung/ruby-exercise.git","ssh_url":"git@github.com:anthedung/ruby-exercise.git","clone_url":"https://github.com/anthedung/ruby-exercise.git","svn_url":"https://github.com/anthedung/ruby-exercise","homepage":null,"size":857,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"tradegecko:master","ref":"master","sha":"f627b2aff6d944946a71f71b306b44d61f6aff8d","user":{"login":"tradegecko","id":1814492,"avatar_url":"https://avatars.githubusercontent.com/u/1814492?v=3","gravatar_id":"","url":"https://api.github.com/users/tradegecko","html_url":"https://github.com/tradegecko","followers_url":"https://api.github.com/users/tradegecko/followers","following_url":"https://api.github.com/users/tradegecko/following{/other_user}","gists_url":"https://api.github.com/users/tradegecko/gists{/gist_id}","starred_url":"https://api.github.com/users/tradegecko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tradegecko/subscriptions","organizations_url":"https://api.github.com/users/tradegecko/orgs","repos_url":"https://api.github.com/users/tradegecko/repos","events_url":"https://api.github.com/users/tradegecko/events{/privacy}","received_events_url":"https://api.github.com/users/tradegecko/received_events","type":"Organization","site_admin":false},"repo":{"id":25526304,"name":"ruby-exercise","full_name":"tradegecko/ruby-exercise","owner":{"login":"tradegecko","id":1814492,"avatar_url":"https://avatars.githubusercontent.com/u/1814492?v=3","gravatar_id":"","url":"https://api.github.com/users/tradegecko","html_url":"https://github.com/tradegecko","followers_url":"https://api.github.com/users/tradegecko/followers","following_url":"https://api.github.com/users/tradegecko/following{/other_user}","gists_url":"https://api.github.com/users/tradegecko/gists{/gist_id}","starred_url":"https://api.github.com/users/tradegecko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tradegecko/subscriptions","organizations_url":"https://api.github.com/users/tradegecko/orgs","repos_url":"https://api.github.com/users/tradegecko/repos","events_url":"https://api.github.com/users/tradegecko/events{/privacy}","received_events_url":"https://api.github.com/users/tradegecko/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/tradegecko/ruby-exercise","description":null,"fork":false,"url":"https://api.github.com/repos/tradegecko/ruby-exercise","forks_url":"https://api.github.com/repos/tradegecko/ruby-exercise/forks","keys_url":"https://api.github.com/repos/tradegecko/ruby-exercise/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tradegecko/ruby-exercise/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tradegecko/ruby-exercise/teams","hooks_url":"https://api.github.com/repos/tradegecko/ruby-exercise/hooks","issue_events_url":"https://api.github.com/repos/tradegecko/ruby-exercise/issues/events{/number}","events_url":"https://api.github.com/repos/tradegecko/ruby-exercise/events","assignees_url":"https://api.github.com/repos/tradegecko/ruby-exercise/assignees{/user}","branches_url":"https://api.github.com/repos/tradegecko/ruby-exercise/branches{/branch}","tags_url":"https://api.github.com/repos/tradegecko/ruby-exercise/tags","blobs_url":"https://api.github.com/repos/tradegecko/ruby-exercise/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tradegecko/ruby-exercise/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tradegecko/ruby-exercise/git/refs{/sha}","trees_url":"https://api.github.com/repos/tradegecko/ruby-exercise/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tradegecko/ruby-exercise/statuses/{sha}","languages_url":"https://api.github.com/repos/tradegecko/ruby-exercise/languages","stargazers_url":"https://api.github.com/repos/tradegecko/ruby-exercise/stargazers","contributors_url":"https://api.github.com/repos/tradegecko/ruby-exercise/contributors","subscribers_url":"https://api.github.com/repos/tradegecko/ruby-exercise/subscribers","subscription_url":"https://api.github.com/repos/tradegecko/ruby-exercise/subscription","commits_url":"https://api.github.com/repos/tradegecko/ruby-exercise/commits{/sha}","git_commits_url":"https://api.github.com/repos/tradegecko/ruby-exercise/git/commits{/sha}","comments_url":"https://api.github.com/repos/tradegecko/ruby-exercise/comments{/number}","issue_comment_url":"https://api.github.com/repos/tradegecko/ruby-exercise/issues/comments{/number}","contents_url":"https://api.github.com/repos/tradegecko/ruby-exercise/contents/{+path}","compare_url":"https://api.github.com/repos/tradegecko/ruby-exercise/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tradegecko/ruby-exercise/merges","archive_url":"https://api.github.com/repos/tradegecko/ruby-exercise/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tradegecko/ruby-exercise/downloads","issues_url":"https://api.github.com/repos/tradegecko/ruby-exercise/issues{/number}","pulls_url":"https://api.github.com/repos/tradegecko/ruby-exercise/pulls{/number}","milestones_url":"https://api.github.com/repos/tradegecko/ruby-exercise/milestones{/number}","notifications_url":"https://api.github.com/repos/tradegecko/ruby-exercise/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tradegecko/ruby-exercise/labels{/name}","releases_url":"https://api.github.com/repos/tradegecko/ruby-exercise/releases{/id}","deployments_url":"https://api.github.com/repos/tradegecko/ruby-exercise/deployments","created_at":"2014-10-21T14:17:31Z","updated_at":"2015-03-31T03:57:43Z","pushed_at":"2016-02-27T04:48:29Z","git_url":"git://github.com/tradegecko/ruby-exercise.git","ssh_url":"git@github.com:tradegecko/ruby-exercise.git","clone_url":"https://github.com/tradegecko/ruby-exercise.git","svn_url":"https://github.com/tradegecko/ruby-exercise","homepage":null,"size":610,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":15,"mirror_url":null,"open_issues_count":1,"forks":15,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/tradegecko/ruby-exercise/pulls/15"},"html":{"href":"https://github.com/tradegecko/ruby-exercise/pull/15"},"issue":{"href":"https://api.github.com/repos/tradegecko/ruby-exercise/issues/15"},"comments":{"href":"https://api.github.com/repos/tradegecko/ruby-exercise/issues/15/comments"},"review_comments":{"href":"https://api.github.com/repos/tradegecko/ruby-exercise/pulls/15/comments"},"review_comment":{"href":"https://api.github.com/repos/tradegecko/ruby-exercise/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/tradegecko/ruby-exercise/pulls/15/commits"},"statuses":{"href":"https://api.github.com/repos/tradegecko/ruby-exercise/statuses/5be69bb2dcc53898491bce71898e54cb01258bd2"}}}}