elixir

Composing dynamic queries with ecto

published on
I was recently working on a project where I needed to compose a dynamic query for filtering a table using ecto. The filter parameters are coming from a graphql resolver. # ~/query.ex #A sample filter input filter_input = %{status: "AVAILABLE", genre: "Comedy", last_update_gte: "2018-10-18 00:00:00", last_update_lte: "2018-10-18 23:59:59" } #The schema I will be querying defmodule Movies do use Ecto.Schema schema "movies" do field(:genre, :string) field(:status, :string) timestamps() end end #My resolver function defmodule MovieFilter do import Ecto. Read More...

Testing with Mocks

published on
The situation was that, I needed to mock multiple external service within my application in order to test my application. These external services are being consumed using HTTPPoison the popular elixir http client. The mock is achieved using the Mock library # ~/multi_mocks.exs Import Mock #Mock multiple functions of the same module test "Test special service that will call other supporting endpoints" do with_mock( HTTPoison, post!: fn endpoint_a, _, _ -> %HTTPoison. Read More...

Elixir Telegram Bot

published on
The quest was to develop a telegram bot over 24hrs, during an office hackathon event. I started out consulting documentation. Bot interaction was implemented as a GenServer named ConversationTree defmodule TelegramService.ConversationTree do use GenServer def start_link(name, conversation \\ %{message: [], response: [], tickets: []}) do {:ok, _} = GenServer.start_link(__MODULE__, conversation, name: name) name end def lookup(name) do GenServer.whereis(name) end def kill(name) do GenServer.stop(name) end def write_message(name, message = %{}) do GenServer. Read More...