Skip to content

Commit

Permalink
Closes #20 and Closes #21
Browse files Browse the repository at this point in the history
  • Loading branch information
tpoisot committed Nov 2, 2021
1 parent 284b806 commit 9ed4bdf
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 19 deletions.
30 changes: 16 additions & 14 deletions src/Mangal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,29 @@ export MangalNode
export MangalInteraction
export MangalReference
export MangalAttribute
export MangalUser

# Endpoints
const _MANGAL_ENDPOINTS = Dict(
MangalReferenceTaxon => "taxonomy",
MangalNode => "node",
MangalInteraction => "interaction",
MangalNetwork => "network",
MangalDataset => "dataset",
MangalReference => "reference",
MangalAttribute => "attribute"
MangalReferenceTaxon => "taxonomy",
MangalNode => "node",
MangalInteraction => "interaction",
MangalNetwork => "network",
MangalDataset => "dataset",
MangalReference => "reference",
MangalAttribute => "attribute",
MangalUser => "user",
)

#user = "user",
#trait = "trait",

# The cache!
global _MANGAL_CACHES = Dict(
MangalNode => Dict{Int64, MangalNode}(),
MangalReferenceTaxon => Dict{Int64, MangalReferenceTaxon}(),
MangalNetwork => Dict{Int64, MangalNetwork}(),
MangalAttribute => Dict{Int64, MangalAttribute}()
)
MangalNode => Dict{Int64,MangalNode}(),
MangalReferenceTaxon => Dict{Int64,MangalReferenceTaxon}(),
MangalNetwork => Dict{Int64,MangalNetwork}(),
MangalAttribute => Dict{Int64,MangalAttribute}(),
)

# Response formatters
include("response_format.jl")
Expand All @@ -59,6 +60,7 @@ export networks, network
export references, reference
export interactions, interaction
export attributes, attribute
export users, user

# Datasets
include(joinpath(".", "dataset.jl"))
Expand All @@ -85,7 +87,7 @@ include(joinpath(".", "count.jl"))
include(joinpath(".", "show.jl"))

# EcologicalNetworks wrapper
import EcologicalNetworks
using EcologicalNetworks: EcologicalNetworks
include(joinpath(".", "ecologicalnetworks.jl"))
export taxonize

Expand Down
3 changes: 2 additions & 1 deletion src/dataset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
Return a single dataset by its name.
"""
function dataset(name::AbstractString)
return first(datasets(Pair("name", name)))
q = datasets(Pair("name", name))
return isequal(1)(length(q)) ? only(q) : nothing
end
7 changes: 4 additions & 3 deletions src/generators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ types_names = (
(MangalDataset, :dataset),
(MangalReference, :reference),
(MangalInteraction, :interaction),
(MangalAttribute, :attribute)
)
(MangalAttribute, :attribute),
(MangalUser, :user),
)

import Base.count

for mg_type_pair in types_names
mg_type, mg_singular = mg_type_pair
mg_plural = Symbol(string(mg_singular)*"s")
mg_plural = Symbol(string(mg_singular) * "s")
@eval begin
"""
count(::Type{$($mg_type)}, query::Pair...)
Expand Down
3 changes: 2 additions & 1 deletion src/network.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ end
Returns a network of a given name.
"""
function network(name::AbstractString)
return first(networks(Pair("name", name)))
q = networks(Pair("name", name))
return isequal(1)(length(q)) ? only(q) : nothing
end
9 changes: 9 additions & 0 deletions src/response_format.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,12 @@ function format_mangal_response(::Type{MangalAttribute}, d::Dict{T,Any}) where {

return MangalAttribute(obj_id, obj_name, obj_description, obj_unit)
end

function format_mangal_response(::Type{MangalUser}, d::Dict{T,Any}) where {T <: AbstractString}
obj_id = d["id"]
obj_name = d["name"]
obj_orcid = d["orcid"]
obj_email = isnothing(d["email"]) ? missing : d["email"]
obj_org = isnothing(d["organization"]) ? missing : d["organization"]
return MangalUser(obj_id, obj_name, obj_email, obj_orcid, obj_org)
end
12 changes: 12 additions & 0 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,15 @@ struct MangalInteraction
updated::DateTime
attribute::Union{Missing,MangalAttribute}
end


"""
MangalUser
"""
struct MangalUser
id::Int64
name::AbstractString
email::Union{Missing,AbstractString}
orcid::Union{Missing,AbstractString}
organization::Union{Missing,AbstractString}
end
2 changes: 2 additions & 0 deletions test/datasets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ module MangalTestDataset
# Dataset by name
@test typeof(dataset("roberson_1929")) <: MangalDataset

@test isnothing(dataset("This_DOESNOT_exist"))

end

0 comments on commit 9ed4bdf

Please sign in to comment.