Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ task :console do
end

namespace :quality do
CODE = '**/*.rb'
task :flog do
sh 'flog lib/'
sh "flog #{CODE}"
end

task :reek do
sh 'reek lib/'
sh "reek #{CODE}"
end
end

Expand Down
96 changes: 0 additions & 96 deletions application/app.rb

This file was deleted.

37 changes: 37 additions & 0 deletions application/controller/app.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require 'roda'

module WiKey
#Web Api
class Api < Roda
plugin :environments
plugin :json
plugin :halt
plugin :multi_route

require_relative 'topic'
require_relative 'paragraphs'
require_relative 'topics'
require_relative 'summaries'

route do |routing|
app = Api
routing.root do
{ 'message' => "WiKey API v0.1 up in #{app.environment}." }
end
# /api branch
routing.on 'api' do
# /api/v0.1 branch
routing.on 'v0.1' do
# /api/v0.1/topic/name branch
routing.multi_route
end
end
end

private

def normalized(string)
string.gsub('_',' ')
end
end
end
1 change: 1 addition & 0 deletions application/controller/init.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative 'app.rb'
26 changes: 26 additions & 0 deletions application/controller/paragraphs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require "roda"

module WiKey

class Api < Roda
# GET /api/v0.1/paragraphs/topic_name/catalog_name
route('paragraphs') do |routing|

routing.on String, String do |topic_name, catalog_name|
topic_name = normalized(topic_name)
catalog_name = normalized(catalog_name)
routing.get do
find_result = FindDatabaseArticle.call(topic: topic_name.capitalize, catalog: catalog_name)
result = find_result.value.message
http_response = HttpResponseRepresenter.new(find_result.value)
response.status = http_response.http_code
if find_result.success?
ArticleRepresenter.new(Article.new(result.topic, result.catalogs, result.paragraphs)).to_json
else
http_response.to_json
end
end
end
end
end
end
26 changes: 26 additions & 0 deletions application/controller/summaries.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require "roda"

module WiKey

class Api < Roda
#GET api/v0.1/summaries/topic_name/catalog_name
route('summaries') do |routing|

routing.on String, String do |topic_name, catalog_name|
topic_name = normalized(topic_name)
catalog_name = normalized(catalog_name)
routing.get do
find_result = FindDatabaseArticle.summarize(topic: topic_name.capitalize, catalog: catalog_name)
result = find_result.value.message
http_response = HttpResponseRepresenter.new(find_result.value)
response.status = http_response.http_code
if find_result.success?
ArticleRepresenter.new(Article.new(result.topic, result.catalogs, result.paragraphs)).to_json
else
http_response.to_json
end
end
end
end
end
end
42 changes: 42 additions & 0 deletions application/controller/topic.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require "roda"

module WiKey

class Api < Roda
route('topic') do |routing|

routing.on String do |topic_name|
# GET /api/v0.1/topic/topic_name request
topic_name = normalized(topic_name)
routing.get do
find_result = FindDatabaseArticle.call(topic: topic_name.capitalize, catalog: 'default')
result = find_result.value.message
http_response = HttpResponseRepresenter.new(find_result.value)
response.status = http_response.http_code
if find_result.success?
ArticleRepresenter.new(Article.new(result.topic, result.catalogs, result.paragraphs)).to_json
else
http_response.to_json
end
end
# POST /api/v0.1/topic/topic_name
routing.post do
service_result = LoadFromWiki.new.call(
gateway: Wiki::Api,
topic: topic_name
)

http_response = HttpResponseRepresenter.new(service_result.value)
result = service_result.value.message
response.status = http_response.http_code
if service_result.success?
response['Loaction'] = "/api/v0.1/source/#{topic_name}"
ArticleRepresenter.new(Article.new(result.topic, result.catalogs, result.paragraphs)).to_json
else
http_response.to_json
end
end
end
end
end
end
21 changes: 21 additions & 0 deletions application/controller/topics.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require "roda"

module WiKey

class Api < Roda
route('topics') do |routing|
routing.on do
routing.get do
topics = FindDatabaseTopic.all
http_response = HttpResponseRepresenter.new(topics.value)
response.status = http_response.http_code
if topics.success?
TopicsRepresenter.new(Topics.new(topics.value.message)).to_json
else
http_response.to_json
end
end
end
end
end
end
2 changes: 1 addition & 1 deletion application/init.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require_relative 'services/init.rb'
require_relative 'representers/init.rb'
require_relative "app.rb"
require_relative "controller/init.rb"
require_relative '../config/environment.rb'
2 changes: 1 addition & 1 deletion coverage/.last_run.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"result": {
"covered_percent": 88.59
"covered_percent": 89.67
}
}
Loading