Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process response #11

Merged
merged 13 commits into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/TagBot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ on:
types:
- created
workflow_dispatch:
inputs:
lookback:
default: 3
permissions:
contents: write
jobs:
TagBot:
if: github.event_name == 'workflow_dispatch' || github.actor == 'JuliaTagBot'
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "IdealistaAPIClient"
uuid = "5722b1ce-14da-11ed-06c6-d930f2b72c9a"
authors = ["Roger Samsó <r.samso@proton.me>"]
version = "0.1.0"
version = "0.2.0"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ valid_fields()
# define search fields
search_fields = (country="es", center="40.430,-3.702", propertyType="homes", distance=15000, operation="sale", bedrooms="1,2,3,4", swimmingPool=true)

response_body = search(;search_fields...)
search(;search_fields...) |> process_response

```

Expand Down
95 changes: 0 additions & 95 deletions docs/Manifest.toml

This file was deleted.

1 change: 0 additions & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
[deps]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
IdealistaAPIClient = "5722b1ce-14da-11ed-06c6-d930f2b72c9a"
3 changes: 2 additions & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ using Documenter, IdealistaAPIClient
DocMeta.setdocmeta!(IdealistaAPIClient, :DocTestSetup, :(using IdealistaAPIClient); recursive=true)

makedocs(sitename="IdealistaAPIClient.jl",
modules = [IdealistaAPIClient],
pages = [
"Introduction" => "intro.md",
"Introduction" => "index.md",
"Usage" => "usage.md",
"API" => Any["Types" => "types.md",
"Functions" => "functions.md"]
Expand Down
16 changes: 3 additions & 13 deletions docs/src/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,7 @@ CurrentModule = IdealistaAPIClient
Pages = ["functions.md"]
```

## Valid fields
```@docs
valid_fields
```

## Generating a token
```@docs
get_token
```

## Performing property searches
```@docs
search
```@autodocs
Modules = [IdealistaAPIClient]
Order = [:function]
```
12 changes: 11 additions & 1 deletion docs/src/intro.md → docs/src/index.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# Introduction
# IdealistaAPIClient.jl

IdealistaAPIClient is a simple julia client for the [Idealista Search API](https://developers.idealista.com/access-request).


# Index
```@contents
Pages = [
"usage.md",
"functions.md",
"types.md",
]
```
10 changes: 3 additions & 7 deletions docs/src/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ Pages = ["types.md"]

## Types specification

```@docs
Search
Garages
Offices
Homes
Premises
Bedrooms
```@autodocs
Modules = [IdealistaAPIClient]
Order = [:type]
```
2 changes: 1 addition & 1 deletion docs/src/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Pkg.add(url="https://github.com/rogersamso/IdealistaAPIClient.jl")

```


# Usage

There are two interfaces to perform searches, one using keyword arguments, and another one using the Search and PropertyFields subtypes.
Expand Down Expand Up @@ -44,3 +43,4 @@ response_body = search(search_fields, home_fields)

```

The response body, as expected, is the body of the response of our request, in the form of a dictionary. The response can be then turned into a `Response` object by passing it to the [`process_response`](@ref) function.
2 changes: 2 additions & 0 deletions src/IdealistaAPIClient.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export
get_token,
search,
valid_fields,
process_response,
Search,
Garages,
Premises,
Expand All @@ -20,6 +21,7 @@ export
Bedrooms

include("types.jl")
include("utils.jl")
include("functions.jl")


Expand Down
51 changes: 44 additions & 7 deletions src/functions.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Base: exit
using IdealistaAPIClient: Response, Element, ParkingSpace, DetailedType

"""
valid_fields(T::Type; indent::Int=0)
Expand Down Expand Up @@ -129,11 +130,6 @@ function valid_fields(;indent::Int=1)
end
end

function struct_to_dict(s)
Dict(String(key)=>getfield(s, key) for key ∈ fieldnames(typeof(s))
if ~isnothing(getfield(s, key)))
end


function generate_credentials(apikey::AbstractString, secret::AbstractString)
return Base64.base64encode(join(map(HTTP.escapeuri, [apikey, secret]), ":"))
Expand Down Expand Up @@ -270,7 +266,9 @@ function search(base_search::Search,
end

search_fields = validate_search_fields(base_search, property)
request_data(token, search_fields)

response = request_data(token, search_fields)

end


Expand Down Expand Up @@ -316,7 +314,42 @@ function search(;token_d::Union{Dict{String, Any}, Nothing}=nothing, kwargs...)

search_fields = validate_search_fields(;(;kwargs...)...)

request_data(token, search_fields)
response = request_data(token, search_fields)

end


"""
process_response(response)

Process the response of the Idealista Search API

Goes through the dictionary of the parsed Idealista Search API response and instantiates a Response object

# Examples

"""
function process_response(response::Dict{String, Any})::Response

resp_cp = deepcopy(response)

elements = pop!(resp_cp, "elementList")

new_elements = Vector{Element}(undef, length(elements))

for (num, element) in enumerate(elements)
if haskey(element, "parkingSpace")
setindex!(element, ParkingSpace(;stringdict_to_nt(element["parkingSpace"])...), "parkingSpace")
end
if haskey(element, "detailedType")
setindex!(element, DetailedType(;stringdict_to_nt(element["detailedType"])...), "detailedType")
end
new_elements[num] = Element(;stringdict_to_nt(element)...)
end

setindex!(resp_cp, new_elements, "elementList")

Response(;stringdict_to_nt(resp_cp)...)

end

Expand Down Expand Up @@ -400,3 +433,7 @@ function request_data(token::AbstractString, search_fields::Dict{String, Any})
end
end
end




Loading