【问题标题】:How can I create prototype objects inside Zapier?如何在 Zapier 中创建原型对象?
【发布时间】:2017-03-03 05:16:04
【问题描述】:

我正在 Zapier 内部进行应用程序集成,并使用 zapier 的内置方法来轮询数据。该脚本现在很长,并且使用了很多重复的函数对象。如何为每个属性调用使用原型继承模型,以便我可以将它重用于对其他属性的类似调用?一个典型的api调用如下:

var Zap = {
    myattribute_post_poll: function(bundle) {
            var results = JSON.parse(bundle.response.content);
            results.value.reverse();

            //attribute call
            var cRequest =  {
                'url': "myURL.com/a/" + bundle.auth_fields.tenant_id + 
                    "/odata/standard.odata/Catalog_attibute(guid'" + results.value[i].attribute_Key + "')?$format=json",
                'headers': {
                  "Authorization": "Basic " + btoa(bundle.auth_fields.username + ':' + bundle.auth_fields.password)
                }, 
                'method': "GET"
            };
            var cResponse = z.request(cRequest);
           try{
                var JSONResponse = JSON.parse(cResponse.content);
                results.value[i].Customer_name = JSONResponse.Description;
            } catch(error){
                console.log(error);
                results.value[i].Customer_name = results.value[i].Company_Key;
            }
return results;
}

【问题讨论】:

    标签: zapier


    【解决方案1】:

    最好的技术就是在Zap 上分解可重用的属性:

    var Zap = {
        reusable_thing: function(arg) {
            return arg + 1;
        },
        attr_pre_poll: function(bundle) {
            bundle.request.params = Zap.reusable_thing(1);
            return bundle.request;
        }
    };
    

    【讨论】:

      【解决方案2】:

      这可能对其他人有帮助,所以在这里添加我的原型对象:

      var Zap = {
      attrGuidRequest : function(obj, document, key){
          var attrResponse = JSON.parse(
              z.request({
              'url': "myUrl" + tenant_id + 
                              "/odata/.." + document + "(guid'" + key + "')?$format=json",
              'headers': {
                            "Authorization": "Basic " + btoa(username + ':' + password)
                          }, 
              'method': "GET"
              }).content) || {};
              return attrResponse;
          }
      }
      

      【讨论】:

        猜你喜欢
        • 2021-05-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-11-26
        • 1970-01-01
        相关资源
        最近更新 更多