Skip to content

Commit d911694

Browse files
committed
Merge branch 'ZeshanHyder-731-feature/layergroups'
2 parents 4392444 + 1db6197 commit d911694

File tree

7 files changed

+156
-43
lines changed

7 files changed

+156
-43
lines changed

lib/geoserver_config/coverages.ex

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,33 @@ defmodule GeoserverConfig.Coverages do
3131
## Example
3232
GeoserverConfig.Coverages.list_coverages("demo_workspace", "dem_store")
3333
"""
34-
@spec list_coverages(String.t(), String.t()) :: Req.Response.t()
34+
@spec list_coverages(String.t(), String.t()) :: {:ok, list()} | {:error, term()}
3535
def list_coverages(workspace, coverage_store) do
3636
url = "#{@base_url}/workspaces/#{workspace}/coveragestores/#{coverage_store}/coverages"
3737

38-
Req.get!(
39-
url,
40-
auth: {:basic, "#{@username}:#{@password}"},
41-
headers: [{"Accept", "application/json"}]
42-
)
38+
case Req.get(
39+
url,
40+
auth: {:basic, "#{@username}:#{@password}"},
41+
headers: [{"Accept", "application/json"}]
42+
) do
43+
{:ok, %{status: 200, body: body}} ->
44+
case body do
45+
%{"coverages" => %{"coverage" => coverages}} when is_list(coverages) ->
46+
{:ok, coverages}
47+
48+
%{"coverages" => %{}} ->
49+
{:ok, []}
50+
51+
_ ->
52+
{:error, :unexpected_format, body}
53+
end
54+
55+
{:ok, %{status: status, body: body}} ->
56+
{:error, {:http_error, status, body}}
57+
58+
{:error, reason} ->
59+
{:error, {:request_failed, reason}}
60+
end
4361
end
4462

4563
@doc """

lib/geoserver_config/coveragestores.ex

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,33 @@ defmodule GeoserverConfig.Coveragestores do
3030
## Example
3131
GeoserverConfig.Coveragestores.list_coveragestores("demo_workspace")
3232
"""
33+
3334
def list_coveragestores(workspace) do
3435
url = "#{@base_url}/workspaces/#{workspace}/coveragestores"
3536

36-
Req.get!(
37-
url,
38-
auth: {:basic, "#{@username}:#{@password}"},
39-
headers: [{"Accept", "application/json"}]
40-
)
37+
case Req.get(
38+
url,
39+
auth: {:basic, "#{@username}:#{@password}"},
40+
headers: [{"Accept", "application/json"}]
41+
) do
42+
{:ok, %{status: 200, body: body}} ->
43+
case body do
44+
%{"coverageStores" => %{"coverageStore" => stores}} when is_list(stores) ->
45+
{:ok, stores}
46+
47+
%{"coverageStores" => %{}} ->
48+
{:ok, []}
49+
50+
_ ->
51+
{:error, :unexpected_format, body}
52+
end
53+
54+
{:ok, %{status: status, body: body}} ->
55+
{:error, {:http_error, status, body}}
56+
57+
{:error, reason} ->
58+
{:error, {:request_failed, reason}}
59+
end
4160
end
4261

4362
@doc """

lib/geoserver_config/datastores.ex

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,41 @@ defmodule GeoserverConfig.Datastores do
3737
## Example
3838
GeoserverConfig.Datastores.list_datastores("demo_workspace")
3939
"""
40+
# def list_datastores(workspace) do
41+
# url = "#{@base_url}/workspaces/#{workspace}/datastores"
42+
43+
# Req.get!(
44+
# url,
45+
# auth: {:basic, "#{@username}:#{@password}"},
46+
# headers: [{"Accept", "application/json"}]
47+
# )
48+
# end
49+
4050
def list_datastores(workspace) do
4151
url = "#{@base_url}/workspaces/#{workspace}/datastores"
4252

43-
Req.get!(
44-
url,
45-
auth: {:basic, "#{@username}:#{@password}"},
46-
headers: [{"Accept", "application/json"}]
47-
)
53+
case Req.get(
54+
url,
55+
auth: {:basic, "#{@username}:#{@password}"},
56+
headers: [{"accept", "application/json"}]
57+
) do
58+
{:ok, %Req.Response{status: 200, body: %{"dataStores" => %{"dataStore" => stores}}}}
59+
when is_list(stores) ->
60+
{:ok, stores}
61+
62+
{:ok, %Req.Response{status: 200, body: %{"dataStores" => %{"dataStore" => store}}}}
63+
when is_map(store) ->
64+
{:ok, [store]}
65+
66+
{:ok, %Req.Response{status: 200, body: %{"dataStores" => _}}} ->
67+
{:ok, []}
68+
69+
{:ok, %Req.Response{status: status, body: body}} ->
70+
{:error, {:http_error, status, body}}
71+
72+
{:error, exception} ->
73+
{:error, exception}
74+
end
4875
end
4976

5077
@doc """

lib/geoserver_config/layergroups.ex

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,27 @@ defmodule GeoserverConfig.LayerGroups do
2626
## Example
2727
GeoserverConfig.list_layer_groups()
2828
"""
29-
@spec list_layer_groups() :: Req.Response.t()
29+
@spec list_layer_groups() :: {:ok, list()} | {:error, any()}
3030
def list_layer_groups do
3131
url = "#{@base_url}/layergroups"
3232

33-
Req.get!(
34-
url,
35-
auth: {:basic, "#{@username}:#{@password}"},
36-
headers: [{"Accept", "application/json"}]
37-
)
33+
case Req.get(
34+
url,
35+
auth: {:basic, "#{@username}:#{@password}"},
36+
headers: [{"Accept", "application/json"}]
37+
) do
38+
{:ok, %{status: 200, body: %{"layerGroups" => %{"layerGroup" => groups}}}} when is_list(groups) ->
39+
{:ok, groups}
40+
41+
{:ok, %{status: 200, body: %{"layerGroups" => %{}}}} ->
42+
{:ok, []}
43+
44+
{:ok, %{status: status, body: body}} ->
45+
{:error, {:http_error, status, body}}
46+
47+
{:error, reason} ->
48+
{:error, {:request_failed, reason}}
49+
end
3850
end
3951

4052
@doc """

lib/geoserver_config/styles.ex

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,27 @@ defmodule GeoserverConfig.Styles do
2525
## Example
2626
GeoserverConfig.Styles.list_styles()
2727
"""
28-
@spec list_styles() :: Req.Response.t()
29-
def list_styles() do
28+
@spec list_styles() :: {:ok, list()} | {:error, any()}
29+
def list_styles do
3030
url = "#{@base_url}/styles"
3131

32-
Req.get!(
33-
url,
34-
auth: {:basic, "#{@username}:#{@password}"},
35-
headers: [{"Accept", "application/json"}]
36-
)
32+
case Req.get(
33+
url,
34+
auth: {:basic, "#{@username}:#{@password}"},
35+
headers: [{"Accept", "application/json"}]
36+
) do
37+
{:ok, %{status: 200, body: %{"styles" => %{"style" => styles}}}} when is_list(styles) ->
38+
{:ok, styles}
39+
40+
{:ok, %{status: 200, body: %{"styles" => %{}}}} ->
41+
{:ok, []}
42+
43+
{:ok, %{status: status, body: body}} ->
44+
{:error, {:http_error, status, body}}
45+
46+
{:error, reason} ->
47+
{:error, {:request_failed, reason}}
48+
end
3749
end
3850

3951
@doc """
@@ -48,14 +60,27 @@ defmodule GeoserverConfig.Styles do
4860
## Example
4961
GeoserverConfig.Styles.list_styles_workspace_specific("demo")
5062
"""
63+
@spec list_styles_workspace_specific(String.t()) :: {:ok, list()} | {:error, any()}
5164
def list_styles_workspace_specific(workspace) do
5265
url = "#{@base_url}/workspaces/#{workspace}/styles"
5366

54-
Req.get!(
55-
url,
56-
auth: {:basic, "#{@username}:#{@password}"},
57-
headers: [{"Accept", "application/json"}]
58-
)
67+
case Req.get(
68+
url,
69+
auth: {:basic, "#{@username}:#{@password}"},
70+
headers: [{"Accept", "application/json"}]
71+
) do
72+
{:ok, %{status: 200, body: %{"styles" => %{"style" => styles}}}} when is_list(styles) ->
73+
{:ok, styles}
74+
75+
{:ok, %{status: 200, body: %{"styles" => %{}}}} ->
76+
{:ok, []}
77+
78+
{:ok, %{status: status, body: body}} ->
79+
{:error, {:http_error, status, body}}
80+
81+
{:error, reason} ->
82+
{:error, {:request_failed, reason}}
83+
end
5984
end
6085

6186
@doc """

lib/geoserver_config/workspaces.ex

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,27 @@ defmodule GeoserverConfig.Workspaces do
2626
## Example
2727
GeoserverConfig.Workspaces.fetch_workspaces()
2828
"""
29+
2930
def fetch_workspaces do
3031
url = "#{@base_url}/workspaces"
3132

32-
Req.get!(
33-
url,
34-
auth: {:basic, "#{@username}:#{@password}"},
35-
headers: [{"Accept", "application/json"}]
36-
)
33+
case Req.get(url,
34+
auth: {:basic, "#{@username}:#{@password}"},
35+
headers: [{"Accept", "application/json"}]
36+
) do
37+
{:ok, %Req.Response{status: 200, body: %{"workspaces" => %{"workspace" => workspaces}}}}
38+
when is_list(workspaces) ->
39+
{:ok, workspaces}
40+
41+
{:ok, %Req.Response{status: 200, body: %{"workspaces" => _}}} ->
42+
{:ok, []}
43+
44+
{:ok, %Req.Response{status: status, body: body}} ->
45+
{:error, {:http_error, status, body}}
46+
47+
{:error, exception} ->
48+
{:error, {:request_failed, Exception.message(exception)}}
49+
end
3750
end
3851

3952
@doc """

run.exs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
# IO.inspect(response)
104104

105105
# GET Method: List of Coverages
106-
# response = GeoserverConfig.Coverages.list_coverages("sf", "sfdem")
106+
# response = GeoserverConfig.Coverages.list_coverages("nurc", "mosaic")
107107
# IO.inspect(response)
108108

109109
# POST Method: Creation of Coverage Layers
@@ -143,7 +143,7 @@
143143
# response = GeoserverConfig.Styles.list_styles()
144144
# IO.inspect(response)
145145

146-
# # GET Method: Styles (Workspace Specific)
146+
# GET Method: Styles (Workspace Specific)
147147
# response = GeoserverConfig.list_styles_workspace_specific("ne")
148148
# IO.inspect(response)
149149

@@ -232,10 +232,9 @@
232232

233233

234234
# LayerGroups GET Method
235-
response = GeoserverConfig.list_layer_groups().body
235+
response = GeoserverConfig.list_layer_groups()
236236
IO.inspect(response)
237237

238-
239238
# LayerGroups POST Method
240239
# xml_body = """
241240
# <?xml version="1.0" encoding="UTF-8"?>

0 commit comments

Comments
 (0)