HISE Logo Forum
    • Categories
    • Register
    • Login

    Sequential Server.callWithGET uses?

    Scheduled Pinned Locked Moved General Questions
    7 Posts 3 Posters 250 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • orangeO
      orange
      last edited by

      Can we use sequential Server.callWithGET commands one after another? I need this because procedure is:

      • First, pushing email to the server, then first response comes
      • Then, taking the user id of that email, inside the first response
      • Then using this id to make another request (with combining other strings)
      • Then second response comes

      Below procedure is not working.

      
      inline function onButton1Control(component, value)
      {
          if(value)
            {
              Server.callWithGET("API Link", "", function(status, response)         
               {          
      
      
               });
           
           
           
              local endpoint1 = "String1";        
              local usid = response.id;
              local endpoint2 = "String2";        
              local totalEndPoint = endpoint1 + usid + endpoint2;
              
      
            
              Server.callWithGET(totalEndPoint, "", function(status, response)         
               {
      
            
               });
      
              
            }
      };
      
      Content.getComponent("Button1").setControlCallback(onButton1Control);
      
      
      

      develop Branch / XCode 13.1
      macOS Monterey / M1 Max

      1 Reply Last reply Reply Quote 0
      • d.healeyD
        d.healey
        last edited by d.healey

        You need to use nested callbacks.

        Libre Wave - Freedom respecting instruments and effects
        My Patreon - HISE tutorials
        YouTube Channel - Public HISE tutorials

        1 Reply Last reply Reply Quote 1
        • Christoph HartC
          Christoph Hart
          last edited by

          Yes David is right and in order to avoid getting spaghetti code, you need to use named functions like this:

          function firstCall(status, response)
          {
              var endpoint1 = "String1";        
              var usid = response.id;
              var endpoint2 = "String2";        
              var totalEndPoint = endpoint1 + usid + endpoint2;
          
              Server.callWithGET(totalEndPoint, "", secondCall);
          }
          
          function secondCall(status, response)
          {
              // continue here...
          }
          
          inline function onButton1Control(component, value)
          {
              if(value)
                  Server.callWithGET("API Link", "", firstCall);
          };
          
          Content.getComponent("Button1").setControlCallback(onButton1Control);
          
          orangeO 1 Reply Last reply Reply Quote 1
          • orangeO
            orange @Christoph Hart
            last edited by

            @Christoph-Hart @d-healey
            Looks very cool, Thank you!

            develop Branch / XCode 13.1
            macOS Monterey / M1 Max

            1 Reply Last reply Reply Quote 0
            • orangeO
              orange
              last edited by orange

              @Christoph-Hart said in Sequential Server.callWithGET uses?:

              Yes David is right and in order to avoid getting spaghetti code, you need to use named functions like this:

              function firstCall(status, response)
              {
                  var endpoint1 = "String1";        
                  var usid = response.id;
                  var endpoint2 = "String2";        
                  var totalEndPoint = endpoint1 + usid + endpoint2;
              
                  Server.callWithGET(totalEndPoint, "", secondCall);
              }
              
              function secondCall(status, response)
              {
                  // continue here...
              }
              
              inline function onButton1Control(component, value)
              {
                  if(value)
                      Server.callWithGET("API Link", "", firstCall);
              };
              
              Content.getComponent("Button1").setControlCallback(onButton1Control);
              

              firstCall response is ok and I can print trace(response) data.

              But var usid = response.id; looks undefined. What am I missing?

              develop Branch / XCode 13.1
              macOS Monterey / M1 Max

              d.healeyD 1 Reply Last reply Reply Quote 0
              • d.healeyD
                d.healey @orange
                last edited by

                @orange I think this is just an example. Your response object probably doesn't have an id field.

                Libre Wave - Freedom respecting instruments and effects
                My Patreon - HISE tutorials
                YouTube Channel - Public HISE tutorials

                orangeO 1 Reply Last reply Reply Quote 1
                • orangeO
                  orange @d.healey
                  last edited by orange

                  @d-healey Ok you are right, it doesn't have directly an id field. Woocommerce user retrieve response is in an array format. So:

                  var usid = response[0].id; works.

                  [
                    {
                      "id": 12345,
                      "date_created": "",
                      "date_created_gmt": "",
                      "date_modified": "",
                      "date_modified_gmt": "",
                      "email": "USER_EMAIL",
                      "first_name": "",
                      "last_name": "",
                      "role": "customer",
                      "username": "",
                      "billing": {
                        "first_name": "",
                        "last_name": "",
                        "company": "",
                        "address_1": "",
                        "address_2": "",
                        "city": "",
                        "postcode": "",
                        "country": "",
                        "state": "",
                        "email": "",
                        "phone": ""
                      },
                      "shipping": {
                        "first_name": "",
                        "last_name": "",
                        "company": "",
                        "address_1": "",
                        "address_2": "",
                        "city": "",
                        "postcode": "",
                        "country": "",
                        "state": ""
                      },
                      "is_paying_customer": true,
                      "avatar_url": "",
                      "meta_data": [
                        {
                          "id": ,
                          "key": "",
                          "value": ""
                        },
                        {
                          "id": ,
                          "key": "",
                          "value": ""
                        }
                      ],
                      "_links": {
                        "self": [
                          {
                            "href": ""
                          }
                        ],
                        "collection": [
                          {
                            "href": ""
                          }
                        ]
                      }
                    }
                  ]
                  

                  develop Branch / XCode 13.1
                  macOS Monterey / M1 Max

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post

                  30

                  Online

                  1.7k

                  Users

                  11.7k

                  Topics

                  102.0k

                  Posts