summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarie <ml.kochsiek@fu-berlin.de>2016-09-14 16:38:51 +0000
committerGitHub <noreply@github.com>2016-09-14 16:38:51 +0000
commitd72c87cb94213c9a507596f2103773969d1cbd30 (patch)
tree7b13646448e64e560101493eeac1a03c3a25dbd8
parent42459748e9e8e30a9cc0c64eaf4b8e10814d2dc2 (diff)
parent22478d315af3590d2a344eb1aa8cf2aec0730506 (diff)
Merge pull request #14 from LoadToCode/develop
Taking it all from branch develop and push it to branch temp_1_marie
-rw-r--r--README.md29
-rw-r--r--app/assets/images/Twitter_Logo_White_On_Blue.pngbin4861 -> 0 bytes
-rw-r--r--app/assets/images/rails.pngbin0 -> 6646 bytes
-rw-r--r--app/assets/stylesheets/twitter.scss8
-rw-r--r--app/helpers/twitter_helper.rb35
-rw-r--r--app/views/home/index.html.haml2
-rw-r--r--app/views/twitter/_index.html.erb19
-rw-r--r--config/defaults.yml1
-rw-r--r--doc/TWITTER_FEED.md35
-rwxr-xr-xscript/invalidate_bearer_token47
10 files changed, 103 insertions, 73 deletions
diff --git a/README.md b/README.md
index 4d9ca39..923b239 100644
--- a/README.md
+++ b/README.md
@@ -9,6 +9,7 @@ The LEAP Web App provides the following functions:
* Webfinger access to user’s public keys
* Email aliases and forwarding
* Localized and Customizable documentation
+* Display of status updates from Twitter (access to tweets via Twitter API)
Written in: Ruby, Rails.
@@ -36,6 +37,7 @@ For more information, see these files in the ``doc`` directory:
* DEPLOY -- for notes on deployment.
* DEVELOP -- for developer notes.
* CUSTOM -- how to customize.
+* TWITTER_FEED -- how to use it.
External docs:
@@ -186,30 +188,3 @@ Known problems
attacks. These are very hard to prevent, because our protocol is
designed to allow query of a user database via proxy in order to
provide network perspective.
-
-Twitter Timeline on Main View
----------------------------
-
-This is a feature to include a twitter feed that displays most recent tweets
-of a (determined) twitter account (accessed via Twitter API).
-If you chose to use it, the feature gets included in `home/index` of
-LEAP web app (as part of the main view).
-
-* Create Twitter Application on https://apps.twitter.com/
- * Visit https://apps.twitter.com/ and log in with the twitter account you want to use
- * Make sure you have a mobile phone number registered with your account to be able to proceed
- * Choose the option to `Create New App`
- * Fill in Application Details and Developer Agreement and `Create your Twitter application`
- * Choose the section "Keys and Access Tokens" to get your consumer key and consumer secret
- * Optional: Go to section "Permissions" and change the "Access" from `Read and Write` (by default) to `Read only`
- * Have your consumer key and secret by hand for one of the next steps
-
-* Activate the feature within your local LEAP Web Application
- * If not already existing create a secrets-file in /config with the name secrets.yml (`/config/secrets.yml`)
- * Secrets-file should contain the following, make sure its in YAML: {"development"=> {"twitter"=>{"enabled"=>false, "twitter_handle"=>"", "bearer_token"=>"", "twitter_picture"=>nil}}, "test"=>{"twitter"=>{"enabled"=>false, "twitter_handle"=>"", "bearer_token"=>"", "twitter_picture"=>nil}}}
- * To have your bearer token created, run script in terminal being in the file of leap_web: `script/generate_bearer_token`
- * To have the script run properly you have to add before running: `--key your_consumerkey --secret your_consumersecret`
- * Add also `--projectroot your_projectroot --twitterhandle your_twitterhandle` as well to not have manually put the data in your secrets-file
- * The full command looks like this: `script/generate_bearer_token --key your_consumerkey --secret your_consumersecret --projectroot your_projectroot --twitterhandle your_twitterhandle`
- * If you didn't give all your information to the script, had a typo or want to change anything else, please do so by finding the secrets-file at `/config/secrets.yml`
- * Make sure that the correct twitterhandle and bearer-token is included
diff --git a/app/assets/images/Twitter_Logo_White_On_Blue.png b/app/assets/images/Twitter_Logo_White_On_Blue.png
deleted file mode 100644
index 25ba09f..0000000
--- a/app/assets/images/Twitter_Logo_White_On_Blue.png
+++ /dev/null
Binary files differ
diff --git a/app/assets/images/rails.png b/app/assets/images/rails.png
new file mode 100644
index 0000000..d5edc04
--- /dev/null
+++ b/app/assets/images/rails.png
Binary files differ
diff --git a/app/assets/stylesheets/twitter.scss b/app/assets/stylesheets/twitter.scss
index b2481db..b2233d0 100644
--- a/app/assets/stylesheets/twitter.scss
+++ b/app/assets/stylesheets/twitter.scss
@@ -13,7 +13,7 @@
position: absolute;
}
-.twitter_pic {
+.twitter_image_frame {
display: block;
width: 40px;
height: 40px;
@@ -23,12 +23,6 @@
top: 0;
}
-.twitter_image_frame {
- width: 40px;
- height: 40px;
- overflow: hidden
- }
-
.twitter_image_frame > img {
display: block;
position: absolute;
diff --git a/app/helpers/twitter_helper.rb b/app/helpers/twitter_helper.rb
index a5e7ae4..f824a03 100644
--- a/app/helpers/twitter_helper.rb
+++ b/app/helpers/twitter_helper.rb
@@ -19,7 +19,13 @@ module TwitterHelper
$twitter_user_info ||= []
end
- def twitter_name
+ def update_twitter_info
+ twitter_user_info[0] = Time.now
+ twitter_user_info[1] = twitter_client.user(twitter_handle).name
+ twitter_user_info[2] = twitter_client.user_timeline(twitter_handle).select{ |tweet| tweet.text.start_with?('RT','@')==false}.take(3)
+ end
+
+ def cached_info
if twitter_user_info[0] == nil
update_twitter_info
else
@@ -27,31 +33,14 @@ module TwitterHelper
update_twitter_info
end
end
- twitter_user_info[1]
+ twitter_user_info
end
- def update_twitter_info
- twitter_user_info[0] = Time.now
- twitter_user_info[1] = twitter_client.user(twitter_handle).name
- end
-
- def twitter_tweets
- $twitter_tweets ||= []
- end
-
- def twitter_timeline
- if twitter_tweets[0] == nil
- update_twitter_timeline
- else
- if Time.now > twitter_tweets[0] + 15.minutes
- update_twitter_timeline
- end
- end
- twitter_tweets[1]
+ def twitter_name
+ cached_info[1]
end
- def update_twitter_timeline
- twitter_tweets[0] = Time.now
- twitter_tweets[1] = twitter_client.user_timeline(twitter_handle).select{ |tweet| tweet.text.start_with?('RT','@')==false}.take(3)
+ def tweets
+ cached_info[2]
end
end
diff --git a/app/views/home/index.html.haml b/app/views/home/index.html.haml
index 5e33e62..147cacd 100644
--- a/app/views/home/index.html.haml
+++ b/app/views/home/index.html.haml
@@ -6,4 +6,4 @@
#push
-# #push is used for sticky footer in bootstrap 2. remove when upgrading to bootstrap 3
#footer
- = render 'layouts/footer'
+ = render 'layouts/footer' \ No newline at end of file
diff --git a/app/views/twitter/_index.html.erb b/app/views/twitter/_index.html.erb
index ba618b3..a7ebd1b 100644
--- a/app/views/twitter/_index.html.erb
+++ b/app/views/twitter/_index.html.erb
@@ -1,24 +1,15 @@
<% if twitter_enabled == true %>
<div class="twitter">
- <div class="twitter_header">
- <div class="twitter_id">
- <div class="twitter_pic twitter_image_frame"><%= image_tag("Twitter_Logo_White_On_Blue.png") %></div>
- <div class="twitter_name"><%= twitter_name%><br><a href="https://twitter.com/loadtocode">@<%= twitter_handle %></a></div>
- </div>
- </div>
-
- <!-- <div class="twitter_header">
- <p>These are the most recent tweets by <%= twitter_name%></p>
-
+ <div class="twitter_header">
<div class="twitter_id">
- <div class="twitter_pic twitter_image_frame"><%= image_tag("Twitter_Logo_White_On_Blue.png") %></div>
- <div class="twitter_name"><a href="https://twitter.com/loadtocode">@<%= twitter_handle %></a></div>
+ <div class="twitter_image_frame"><%= image_tag("Twitter_Logo_Blue.png") %></div>
+ <div class="twitter_name"><%= twitter_name%><br><a href="https://twitter.com/loadtocode">@<%= twitter_handle %></a></div>
</div>
- </div> -->
+ </div>
<div class="twitter_list">
- <% twitter_timeline.each do |e| %>
+ <% tweets.each do |e| %>
<div class="tweet">
<div class="tweet_text"><%= " #{e.text}" %>
</div>
diff --git a/config/defaults.yml b/config/defaults.yml
index bcb8dac..7e2ea58 100644
--- a/config/defaults.yml
+++ b/config/defaults.yml
@@ -32,7 +32,6 @@ common: &common
pagination_size: 30
auth:
token_expires_after: 60
-
# handles that will be blocked from being used as logins or email aliases
# in addition to the ones in /etc/passwd and http://tools.ietf.org/html/rfc2142
handle_blacklist:
diff --git a/doc/TWITTER_FEED.md b/doc/TWITTER_FEED.md
new file mode 100644
index 0000000..dd3954c
--- /dev/null
+++ b/doc/TWITTER_FEED.md
@@ -0,0 +1,35 @@
+# Display of status updates from twitter on main view #
+
+This is a feature to include status updates that displays most recent tweets
+of a (determined) twitter account (accessed via Twitter API).
+If you chose to use it, the feature gets included in `home/index` of
+LEAP web app (as part of the main view).
+
+## How to use it ##
+
+* Create Twitter Application on https://apps.twitter.com/
+ * Visit https://apps.twitter.com/ and log in with the twitter account you want to use
+ * Make sure you have a mobile phone number registered with your account to be able to proceed
+ * Choose the option to `Create New App`
+ * Fill in Application Details and Developer Agreement and `Create your Twitter application`
+ * Choose the section "Keys and Access Tokens" to get your consumer key and consumer secret
+ * Optional: Go to section "Permissions" and change the "Access" from `Read and Write` (by default) to `Read only`
+ * Have your consumer key and secret by hand for one of the next steps
+
+* Activate the feature within your local LEAP Web Application
+ * If not already existing create a secrets-file in /config with the name secrets.yml (`/config/secrets.yml`)
+ * Secrets-file should contain the following, make sure its in YAML: {"development"=> {"twitter"=>{"enabled"=>false, "twitter_handle"=>"", "bearer_token"=>"", "twitter_picture"=>nil}}, "test"=>{"twitter"=>{"enabled"=>false, "twitter_handle"=>"", "bearer_token"=>"", "twitter_picture"=>nil}}}
+ * To have your bearer token created, run script in terminal being in the file of leap_web: `script/generate_bearer_token`
+ * To have the script run properly you have to add before running: `--key your_consumerkey --secret your_consumersecret`
+ * Add also `--projectroot your_projectroot --twitterhandle your_twitterhandle` as well to not have manually put the data in your secrets-file
+ * The full command looks like this: `script/generate_bearer_token --key your_consumerkey --secret your_consumersecret --projectroot your_projectroot --twitterhandle your_twitterhandle`
+ * If you didn't give all your information to the script, had a typo or want to change anything else, please do so by finding the secrets-file at `/config/secrets.yml`
+ * Make sure that the correct twitterhandle and bearer-token is included
+
+* Deactivate your bearer token
+ * To deactivate your generated bearer token you can run script/invalidate_bearer_token
+ * The full command looks like this: script/invalidate_bearer_token --key your_consumerkey --secret your_consumersecret --token your_bearer_token
+
+### Default avatar image ###
+
+This feature uses by default the twitter bird as avatar picture (Twitter_Logo_Blue.png). By using the Twitter trademarks, you agree to follow the Twitter Trademark Guidelines as well as Twitter's Terms of Service and all other Twitter rules and policies. Please find more details here: https://brand.twitter.com/.
diff --git a/script/invalidate_bearer_token b/script/invalidate_bearer_token
new file mode 100755
index 0000000..eda1c7d
--- /dev/null
+++ b/script/invalidate_bearer_token
@@ -0,0 +1,47 @@
+#!/usr/bin/env ruby
+
+require "net/http"
+require "uri"
+require "json"
+require "base64"
+require "optparse"
+
+options = {}
+
+option_parser = OptionParser.new do |opts|
+ opts.banner = "Invalidate your bearer_token for twitter by including the following [options]. The bearer token can't be used afterwards anymore. Please create a new bearer-token if you want to activate the twitter feature again."
+
+ opts.on("--key KEY", "consumer_key of your twitter application") do |key|
+ options[:conkey] = key
+ end
+
+ opts.on("--secret SECRET", "consumer_secret of your twitter application") do |secret|
+ options[:consec] = secret
+ end
+
+ opts.on("--token TOKEN", "bearer token for twitter") do |token|
+ options[:token] = token
+ end
+
+end
+
+option_parser.parse!
+
+if options[:conkey].nil? || options[:consec].nil? || options[:token].nil? then
+ puts option_parser
+ exit
+else
+ consumer_key = options[:conkey]
+ consumer_secret = options[:consec]
+ bearer_token = options[:token]
+end
+
+uri = URI("https://api.twitter.com/oauth2/invalidate_token")
+data = "access_token=#{bearer_token}"
+cre = Base64.strict_encode64("#{consumer_key}:#{consumer_secret}")
+authorization_headers = { "Authorization" => "Basic #{cre}"}
+
+Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
+ response = http.request_post(uri, data, authorization_headers)
+ puts JSON.parse(response.body)
+end