{"id":25909637,"url":"https://github.com/wise-home/wise_homex","last_synced_at":"2025-03-03T08:18:09.124Z","repository":{"id":35228591,"uuid":"175565658","full_name":"wise-home/wise_homex","owner":"wise-home","description":"API Client for Wise Home in Elixir","archived":false,"fork":false,"pushed_at":"2025-01-22T12:15:08.000Z","size":988,"stargazers_count":2,"open_issues_count":1,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-22T13:28:06.122Z","etag":null,"topics":["elixir","iot","wise-home"],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wise-home.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-03-14T06:57:05.000Z","updated_at":"2025-01-22T12:15:11.000Z","dependencies_parsed_at":"2023-10-25T19:33:03.501Z","dependency_job_id":"b7f905fd-99b0-4e07-a8b4-4b160d89ace2","html_url":"https://github.com/wise-home/wise_homex","commit_stats":null,"previous_names":[],"tags_count":152,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wise-home%2Fwise_homex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wise-home%2Fwise_homex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wise-home%2Fwise_homex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wise-home%2Fwise_homex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wise-home","download_url":"https://codeload.github.com/wise-home/wise_homex/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241629714,"owners_count":19993711,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["elixir","iot","wise-home"],"created_at":"2025-03-03T08:18:08.553Z","updated_at":"2025-03-03T08:18:09.111Z","avatar_url":"https://github.com/wise-home.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Wise Home API Client for Elixir\n\n![](https://github.com/wise-home/wise_homex/workflows/CI/badge.svg)\n\n**This api client is currently under development, and is currently only for internal use in [Wise Home](https://wisehome.dk).**\n\nJump to:\n\n- [Usage](#usage)\n- [Testing](#testing)\n\n\n## Usage:\n\n### Adding the dependency\n\nSince the package is only available on GitHub at the moment, it can be added to `mix.exs` using:\n\n```elixir\ndef deps do\n  [\n    # Add WiseHomex from GitHub\n    {:wise_homex, git: \"https://github.com/wise-home/wise_homex.git\", tag: \"0.6.2\"}\n  ]\nend\n```\n\n### Getting a configuration\n\nFirst, get a configuration struct by invoking `new_config/2` or `new_config/3` with either `:api_key`, `:plain` or `:auth_header` as first argument.\n\n```\nconfig = WiseHomex.new_config(:api_key, \"your_api_key\")\nconfig = WiseHomex.new_config(:plain, {\"user_name\", \"password\"})\nconfig = WiseHomex.new_config(:auth_header, \"auth_header\")\n```\n\nOptionally you can call `new_config/3` with a keyword list for overriding the default configuration values, `base_url`, `timeout` and `api_version`\n\n```\nconfig = WiseHomex.new_config(:api_key, \"your_api_key\", timeout: 60_000, base_url: \"https://another.wisehome.server.dk\", api_version: \"v4\")\n```\n\n### Making requests\n\nNext, use that `config` to do requests to the Wise Home API.\n\n```\nconfig |\u003e WiseHomex.get_gateways()\n```\n\nMost `GET`-requests have a `query` that will be encoded and included.\n\n```\nconfig |\u003e WiseHomex.get_gateways(%{\"include\" =\u003e \"sim\"})\n```\n\nMany `POST` and `PATCH` requests take a map for `attributes` and `relationships` for the created or updated entity, for example:\n\n```\nattributes = %{move_in_date: \"2019-01-01\", move_out_date: \"2019-02-01\"}\n\nrelationships = %{\n  \"household\" =\u003e %{\n    data: %{\n      type: \"households\",\n      id: \"123\"\n    }\n  },\n  \"tenant\" =\u003e %{\n    data: %{\n      type: \"accounts\",\n      id: \"987\"\n    }\n  }\n}\n\nconfig |\u003e WiseHomex.create_tenancy(attributes, relationships)\n```\n\nIf the request is successful, you will receive a response of the `{:ok, data}` where data is the included Ecto models. If the response is empty, the response will be {:ok, :empty}\n\nIf unsuccessful, the response will be one of\n\n```\n{:invalid_request, map | nil}\n{:not_authorized, map | nil}\n{:not_found, map | nil}\n:server_error\n:bad_gateway\n{:service_not_available, map | nil}\n:econnrefused\n:connect_timeout\n:closed\n```\n\n\n## Testing\n\nThe WiseHomex Api Client can be mocked during tests. By default the client uses the http implementation, but it can be overridden by setting in your `config/test.exs` file:\n\n```\n# Use the WiseHomex ApiMock\nconfig :wise_homex, :api_client_impl, WiseHomex.Test.ApiClientMock\n```\n\nThis will make all api calls reach the WiseHomex mock instead. Since the mock is a genserver, it needs to be started before all tests, and the tests cannot be async at this time.\n\nA sample test:\n\n```elixir\ndefmodule MyModule.SampleTest do\n  use ExUnit.Case\n\n  alias WiseHomex.Test.ApiClientMockServer, as: MockServer\n\n  test \"it calls ping with the expected includes\" do\n    config = WiseHomex.new_config(:api_key, \"test\")\n\n    MockServer.start_link()\n    MockServer.set(:ping, %{query: %{\"include\" =\u003e \"user,account\"}}, {:ok, :put_mock_response_here})\n\n    {:ok, _response} = config |\u003e WiseHomex.ping(%{\"include\" =\u003e \"user,account\"})\n\n    # Assert on the calls that have been made\n    assert MockServer.called?(:ping) == %{query: %{\"include\" =\u003e \"user,account\"}}\n\n    # Assert that all set up mocks have been called\n    # Useful for seeing what was not called\n    assert MockServer.remaining_calls() == %{}\n  end\nend\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwise-home%2Fwise_homex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwise-home%2Fwise_homex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwise-home%2Fwise_homex/lists"}