{"id":18078372,"url":"https://github.com/techgaun/xmart-things","last_synced_at":"2025-04-12T11:52:42.595Z","repository":{"id":57557502,"uuid":"76020597","full_name":"techgaun/xmart-things","owner":"techgaun","description":"Elixir client for Smart Things","archived":false,"fork":false,"pushed_at":"2018-07-15T20:16:17.000Z","size":16,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-04-14T06:05:50.983Z","etag":null,"topics":["elixir","internet-of-things","samsung","sdk-elixir","smartthings"],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/techgaun.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-12-09T09:20:34.000Z","updated_at":"2018-07-15T20:16:18.000Z","dependencies_parsed_at":"2022-09-03T03:12:22.421Z","dependency_job_id":null,"html_url":"https://github.com/techgaun/xmart-things","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techgaun%2Fxmart-things","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techgaun%2Fxmart-things/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techgaun%2Fxmart-things/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techgaun%2Fxmart-things/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/techgaun","download_url":"https://codeload.github.com/techgaun/xmart-things/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248565034,"owners_count":21125414,"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","internet-of-things","samsung","sdk-elixir","smartthings"],"created_at":"2024-10-31T12:13:48.544Z","updated_at":"2025-04-12T11:52:42.571Z","avatar_url":"https://github.com/techgaun.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# xmart_things\n\n[![Hex version](https://img.shields.io/hexpm/v/xmart_things.svg \"Hex version\")](https://hex.pm/packages/xmart_things) ![Hex downloads](https://img.shields.io/hexpm/dt/xmart_things.svg \"Hex downloads\")\n\n\u003e SmartThings OAuth2 Strategy and Client for Elixir\n\nThis was implemented while I followed [this](http://docs.smartthings.com/en/latest/smartapp-web-services-developers-guide/overview.html) but can be used for all the needs to build Web Services SmartApps with SmartThings.\n\n## Installation\n\nIf [available in Hex](https://hex.pm/docs/publish), the package can be installed as:\n\n- Add `xmart_things` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [{:xmart_things, \"~\u003e 0.1.0\"}]\nend\n```\n\n- Ensure `xmart_things` is started before your application:\n\n```elixir\ndef application do\n  [applications: [:xmart_things]]\nend\n```\n\n## Configuration\n\nAdd a configuration block as below in your configuration:\n\n```elixir\nconfig :xmart_things,\n  client_id: System.get_env(\"ST_CLIENT_ID\"),\n  client_secret: System.get_env(\"ST_CLIENT_SECRET\"),\n  redirect_uri: System.get_env(\"ST_REDIRECT_URI\"),\n  scope: \"app\"\n  # , app_uuid: \"\" # set this if you wish to explicitly specify site/smartapp base uri to call\n```\n\n## Usage\n\n```elixir\n# Generate the authorization to redirect client for authorization\nXmartThings.authorize_url!\n\n# Capture the `code` from redirect in your callback handler route\nst_client = XmartThings.get_token!(code: code)\n\n# Use the access token to access resources\n\nlocks = XmartThings.get!(st_client, \"/locks\").body\n\n# or\ncase XmartThings.get(st_client, \"/locks\") do\n  {:ok, %OAuth2.Response{status_code: 401, body: body}} -\u003e\n    {:error, \"unauthorized token\"}\n  {:ok, %OAuth2.Response{status_code: status_code, body: locks}} when status_code in [200..399] -\u003e\n    locks\n  {:error, %OAuth2.Error{reason: reason}} -\u003e\n    {:error, reason}\nend\n\n# Use `endpoints/1` or `endpoints!/1` to get the list of endpoints that you can use to talk with SmartApp\nXmartThings.endpoints!(st_client)\n\n# It can return bunch of responses. Pick one of those (usually the first one) to perform your requests to SmartApp\n\n[%{\"uri\" =\u003e uri} | _] = XmartThings.endpoints!(st_client).body\n\n# and now send the requests to URLs like below:\n\nXmartThings.get(%{st_client | site: uri}, \"/locks\")\n\n# if you set `app_uuid` on your config, you don't need to update `site` in the `st_client` struct\n\nXmartThings.get(st_client, \"/locks\")\n```\n\n## Parent-Child Apps\n\nIf you have parent and child apps on smartthings and you get an error with oAuth, you might need to add `oauth: true` in your child apps definition. This happens when your child apps have access to devices but parents have access only through the child apps.\n\n```groovy\ndefinition(\n    name: \"Some Child App\",\n    namespace: \"techgaun\",\n    author: \"techgaun\",\n    description: \"Some child app\",\n    category: \"\",\n    oauth: true,\n    parent: \"smartthings_something:sometest\"\n)\n```\n\n## Example\n\nA sample implementation that interacts with *Locks* is available [HERE](https://github.com/techgaun/xmart-things-demo)\n\n## Author\n\n- [techgaun](https://github.com/techgaun)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechgaun%2Fxmart-things","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftechgaun%2Fxmart-things","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechgaun%2Fxmart-things/lists"}