From 57d294e4fd5704698a6d14c8b3bd213c9e1720a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=C3=B1or=20Rolando?= Date: Sun, 8 Dec 2013 23:09:27 +0100 Subject: [PATCH] Prepare for authentification via web flow. --- app/assets/stylesheets/reposts.css.scss | 40 ++++++++++++++++++++++ app/controllers/reposts_controller.rb | 45 +++++++++++++++++++++++++ app/views/reposts/index.html.erb | 14 ++++++++ app/views/reposts/new.html.erb | 5 +++ config/routes.rb | 1 + 5 files changed, 105 insertions(+) create mode 100644 app/views/reposts/new.html.erb diff --git a/app/assets/stylesheets/reposts.css.scss b/app/assets/stylesheets/reposts.css.scss index 4b98949..84c25fd 100644 --- a/app/assets/stylesheets/reposts.css.scss +++ b/app/assets/stylesheets/reposts.css.scss @@ -1,3 +1,43 @@ // Place all the styles related to the Reposts controller here. // They will automatically be included in application.css. // You can use Sass (SCSS) here: http://sass-lang.com/ +/* flash messages */ +#error { + background-color: red; +} +#alert { + background-color: #ffffe0; +} +#notice { + background-color: green; + color: rgb(249, 249, 249); +} +#alert, #error, #notice { + border-bottom-color: #e6db55; + border-left-color: #e6db55; + border-right-color: #e6db55; + border-top-color: #e6db55; + border-bottom-left-radius: 3px; + border-bottom-right-radius: 3px; + border-bottom-style: solid; + border-bottom-width: 1px; + border-left-style: solid; + border-left-width: 1px; + border-right-style: solid; + border-right-width: 1px; + border-top-left-radius: 3px; + border-top-right-radius: 3px; + border-top-style: solid; + border-top-width: 1px; + margin-bottom: 16px; + margin-left: 8px; + margin-right: 0px; + margin-top: 0px; + padding-bottom: 12px; + padding-left: 12px; + padding-right: 12px; + padding-top: 12px; +} +.flash { + line-height: 1.75em; +} diff --git a/app/controllers/reposts_controller.rb b/app/controllers/reposts_controller.rb index 228f00e..95847d9 100644 --- a/app/controllers/reposts_controller.rb +++ b/app/controllers/reposts_controller.rb @@ -1,4 +1,49 @@ +require 'net/http' +require 'uri' + class RepostsController < ApplicationController def index + config = YAML.load_file('config/client.yml') + client_id = config["client_id"] + client_secret = config["client_secret"] + + # connect to ADN via a user token + uri = URI.parse("https://account.app.net/oauth/authenticate") + http = Net::HTTP.new(uri.host, uri.port) + http.use_ssl = true + http.verify_mode = OpenSSL::SSL::VERIFY_NONE + + response = Net::HTTP::post_form( uri, {"client_id" => client_id, "response_type" => "code", "redirect_uri" => "http://localhost:3000/", "scope" => "stream"}) + + # [temp] status + @res_code = response.code + @res_message = response.message + @res_class = response.class.name + + if not response.is_a?(Net::HTTPSuccess) + flash[:error] = "Could not connect to ADN." + return + end + + # ... + end + + # TODO rework from file handling to use of 'reposts' model. + def new + # retrieve latest repost + # TODO: select max(postid) from reposts; + #history = YAML.load('history.yml', :safe => true) + #lastrepostid = history["lastrepost"] + #latestid = lastrepostid + + # fetch all mentions since last one + ## API - fetch( since_id=previous max_id ) + #new_mentions.each do | post | + ## API - repost(post) + #latestid = post.id + #end + + # store latest repost for next time + # TODO insert into reposts values("karlsruher", post.id, latestid) end end diff --git a/app/views/reposts/index.html.erb b/app/views/reposts/index.html.erb index d6e0e47..1f6f36a 100644 --- a/app/views/reposts/index.html.erb +++ b/app/views/reposts/index.html.erb @@ -5,3 +5,17 @@

There is nothing much to see here directly, though.

+ +<% flash.each do |name, msg| %> +
"> + × + <%= content_tag :div, msg, :id => "flash_#{name}" if msg.is_a?(String) %> +
+<% end %> + +

+

Response

+ code: <%= @res_code %>
+ message: <%= @res_message %>
+ class: <%= @res_class %> +

diff --git a/app/views/reposts/new.html.erb b/app/views/reposts/new.html.erb new file mode 100644 index 0000000..78962c8 --- /dev/null +++ b/app/views/reposts/new.html.erb @@ -0,0 +1,5 @@ +

Reposts

+ +

+ Currently, reposts don't work, yet. +

diff --git a/config/routes.rb b/config/routes.rb index f9d57be..4e12d22 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,4 @@ AdnRepostmentions::Application.routes.draw do root :to => 'reposts#index' + resources :reposts end