This repository has been archived by the owner on Aug 7, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#22 RSpec-Tests, twittercontent displayed in the content-area
- Loading branch information
1 parent
4cc875d
commit 92562dc
Showing
7 changed files
with
76 additions
and
50 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
class IslandsController < ApplicationController | ||
def index; end | ||
def index | ||
twitter = TwitterService.new | ||
@trend_names = twitter.trend_names | ||
@tweets = twitter.search_tweets('', 5, 'puppy', 'cute') | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,44 @@ | ||
|
||
require 'twitter' | ||
|
||
APP_CONFIG = YAML.load(File.read('config/settings/development.yml')) | ||
.with_indifferent_access | ||
class TwitterService | ||
APP_CONFIG = YAML.load(File.read('config/settings/development.yml')) | ||
.with_indifferent_access | ||
|
||
def initialize | ||
@client = Twitter::REST::Client.new do |config| | ||
@twitter = Twitter::REST::Client.new do |config| | ||
config.consumer_key = APP_CONFIG['consumer_key'] | ||
config.consumer_secret = APP_CONFIG['consumer_secret'] | ||
config.access_token = APP_CONFIG['access_token'] | ||
config.access_token_secret = APP_CONFIG['access_token_secret'] | ||
end | ||
end | ||
|
||
def tweets_from_user_that_contain(user, number_of_posts = 5, *tags) | ||
@client.search("from:#{user} #{make_hashtags(tags)}", result_type: 'recent') | ||
.take(number_of_posts) | ||
.each do |tweet| | ||
puts tweet.text | ||
end | ||
end | ||
|
||
def tweets_containing(*tags) | ||
tweets = @client.search(make_hashtags(tags), | ||
result_type: 'recent', | ||
language: 'en') | ||
tweets.attrs[:statuses].each do |tweet| | ||
"#{tweet[:user][:name]}: #{tweet[:text]}" | ||
end | ||
def search_tweets(user = '', number_of_posts = 5, *tags) | ||
@twitter.search("#{user} #{make_hashtags(tags)}", result_type: 'recent') | ||
.take(number_of_posts) | ||
end | ||
|
||
def trend_names | ||
names = [] | ||
trends.attrs[:trends].each do |trend| | ||
puts trend[:name] | ||
names << trend[:name] | ||
end | ||
names | ||
end | ||
|
||
private | ||
|
||
def trends #returns Twitter::Trendresults | ||
@client.trends | ||
def trends # returns Twitter::Trendresults | ||
@twitter.trends | ||
end | ||
|
||
def make_hashtags(tags) # takes an array of words | ||
hashtags = [] | ||
tags.each do |tag| | ||
hashtags << '#' + tag | ||
hashtags << if tag[0] == '#' | ||
tag | ||
else | ||
'#' + tag | ||
end | ||
end | ||
hashtags.join(', ') | ||
end | ||
|
||
|
||
|
||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<h1> Wow there is content on this island! </h1> | ||
|
||
<% @tweets.each do |tweet| %> | ||
<h3><%= tweet.user.name %></h3><a href="<%= tweet.url %>"> Show source tweet</a> | ||
<p><%= tweet.text %><p> | ||
|
||
<% tweet.media.each do |item| %> | ||
<img src="<% item.display_url %>" > | ||
<% end %> | ||
<br> | ||
<% end %> |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
consumer_key: consumer_key | ||
consumer_secret: consumer_secret | ||
access_token: consumer_secret | ||
access_token_secret: access_token_secret |
Empty file.
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