DeviceStructure

This module is designed to facilitate the Device structure (Plug.Conn.assign) and easy connection to other projects.

Installation

The module can be installed by adding ds to your list of dependencies in mix.exs with git url:

def deps do
  [
    {:ds, "~> 1.0"}
  ]
end

Run mix task for download UAInspector databases:

$ mix ua_inspector.download

Usage

Create new pipeline in your Router file:

defmodule ExampleWeb.Router do
  use ExampleWeb.Router

  pipeline :device_detectable do
    plug DSPlug
  end

  # Add pipeline to scope
  scope "/", ExampleWeb do
    pipe_through [:browser, :device_detectable]
    get "/", ExampleController, :index
  end
end

Now you can access it from your controller.

def ExampleController do
  use ExampleWeb, :controller

  def index(conn, _params) do
    IO.inspect(conn.assigns[:device_info])
    text(conn, "OK")
  end
end

Dependencies used in library

defp deps do
    [
      {:plug_cowboy, "~> 2.0"},
      {:ua_inspector, "~> 0.20"},
      {:jason, "~> 1.1"}
    ]
  end

License

This project is licensed under the terms of the MIT license.