jdav-dev / ex_rets

RETS client for Elixir
Apache License 2.0
2 stars 0 forks source link

Demo Code. #2

Open PremierDevs opened 1 year ago

PremierDevs commented 1 year ago

I was wondering if you could provide some demo code to login and search. I have less than 5 hours with elixir and am struggling to make sense of the docs.

jdav-dev commented 1 year ago

Sure thing. I have a branch where I'm updating things for the first time in 3 years. I'll be sure to include example usage before merging that branch.

jdav-dev commented 1 year ago

I didn't get back to this as quickly as I anticipated, so here's a quick example.

Fill out the ExRets.Credentials struct:

credentials = %ExRets.Credentials{
  system_id: :my_mls,
  login_uri: "https://example.com/login",
  username: "my username",
  password: "my password",
  user_agent: "might have a user agent",
  user_agent_password: "might have a user agent password",
  rets_version: "RETS/1.8"
}

Login with the credentials to get a RETS client:

{:ok, %ExRets.RetsClient{} = rets_client} = ExRets.login(credentials)

Fill out the ExRets.SearchArguments struct:

search_arguments = %ExRets.SearchArguments{
  search_type: "Property",
  class: "CrossProperty",
  select: "ListingKeyNumeric",
  limit: "NONE",
  query: "(ModificationTimestamp=2023-07-12T17:32:41Z+)",
  count: :include_record_count
}

Perform the RETS search:

{:ok, rets_response} = ExRets.search(rets_client, search_arguments)

If all goes well, rets_response.response will contain the ExRets.SearchResponse struct which has the response columns, rows, count, etc.