Skip to content
Snippets Groups Projects
Commit 709c6685 authored by Eugen Rochko's avatar Eugen Rochko
Browse files

Made some progress

parent 9c4856bd
No related branches found
No related tags found
No related merge requests found
Showing
with 149 additions and 9 deletions
...@@ -38,6 +38,8 @@ group :development do ...@@ -38,6 +38,8 @@ group :development do
gem 'web-console', '~> 2.0' gem 'web-console', '~> 2.0'
gem 'spring' gem 'spring'
gem 'rubocop', require: false gem 'rubocop', require: false
gem 'better_errors'
gem 'binding_of_caller'
end end
group :production do group :production do
......
...@@ -43,6 +43,10 @@ GEM ...@@ -43,6 +43,10 @@ GEM
descendants_tracker (~> 0.0.4) descendants_tracker (~> 0.0.4)
ice_nine (~> 0.11.0) ice_nine (~> 0.11.0)
thread_safe (~> 0.3, >= 0.3.1) thread_safe (~> 0.3, >= 0.3.1)
better_errors (2.1.1)
coderay (>= 1.0.0)
erubis (>= 2.6.6)
rack (>= 0.9.0)
binding_of_caller (0.7.2) binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1) debug_inspector (>= 0.0.1)
builder (3.2.2) builder (3.2.2)
...@@ -284,6 +288,8 @@ PLATFORMS ...@@ -284,6 +288,8 @@ PLATFORMS
DEPENDENCIES DEPENDENCIES
addressable addressable
better_errors
binding_of_caller
byebug byebug
coffee-rails (~> 4.1.0) coffee-rails (~> 4.1.0)
dotenv-rails dotenv-rails
......
...@@ -3,6 +3,8 @@ module Mastodon ...@@ -3,6 +3,8 @@ module Mastodon
class Account < Grape::Entity class Account < Grape::Entity
expose :username expose :username
expose :domain expose :domain
expose :display_name
expose :note
end end
class Status < Grape::Entity class Status < Grape::Entity
......
...@@ -8,12 +8,10 @@ module Mastodon ...@@ -8,12 +8,10 @@ module Mastodon
resource :subscriptions do resource :subscriptions do
helpers do helpers do
def subscription_url(account) include ApplicationHelper
"https://649841dc.ngrok.io/api#{subscriptions_path(id: account.id)}"
end
end end
desc 'Receive updates from a feed' desc 'Receive updates from an account'
params do params do
requires :id, type: String, desc: 'Account ID' requires :id, type: String, desc: 'Account ID'
...@@ -23,14 +21,14 @@ module Mastodon ...@@ -23,14 +21,14 @@ module Mastodon
body = request.body.read body = request.body.read
if @account.subscription(subscription_url(@account)).verify(body, env['HTTP_X_HUB_SIGNATURE']) if @account.subscription(subscription_url(@account)).verify(body, env['HTTP_X_HUB_SIGNATURE'])
ProcessFeedUpdateService.new.(body, @account) ProcessFeedService.new.(body, @account)
status 201 status 201
else else
status 202 status 202
end end
end end
desc 'Confirm PuSH subscription to a feed' desc 'Confirm PuSH subscription to an account'
params do params do
requires :id, type: String, desc: 'Account ID' requires :id, type: String, desc: 'Account ID'
...@@ -49,14 +47,15 @@ module Mastodon ...@@ -49,14 +47,15 @@ module Mastodon
end end
resource :salmon do resource :salmon do
desc 'Receive Salmon updates' desc 'Receive Salmon updates targeted to account'
params do params do
requires :id, type: String, desc: 'Account ID' requires :id, type: String, desc: 'Account ID'
end end
post ':id' do post ':id' do
# todo ProcessInteractionService.new.(request.body.read, @account)
status 201
end end
end end
end end
......
...@@ -5,9 +5,34 @@ module Mastodon ...@@ -5,9 +5,34 @@ module Mastodon
resource :statuses do resource :statuses do
desc 'Return a public timeline' desc 'Return a public timeline'
get :all do get :all do
present Status.all, with: Mastodon::Entities::Status present Status.all, with: Mastodon::Entities::Status
end end
desc 'Return the home timeline of a logged in user'
get :home do
# todo
end
desc 'Return the notifications timeline of a logged in user'
get :notifications do
# todo
end
end
resource :accounts do
desc 'Return a user profile'
params do
requires :id, type: String, desc: 'Account ID'
end
get ':id' do
present Account.find(params[:id]), with: Mastodon::Entities::Account
end
end end
end end
end end
...@@ -12,5 +12,4 @@ ...@@ -12,5 +12,4 @@
// //
//= require jquery //= require jquery
//= require jquery_ujs //= require jquery_ujs
//= require turbolinks
//= require_tree . //= require_tree .
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
// Place all the styles related to the Atom controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
// Place all the styles related to the Home controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
// Place all the styles related to the Profile controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
// Place all the styles related to the XRD controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
class AtomController < ApplicationController
before_filter :set_format
def user_stream
@account = Account.find_by!(id: params[:id], domain: nil)
end
private
def set_format
request.format = 'xml'
response.headers['Content-Type'] = 'application/atom+xml'
end
end
class HomeController < ApplicationController
def index
end
end
class ProfileController < ApplicationController
def show
end
end
class XrdController < ApplicationController
before_filter :set_format
def host_meta
@webfinger_template = "#{webfinger_url}?resource={uri}"
end
def webfinger
@account = Account.find_by!(username: username_from_resource, domain: nil)
@canonical_account_uri = "acct:#{@account.username}#{LOCAL_DOMAIN}"
@magic_key = pem_to_magic_key(@account.keypair.public_key)
end
private
def set_format
request.format = 'xml'
response.headers['Content-Type'] = 'application/xrd+xml'
end
def username_from_resource
params[:resource].split('@').first.gsub('acct:', '')
end
def pem_to_magic_key(public_key)
modulus, exponent = [public_key.n, public_key.e].map do |component|
result = ""
until component == 0 do
result << [component % 256].pack('C')
component >>= 8
end
result.reverse!
end
(["RSA"] + [modulus, exponent].map { |n| Base64.urlsafe_encode64(n) }).join('.')
end
end
module ApplicationHelper module ApplicationHelper
include GrapeRouteHelpers::NamedRouteMatcher
def unique_tag(date, id, type)
"tag:#{LOCAL_DOMAIN},#{date.strftime('%Y-%m-%d')}:objectId=#{id}:objectType=#{type}"
end
def subscription_url(account)
add_base_url_prefix subscription_path(id: account.id, format: '')
end
def salmon_url(account)
add_base_url_prefix salmon_path(id: account.id, format: '')
end
def add_base_url_prefix(suffix)
"#{root_url}api#{suffix}"
end
end end
module AtomHelper
def stream_updated_at
@account.stream_entries.last ? @account.stream_entries.last.created_at.iso8601 : @account.updated_at.iso8601
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment