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
28 changes: 14 additions & 14 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
source 'https://rubygems.org'
source "https://rubygems.org"

git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
"https://github.com/#{repo_name}.git"
end


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2.0'
gem "rails", "~> 5.2.0"
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
gem "sqlite3"
# Use Puma as the app server
gem 'puma', '~> 3.7'
gem "puma", "~> 3.7"
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
# gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
Expand All @@ -25,25 +24,26 @@ gem 'puma', '~> 3.7'
# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
# gem 'rack-cors'

gem 'bootsnap', require: false
gem "bootsnap", require: false

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platform: :mri
gem 'rspec', '~> 3.10.0'
gem 'rspec-rails', '~> 5.0.0'
gem "byebug", platform: :mri
gem "rspec", "~> 3.10.0"
gem "rspec-rails", "~> 5.0.0"
gem "standard"
end

group :development do
gem 'listen', '>= 3.0.5', '< 3.2'
gem "listen", ">= 3.0.5", "< 3.2"
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
gem "spring"
gem "spring-watcher-listen", "~> 2.0.0"
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw, :jruby]

# using rest-client because I've had far more luck than the
# stlib net/http
gem 'rest-client', '>= 2.1.0.rc1', '< 2.2'
gem "rest-client", ">= 2.1.0.rc1", "< 2.2"
27 changes: 27 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ GEM
minitest (~> 5.1)
tzinfo (~> 1.1)
arel (9.0.0)
ast (2.4.2)
bootsnap (1.8.1)
msgpack (~> 1.0)
builder (3.2.4)
Expand Down Expand Up @@ -84,6 +85,9 @@ GEM
nokogiri (1.12.4)
mini_portile2 (~> 2.6.1)
racc (~> 1.4)
parallel (1.21.0)
parser (3.0.2.0)
ast (~> 2.4.1)
puma (3.12.6)
racc (1.5.2)
rack (2.2.3)
Expand Down Expand Up @@ -113,15 +117,18 @@ GEM
method_source
rake (>= 0.8.7)
thor (>= 0.19.0, < 2.0)
rainbow (3.0.0)
rake (13.0.6)
rb-fsevent (0.11.0)
rb-inotify (0.10.1)
ffi (~> 1.0)
regexp_parser (2.1.1)
rest-client (2.1.0)
http-accept (>= 1.7.0, < 2.0)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
rexml (3.2.5)
rspec (3.10.0)
rspec-core (~> 3.10.0)
rspec-expectations (~> 3.10.0)
Expand All @@ -143,6 +150,21 @@ GEM
rspec-mocks (~> 3.10)
rspec-support (~> 3.10)
rspec-support (3.10.2)
rubocop (1.22.3)
parallel (~> 1.10)
parser (>= 3.0.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml
rubocop-ast (>= 1.12.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.12.0)
parser (>= 3.0.1.1)
rubocop-performance (1.11.5)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
ruby-progressbar (1.11.0)
ruby_dep (1.5.0)
spring (2.1.1)
spring-watcher-listen (2.0.1)
Expand All @@ -156,13 +178,17 @@ GEM
activesupport (>= 4.0)
sprockets (>= 3.0.0)
sqlite3 (1.4.2)
standard (1.4.0)
rubocop (= 1.22.3)
rubocop-performance (= 1.11.5)
thor (1.1.0)
thread_safe (0.3.6)
tzinfo (1.2.9)
thread_safe (~> 0.1)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.7)
unicode-display_width (2.1.0)
websocket-driver (0.7.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
Expand All @@ -182,6 +208,7 @@ DEPENDENCIES
spring
spring-watcher-listen (~> 2.0.0)
sqlite3
standard
tzinfo-data

BUNDLED WITH
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Apium is an API to access all public Center for Digital Research in the Humaniti

This project is licensed under the terms of the [MIT license](LICENSE.md).

## Run tests
## Run tests and linter

Run tests with `rails spec` or `rspec`
Run tests with `rails spec` or `rspec`.

Run linter with `standardrb`.
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require_relative 'config/application'
require_relative "config/application"

Rails.application.load_tasks
13 changes: 5 additions & 8 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
require 'rest-client'
require "rest-client"

class ApplicationController < ActionController::API

def post_search(json, error_method=method(:display_error))
res = RestClient.post("#{ES_URI}/_search", json.to_json, { "content-type" => "json" })
raise
return JSON.parse(res.body)
def post_search(json, error_method = method(:display_error))
res = RestClient.post("#{ES_URI}/_search", json.to_json, {"content-type" => "json"})
raise JSON.parse(res.body)
rescue => e
error_method.call(e, json)
return nil
nil
end

# I am so pleased that this works
Expand All @@ -30,5 +28,4 @@ def display_error(error, req_body)
}
})) and return
end

end
2 changes: 0 additions & 2 deletions app/controllers/collection_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class CollectionController < ApplicationController

def index
res = SearchService.new(ES_URI, params, request.fullpath)
.search_collections
Expand All @@ -24,5 +23,4 @@ def show
}
})
end

end
23 changes: 10 additions & 13 deletions app/controllers/default_controller.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
=begin
CDRH API

API to access all public Center for Digital Research in the Humanities resources

OpenAPI spec version: 0.1.0

Generated by: https://github.com/swagger-api/swagger-codegen.git

=end
# CDRH API
#
# API to access all public Center for Digital Research in the Humanities resources
#
# OpenAPI spec version: 0.1.0
#
# Generated by: https://github.com/swagger-api/swagger-codegen.git
#

class DefaultController < ApplicationController

def root
json = JSON.pretty_generate({
"req" => {
Expand All @@ -35,14 +32,14 @@ def root
"/item/{id}",
"/collections",
"/collection/{collection}/info",
"/collection/{collection}/item/{id}",
"/collection/{collection}/item/{id}"
],
# TODO get descriptions from ES mapping?
# would rather not manually type in somewhere
# or possibly by reading in the YML file for the
# schema definitions, which would prevent project
# specific fields from popping up in this result
"fields" => {},
"fields" => {}
}
}
})
Expand Down
3 changes: 0 additions & 3 deletions app/controllers/item_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
class ItemController < ApplicationController


def index
if params["collection"].present?
params["f"] = [] if params["f"].blank?
Expand All @@ -18,5 +16,4 @@ def show
code = res.dig("res", "code")
render status: code, json: JSON.pretty_generate(res)
end

end
4 changes: 2 additions & 2 deletions app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class ApplicationMailer < ActionMailer::Base
default from: 'from@example.com'
layout 'mailer'
default from: "from@example.com"
layout "mailer"
end
38 changes: 18 additions & 20 deletions app/services/search_coll_res.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class SearchCollRes

@@collections = ["aggregations", "collections", "buckets"]

def initialize(res)
Expand All @@ -10,26 +9,25 @@ def build_response
route_paths = Rails.application.routes.url_helpers

collections = @body.dig(*@@collections)
collections = [] if !collections
collections.map! do |coll|
{
"collection_name" => coll["key"],
"description" => "TODO",
"image_id" => "TODO",
"uri" => "TODO",
"collection" => coll["key"],
"item_count" => coll["doc_count"],
"endpoint" => route_paths.collection_path(coll["key"])
}
end
collections = [] if !collections
collections.map! do |coll|
{
"collection_name" => coll["key"],
"description" => "TODO",
"image_id" => "TODO",
"uri" => "TODO",
"collection" => coll["key"],
"item_count" => coll["doc_count"],
"endpoint" => route_paths.collection_path(coll["key"])
}
end

return {
"code" => 200,
"info" => {
"count" => collections.length,
"collections" => collections
}
{
"code" => 200,
"info" => {
"count" => collections.length,
"collections" => collections
}
}
end

end
Loading