Created
May 28, 2017 07:43
-
-
Save phensalves/3422a2fafd8be50b4d4f1f9efff5fa86 to your computer and use it in GitHub Desktop.
manager
This file contains 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 Api | |
class TweetsApiManager | |
def initialize options={} | |
end | |
def execute | |
connect_to_twitter_api(ENV['API_ENDPOINT']) | |
elect_tweets | |
end | |
private | |
def connect_to_twitter_api uri | |
url = URI(ENV['API_ENDPOINT']) | |
http = Net::HTTP.new(url.host, url.port) | |
request = Net::HTTP::Get.new(url) | |
request["username"] = ENV['USERNAME'] | |
@response = http.request(request) | |
@response = parse_response(@response.body) | |
@response = @response['statuses'] | |
end | |
def elect_tweets | |
@elegible_tweets = [] | |
@response.each do |tweet| | |
@elegible_tweets << tweet if (tweet['text'].include?("@locaweb") && tweet['in_reply_to_user_id_str'] != 42) | |
end | |
end | |
def parse_response response | |
JSON.parse(response) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment