From e1e98d0229b8b79de2105515f0312903a23dc335 Mon Sep 17 00:00:00 2001 From: luca-marie Date: Wed, 24 Aug 2016 15:23:07 +0200 Subject: Update with Twitter --- .gitignore | 4 +- Gemfile | 1 + Gemfile.lock | 35 ++++++++++++++- app/assets/stylesheets/application.scss | 1 + app/assets/stylesheets/twitter.scss | 76 +++++++++++++++++++++++++++++++++ app/controllers/home_controller.rb | 17 ++++++++ app/controllers/twitter_controller.rb | 19 +++++++++ app/helpers/twitter_helper.rb | 2 + app/views/home/_content.html.haml | 6 ++- app/views/home/index.html.haml | 3 +- app/views/twitter/_index.html.erb | 26 +++++++++++ config/defaults.yml | 6 +++ config/routes.rb | 2 + 13 files changed, 193 insertions(+), 5 deletions(-) create mode 100644 app/assets/stylesheets/twitter.scss create mode 100644 app/controllers/twitter_controller.rb create mode 100644 app/helpers/twitter_helper.rb create mode 100644 app/views/twitter/_index.html.erb diff --git a/.gitignore b/.gitignore index 8d49deb..5565d6e 100644 --- a/.gitignore +++ b/.gitignore @@ -33,7 +33,9 @@ public/assets/* public/ca.crt public/config/* public/provider.json -config/config.yml +# config/config.yml +config.secrets.yml +config/initializers/test.rb public/1/* vendor/bundle/* public/img diff --git a/Gemfile b/Gemfile index 1e82977..3b5435e 100644 --- a/Gemfile +++ b/Gemfile @@ -98,6 +98,7 @@ end ## ## OPTIONAL GEMS AND ENGINES ## +gem 'twitter' enabled_engines.each do |name, gem_info| gem gem_info[:name], :path => gem_info[:path], :groups => gem_info[:env] diff --git a/Gemfile.lock b/Gemfile.lock index ab97719..8601b75 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -76,6 +76,7 @@ GEM sass (>= 3.3.4) braintree (2.65.0) builder (>= 2.0.0) + buftok (0.2.0) builder (3.2.2) byebug (9.0.5) capybara (2.7.1) @@ -126,6 +127,9 @@ GEM cucumber-wire (0.0.1) debug_inspector (0.0.2) diff-lcs (1.2.5) + domain_name (0.5.20160615) + unf (>= 0.0.5, < 1.0.0) + equalizer (0.0.10) erubis (2.7.0) execjs (2.7.0) factory_girl (4.7.0) @@ -140,6 +144,8 @@ GEM sinatra faker (1.6.6) i18n (~> 0.5) + faraday (0.9.2) + multipart-post (>= 1.2, < 3) ffi (1.9.14) gherkin (4.0.0) globalid (0.3.7) @@ -157,7 +163,16 @@ GEM haml (~> 4.0.0) nokogiri (~> 1.6.0) ruby_parser (~> 3.5) + http (1.0.4) + addressable (~> 2.3) + http-cookie (~> 1.0) + http-form_data (~> 1.0.1) + http_parser.rb (~> 0.6.0) + http-cookie (1.0.2) + domain_name (~> 0.5) + http-form_data (1.0.1) http_accept_language (2.0.5) + http_parser.rb (0.6.0) httpclient (2.8.1) i18n (0.7.0) i18n-missing_translations (0.0.1) @@ -178,6 +193,8 @@ GEM nokogiri (>= 1.5.9) mail (2.6.4) mime-types (>= 1.16, < 4) + memoizable (0.4.2) + thread_safe (~> 0.3, >= 0.3.1) metaclass (0.0.4) method_source (0.8.2) mime-types (3.1) @@ -190,6 +207,8 @@ GEM metaclass (~> 0.0.1) multi_json (1.12.1) multi_test (0.1.2) + multipart-post (2.0.0) + naught (1.1.0) nokogiri (1.6.8) mini_portile2 (~> 2.1.0) pkg-config (~> 1.1.7) @@ -258,6 +277,7 @@ GEM simple_form (3.2.1) actionpack (> 4, < 5.1) activemodel (> 4, < 5.1) + simple_oauth (0.3.1) sinatra (1.4.7) rack (~> 1.5) rack-protection (~> 1.4) @@ -278,10 +298,22 @@ GEM thor (0.19.1) thread_safe (0.3.5) tilt (2.0.5) + twitter (5.16.0) + addressable (~> 2.3) + buftok (~> 0.2.0) + equalizer (= 0.0.10) + faraday (~> 0.9.0) + http (~> 1.0) + http_parser.rb (~> 0.6.0) + json (~> 1.8) + memoizable (~> 0.4.0) + naught (~> 1.0) + simple_oauth (~> 0.3.0) tzinfo (1.2.2) thread_safe (~> 0.1) uglifier (3.0.1) execjs (>= 0.3.0, < 3) + unf (0.2.0.beta2) valid_email (0.0.13) activemodel mail (~> 2.6.1) @@ -337,8 +369,9 @@ DEPENDENCIES sass-rails simple_form therubyracer + twitter uglifier valid_email BUNDLED WITH - 1.11.2 + 1.12.5 diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 856a559..f42044b 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -16,6 +16,7 @@ // LEAP web app specific overrides // @import "leap"; +@import "twitter"; // And finally bootswatch style itself // @import "bootswatch/cerulean/bootswatch"; diff --git a/app/assets/stylesheets/twitter.scss b/app/assets/stylesheets/twitter.scss new file mode 100644 index 0000000..1d54785 --- /dev/null +++ b/app/assets/stylesheets/twitter.scss @@ -0,0 +1,76 @@ +.twitter { + // position: fixed; + // top: 0; + // right: 10px; + // bottom: 0; + // overflow: auto; + // width: 250px; +} +.twitter_header { + padding-top: 8px; + height: 30px; + font-size: 20px ; + text-align: center; +} + +.tweets:hover { + background-color: #ccf2ff; + } + +.tweets { + border-bottom-style: solid; + border-color: #bfbfbf; + // display: inline; + // height: 32px; + // width: 100%; + // position: absolute; + // text-align: center; +} + +.tweets_pic { + display: block; + float: left; + width: 28px; + height: 33px; + padding-left: 8px; + padding-top: 8px; + // background: hsl(0, 0%, 30%); +} + +.tweets_name { + padding-left: 45px; + padding-top: 16px; + // border-bottom-style: solid; + // border-color: #00bfff; +} + +.tweet_text { + padding-left: 8px; + padding-top: 15px; +} + +.text_date { + text-align: right; + padding-top: 4px; + font-size: 12px ; +} +.twitter_footer { + padding-top: 8px; +} + +.twitter-image-frame { + width: 40px; + height: 40px; + overflow: hidden; + position: relative; +} + +.twitter-image-frame > img { + display: block; + position: absolute; + top: 0; + bottom: 0; + left: 0; + width: 100%; + margin: auto; +} diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 86c36e9..49471ff 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -4,8 +4,25 @@ class HomeController < ApplicationController respond_to :html def index + unless Rails.application.secrets.twitter['enabled'] == false + twitter_handle = Rails.application.secrets.twitter['twitter_handle'] + @twitter_screen_name = twitter_handle + @twitter_name = twitter_client.user(twitter_handle).name + @tweets = twitter_client.user_timeline(twitter_handle).select{ |tweet| tweet.text.start_with?('RT','@')==false} + @tweet_time = "tweeted on" + end + if logged_in? redirect_to current_user end end + + def twitter_client + Twitter::REST::Client.new do |config| + config.consumer_key = Rails.application.secrets.twitter['consumer_key'] + config.consumer_secret = Rails.application.secrets.twitter['consumer_secret'] + config.bearer_token = Rails.application.secrets.twitter['bearer_token'] + end + end + end diff --git a/app/controllers/twitter_controller.rb b/app/controllers/twitter_controller.rb new file mode 100644 index 0000000..0f6a773 --- /dev/null +++ b/app/controllers/twitter_controller.rb @@ -0,0 +1,19 @@ +class TwitterController < ApplicationController + def twitter_client + Twitter::REST::Client.new do |config| + config.consumer_key = Rails.application.secrets.twitter['consumer_key'] + config.consumer_secret = Rails.application.secrets.twitter['consumer_secret'] + config.bearer_token = Rails.application.secrets.twitter['bearer_token'] + end + end + + def index + unless Rails.application.secrets.twitter['enabled'] == false + twitter_handle = Rails.application.secrets.twitter['twitter_handle'] + @twitter_screen_name = twitter_handle + @twitter_name = twitter_client.user(twitter_handle).name + @tweets = twitter_client.user_timeline(twitter_handle).select{ |tweet| tweet.text.start_with?('RT','@')==false} + @tweet_time = "tweeted on" + end + end +end diff --git a/app/helpers/twitter_helper.rb b/app/helpers/twitter_helper.rb new file mode 100644 index 0000000..bb3ed2d --- /dev/null +++ b/app/helpers/twitter_helper.rb @@ -0,0 +1,2 @@ +module TwitterHelper +end diff --git a/app/views/home/_content.html.haml b/app/views/home/_content.html.haml index 67e4533..725c391 100644 --- a/app/views/home/_content.html.haml +++ b/app/views/home/_content.html.haml @@ -1,10 +1,12 @@ -.row +.left.column %h1= t(:welcome, :provider => APP_CONFIG[:domain]) .p=t(:welcome_message_html) -.row = home_page_buttons +.right.column + = render :partial => 'twitter/index' + - if Rails.env == 'development' .row %hr diff --git a/app/views/home/index.html.haml b/app/views/home/index.html.haml index 147cacd..7f07460 100644 --- a/app/views/home/index.html.haml +++ b/app/views/home/index.html.haml @@ -3,7 +3,8 @@ #main .container-fluid = render 'home/content' + #push -# #push is used for sticky footer in bootstrap 2. remove when upgrading to bootstrap 3 #footer - = render 'layouts/footer' \ No newline at end of file + = render 'layouts/footer' diff --git a/app/views/twitter/_index.html.erb b/app/views/twitter/_index.html.erb new file mode 100644 index 0000000..9825afa --- /dev/null +++ b/app/views/twitter/_index.html.erb @@ -0,0 +1,26 @@ +<% unless Rails.application.secrets.twitter['enabled'] == false %> +
+ + + <% @tweets.each do |e| %> +
+ + +
+ @<%= @twitter_screen_name %> +
+
+ <%= " #{e.text}" %> +
+
+ <%= @tweet_time %> <% t = e.created_at%> <%="#{t.strftime("%m/%d/%Y")}"%> +
+
+ <% end %> + +
+ <% end %> diff --git a/config/defaults.yml b/config/defaults.yml index 7e2ea58..1c9195f 100644 --- a/config/defaults.yml +++ b/config/defaults.yml @@ -32,6 +32,7 @@ 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: @@ -125,6 +126,11 @@ development: secret_token: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' reraise_errors: true + twitter: + consumer_key : Change_to_your_consumer_key + consumer_secret : Change_to_your_consumer_secret + bearer_token : Change_to_your_bearer_token + test: <<: *downloads <<: *dev_ca diff --git a/config/routes.rb b/config/routes.rb index b152c9c..cb39dc6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,6 @@ LeapWeb::Application.routes.draw do + get 'twitter/index' + # # Please do not use root_path or root_url. Use home_path and home_url instead, # so that the path will be correctly prefixed with the locale. -- cgit v1.2.3 From 1a8ad3afdb26acf6ae05d5acca2de43ce44086e0 Mon Sep 17 00:00:00 2001 From: luca-marie Date: Wed, 24 Aug 2016 15:31:30 +0200 Subject: Update in config --- config/config.yml | 167 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 167 insertions(+) create mode 100644 config/config.yml diff --git a/config/config.yml b/config/config.yml new file mode 100644 index 0000000..ff3d936 --- /dev/null +++ b/config/config.yml @@ -0,0 +1,167 @@ +dev_ca: &dev_ca + client_ca_key: "./test/files/ca.key" + client_ca_cert: "./test/files/ca.crt" + ca_key_password: nil + +cert_options: &cert_options + client_cert_lifespan: "2 months" + client_cert_bit_size: 2024 + client_cert_hash: "SHA256" + allow_limited_certs: false + allow_unlimited_certs: true + allow_anonymous_certs: false + limited_cert_prefix: "LIMITED" + unlimited_cert_prefix: "UNLIMITED" + +downloads: &downloads + client_download_domain: https://dl.bitmask.net + available_clients: + - linux + - osx + - windows + - android + download_paths: + android: /android/ + linux: /linux/ + osx: /mac/ + windows: /windows/ + other: / + +common: &common + force_ssl: false + 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: + - certmaster + - ssladmin + - arin-admin + - administrator + - www-data + - maildrop + - postmaster + - admin + - contact + - info + - noreply + - robot + - helpdesk + - help + - tickets + - owner + # handles that will be allowed despite being in /etc/passwd or rfc2142 + handle_whitelist: [] + # actions enabled in the account settings + # see /users/app/views/users/_edit.html.haml for a list. + user_actions: ['contact_email', 'destroy_account'] + admin_actions: ['contact_email', 'change_pgp_key', 'change_service_level', 'destroy_account'] + billing: ~ + default_locale: :en + available_locales: + - :cs + - :de + - :el + - :en + - :es + - :fi + - :fr + - :hu + - :it + - :lt + - :nb + - :nl + - :pl + - :pt + - :ru + - :tr + - :zh + minimum_client_version: "0.5" + engines: + - support + - billing + allow_registration: true + invite_required: false + config_file_paths: + soledad-service: 'public/1/config/soledad-service.json' + eip-service: 'public/1/config/eip-service.json' + smtp-service: 'public/1/config/smtp-service.json' + provider: 'config/provider/provider.json' + mailer: + from_address: 'noreply' + +service_levels: &service_levels + service_levels: + 1: + name: free + description: "free account, with rate limited VPN" + eip_rate_limit: true + storage: 100 + services: + - eip + 2: + name: premium + description: "premium account, with unlimited vpn" + rate: + USD: 10 + EUR: 10 + services: + - eip + - email + default_service_level: 1 + +development: + <<: *downloads + <<: *dev_ca + <<: *cert_options + <<: *common + <<: *service_levels + admins: [blue, red, staff, ava] + api_tokens: + monitor: nil + admin: nil + domain: example.org + secret_token: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' + reraise_errors: true + + twitter: + twitter_handle : 'xxxxxxxxxxxxxxxxx' + consumer_key : 'xxxxxxxxxxxxxxxxx' + consumer_secret : 'xxxxxxxxxxxxxxxxx' + bearer_token : 'xxxxxxxxxxxxxxxxx' + +test: + <<: *downloads + <<: *dev_ca + <<: *cert_options + <<: *common + <<: *service_levels + admins: [admin, admin2] + api_tokens: + monitor: "212da28a59dcaca487365309dc93aa09" + admin: nil + allowed_ips: + - 0.0.0.0 + domain: test.me + secret_token: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' + reraise_errors: true + billing: {} + default_locale: :en + available_locales: + - :en + - :de + +production: + <<: *downloads + <<: *cert_options + <<: *common + admins: [] + api_tokens: + monitor: nil + admin: nil + domain: example.net + engines: + - support + # logfile: /path/to/your/logs -- cgit v1.2.3 From 112d76fe1ba6c66c66e0b3beade901bcadd3410f Mon Sep 17 00:00:00 2001 From: luca-marie Date: Thu, 25 Aug 2016 18:05:45 +0200 Subject: One more gif to play with --- app/assets/images/team-loadtocode-Loading_icon.gif | Bin 0 -> 17490 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 app/assets/images/team-loadtocode-Loading_icon.gif diff --git a/app/assets/images/team-loadtocode-Loading_icon.gif b/app/assets/images/team-loadtocode-Loading_icon.gif new file mode 100644 index 0000000..a718bd8 Binary files /dev/null and b/app/assets/images/team-loadtocode-Loading_icon.gif differ -- cgit v1.2.3 From 4054060a68c119c509228db34ec139f0a0e0c00a Mon Sep 17 00:00:00 2001 From: luca-marie Date: Thu, 25 Aug 2016 18:14:40 +0200 Subject: Update --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 5565d6e..49a57be 100644 --- a/.gitignore +++ b/.gitignore @@ -34,7 +34,7 @@ public/ca.crt public/config/* public/provider.json # config/config.yml -config.secrets.yml +config/secrets.yml config/initializers/test.rb public/1/* vendor/bundle/* -- cgit v1.2.3 From fecc0e9e1985be2d3767664453d4776ac20897c0 Mon Sep 17 00:00:00 2001 From: luca-marie Date: Thu, 25 Aug 2016 20:50:12 +0200 Subject: Twitter controller now as helper, some more styling in CSS, bug fix --- app/assets/stylesheets/twitter.scss | 21 ++++++++++++-------- app/controllers/home_controller.rb | 17 ----------------- app/helpers/twitter_helper.rb | 22 +++++++++++++++++++++ app/views/home/_content.html.haml | 13 +++++++------ app/views/twitter/_index.html.erb | 38 ++++++++++++++++++------------------- config/routes.rb | 2 -- 6 files changed, 60 insertions(+), 53 deletions(-) diff --git a/app/assets/stylesheets/twitter.scss b/app/assets/stylesheets/twitter.scss index 1d54785..6b74cf7 100644 --- a/app/assets/stylesheets/twitter.scss +++ b/app/assets/stylesheets/twitter.scss @@ -1,5 +1,5 @@ .twitter { - // position: fixed; + position: relative; // top: 0; // right: 10px; // bottom: 0; @@ -11,13 +11,18 @@ height: 30px; font-size: 20px ; text-align: center; + margin-bottom: 20px; +} + +.twitter_list { + position: relative; } -.tweets:hover { +.tweet:hover { background-color: #ccf2ff; } -.tweets { +.tweet { border-bottom-style: solid; border-color: #bfbfbf; // display: inline; @@ -27,7 +32,7 @@ // text-align: center; } -.tweets_pic { +.tweet_pic { display: block; float: left; width: 28px; @@ -37,7 +42,7 @@ // background: hsl(0, 0%, 30%); } -.tweets_name { +.tweet_name { padding-left: 45px; padding-top: 16px; // border-bottom-style: solid; @@ -49,7 +54,7 @@ padding-top: 15px; } -.text_date { +.tweet_text_date { text-align: right; padding-top: 4px; font-size: 12px ; @@ -58,14 +63,14 @@ padding-top: 8px; } -.twitter-image-frame { +.twitter_image_frame { width: 40px; height: 40px; overflow: hidden; position: relative; } -.twitter-image-frame > img { +.twitter_image_frame > img { display: block; position: absolute; top: 0; diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 49471ff..86c36e9 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -4,25 +4,8 @@ class HomeController < ApplicationController respond_to :html def index - unless Rails.application.secrets.twitter['enabled'] == false - twitter_handle = Rails.application.secrets.twitter['twitter_handle'] - @twitter_screen_name = twitter_handle - @twitter_name = twitter_client.user(twitter_handle).name - @tweets = twitter_client.user_timeline(twitter_handle).select{ |tweet| tweet.text.start_with?('RT','@')==false} - @tweet_time = "tweeted on" - end - if logged_in? redirect_to current_user end end - - def twitter_client - Twitter::REST::Client.new do |config| - config.consumer_key = Rails.application.secrets.twitter['consumer_key'] - config.consumer_secret = Rails.application.secrets.twitter['consumer_secret'] - config.bearer_token = Rails.application.secrets.twitter['bearer_token'] - end - end - end diff --git a/app/helpers/twitter_helper.rb b/app/helpers/twitter_helper.rb index bb3ed2d..9fd4ffd 100644 --- a/app/helpers/twitter_helper.rb +++ b/app/helpers/twitter_helper.rb @@ -1,2 +1,24 @@ module TwitterHelper + + def twitter_client + Twitter::REST::Client.new do |config| + config.consumer_key = Rails.application.secrets.twitter['consumer_key'] + config.consumer_secret = Rails.application.secrets.twitter['consumer_secret'] + config.bearer_token = Rails.application.secrets.twitter['bearer_token'] + end + end + + def twitter_handle + Rails.application.secrets.twitter['twitter_handle'] + end + + def twitter_name + twitter_client.user(twitter_handle).name + end + + def tweets + twitter_client.user_timeline(twitter_handle).select{ |tweet| tweet.text.start_with?('RT','@')==false} + end end + +# unless Rails.application.secrets.twitter['enabled'] == false diff --git a/app/views/home/_content.html.haml b/app/views/home/_content.html.haml index 725c391..6efd2d0 100644 --- a/app/views/home/_content.html.haml +++ b/app/views/home/_content.html.haml @@ -1,14 +1,15 @@ -.left.column +.row %h1= t(:welcome, :provider => APP_CONFIG[:domain]) .p=t(:welcome_message_html) - = home_page_buttons - -.right.column - = render :partial => 'twitter/index' +.row + .col-md-9 + = home_page_buttons + .col-md-3 + = render 'twitter/index' - if Rails.env == 'development' .row %hr %p - = link_to "make donation", new_payment_path if APP_CONFIG[:payment].present? += link_to "make donation", new_payment_path if APP_CONFIG[:payment].present? diff --git a/app/views/twitter/_index.html.erb b/app/views/twitter/_index.html.erb index 9825afa..3dab567 100644 --- a/app/views/twitter/_index.html.erb +++ b/app/views/twitter/_index.html.erb @@ -1,26 +1,24 @@ -<% unless Rails.application.secrets.twitter['enabled'] == false %> -