Skip to content

Commit b1a5953

Browse files
authored
Merge pull request #22 from EcoJulia/feature-endpoint-user
Various issues fix
2 parents 284b806 + d168f6a commit b1a5953

10 files changed

+73
-32
lines changed

src/Mangal.jl

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,29 @@ export MangalNode
2121
export MangalInteraction
2222
export MangalReference
2323
export MangalAttribute
24+
export MangalUser
2425

2526
# Endpoints
2627
const _MANGAL_ENDPOINTS = Dict(
27-
MangalReferenceTaxon => "taxonomy",
28-
MangalNode => "node",
29-
MangalInteraction => "interaction",
30-
MangalNetwork => "network",
31-
MangalDataset => "dataset",
32-
MangalReference => "reference",
33-
MangalAttribute => "attribute"
28+
MangalReferenceTaxon => "taxonomy",
29+
MangalNode => "node",
30+
MangalInteraction => "interaction",
31+
MangalNetwork => "network",
32+
MangalDataset => "dataset",
33+
MangalReference => "reference",
34+
MangalAttribute => "attribute",
35+
MangalUser => "user",
3436
)
3537

36-
#user = "user",
3738
#trait = "trait",
3839

3940
# The cache!
4041
global _MANGAL_CACHES = Dict(
41-
MangalNode => Dict{Int64, MangalNode}(),
42-
MangalReferenceTaxon => Dict{Int64, MangalReferenceTaxon}(),
43-
MangalNetwork => Dict{Int64, MangalNetwork}(),
44-
MangalAttribute => Dict{Int64, MangalAttribute}()
45-
)
42+
MangalNode => Dict{Int64,MangalNode}(),
43+
MangalReferenceTaxon => Dict{Int64,MangalReferenceTaxon}(),
44+
MangalNetwork => Dict{Int64,MangalNetwork}(),
45+
MangalAttribute => Dict{Int64,MangalAttribute}(),
46+
)
4647

4748
# Response formatters
4849
include("response_format.jl")
@@ -59,6 +60,7 @@ export networks, network
5960
export references, reference
6061
export interactions, interaction
6162
export attributes, attribute
63+
export users, user
6264

6365
# Datasets
6466
include(joinpath(".", "dataset.jl"))
@@ -85,7 +87,7 @@ include(joinpath(".", "count.jl"))
8587
include(joinpath(".", "show.jl"))
8688

8789
# EcologicalNetworks wrapper
88-
import EcologicalNetworks
90+
using EcologicalNetworks: EcologicalNetworks
8991
include(joinpath(".", "ecologicalnetworks.jl"))
9092
export taxonize
9193

src/dataset.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
Return a single dataset by its name.
55
"""
66
function dataset(name::AbstractString)
7-
return first(datasets(Pair("name", name)))
7+
q = datasets(Pair("name", name))
8+
return isequal(1)(length(q)) ? only(q) : nothing
89
end

src/generators.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ types_names = (
55
(MangalDataset, :dataset),
66
(MangalReference, :reference),
77
(MangalInteraction, :interaction),
8-
(MangalAttribute, :attribute)
9-
)
8+
(MangalAttribute, :attribute),
9+
(MangalUser, :user),
10+
)
1011

1112
import Base.count
1213

1314
for mg_type_pair in types_names
1415
mg_type, mg_singular = mg_type_pair
15-
mg_plural = Symbol(string(mg_singular)*"s")
16+
mg_plural = Symbol(string(mg_singular) * "s")
1617
@eval begin
1718
"""
1819
count(::Type{$($mg_type)}, query::Pair...)

src/network.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ end
1313
Returns a network of a given name.
1414
"""
1515
function network(name::AbstractString)
16-
return first(networks(Pair("name", name)))
16+
q = networks(Pair("name", name))
17+
return isequal(1)(length(q)) ? only(q) : nothing
1718
end

src/response_format.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,12 @@ function format_mangal_response(::Type{MangalAttribute}, d::Dict{T,Any}) where {
123123

124124
return MangalAttribute(obj_id, obj_name, obj_description, obj_unit)
125125
end
126+
127+
function format_mangal_response(::Type{MangalUser}, d::Dict{T,Any}) where {T <: AbstractString}
128+
obj_id = d["id"]
129+
obj_name = d["name"]
130+
obj_orcid = d["orcid"]
131+
obj_email = isnothing(d["email"]) ? missing : d["email"]
132+
obj_org = isnothing(d["organization"]) ? missing : d["organization"]
133+
return MangalUser(obj_id, obj_name, obj_email, obj_orcid, obj_org)
134+
end

src/show.jl

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,26 @@ function _short_desc(s::String)
22
return length(s) < 80 ? s : strip(s[1:79]*"")
33
end
44

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

10-
function Base.show(io::IO, dataset::MangalDataset)
11-
print(io, """Mangal dataset #$(dataset.id) ($(dataset.name))""")
9+
function Base.show(io::IO, network::MangalNetwork)
10+
print(io, """🕸️ Mangal network #$(network.id) ($(network.name))""")
1211
end
1312

14-
function Base.show(io::IO, ::MIME"text/plain", network::MangalNetwork)
15-
print(io, """Mangal network #$(network.id) ($(network.name))
16-
$(_short_desc(network.description))
17-
→ Part of dataset #$(network.dataset.id) ($(network.dataset.name))
18-
""")
13+
function Base.show(io::IO, interaction::MangalInteraction)
14+
print(io, """🔄 Mangal int° #$(interaction.id): from $(interaction.from.name) to $(interaction.to.name)""")
1915
end
2016

21-
function Base.show(io::IO, network::MangalNetwork)
22-
print(io, """Mangal network #$(network.id) ($(network.name))""")
17+
function Base.show(io::IO, user::MangalUser)
18+
print(io, """🫂 Mangal contributor #$(user.id): $(user.name) - $(user.orcid)""")
19+
end
20+
21+
function Base.show(io::IO, node::MangalNode)
22+
print(io, """🦝 Mangal node #$(node.id): $(node.name)""")
23+
end
24+
25+
function Base.show(io::IO, taxon::MangalReferenceTaxon)
26+
print(io, """🌲 Mangal taxon #$(taxon.id): $(taxon.name)""")
2327
end

src/types.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,15 @@ struct MangalInteraction
153153
updated::DateTime
154154
attribute::Union{Missing,MangalAttribute}
155155
end
156+
157+
158+
"""
159+
MangalUser
160+
"""
161+
struct MangalUser
162+
id::Int64
163+
name::AbstractString
164+
email::Union{Missing,AbstractString}
165+
orcid::Union{Missing,AbstractString}
166+
organization::Union{Missing,AbstractString}
167+
end

test/datasets.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ module MangalTestDataset
1717
# Dataset by name
1818
@test typeof(dataset("roberson_1929")) <: MangalDataset
1919

20+
@test isnothing(dataset("This_DOESNOT_exist"))
21+
2022
end

test/runtests.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ my_tests = [
99
"datasets.jl",
1010
"networks.jl",
1111
"interactions.jl",
12-
"knownbugs.jl"
12+
"knownbugs.jl",
13+
"users.jl"
1314
]
1415

1516
global test_n

test/users.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module MangalTestUsers
2+
3+
using Mangal
4+
using Test
5+
6+
@test typeof(users()) <: Vector{MangalUser}
7+
8+
end

0 commit comments

Comments
 (0)