Skip to content

Commit

Permalink
Merge pull request #22 from EcoJulia/feature-endpoint-user
Browse files Browse the repository at this point in the history
Various issues fix
  • Loading branch information
tpoisot authored Nov 2, 2021
2 parents 284b806 + d168f6a commit b1a5953
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 32 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
28 changes: 16 additions & 12 deletions src/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,26 @@ function _short_desc(s::String)
return length(s) < 80 ? s : strip(s[1:79]*"")
end

function Base.show(io::IO, ::MIME"text/plain", dataset::MangalDataset)
print(io, """Mangal dataset #$(dataset.id) ($(dataset.name))
$(_short_desc(dataset.description))""")
function Base.show(io::IO, dataset::MangalDataset)
print(io, """🗃️ Mangal dataset #$(dataset.id) ($(dataset.name))""")
end

function Base.show(io::IO, dataset::MangalDataset)
print(io, """Mangal dataset #$(dataset.id) ($(dataset.name))""")
function Base.show(io::IO, network::MangalNetwork)
print(io, """🕸️ Mangal network #$(network.id) ($(network.name))""")
end

function Base.show(io::IO, ::MIME"text/plain", network::MangalNetwork)
print(io, """Mangal network #$(network.id) ($(network.name))
$(_short_desc(network.description))
→ Part of dataset #$(network.dataset.id) ($(network.dataset.name))
""")
function Base.show(io::IO, interaction::MangalInteraction)
print(io, """🔄 Mangal int° #$(interaction.id): from $(interaction.from.name) to $(interaction.to.name)""")
end

function Base.show(io::IO, network::MangalNetwork)
print(io, """Mangal network #$(network.id) ($(network.name))""")
function Base.show(io::IO, user::MangalUser)
print(io, """🫂 Mangal contributor #$(user.id): $(user.name) - $(user.orcid)""")
end

function Base.show(io::IO, node::MangalNode)
print(io, """🦝 Mangal node #$(node.id): $(node.name)""")
end

function Base.show(io::IO, taxon::MangalReferenceTaxon)
print(io, """🌲 Mangal taxon #$(taxon.id): $(taxon.name)""")
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
3 changes: 2 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ my_tests = [
"datasets.jl",
"networks.jl",
"interactions.jl",
"knownbugs.jl"
"knownbugs.jl",
"users.jl"
]

global test_n
Expand Down
8 changes: 8 additions & 0 deletions test/users.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module MangalTestUsers

using Mangal
using Test

@test typeof(users()) <: Vector{MangalUser}

end

2 comments on commit b1a5953

@tpoisot
Copy link
Member Author

@tpoisot tpoisot commented on b1a5953 Nov 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/48017

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.4.1 -m "<description of version>" b1a59538a0728f29044af8c876dbaf8ed3ac31fb
git push origin v0.4.1

Please sign in to comment.