summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarie <ml.kochsiek@fu-berlin.de>2016-09-09 15:37:48 +0000
committerGitHub <noreply@github.com>2016-09-09 15:37:48 +0000
commit8fd3aae30e7bfae18d99d936ef5428e8046ab58a (patch)
treebb11c70b265ceee60453b88bdcd6f170141d3161
parentdd568d93d86876d80d93cfc96417b0882391f7f7 (diff)
parentdcd20f9b532bc7490e45ddda68e228f4c9bf2b93 (diff)
Merge pull request #5 from LoadToCode/thea
Cool! \o/ timing for twitter caching + script for invalidating token
-rw-r--r--app/helpers/twitter_helper.rb2
-rwxr-xr-xscript/invalidate_bearer_token47
2 files changed, 48 insertions, 1 deletions
diff --git a/app/helpers/twitter_helper.rb b/app/helpers/twitter_helper.rb
index a5e7ae4..0b8f79c 100644
--- a/app/helpers/twitter_helper.rb
+++ b/app/helpers/twitter_helper.rb
@@ -23,7 +23,7 @@ module TwitterHelper
if twitter_user_info[0] == nil
update_twitter_info
else
- if Time.now > twitter_user_info[0] + 15.minutes
+ if Time.now > twitter_user_info[0] + 120.minutes
update_twitter_info
end
end
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