-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: API that can filter and transform data before forwading on to Se…
…nzing.
- Loading branch information
1 parent
9157a89
commit 26c2f4d
Showing
13 changed files
with
171 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require_relative 'lib/api' | ||
|
||
use Rack::RewindableInput::Middleware | ||
|
||
run API |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'grape' | ||
|
||
require_relative 'config' | ||
require_relative 'import' | ||
|
||
# Provides a proxy api for entity resolution. | ||
class API < Grape::API | ||
format :json | ||
|
||
resource :health do | ||
get do | ||
{ status: 'ok' } | ||
end | ||
end | ||
|
||
resource :import do | ||
desc 'Import a single record into Senzing.' | ||
params do | ||
requires :source, type: Symbol, desc: 'The name of the data source.' | ||
end | ||
post do | ||
# TODO: Load and modify the config once at startup. | ||
config = Config.from_file(ENV.fetch('CMR_CONFIG_FILE', 'config/config.yml')) | ||
|
||
# TODO: Return a 404 if the source is not found. | ||
source = config.sources[params[:source]] | ||
if source.nil? | ||
status 404 | ||
return "Source \"#{params[:source]}\" not found." | ||
end | ||
|
||
# Override configured sources as we only want to use this one. | ||
source[:type] = 'API::JSON' | ||
source[:payload] = params | ||
config.sources = { params[:source] => source } | ||
|
||
# TODO: Pass the source name here as an optional argument. | ||
Import.new(config).import | ||
|
||
# TODO: Return something better. Make it JSONy. | ||
'Record imported.' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require_relative 'api/json' | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../base' | ||
|
||
module Source | ||
module API | ||
# Base class for API data sources. | ||
class Base < Source::Base | ||
def each | ||
records = @source_config[:payload].is_a?(Array) ? @source_config[:payload] : [@source_config[:payload]] | ||
records.each do |row| | ||
row.transform_keys! { |key| field_mapper(key) } | ||
yield row | ||
end | ||
end | ||
|
||
private | ||
|
||
def default_name | ||
"API::#{super}" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative 'base' | ||
|
||
module Source | ||
module API | ||
# Import JSON records from the API. | ||
# TODO: Do we actually need this? | ||
class JSON < Base | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters