Giter Club home page Giter Club logo

yarnex's Introduction

Yarnex

TODO: Add description

Installation

Will eventually publish the CLI client to Homebrew. After that, will be installable through

brew install yarnex #on any linux or macOS system with homebrew on it

Yarn-related stuff

The entirety of yarn.social-related logic in Elixir lives below:

defmodule Yarn do
  require HTTPoison
  require Poison
  @spec api_endpoint(String.t()) :: <<_::64, _::_*8>>
  def api_endpoint(yarnpod) do
    "https://#{yarnpod}/api/v1"
  end

  @spec get_jwt_token(String.t(), String.t(), String.t()) :: String.t()
  def get_jwt_token(username, password, endpoint) do
    {:ok, response} =
      HTTPoison.post(
        "#{endpoint}/auth",
        Poison.encode!(%{username: username, password: password}),
        %{"Content-Type" => "application/json"}
      )

    Poison.decode!(response.body)["token"]
  end

  @spec authenticated_headers(String.t()) :: %{optional(<<_::40, _::_*56>>) => binary}
  def authenticated_headers(token) do
    %{"Token" => "#{token}", "Content-Type" => "application/json"}
  end

  def post_twt(token, yarnpod, twt) do
    {:ok, response} =
      HTTPoison.post(
        "#{api_endpoint(yarnpod)}/post",
        Poison.encode!(%{text: twt, post_as: ""}),
        authenticated_headers(token)
      )

    Poison.decode!(response.body)
  end

  def reply_twt(token, yarnpod, hash, twt) do
    post_twt(token, yarnpod, "(##{hash}) #{twt}") # damn that's some ugly code
    # well it basically just merges the hash and twt into a single string so it looks like
    # --> "(#abcdefg) yes you're so right!"
    # and then posts it to your yarn account where yarn can aggregate it into being a reply to
    # the twt with hash of abcdefg, in this example
  end
end

That's everything it takes to implement a simple yarn.social client in Elixir!

yarnex's People

Contributors

shreyanjain9 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.