GithubHelp home page GithubHelp logo

How to use Elixir about code-for-conduct HOT 7 OPEN

WLPhoenix avatar WLPhoenix commented on July 26, 2024
How to use Elixir

from code-for-conduct.

Comments (7)

jbunting avatar jbunting commented on July 26, 2024

Here's how I do a post request:

 13     body = "code=#{code}&grant_type=authorization_code&client_secret=CDRPVW63YBXLHSPGL4Q25AFJKTXC7EYWOJ6LOQEE3UDIOABT6N&client_id=7EBFEB24BRVOV6J5KG"
 14     case HTTPoison.post("https://www.eventbrite.com/oauth/token", body, [{<<"Content-Type">>, <<"application/x-www-form-urlencoded">>}]) do
 15       {:ok, %HTTPoison.Response{status_code: 200, body: body}} ->
 16         IO.puts "BODY :: [[#{body}]]"
 17       {:ok, %HTTPoison.Response{status_code: 404, body: body}} ->
 18         IO.puts "Not found :-( #{body}"
 19       {:ok, %HTTPoison.Response{status_code: status_code, body: body}} ->
 20         IO.puts "I got a different code #{status_code} -- what the hell? #{body}"
 21       {:error, %HTTPoison.Error{reason: reason}} ->
 22         IO.inspect reason
 23     end

from code-for-conduct.

jbunting avatar jbunting commented on July 26, 2024

Added a new route like this:

  9     get "/auth", CodeForConduct.PageController, :auth, as: :pages

from code-for-conduct.

jbunting avatar jbunting commented on July 26, 2024

When I want different handling based on query params, I can do it like this:

  # when there is a "code" query param
  def auth(conn, %{"code" => code}) do
    ...
  end
  # otherwise
  def auth(conn, _params) do
    ...
  end

Both of these are the same method, and they pattern match on the incoming parameters to select which body to execute.

from code-for-conduct.

jbunting avatar jbunting commented on July 26, 2024

How to do a redirect from a controller function:

 29     redirect conn, "https://www.eventbrite.com/oauth/authorize?response_type=code&client_id=7EBFEB24BRVOV6J5KG"

from code-for-conduct.

WLPhoenix avatar WLPhoenix commented on July 26, 2024
# Where body is a map
case Poison.encode body do                                            
  {:ok, json} -> HTTPoison.post('http://localhost:3300', json) 
  {:error, r} -> IO.puts r
end

from code-for-conduct.

WLPhoenix avatar WLPhoenix commented on July 26, 2024
# How to get environment variable, and default if not found
[port: System.get_env("PORT") || 4000]

from code-for-conduct.

jbunting avatar jbunting commented on July 26, 2024

ERLANG NOT HAVE MUTABLE STATE.

To be more specific:

put_session(conn, "key", "value")

is NOT the same as:

conn = put_session(conn, "key", "value")

Use the second one, otherwise you just threw away your session value.

from code-for-conduct.

Related Issues (1)

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.