roganjoshua

roganjoshua

(Customerbuilder.GitLab.get!("/projects/5112/pipelines/245667/variables", [{"Accept", "Application/json"}, {"PRIVATE-TOKEN", token}]) |> Map.get(:body),

This is an array of maps coming from gitlab

[
  %{
    "key" => "CUSTOMER",
    "raw" => false,
    "value" => "EOG.Acme.ManualXML",
    "variable_type" => "env_var"
  },
  %{
    "key" => "TRIGGER_PAYLOAD",
    "raw" => false,
    "value" => "{\"variables\":{\"CUSTOMER\":\"EOG.Acme.ManualXML\",\"VERSION\":\"Version-8.6.2\"},\"id\":\"5112\",\"ref\":\"main\"}",
    "variable_type" => "file"
  },
  %{
    "key" => "VERSION",
    "raw" => false,
    "value" => "Version-8.6.2",
    "variable_type" => "env_var"
  }
]

I want to put the version and customer into a new struct or something so I can pass it to a heex template. I need to add some other details like if the build is running/failed/success.

This seems easy but I am finding this difficult :confused:

|> Enum.into(%{ “key” => key})

|> Map.get(:body), :key)

|> Map.get(:body), “key”)

|> [ key: “CUSTOMER” ]

|> Map.get(:body) |> [ key: “CUSTOMER” ]

Showing Posts 1 to 10

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Hi @roganjoshua can you show what you’ve tried so far?

dimitarvp

dimitarvp

What’s the final shape of the data you want to arrive at?

roganjoshua

roganjoshua OP

[
%Build{status: "running", version: "8.6.1", customer: "Acme"},
%Build{status: "running", version: "8.6.1", customer: "Bloggs Inc"}
]

I want to iterate of the list in a <.table in the Heex - I think that is the right model?

dimitarvp

dimitarvp

Where does status come from? I can only see customer and version in your initial snippet.

roganjoshua

roganjoshua OP

it comes from a previous request

  case GitLab.get(
           "/projects/5112/jobs?scope[]=pending&scope[]=running",
           [
             {"Accept", "Application/json"},
             {"Content-Type", "Application/json"},
             {"PRIVATE-TOKEN", token}
           ]
         ) do
      {:ok, %HTTPoison.Response{status_code: 200, body: body}} ->
        body
        |> Enum.map(fn x ->
          %{
            "pipelineid" => x["pipeline"]["id"],
            "status" => x["status"]
          }
        end)
        |> Enum.map(fn x ->
          {
            case GitLab.get(
                   "/projects/5112/pipelines/#{x["pipelineid"]}/variables",
                   [
                     {"Accept", "Application/json"},
                     {"Content-Type", "Application/json"},
                     {"PRIVATE-TOKEN", token}
                   ]
                 ) do
              {:ok, %HTTPoison.Response{status_code: 200, body: body}} ->
                body |> IO.inspect()
            end
          }
        end)
        |> Enum.map(fn x ->
          x["key"]  -> "CUSTOMER"

          %{
            "Version" => x["value"],
            "Customer" => x["value"]
          }
        end)
        |> Enum.map(&IO.puts/1)

This is sub-optimal but I am trying to sort of test to get something working

dimitarvp

dimitarvp

There are a few things I could change but let’s get your stuff working first.

As Ben asked, what have you tried? You edited your first post but I didn’t find that snippet there convincing, or even fully related to the input data.

BTW do you know about dbg/2? You can put it after each phase of your pipe to see how the data changed. Or you can just do it step by step in iex.

To me it’s fairly easy to get customer and version from your original map and convert it like you need but I’d like to see your thought process and how would you go about solving the problem.

roganjoshua

roganjoshua OP

I didn’t know about dbg/2

roganjoshua

roganjoshua OP

|> Enum.into(%{ “key” => key})

OR 

|> Map.get(:body), :key)
OR 

|> Map.get(:body), “key”)
OR 

|> [ key: “CUSTOMER” ]
OR 

|> Map.get(:body) |> [ key: “CUSTOMER” ]


dimitarvp

dimitarvp

That shouldn’t even compile, no?

roganjoshua

roganjoshua OP

probably not :frowning:

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
jaybe78
Hello, I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter). The diffic...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New
aseigo
ICal is a library for interacting with iCalendar data. It parses iCalendars into typed Elixir structs via ICal.from_ics, and can prepare ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews