Browse Source

Initial commit

Eugen Rochko 2 years ago
commit
9c4856bdb1
73 changed files with 1393 additions and 0 deletions
  1. 17
    0
      .gitignore
  2. 1
    0
      .ruby-version
  3. 45
    0
      Gemfile
  4. 319
    0
      Gemfile.lock
  5. 28
    0
      README.rdoc
  6. 6
    0
      Rakefile
  7. 8
    0
      app/api/mastodon/api.rb
  8. 21
    0
      app/api/mastodon/entities.rb
  9. 63
    0
      app/api/mastodon/ostatus.rb
  10. 13
    0
      app/api/mastodon/rest.rb
  11. 0
    0
      app/assets/images/.keep
  12. 16
    0
      app/assets/javascripts/application.js
  13. 15
    0
      app/assets/stylesheets/application.css
  14. 5
    0
      app/controllers/application_controller.rb
  15. 0
    0
      app/controllers/concerns/.keep
  16. 2
    0
      app/helpers/application_helper.rb
  17. 0
    0
      app/mailers/.keep
  18. 0
    0
      app/models/.keep
  19. 7
    0
      app/models/account.rb
  20. 0
    0
      app/models/concerns/.keep
  21. 3
    0
      app/models/status.rb
  22. 5
    0
      app/services/fetch_feed_service.rb
  23. 60
    0
      app/services/follow_remote_user_service.rb
  24. 20
    0
      app/services/process_feed_update_service.rb
  25. 14
    0
      app/views/layouts/application.html.erb
  26. 3
    0
      bin/bundle
  27. 9
    0
      bin/rails
  28. 9
    0
      bin/rake
  29. 29
    0
      bin/setup
  30. 15
    0
      bin/spring
  31. 4
    0
      config.ru
  32. 29
    0
      config/application.rb
  33. 3
    0
      config/boot.rb
  34. 19
    0
      config/database.yml
  35. 5
    0
      config/environment.rb
  36. 41
    0
      config/environments/development.rb
  37. 79
    0
      config/environments/production.rb
  38. 42
    0
      config/environments/test.rb
  39. 11
    0
      config/initializers/assets.rb
  40. 7
    0
      config/initializers/backtrace_silencers.rb
  41. 3
    0
      config/initializers/cookies_serializer.rb
  42. 4
    0
      config/initializers/filter_parameter_logging.rb
  43. 16
    0
      config/initializers/inflections.rb
  44. 4
    0
      config/initializers/mime_types.rb
  45. 13
    0
      config/initializers/reload_api.rb
  46. 3
    0
      config/initializers/session_store.rb
  47. 14
    0
      config/initializers/wrap_parameters.rb
  48. 23
    0
      config/locales/en.yml
  49. 3
    0
      config/routes.rb
  50. 22
    0
      config/secrets.yml
  51. 25
    0
      db/migrate/20160220174730_create_accounts.rb
  52. 13
    0
      db/migrate/20160220211917_create_statuses.rb
  53. 45
    0
      db/schema.rb
  54. 7
    0
      db/seeds.rb
  55. 0
    0
      lib/assets/.keep
  56. 0
    0
      lib/tasks/.keep
  57. 0
    0
      log/.keep
  58. 67
    0
      public/404.html
  59. 67
    0
      public/422.html
  60. 66
    0
      public/500.html
  61. 0
    0
      public/favicon.ico
  62. 5
    0
      public/robots.txt
  63. 5
    0
      spec/models/account_spec.rb
  64. 5
    0
      spec/models/status_spec.rb
  65. 0
    0
      test/controllers/.keep
  66. 0
    0
      test/fixtures/.keep
  67. 0
    0
      test/helpers/.keep
  68. 0
    0
      test/integration/.keep
  69. 0
    0
      test/mailers/.keep
  70. 0
    0
      test/models/.keep
  71. 10
    0
      test/test_helper.rb
  72. 0
    0
      vendor/assets/javascripts/.keep
  73. 0
    0
      vendor/assets/stylesheets/.keep

+ 17
- 0
.gitignore View File

@@ -0,0 +1,17 @@
1
+# See https://help.github.com/articles/ignoring-files for more about ignoring files.
2
+#
3
+# If you find yourself ignoring temporary files generated by your text editor
4
+# or operating system, you probably want to add a global ignore instead:
5
+#   git config --global core.excludesfile '~/.gitignore_global'
6
+
7
+# Ignore bundler config.
8
+/.bundle
9
+
10
+# Ignore the default SQLite database.
11
+/db/*.sqlite3
12
+/db/*.sqlite3-journal
13
+
14
+# Ignore all logfiles and tempfiles.
15
+/log/*
16
+!/log/.keep
17
+/tmp

+ 1
- 0
.ruby-version View File

@@ -0,0 +1 @@
1
+ruby-2.2.4

+ 45
- 0
Gemfile View File

@@ -0,0 +1,45 @@
1
+source 'https://rubygems.org'
2
+
3
+gem 'rails', '4.2.5.1'
4
+gem 'sqlite3'
5
+gem 'sass-rails', '~> 5.0'
6
+gem 'uglifier', '>= 1.3.0'
7
+gem 'coffee-rails', '~> 4.1.0'
8
+gem 'therubyracer', platforms: :ruby
9
+gem 'jquery-rails'
10
+gem 'jbuilder', '~> 2.0'
11
+gem 'sdoc', '~> 0.4.0', group: :doc
12
+gem 'puma'
13
+
14
+gem 'haml-rails'
15
+gem 'pg'
16
+gem 'dotenv-rails'
17
+
18
+gem 'grape'
19
+gem 'grape-route-helpers'
20
+gem 'grape-entity'
21
+gem 'hashie-forbidden_attributes'
22
+
23
+gem 'http'
24
+gem 'addressable'
25
+gem 'nokogiri'
26
+gem 'ostatus2'
27
+gem 'goldfinger'
28
+
29
+group :development, :test do
30
+  gem 'byebug'
31
+  gem 'rspec-rails'
32
+  gem 'quiet_assets'
33
+  gem 'nyan-cat-formatter'
34
+  gem 'pry-rails'
35
+end
36
+
37
+group :development do
38
+  gem 'web-console', '~> 2.0'
39
+  gem 'spring'
40
+  gem 'rubocop', require: false
41
+end
42
+
43
+group :production do
44
+  gem 'rails_12factor'
45
+end

+ 319
- 0
Gemfile.lock View File

@@ -0,0 +1,319 @@
1
+GEM
2
+  remote: https://rubygems.org/
3
+  specs:
4
+    actionmailer (4.2.5.1)
5
+      actionpack (= 4.2.5.1)
6
+      actionview (= 4.2.5.1)
7
+      activejob (= 4.2.5.1)
8
+      mail (~> 2.5, >= 2.5.4)
9
+      rails-dom-testing (~> 1.0, >= 1.0.5)
10
+    actionpack (4.2.5.1)
11
+      actionview (= 4.2.5.1)
12
+      activesupport (= 4.2.5.1)
13
+      rack (~> 1.6)
14
+      rack-test (~> 0.6.2)
15
+      rails-dom-testing (~> 1.0, >= 1.0.5)
16
+      rails-html-sanitizer (~> 1.0, >= 1.0.2)
17
+    actionview (4.2.5.1)
18
+      activesupport (= 4.2.5.1)
19
+      builder (~> 3.1)
20
+      erubis (~> 2.7.0)
21
+      rails-dom-testing (~> 1.0, >= 1.0.5)
22
+      rails-html-sanitizer (~> 1.0, >= 1.0.2)
23
+    activejob (4.2.5.1)
24
+      activesupport (= 4.2.5.1)
25
+      globalid (>= 0.3.0)
26
+    activemodel (4.2.5.1)
27
+      activesupport (= 4.2.5.1)
28
+      builder (~> 3.1)
29
+    activerecord (4.2.5.1)
30
+      activemodel (= 4.2.5.1)
31
+      activesupport (= 4.2.5.1)
32
+      arel (~> 6.0)
33
+    activesupport (4.2.5.1)
34
+      i18n (~> 0.7)
35
+      json (~> 1.7, >= 1.7.7)
36
+      minitest (~> 5.1)
37
+      thread_safe (~> 0.3, >= 0.3.4)
38
+      tzinfo (~> 1.1)
39
+    addressable (2.4.0)
40
+    arel (6.0.3)
41
+    ast (2.2.0)
42
+    axiom-types (0.1.1)
43
+      descendants_tracker (~> 0.0.4)
44
+      ice_nine (~> 0.11.0)
45
+      thread_safe (~> 0.3, >= 0.3.1)
46
+    binding_of_caller (0.7.2)
47
+      debug_inspector (>= 0.0.1)
48
+    builder (3.2.2)
49
+    byebug (8.2.2)
50
+    coderay (1.1.1)
51
+    coercible (1.0.0)
52
+      descendants_tracker (~> 0.0.1)
53
+    coffee-rails (4.1.1)
54
+      coffee-script (>= 2.2.0)
55
+      railties (>= 4.0.0, < 5.1.x)
56
+    coffee-script (2.4.1)
57
+      coffee-script-source
58
+      execjs
59
+    coffee-script-source (1.10.0)
60
+    concurrent-ruby (1.0.0)
61
+    debug_inspector (0.0.2)
62
+    descendants_tracker (0.0.4)
63
+      thread_safe (~> 0.3, >= 0.3.1)
64
+    diff-lcs (1.2.5)
65
+    domain_name (0.5.20160128)
66
+      unf (>= 0.0.5, < 1.0.0)
67
+    dotenv (2.1.0)
68
+    dotenv-rails (2.1.0)
69
+      dotenv (= 2.1.0)
70
+      railties (>= 4.0, < 5.1)
71
+    equalizer (0.0.11)
72
+    erubis (2.7.0)
73
+    execjs (2.6.0)
74
+    globalid (0.3.6)
75
+      activesupport (>= 4.1.0)
76
+    goldfinger (1.0.1)
77
+      addressable (~> 2.4)
78
+      http (~> 1.0)
79
+      nokogiri (~> 1.6)
80
+    grape (0.14.0)
81
+      activesupport
82
+      builder
83
+      hashie (>= 2.1.0)
84
+      multi_json (>= 1.3.2)
85
+      multi_xml (>= 0.5.2)
86
+      rack (>= 1.3.0)
87
+      rack-accept
88
+      rack-mount
89
+      virtus (>= 1.0.0)
90
+    grape-entity (0.5.0)
91
+      activesupport
92
+      multi_json (>= 1.3.2)
93
+    grape-route-helpers (1.2.1)
94
+      activesupport
95
+      grape
96
+      rake
97
+    haml (4.0.7)
98
+      tilt
99
+    haml-rails (0.9.0)
100
+      actionpack (>= 4.0.1)
101
+      activesupport (>= 4.0.1)
102
+      haml (>= 4.0.6, < 5.0)
103
+      html2haml (>= 1.0.1)
104
+      railties (>= 4.0.1)
105
+    hashie (3.4.3)
106
+    hashie-forbidden_attributes (0.1.1)
107
+      hashie (>= 3.0)
108
+    html2haml (2.0.0)
109
+      erubis (~> 2.7.0)
110
+      haml (~> 4.0.0)
111
+      nokogiri (~> 1.6.0)
112
+      ruby_parser (~> 3.5)
113
+    http (1.0.2)
114
+      addressable (~> 2.3)
115
+      http-cookie (~> 1.0)
116
+      http-form_data (~> 1.0.1)
117
+      http_parser.rb (~> 0.6.0)
118
+    http-cookie (1.0.2)
119
+      domain_name (~> 0.5)
120
+    http-form_data (1.0.1)
121
+    http_parser.rb (0.6.0)
122
+    i18n (0.7.0)
123
+    ice_nine (0.11.2)
124
+    jbuilder (2.4.1)
125
+      activesupport (>= 3.0.0, < 5.1)
126
+      multi_json (~> 1.2)
127
+    jquery-rails (4.1.0)
128
+      rails-dom-testing (~> 1.0)
129
+      railties (>= 4.2.0)
130
+      thor (>= 0.14, < 2.0)
131
+    json (1.8.3)
132
+    libv8 (3.16.14.13)
133
+    loofah (2.0.3)
134
+      nokogiri (>= 1.5.9)
135
+    mail (2.6.3)
136
+      mime-types (>= 1.16, < 3)
137
+    method_source (0.8.2)
138
+    mime-types (2.99)
139
+    mini_portile2 (2.0.0)
140
+    minitest (5.8.4)
141
+    multi_json (1.11.2)
142
+    multi_xml (0.5.5)
143
+    nokogiri (1.6.7.2)
144
+      mini_portile2 (~> 2.0.0.rc2)
145
+    nyan-cat-formatter (0.11)
146
+      rspec (>= 2.99, >= 2.14.2, < 4)
147
+    ostatus2 (0.1.1)
148
+      addressable (~> 2.4)
149
+      http (~> 1.0)
150
+      nokogiri (~> 1.6)
151
+    parser (2.3.0.6)
152
+      ast (~> 2.2)
153
+    pg (0.18.4)
154
+    powerpack (0.1.1)
155
+    pry (0.10.3)
156
+      coderay (~> 1.1.0)
157
+      method_source (~> 0.8.1)
158
+      slop (~> 3.4)
159
+    pry-rails (0.3.4)
160
+      pry (>= 0.9.10)
161
+    puma (2.16.0)
162
+    quiet_assets (1.1.0)
163
+      railties (>= 3.1, < 5.0)
164
+    rack (1.6.4)
165
+    rack-accept (0.4.5)
166
+      rack (>= 0.4)
167
+    rack-mount (0.8.3)
168
+      rack (>= 1.0.0)
169
+    rack-test (0.6.3)
170
+      rack (>= 1.0)
171
+    rails (4.2.5.1)
172
+      actionmailer (= 4.2.5.1)
173
+      actionpack (= 4.2.5.1)
174
+      actionview (= 4.2.5.1)
175
+      activejob (= 4.2.5.1)
176
+      activemodel (= 4.2.5.1)
177
+      activerecord (= 4.2.5.1)
178
+      activesupport (= 4.2.5.1)
179
+      bundler (>= 1.3.0, < 2.0)
180
+      railties (= 4.2.5.1)
181
+      sprockets-rails
182
+    rails-deprecated_sanitizer (1.0.3)
183
+      activesupport (>= 4.2.0.alpha)
184
+    rails-dom-testing (1.0.7)
185
+      activesupport (>= 4.2.0.beta, < 5.0)
186
+      nokogiri (~> 1.6.0)
187
+      rails-deprecated_sanitizer (>= 1.0.1)
188
+    rails-html-sanitizer (1.0.3)
189
+      loofah (~> 2.0)
190
+    rails_12factor (0.0.3)
191
+      rails_serve_static_assets
192
+      rails_stdout_logging
193
+    rails_serve_static_assets (0.0.5)
194
+    rails_stdout_logging (0.0.4)
195
+    railties (4.2.5.1)
196
+      actionpack (= 4.2.5.1)
197
+      activesupport (= 4.2.5.1)
198
+      rake (>= 0.8.7)
199
+      thor (>= 0.18.1, < 2.0)
200
+    rainbow (2.1.0)
201
+    rake (10.5.0)
202
+    rdoc (4.2.2)
203
+      json (~> 1.4)
204
+    ref (2.0.0)
205
+    rspec (3.4.0)
206
+      rspec-core (~> 3.4.0)
207
+      rspec-expectations (~> 3.4.0)
208
+      rspec-mocks (~> 3.4.0)
209
+    rspec-core (3.4.3)
210
+      rspec-support (~> 3.4.0)
211
+    rspec-expectations (3.4.0)
212
+      diff-lcs (>= 1.2.0, < 2.0)
213
+      rspec-support (~> 3.4.0)
214
+    rspec-mocks (3.4.1)
215
+      diff-lcs (>= 1.2.0, < 2.0)
216
+      rspec-support (~> 3.4.0)
217
+    rspec-rails (3.4.2)
218
+      actionpack (>= 3.0, < 4.3)
219
+      activesupport (>= 3.0, < 4.3)
220
+      railties (>= 3.0, < 4.3)
221
+      rspec-core (~> 3.4.0)
222
+      rspec-expectations (~> 3.4.0)
223
+      rspec-mocks (~> 3.4.0)
224
+      rspec-support (~> 3.4.0)
225
+    rspec-support (3.4.1)
226
+    rubocop (0.37.2)
227
+      parser (>= 2.3.0.4, < 3.0)
228
+      powerpack (~> 0.1)
229
+      rainbow (>= 1.99.1, < 3.0)
230
+      ruby-progressbar (~> 1.7)
231
+      unicode-display_width (~> 0.3)
232
+    ruby-progressbar (1.7.5)
233
+    ruby_parser (3.8.1)
234
+      sexp_processor (~> 4.1)
235
+    sass (3.4.21)
236
+    sass-rails (5.0.4)
237
+      railties (>= 4.0.0, < 5.0)
238
+      sass (~> 3.1)
239
+      sprockets (>= 2.8, < 4.0)
240
+      sprockets-rails (>= 2.0, < 4.0)
241
+      tilt (>= 1.1, < 3)
242
+    sdoc (0.4.1)
243
+      json (~> 1.7, >= 1.7.7)
244
+      rdoc (~> 4.0)
245
+    sexp_processor (4.7.0)
246
+    slop (3.6.0)
247
+    spring (1.6.3)
248
+    sprockets (3.5.2)
249
+      concurrent-ruby (~> 1.0)
250
+      rack (> 1, < 3)
251
+    sprockets-rails (3.0.1)
252
+      actionpack (>= 4.0)
253
+      activesupport (>= 4.0)
254
+      sprockets (>= 3.0.0)
255
+    sqlite3 (1.3.11)
256
+    therubyracer (0.12.2)
257
+      libv8 (~> 3.16.14.0)
258
+      ref
259
+    thor (0.19.1)
260
+    thread_safe (0.3.5)
261
+    tilt (2.0.2)
262
+    tzinfo (1.2.2)
263
+      thread_safe (~> 0.1)
264
+    uglifier (2.7.2)
265
+      execjs (>= 0.3.0)
266
+      json (>= 1.8.0)
267
+    unf (0.1.4)
268
+      unf_ext
269
+    unf_ext (0.0.7.2)
270
+    unicode-display_width (0.3.1)
271
+    virtus (1.0.5)
272
+      axiom-types (~> 0.1)
273
+      coercible (~> 1.0)
274
+      descendants_tracker (~> 0.0, >= 0.0.3)
275
+      equalizer (~> 0.0, >= 0.0.9)
276
+    web-console (2.3.0)
277
+      activemodel (>= 4.0)
278
+      binding_of_caller (>= 0.7.2)
279
+      railties (>= 4.0)
280
+      sprockets-rails (>= 2.0, < 4.0)
281
+
282
+PLATFORMS
283
+  ruby
284
+
285
+DEPENDENCIES
286
+  addressable
287
+  byebug
288
+  coffee-rails (~> 4.1.0)
289
+  dotenv-rails
290
+  goldfinger
291
+  grape
292
+  grape-entity
293
+  grape-route-helpers
294
+  haml-rails
295
+  hashie-forbidden_attributes
296
+  http
297
+  jbuilder (~> 2.0)
298
+  jquery-rails
299
+  nokogiri
300
+  nyan-cat-formatter
301
+  ostatus2
302
+  pg
303
+  pry-rails
304
+  puma
305
+  quiet_assets
306
+  rails (= 4.2.5.1)
307
+  rails_12factor
308
+  rspec-rails
309
+  rubocop
310
+  sass-rails (~> 5.0)
311
+  sdoc (~> 0.4.0)
312
+  spring
313
+  sqlite3
314
+  therubyracer
315
+  uglifier (>= 1.3.0)
316
+  web-console (~> 2.0)
317
+
318
+BUNDLED WITH
319
+   1.11.2

+ 28
- 0
README.rdoc View File

@@ -0,0 +1,28 @@
1
+== README
2
+
3
+This README would normally document whatever steps are necessary to get the
4
+application up and running.
5
+
6
+Things you may want to cover:
7
+
8
+* Ruby version
9
+
10
+* System dependencies
11
+
12
+* Configuration
13
+
14
+* Database creation
15
+
16
+* Database initialization
17
+
18
+* How to run the test suite
19
+
20
+* Services (job queues, cache servers, search engines, etc.)
21
+
22
+* Deployment instructions
23
+
24
+* ...
25
+
26
+
27
+Please feel free to use a different markup language if you do not plan to run
28
+<tt>rake doc:app</tt>.

+ 6
- 0
Rakefile View File

@@ -0,0 +1,6 @@
1
+# Add your own tasks in files placed in lib/tasks ending in .rake,
2
+# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+require File.expand_path('../config/application', __FILE__)
5
+
6
+Rails.application.load_tasks

+ 8
- 0
app/api/mastodon/api.rb View File

@@ -0,0 +1,8 @@
1
+module Mastodon
2
+  class API < Grape::API
3
+    rescue_from :all
4
+
5
+    mount Mastodon::Ostatus
6
+    mount Mastodon::Rest
7
+  end
8
+end

+ 21
- 0
app/api/mastodon/entities.rb View File

@@ -0,0 +1,21 @@
1
+module Mastodon
2
+  module Entities
3
+    class Account < Grape::Entity
4
+      expose :username
5
+      expose :domain
6
+    end
7
+
8
+    class Status < Grape::Entity
9
+      format_with(:iso_timestamp) { |dt| dt.iso8601 }
10
+
11
+      expose :uri
12
+      expose :text
13
+      expose :account, using: Mastodon::Entities::Account
14
+
15
+      with_options(format_with: :iso_timestamp) do
16
+        expose :created_at
17
+        expose :updated_at
18
+      end
19
+    end
20
+  end
21
+end

+ 63
- 0
app/api/mastodon/ostatus.rb View File

@@ -0,0 +1,63 @@
1
+module Mastodon
2
+  class Ostatus < Grape::API
3
+    format :txt
4
+
5
+    before do
6
+      @account = Account.find(params[:id])
7
+    end
8
+
9
+    resource :subscriptions do
10
+      helpers do
11
+        def subscription_url(account)
12
+          "https://649841dc.ngrok.io/api#{subscriptions_path(id: account.id)}"
13
+        end
14
+      end
15
+
16
+      desc 'Receive updates from a feed'
17
+
18
+      params do
19
+        requires :id, type: String, desc: 'Account ID'
20
+      end
21
+
22
+      post ':id' do
23
+        body = request.body.read
24
+
25
+        if @account.subscription(subscription_url(@account)).verify(body, env['HTTP_X_HUB_SIGNATURE'])
26
+          ProcessFeedUpdateService.new.(body, @account)
27
+          status 201
28
+        else
29
+          status 202
30
+        end
31
+      end
32
+
33
+      desc 'Confirm PuSH subscription to a feed'
34
+
35
+      params do
36
+        requires :id, type: String, desc: 'Account ID'
37
+        requires 'hub.topic', type: String, desc: 'Topic URL'
38
+        requires 'hub.verify_token', type: String, desc: 'Verification token'
39
+        requires 'hub.challenge', type: String, desc: 'Hub challenge'
40
+      end
41
+
42
+      get ':id' do
43
+        if @account.subscription(subscription_url(@account)).valid?(params['hub.topic'], params['hub.verify_token'])
44
+          params['hub.challenge']
45
+        else
46
+          error! :not_found, 404
47
+        end
48
+      end
49
+    end
50
+
51
+    resource :salmon do
52
+      desc 'Receive Salmon updates'
53
+
54
+      params do
55
+        requires :id, type: String, desc: 'Account ID'
56
+      end
57
+
58
+      post ':id' do
59
+        # todo
60
+      end
61
+    end
62
+  end
63
+end

+ 13
- 0
app/api/mastodon/rest.rb View File

@@ -0,0 +1,13 @@
1
+module Mastodon
2
+  class Rest < Grape::API
3
+    version 'v1', using: :path
4
+    format :json
5
+
6
+    resource :statuses do
7
+      desc 'Return a public timeline'
8
+      get :all do
9
+        present Status.all, with: Mastodon::Entities::Status
10
+      end
11
+    end
12
+  end
13
+end

+ 0
- 0
app/assets/images/.keep View File


+ 16
- 0
app/assets/javascripts/application.js View File

@@ -0,0 +1,16 @@
1
+// This is a manifest file that'll be compiled into application.js, which will include all the files
2
+// listed below.
3
+//
4
+// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+//
7
+// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+// compiled file.
9
+//
10
+// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+// about supported directives.
12
+//
13
+//= require jquery
14
+//= require jquery_ujs
15
+//= require turbolinks
16
+//= require_tree .

+ 15
- 0
app/assets/stylesheets/application.css View File

@@ -0,0 +1,15 @@
1
+/*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */

+ 5
- 0
app/controllers/application_controller.rb View File

@@ -0,0 +1,5 @@
1
+class ApplicationController < ActionController::Base
2
+  # Prevent CSRF attacks by raising an exception.
3
+  # For APIs, you may want to use :null_session instead.
4
+  protect_from_forgery with: :exception
5
+end

+ 0
- 0
app/controllers/concerns/.keep View File


+ 2
- 0
app/helpers/application_helper.rb View File

@@ -0,0 +1,2 @@
1
+module ApplicationHelper
2
+end

+ 0
- 0
app/mailers/.keep View File


+ 0
- 0
app/models/.keep View File


+ 7
- 0
app/models/account.rb View File

@@ -0,0 +1,7 @@
1
+class Account < ActiveRecord::Base
2
+  has_many :statuses, inverse_of: :account
3
+
4
+  def subscription(webhook_url)
5
+    @subscription ||= OStatus2::Subscription.new(self.remote_url, secret: self.secret, token: self.verify_token, webhook: webhook_url, hub: self.hub_url)
6
+  end
7
+end

+ 0
- 0
app/models/concerns/.keep View File


+ 3
- 0
app/models/status.rb View File

@@ -0,0 +1,3 @@
1
+class Status < ActiveRecord::Base
2
+  belongs_to :account, inverse_of: :statuses
3
+end

+ 5
- 0
app/services/fetch_feed_service.rb View File

@@ -0,0 +1,5 @@
1
+class FetchFeedService
2
+  def call(account)
3
+    # todo
4
+  end
5
+end

+ 60
- 0
app/services/follow_remote_user_service.rb View File

@@ -0,0 +1,60 @@
1
+class FollowRemoteUserService
2
+  include GrapeRouteHelpers::NamedRouteMatcher
3
+
4
+  def call(user)
5
+    username, domain = user.split('@')
6
+    account = Account.where(username: username, domain: domain).first
7
+
8
+    return account unless account.nil?
9
+
10
+    account = Account.new(username: username, domain: domain)
11
+    data    = Goldfinger.finger("acct:#{user}")
12
+
13
+    account.remote_url  = data.link('http://schemas.google.com/g/2010#updates-from').href
14
+    account.salmon_url  = data.link('salmon').href
15
+    account.public_key  = magic_key_to_pem(data.link('magic-public-key').href)
16
+    account.private_key = nil
17
+
18
+    account.secret       = SecureRandom.hex
19
+    account.verify_token = SecureRandom.hex
20
+
21
+    feed = get_feed(account.remote_url)
22
+    hubs = feed.xpath('//xmlns:link[@rel="hub"]')
23
+
24
+    return false if hubs.empty? || hubs.first.attribute('href').nil?
25
+
26
+    account.hub_url = hubs.first.attribute('href').value
27
+    account.save!
28
+
29
+    subscription = account.subscription(subscription_url(account))
30
+    subscription.subscribe
31
+  rescue Goldfinger::Error, HTTP::Error => e
32
+    false
33
+  end
34
+
35
+  private
36
+
37
+  def get_feed(url)
38
+    response = http_client.get(Addressable::URI.parse(url))
39
+    Nokogiri::XML(response)
40
+  end
41
+
42
+  def magic_key_to_pem(magic_key)
43
+    _, modulus, exponent = magic_key.split('.')
44
+    modulus, exponent = [modulus, exponent].map { |n| Base64.urlsafe_decode64(n).bytes.inject(0) { |num, byte| (num << 8) | byte } }
45
+
46
+    key   = OpenSSL::PKey::RSA.new
47
+    key.n = modulus
48
+    key.d = exponent
49
+
50
+    key.to_pem
51
+  end
52
+
53
+  def http_client
54
+    HTTP
55
+  end
56
+
57
+  def subscription_url(account)
58
+    "https://649841dc.ngrok.io/api#{subscriptions_path(id: account.id)}"
59
+  end
60
+end

+ 20
- 0
app/services/process_feed_update_service.rb View File

@@ -0,0 +1,20 @@
1
+class ProcessFeedUpdateService
2
+  def call(body, account)
3
+    xml = Nokogiri::XML(body)
4
+
5
+    xml.xpath('/xmlns:feed/xmlns:entry').each do |entry|
6
+      uri    = entry.at_xpath('./xmlns:id').content
7
+      status = Status.find_by(uri: uri)
8
+
9
+      next unless status.nil?
10
+
11
+      status = Status.new
12
+      status.account    = account
13
+      status.uri        = uri
14
+      status.text       = entry.at_xpath('./xmlns:content').content
15
+      status.created_at = entry.at_xpath('./xmlns:published').content
16
+      status.updated_at = entry.at_xpath('./xmlns:updated').content
17
+      status.save!
18
+    end
19
+  end
20
+end

+ 14
- 0
app/views/layouts/application.html.erb View File

@@ -0,0 +1,14 @@
1
+<!DOCTYPE html>
2
+<html>
3
+<head>
4
+  <title>Mastodon</title>
5
+  <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
6
+  <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
7
+  <%= csrf_meta_tags %>
8
+</head>
9
+<body>
10
+
11
+<%= yield %>
12
+
13
+</body>
14
+</html>

+ 3
- 0
bin/bundle View File

@@ -0,0 +1,3 @@
1
+#!/usr/bin/env ruby
2
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+load Gem.bin_path('bundler', 'bundle')

+ 9
- 0
bin/rails View File

@@ -0,0 +1,9 @@
1
+#!/usr/bin/env ruby
2
+begin
3
+  load File.expand_path('../spring', __FILE__)
4
+rescue LoadError => e
5
+  raise unless e.message.include?('spring')
6
+end
7
+APP_PATH = File.expand_path('../../config/application', __FILE__)
8
+require_relative '../config/boot'
9
+require 'rails/commands'

+ 9
- 0
bin/rake View File

@@ -0,0 +1,9 @@
1
+#!/usr/bin/env ruby
2
+begin
3
+  load File.expand_path('../spring', __FILE__)
4
+rescue LoadError => e
5
+  raise unless e.message.include?('spring')
6
+end
7
+require_relative '../config/boot'
8
+require 'rake'
9
+Rake.application.run

+ 29
- 0
bin/setup View File

@@ -0,0 +1,29 @@
1
+#!/usr/bin/env ruby
2
+require 'pathname'
3
+
4
+# path to your application root.
5
+APP_ROOT = Pathname.new File.expand_path('../../',  __FILE__)
6
+
7
+Dir.chdir APP_ROOT do
8
+  # This script is a starting point to setup your application.
9
+  # Add necessary setup steps to this file:
10
+
11
+  puts "== Installing dependencies =="
12
+  system "gem install bundler --conservative"
13
+  system "bundle check || bundle install"
14
+
15
+  # puts "\n== Copying sample files =="
16
+  # unless File.exist?("config/database.yml")
17
+  #   system "cp config/database.yml.sample config/database.yml"
18
+  # end
19
+
20
+  puts "\n== Preparing database =="
21
+  system "bin/rake db:setup"
22
+
23
+  puts "\n== Removing old logs and tempfiles =="
24
+  system "rm -f log/*"
25
+  system "rm -rf tmp/cache"
26
+
27
+  puts "\n== Restarting application server =="
28
+  system "touch tmp/restart.txt"
29
+end

+ 15
- 0
bin/spring View File

@@ -0,0 +1,15 @@
1
+#!/usr/bin/env ruby
2
+
3
+# This file loads spring without using Bundler, in order to be fast.
4
+# It gets overwritten when you run the `spring binstub` command.
5
+
6
+unless defined?(Spring)
7
+  require 'rubygems'
8
+  require 'bundler'
9
+
10
+  if (match = Bundler.default_lockfile.read.match(/^GEM$.*?^    (?:  )*spring \((.*?)\)$.*?^$/m))
11
+    Gem.paths = { 'GEM_PATH' => [Bundler.bundle_path.to_s, *Gem.path].uniq }
12
+    gem 'spring', match[1]
13
+    require 'spring/binstub'
14
+  end
15
+end

+ 4
- 0
config.ru View File

@@ -0,0 +1,4 @@
1
+# This file is used by Rack-based servers to start the application.
2
+
3
+require ::File.expand_path('../config/environment', __FILE__)
4
+run Rails.application

+ 29
- 0
config/application.rb View File

@@ -0,0 +1,29 @@
1
+require File.expand_path('../boot', __FILE__)
2
+
3
+require 'rails/all'
4
+
5
+# Require the gems listed in Gemfile, including any gems
6
+# you've limited to :test, :development, or :production.
7
+Bundler.require(*Rails.groups)
8
+
9
+module Mastodon
10
+  class Application < Rails::Application
11
+    # Settings in config/environments/* take precedence over those specified here.
12
+    # Application configuration should go into files in config/initializers
13
+    # -- all .rb files in that directory are automatically loaded.
14
+
15
+    # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
16
+    # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
17
+    # config.time_zone = 'Central Time (US & Canada)'
18
+
19
+    # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
20
+    # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
21
+    # config.i18n.default_locale = :de
22
+
23
+    # Do not swallow errors in after_commit/after_rollback callbacks.
24
+    config.active_record.raise_in_transactional_callbacks = true
25
+
26
+    config.paths.add File.join('app', 'api'), glob: File.join('**', '*.rb')
27
+    config.autoload_paths += Dir[Rails.root.join('app', 'api', '*')]
28
+  end
29
+end

+ 3
- 0
config/boot.rb View File

@@ -0,0 +1,3 @@
1
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
2
+
3
+require 'bundler/setup' # Set up gems listed in the Gemfile.

+ 19
- 0
config/database.yml View File

@@ -0,0 +1,19 @@
1
+default: &default
2
+  adapter: postgresql
3
+  pool: 5
4
+  timeout: 5000
5
+
6
+development:
7
+  <<: *default
8
+  database: mastodon_development
9
+
10
+# Warning: The database defined as "test" will be erased and
11
+# re-generated from your development database when you run "rake".
12
+# Do not set this db to the same as development or production.
13
+test:
14
+  <<: *default
15
+  database: mastodon_test
16
+
17
+production:
18
+  <<: *default
19
+  database: mastodon_production

+ 5
- 0
config/environment.rb View File

@@ -0,0 +1,5 @@
1
+# Load the Rails application.
2
+require File.expand_path('../application', __FILE__)
3
+
4
+# Initialize the Rails application.
5
+Rails.application.initialize!

+ 41
- 0
config/environments/development.rb View File

@@ -0,0 +1,41 @@
1
+Rails.application.configure do
2
+  # Settings specified here will take precedence over those in config/application.rb.
3
+
4
+  # In the development environment your application's code is reloaded on
5
+  # every request. This slows down response time but is perfect for development
6
+  # since you don't have to restart the web server when you make code changes.
7
+  config.cache_classes = false
8
+
9
+  # Do not eager load code on boot.
10
+  config.eager_load = false
11
+
12
+  # Show full error reports and disable caching.
13
+  config.consider_all_requests_local       = true
14
+  config.action_controller.perform_caching = false
15
+
16
+  # Don't care if the mailer can't send.
17
+  config.action_mailer.raise_delivery_errors = false
18
+
19
+  # Print deprecation notices to the Rails logger.
20
+  config.active_support.deprecation = :log
21
+
22
+  # Raise an error on page load if there are pending migrations.
23
+  config.active_record.migration_error = :page_load
24
+
25
+  # Debug mode disables concatenation and preprocessing of assets.
26
+  # This option may cause significant delays in view rendering with a large
27
+  # number of complex assets.
28
+  config.assets.debug = true
29
+
30
+  # Asset digests allow you to set far-future HTTP expiration dates on all assets,
31
+  # yet still be able to expire them through the digest params.
32
+  config.assets.digest = true
33
+
34
+  # Adds additional error checking when serving assets at runtime.
35
+  # Checks for improperly declared sprockets dependencies.
36
+  # Raises helpful error messages.
37
+  config.assets.raise_runtime_errors = true
38
+
39
+  # Raises error for missing translations
40
+  # config.action_view.raise_on_missing_translations = true
41
+end

+ 79
- 0
config/environments/production.rb View File

@@ -0,0 +1,79 @@
1
+Rails.application.configure do
2
+  # Settings specified here will take precedence over those in config/application.rb.
3
+
4
+  # Code is not reloaded between requests.
5
+  config.cache_classes = true
6
+
7
+  # Eager load code on boot. This eager loads most of Rails and
8
+  # your application in memory, allowing both threaded web servers
9
+  # and those relying on copy on write to perform better.
10
+  # Rake tasks automatically ignore this option for performance.
11
+  config.eager_load = true
12
+
13
+  # Full error reports are disabled and caching is turned on.
14
+  config.consider_all_requests_local       = false
15
+  config.action_controller.perform_caching = true
16
+
17
+  # Enable Rack::Cache to put a simple HTTP cache in front of your application
18
+  # Add `rack-cache` to your Gemfile before enabling this.
19
+  # For large-scale production use, consider using a caching reverse proxy like
20
+  # NGINX, varnish or squid.
21
+  # config.action_dispatch.rack_cache = true
22
+
23
+  # Disable serving static files from the `/public` folder by default since
24
+  # Apache or NGINX already handles this.
25
+  config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
26
+
27
+  # Compress JavaScripts and CSS.
28
+  config.assets.js_compressor = :uglifier
29
+  # config.assets.css_compressor = :sass
30
+
31
+  # Do not fallback to assets pipeline if a precompiled asset is missed.
32
+  config.assets.compile = false
33
+
34
+  # Asset digests allow you to set far-future HTTP expiration dates on all assets,
35
+  # yet still be able to expire them through the digest params.
36
+  config.assets.digest = true
37
+
38
+  # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
39
+
40
+  # Specifies the header that your server uses for sending files.
41
+  # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
42
+  # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
43
+
44
+  # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
45
+  # config.force_ssl = true
46
+
47
+  # Use the lowest log level to ensure availability of diagnostic information
48
+  # when problems arise.
49
+  config.log_level = :debug
50
+
51
+  # Prepend all log lines with the following tags.
52
+  # config.log_tags = [ :subdomain, :uuid ]
53
+
54
+  # Use a different logger for distributed setups.
55
+  # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
56
+
57
+  # Use a different cache store in production.
58
+  # config.cache_store = :mem_cache_store
59
+
60
+  # Enable serving of images, stylesheets, and JavaScripts from an asset server.
61
+  # config.action_controller.asset_host = 'http://assets.example.com'
62
+
63
+  # Ignore bad email addresses and do not raise email delivery errors.
64
+  # Set this to true and configure the email server for immediate delivery to raise delivery errors.
65
+  # config.action_mailer.raise_delivery_errors = false
66
+
67
+  # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
68
+  # the I18n.default_locale when a translation cannot be found).
69
+  config.i18n.fallbacks = true
70
+
71
+  # Send deprecation notices to registered listeners.
72
+  config.active_support.deprecation = :notify
73
+
74
+  # Use default logging formatter so that PID and timestamp are not suppressed.
75
+  config.log_formatter = ::Logger::Formatter.new
76
+
77
+  # Do not dump schema after migrations.
78
+  config.active_record.dump_schema_after_migration = false
79
+end

+ 42
- 0
config/environments/test.rb View File

@@ -0,0 +1,42 @@
1
+Rails.application.configure do
2
+  # Settings specified here will take precedence over those in config/application.rb.
3
+
4
+  # The test environment is used exclusively to run your application's
5
+  # test suite. You never need to work with it otherwise. Remember that
6
+  # your test database is "scratch space" for the test suite and is wiped
7
+  # and recreated between test runs. Don't rely on the data there!
8
+  config.cache_classes = true
9
+
10
+  # Do not eager load code on boot. This avoids loading your whole application
11
+  # just for the purpose of running a single test. If you are using a tool that
12
+  # preloads Rails for running tests, you may have to set it to true.
13
+  config.eager_load = false
14
+
15
+  # Configure static file server for tests with Cache-Control for performance.
16
+  config.serve_static_files   = true
17
+  config.static_cache_control = 'public, max-age=3600'
18
+
19
+  # Show full error reports and disable caching.
20
+  config.consider_all_requests_local       = true
21
+  config.action_controller.perform_caching = false
22
+
23
+  # Raise exceptions instead of rendering exception templates.
24
+  config.action_dispatch.show_exceptions = false
25
+
26
+  # Disable request forgery protection in test environment.
27
+  config.action_controller.allow_forgery_protection = false
28
+
29
+  # Tell Action Mailer not to deliver emails to the real world.
30
+  # The :test delivery method accumulates sent emails in the
31
+  # ActionMailer::Base.deliveries array.
32
+  config.action_mailer.delivery_method = :test
33
+
34
+  # Randomize the order test cases are executed.
35
+  config.active_support.test_order = :random
36
+
37
+  # Print deprecation notices to the stderr.
38
+  config.active_support.deprecation = :stderr
39
+
40
+  # Raises error for missing translations
41
+  # config.action_view.raise_on_missing_translations = true
42
+end

+ 11
- 0
config/initializers/assets.rb View File

@@ -0,0 +1,11 @@
1
+# Be sure to restart your server when you modify this file.
2
+
3
+# Version of your assets, change this if you want to expire all your assets.
4
+Rails.application.config.assets.version = '1.0'
5
+
6
+# Add additional assets to the asset load path
7
+# Rails.application.config.assets.paths << Emoji.images_path
8
+
9
+# Precompile additional assets.
10
+# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
11
+# Rails.application.config.assets.precompile += %w( search.js )

+ 7
- 0
config/initializers/backtrace_silencers.rb View File

@@ -0,0 +1,7 @@
1
+# Be sure to restart your server when you modify this file.
2
+
3
+# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
+# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
+
6
+# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7
+# Rails.backtrace_cleaner.remove_silencers!

+ 3
- 0
config/initializers/cookies_serializer.rb View File

@@ -0,0 +1,3 @@
1
+# Be sure to restart your server when you modify this file.
2
+
3
+Rails.application.config.action_dispatch.cookies_serializer = :json

+ 4
- 0
config/initializers/filter_parameter_logging.rb View File

@@ -0,0 +1,4 @@
1
+# Be sure to restart your server when you modify this file.
2
+
3
+# Configure sensitive parameters which will be filtered from the log file.
4
+Rails.application.config.filter_parameters += [:password]

+ 16
- 0
config/initializers/inflections.rb View File

@@ -0,0 +1,16 @@
1
+# Be sure to restart your server when you modify this file.
2
+
3
+# Add new inflection rules using the following format. Inflections
4
+# are locale specific, and you may define rules for as many different
5
+# locales as you wish. All of these examples are active by default:
6
+# ActiveSupport::Inflector.inflections(:en) do |inflect|
7
+#   inflect.plural /^(ox)$/i, '\1en'
8
+#   inflect.singular /^(ox)en/i, '\1'
9
+#   inflect.irregular 'person', 'people'
10
+#   inflect.uncountable %w( fish sheep )
11
+# end
12
+
13
+# These inflection rules are supported but not enabled by default:
14
+# ActiveSupport::Inflector.inflections(:en) do |inflect|
15
+#   inflect.acronym 'RESTful'
16
+# end

+ 4
- 0
config/initializers/mime_types.rb View File

@@ -0,0 +1,4 @@
1
+# Be sure to restart your server when you modify this file.
2
+
3
+# Add new mime types for use in respond_to blocks:
4
+# Mime::Type.register "text/richtext", :rtf

+ 13
- 0
config/initializers/reload_api.rb View File

@@ -0,0 +1,13 @@
1
+if Rails.env.development?
2
+  ActiveSupport::Dependencies.explicitly_unloadable_constants << 'Twitter::API'
3
+
4
+  api_files = Dir[Rails.root.join('app', 'api', '**', '*.rb')]
5
+
6
+  api_reloader = ActiveSupport::FileUpdateChecker.new(api_files) do
7
+    Rails.application.reload_routes!
8
+  end
9
+
10
+  ActionDispatch::Callbacks.to_prepare do
11
+    api_reloader.execute_if_updated
12
+  end
13
+end

+ 3
- 0
config/initializers/session_store.rb View File

@@ -0,0 +1,3 @@
1
+# Be sure to restart your server when you modify this file.
2
+
3
+Rails.application.config.session_store :cookie_store, key: '_mastodon_session'

+ 14
- 0
config/initializers/wrap_parameters.rb View File

@@ -0,0 +1,14 @@
1
+# Be sure to restart your server when you modify this file.
2
+
3
+# This file contains settings for ActionController::ParamsWrapper which
4
+# is enabled by default.
5
+
6
+# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
+ActiveSupport.on_load(:action_controller) do
8
+  wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
9
+end
10
+
11
+# To enable root element in JSON for ActiveRecord objects.
12
+# ActiveSupport.on_load(:active_record) do
13
+#  self.include_root_in_json = true
14
+# end

+ 23
- 0
config/locales/en.yml View File

@@ -0,0 +1,23 @@
1
+# Files in the config/locales directory are used for internationalization
2
+# and are automatically loaded by Rails. If you want to use locales other
3
+# than English, add the necessary files in this directory.
4
+#
5
+# To use the locales, use `I18n.t`:
6
+#
7
+#     I18n.t 'hello'
8
+#
9
+# In views, this is aliased to just `t`:
10
+#
11
+#     <%= t('hello') %>
12
+#
13
+# To use a different locale, set it with `I18n.locale`:
14
+#
15
+#     I18n.locale = :es
16
+#
17
+# This would use the information in config/locales/es.yml.
18
+#
19
+# To learn more, please read the Rails Internationalization guide
20
+# available at http://guides.rubyonrails.org/i18n.html.
21
+
22
+en:
23
+  hello: "Hello world"

+ 3
- 0
config/routes.rb View File

@@ -0,0 +1,3 @@
1
+Rails.application.routes.draw do
2
+  mount Mastodon::API => '/api/'
3
+end

+ 22
- 0
config/secrets.yml View File

@@ -0,0 +1,22 @@
1
+# Be sure to restart your server when you modify this file.
2
+
3
+# Your secret key is used for verifying the integrity of signed cookies.
4
+# If you change this key, all old signed cookies will become invalid!
5
+
6
+# Make sure the secret is at least 30 characters and all random,
7
+# no regular words or you'll be exposed to dictionary attacks.
8
+# You can use `rake secret` to generate a secure secret key.
9
+
10
+# Make sure the secrets in this file are kept private
11
+# if you're sharing your code publicly.
12
+
13
+development:
14
+  secret_key_base: d4398e4af52f1fc5be5c3c8764e9ecce7beac5462826cb8b649373b2aad5a0f133598ed817c4e9931e943041460d6b6eda40a854e825e1bbd510c4594b1538f2
15
+
16
+test:
17
+  secret_key_base: 5be187ddbd651211a906f9aa399f4a148edf6e06b971c7c0b5429b9483df6e21d262cc846447d0f89b89c32d56a99e151039df5dd874ede7f712afbe041a9269
18
+
19
+# Do not keep production secrets in the repository,
20
+# instead read values from the environment.
21
+production:
22
+  secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>

+ 25
- 0
db/migrate/20160220174730_create_accounts.rb View File

@@ -0,0 +1,25 @@
1
+class CreateAccounts < ActiveRecord::Migration
2
+  def change
3
+    create_table :accounts do |t|
4
+      t.string :username, null: false, default: ''
5
+      t.string :domain, null: true
6
+
7
+      # PuSH credentials
8
+      t.string :verify_token, null: false, default: ''
9
+      t.string :secret, null: false, default: ''
10
+
11
+      # RSA key pair
12
+      t.text :private_key, null: true
13
+      t.text :public_key, null: false, default: ''
14
+
15
+      # URLs
16
+      t.string :remote_url, null: false, default: ''
17
+      t.string :salmon_url, null: false, default: ''
18
+      t.string :hub_url, null: false, default: ''
19
+
20
+      t.timestamps null: false
21
+    end
22
+
23
+    add_index :accounts, [:username, :domain], unique: true
24
+  end
25
+end

+ 13
- 0
db/migrate/20160220211917_create_statuses.rb View File

@@ -0,0 +1,13 @@
1
+class CreateStatuses < ActiveRecord::Migration
2
+  def change
3
+    create_table :statuses do |t|
4
+      t.string :uri, null: false, default: ''
5
+      t.integer :account_id, null: false
6
+      t.text :text, null: false, default: ''
7
+
8
+      t.timestamps null: false
9
+    end
10
+
11
+    add_index :statuses, :uri, unique: true
12
+  end
13
+end

+ 45
- 0
db/schema.rb View File

@@ -0,0 +1,45 @@
1
+# encoding: UTF-8
2
+# This file is auto-generated from the current state of the database. Instead
3
+# of editing this file, please use the migrations feature of Active Record to
4
+# incrementally modify your database, and then regenerate this schema definition.
5
+#
6
+# Note that this schema.rb definition is the authoritative source for your
7
+# database schema. If you need to create the application database on another
8
+# system, you should be using db:schema:load, not running all the migrations
9
+# from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
+# you'll amass, the slower it'll run and the greater likelihood for issues).
11
+#
12
+# It's strongly recommended that you check this file into your version control system.
13
+
14
+ActiveRecord::Schema.define(version: 20160220211917) do
15
+
16
+  # These are extensions that must be enabled in order to support this database
17
+  enable_extension "plpgsql"
18
+
19
+  create_table "accounts", force: :cascade do |t|
20
+    t.string   "username",     default: "", null: false
21
+    t.string   "domain"
22
+    t.string   "verify_token", default: "", null: false
23
+    t.string   "secret",       default: "", null: false
24
+    t.text     "private_key"
25
+    t.text     "public_key",   default: "", null: false
26
+    t.string   "remote_url",   default: "", null: false
27
+    t.string   "salmon_url",   default: "", null: false
28
+    t.string   "hub_url",      default: "", null: false
29
+    t.datetime "created_at",                null: false
30
+    t.datetime "updated_at",                null: false
31
+  end
32
+
33
+  add_index "accounts", ["username", "domain"], name: "index_accounts_on_username_and_domain", unique: true, using: :btree
34
+
35
+  create_table "statuses", force: :cascade do |t|
36
+    t.string   "uri",        default: "", null: false
37
+    t.integer  "account_id",              null: false
38
+    t.text     "text",       default: "", null: false
39
+    t.datetime "created_at",              null: false
40
+    t.datetime "updated_at",              null: false
41
+  end
42
+
43
+  add_index "statuses", ["uri"], name: "index_statuses_on_uri", unique: true, using: :btree
44
+
45
+end

+ 7
- 0
db/seeds.rb View File

@@ -0,0 +1,7 @@
1
+# This file should contain all the record creation needed to seed the database with its default values.
2
+# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
3
+#
4
+# Examples:
5
+#
6
+#   cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
7
+#   Mayor.create(name: 'Emanuel', city: cities.first)

+ 0
- 0
lib/assets/.keep View File


+ 0
- 0
lib/tasks/.keep View File


+ 0
- 0
log/.keep View File


+ 67
- 0
public/404.html View File

@@ -0,0 +1,67 @@
1
+<!DOCTYPE html>
2
+<html>
3
+<head>
4
+  <title>The page you were looking for doesn't exist (404)</title>
5
+  <meta name="viewport" content="width=device-width,initial-scale=1">
6
+  <style>
7
+  body {
8
+    background-color: #EFEFEF;
9
+    color: #2E2F30;
10
+    text-align: center;
11
+    font-family: arial, sans-serif;
12
+    margin: 0;
13
+  }
14
+
15
+  div.dialog {
16
+    width: 95%;
17
+    max-width: 33em;
18
+    margin: 4em auto 0;
19
+  }
20
+
21
+  div.dialog > div {
22
+    border: 1px solid #CCC;
23
+    border-right-color: #999;
24
+    border-left-color: #999;
25
+    border-bottom-color: #BBB;
26
+    border-top: #B00100 solid 4px;
27
+    border-top-left-radius: 9px;
28
+    border-top-right-radius: 9px;
29
+    background-color: white;
30
+    padding: 7px 12% 0;
31
+    box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+  }
33
+
34
+  h1 {
35
+    font-size: 100%;
36
+    color: #730E15;
37
+    line-height: 1.5em;
38
+  }
39
+
40
+  div.dialog > p {
41
+    margin: 0 0 1em;
42
+    padding: 1em;
43
+    background-color: #F7F7F7;
44
+    border: 1px solid #CCC;
45
+    border-right-color: #999;
46
+    border-left-color: #999;
47
+    border-bottom-color: #999;
48
+    border-bottom-left-radius: 4px;
49
+    border-bottom-right-radius: 4px;
50
+    border-top-color: #DADADA;
51
+    color: #666;
52
+    box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+  }
54
+  </style>
55
+</head>
56
+
57
+<body>
58
+  <!-- This file lives in public/404.html -->
59
+  <div class="dialog">
60
+    <div>
61
+      <h1>The page you were looking for doesn't exist.</h1>
62
+      <p>You may have mistyped the address or the page may have moved.</p>
63
+    </div>
64
+    <p>If you are the application owner check the logs for more information.</p>
65
+  </div>
66
+</body>
67
+</html>

+ 67
- 0
public/422.html View File

@@ -0,0 +1,67 @@
1
+<!DOCTYPE html>
2
+<html>
3
+<head>
4
+  <title>The change you wanted was rejected (422)</title>
5
+  <meta name="viewport" content="width=device-width,initial-scale=1">
6
+  <style>
7
+  body {
8
+    background-color: #EFEFEF;
9
+    color: #2E2F30;
10
+    text-align: center;
11
+    font-family: arial, sans-serif;
12
+    margin: 0;
13
+  }
14
+
15
+  div.dialog {
16
+    width: 95%;
17
+    max-width: 33em;
18
+    margin: 4em auto 0;
19
+  }
20
+
21
+  div.dialog > div {
22
+    border: 1px solid #CCC;
23
+    border-right-color: #999;
24
+    border-left-color: #999;
25
+    border-bottom-color: #BBB;
26
+    border-top: #B00100 solid 4px;
27
+    border-top-left-radius: 9px;
28
+    border-top-right-radius: 9px;
29
+    background-color: white;
30
+    padding: 7px 12% 0;
31
+    box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+  }
33
+
34
+  h1 {
35
+    font-size: 100%;
36
+    color: #730E15;
37
+    line-height: 1.5em;
38
+  }
39
+
40
+  div.dialog > p {
41
+    margin: 0 0 1em;
42
+    padding: 1em;
43
+    background-color: #F7F7F7;
44
+    border: 1px solid #CCC;
45
+    border-right-color: #999;
46
+    border-left-color: #999;
47
+    border-bottom-color: #999;
48
+    border-bottom-left-radius: 4px;
49
+    border-bottom-right-radius: 4px;
50
+    border-top-color: #DADADA;
51
+    color: #666;
52
+    box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+  }
54
+  </style>
55
+</head>
56
+
57
+<body>
58
+  <!-- This file lives in public/422.html -->
59
+  <div class="dialog">
60
+    <div>
61
+      <h1>The change you wanted was rejected.</h1>
62
+      <p>Maybe you tried to change something you didn't have access to.</p>
63
+    </div>
64
+    <p>If you are the application owner check the logs for more information.</p>
65
+  </div>
66
+</body>
67
+</html>

+ 66
- 0
public/500.html View File

@@ -0,0 +1,66 @@
1
+<!DOCTYPE html>
2
+<html>
3
+<head>
4
+  <title>We're sorry, but something went wrong (500)</title>
5
+  <meta name="viewport" content="width=device-width,initial-scale=1">
6
+  <style>
7
+  body {
8
+    background-color: #EFEFEF;
9
+    color: #2E2F30;
10
+    text-align: center;
11
+    font-family: arial, sans-serif;
12
+    margin: 0;
13
+  }
14
+
15
+  div.dialog {
16
+    width: 95%;
17
+    max-width: 33em;
18
+    margin: 4em auto 0;
19
+  }
20
+
21
+  div.dialog > div {
22
+    border: 1px solid #CCC;
23
+    border-right-color: #999;
24
+    border-left-color: #999;
25
+    border-bottom-color: #BBB;
26
+    border-top: #B00100 solid 4px;
27
+    border-top-left-radius: 9px;
28
+    border-top-right-radius: 9px;
29
+    background-color: white;
30
+    padding: 7px 12% 0;
31
+    box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+  }
33
+
34
+  h1 {
35
+    font-size: 100%;
36
+    color: #730E15;
37
+    line-height: 1.5em;
38
+  }
39
+
40
+  div.dialog > p {
41
+    margin: 0 0 1em;
42
+    padding: 1em;
43
+    background-color: #F7F7F7;
44
+    border: 1px solid #CCC;
45
+    border-right-color: #999;
46
+    border-left-color: #999;
47
+    border-bottom-color: #999;
48
+    border-bottom-left-radius: 4px;
49
+    border-bottom-right-radius: 4px;
50
+    border-top-color: #DADADA;
51
+    color: #666;
52
+    box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+  }
54
+  </style>
55
+</head>
56
+
57
+<body>
58
+  <!-- This file lives in public/500.html -->
59
+  <div class="dialog">
60
+    <div>
61
+      <h1>We're sorry, but something went wrong.</h1>
62
+    </div>
63
+    <p>If you are the application owner check the logs for more information.</p>
64
+  </div>
65
+</body>
66
+</html>

+ 0
- 0
public/favicon.ico View File


+ 5
- 0
public/robots.txt View File

@@ -0,0 +1,5 @@
1
+# See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
2
+#
3
+# To ban all spiders from the entire site uncomment the next two lines:
4
+# User-agent: *
5
+# Disallow: /

+ 5
- 0
spec/models/account_spec.rb View File

@@ -0,0 +1,5 @@
1
+require 'rails_helper'
2
+
3
+RSpec.describe Account, type: :model do
4
+  pending "add some examples to (or delete) #{__FILE__}"
5
+end

+ 5
- 0
spec/models/status_spec.rb View File

@@ -0,0 +1,5 @@
1
+require 'rails_helper'
2
+
3
+RSpec.describe Status, type: :model do
4
+  pending "add some examples to (or delete) #{__FILE__}"
5
+end

+ 0
- 0
test/controllers/.keep View File


+ 0
- 0
test/fixtures/.keep View File


+ 0
- 0
test/helpers/.keep View File


+ 0
- 0
test/integration/.keep View File


+ 0
- 0
test/mailers/.keep View File


+ 0
- 0
test/models/.keep View File


+ 10
- 0
test/test_helper.rb View File

@@ -0,0 +1,10 @@
1
+ENV['RAILS_ENV'] ||= 'test'
2
+require File.expand_path('../../config/environment', __FILE__)
3
+require 'rails/test_help'
4
+
5
+class ActiveSupport::TestCase
6
+  # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
7
+  fixtures :all
8
+
9
+  # Add more helper methods to be used by all tests here...
10
+end

+ 0
- 0
vendor/assets/javascripts/.keep View File


+ 0
- 0
vendor/assets/stylesheets/.keep View File