From 6a8afd2f69a13f62841a3fe909beaad96928fadb Mon Sep 17 00:00:00 2001 From: thea Date: Thu, 15 Sep 2016 12:23:14 +0200 Subject: twitter readme now contains github markup to show secrets-file content --- doc/TWITTER_FEED.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/doc/TWITTER_FEED.md b/doc/TWITTER_FEED.md index dd3954c..221c334 100644 --- a/doc/TWITTER_FEED.md +++ b/doc/TWITTER_FEED.md @@ -19,6 +19,18 @@ LEAP web app (as part of the main view). * 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}}} +``` +development: + twitter: + enabled: false # set to true for usage + twitter_handle: XXXXX #put your twitter handle here + bearer_token: XXXXX #put your bearer token here +test: + twitter: + enabled: false # set to true for usage + twitter_handle: XXXXX #put your twitter handle here + bearer_token: XXXXX #put your bearer token here +``` * 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 -- cgit v1.2.3 From 94a5b32a58f5f4fb63eaf677a91af63e1fe3e325 Mon Sep 17 00:00:00 2001 From: thea Date: Thu, 15 Sep 2016 15:29:10 +0200 Subject: included production for readme & secrets --- doc/TWITTER_FEED.md | 5 +++++ script/generate_bearer_token | 2 ++ 2 files changed, 7 insertions(+) diff --git a/doc/TWITTER_FEED.md b/doc/TWITTER_FEED.md index 221c334..592cd38 100644 --- a/doc/TWITTER_FEED.md +++ b/doc/TWITTER_FEED.md @@ -30,6 +30,11 @@ test: enabled: false # set to true for usage twitter_handle: XXXXX #put your twitter handle here bearer_token: XXXXX #put your bearer token here +production: + twitter: + enabled: false # set to true for usage + twitter_handle: XXXXX #put your twitter handle here + bearer_token: XXXXX #put your bearer token here ``` * 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` diff --git a/script/generate_bearer_token b/script/generate_bearer_token index 7091a8d..60e4600 100755 --- a/script/generate_bearer_token +++ b/script/generate_bearer_token @@ -73,10 +73,12 @@ else else secrets["development"]["twitter"]["twitter_handle"] = options[:twitterhandle] secrets["test"]["twitter"]["twitter_handle"] = options[:twitterhandle] + secrets["production"]["twitter"]["twitter_handle"] = options[:twitterhandle] end secrets["development"]["twitter"]["bearer_token"] = $bearer_token secrets["test"]["twitter"]["bearer_token"] = $bearer_token + secrets["production"]["twitter"]["twitter_handle"] = $bearer_token File.open("#{options[:projectroot]}/leap_web/config/secrets.yml", "r+") do |file| file.write(secrets.to_yaml) -- cgit v1.2.3 From a95c0dfe3f70671ee354648fc4b25a79d5b57824 Mon Sep 17 00:00:00 2001 From: thea Date: Tue, 20 Sep 2016 12:13:30 +0200 Subject: deleted leap_web from projectroot --- script/generate_bearer_token | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/script/generate_bearer_token b/script/generate_bearer_token index 60e4600..3a09382 100755 --- a/script/generate_bearer_token +++ b/script/generate_bearer_token @@ -55,8 +55,8 @@ if options[:projectroot].nil? then puts "You didn't tell us the directory to have your secrets-file created or being filled. Feel free to copy/paste your bearer_token:" puts $bearer_token else - if File.exist?("#{options[:projectroot]}/leap_web/config/secrets.yml") - secrets = YAML.load_file("#{options[:projectroot]}/leap_web/config/secrets.yml") + if File.exist?("#{options[:projectroot]}/config/secrets.yml") + secrets = YAML.load_file("#{options[:projectroot]}/config/secrets.yml") else puts "Please make sure that you created a secrets-file as described in the documentation or have given the correct directory. No secrets-file could be found." exit -- cgit v1.2.3 From 460129e5965751127bb6cb363a661afb7c7d5ab4 Mon Sep 17 00:00:00 2001 From: thea Date: Wed, 21 Sep 2016 14:08:38 +0200 Subject: included error-handling: twitter-helper includes rescue and error message for fourth value in array. there will always be an empty array that view (text and each - method) does not break. if empty array in view the error-message is shown. (its WIP) --- app/helpers/twitter_helper.rb | 24 ++++++++++++++++++++++++ app/views/twitter/_index.html.erb | 15 ++++++++------- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/app/helpers/twitter_helper.rb b/app/helpers/twitter_helper.rb index f824a03..8503f24 100644 --- a/app/helpers/twitter_helper.rb +++ b/app/helpers/twitter_helper.rb @@ -23,6 +23,26 @@ module TwitterHelper 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) + if twitter_user_info[2] == nil + error_handling + twitter_user_info[3] = "The twitter-handle does not exist or the account is private. Please change it or contact your provider-admin." + end + rescue Twitter::Error::BadRequest + error_handling + rescue Twitter::Error::Unauthorized + error_handling + rescue Twitter::Error::Forbidden + error_handling + rescue Twitter::Error::NotAcceptable + error_handling + rescue Twitter::Error::TooManyRequests + error_handling + end + + def error_handling + twitter_user_info[2] = [] + twitter_user_info[3] = "The twitter-handle does not exist or the account is private. Please change it or contact your provider-admin." + return twitter_user_info end def cached_info @@ -43,4 +63,8 @@ module TwitterHelper def tweets cached_info[2] end + + def error_message + cached_info[3] + end end diff --git a/app/views/twitter/_index.html.erb b/app/views/twitter/_index.html.erb index a7ebd1b..8529b83 100644 --- a/app/views/twitter/_index.html.erb +++ b/app/views/twitter/_index.html.erb @@ -9,14 +9,15 @@