I am using detergent to make soap call to salesforce soap api.
I want to call its function call/4 but it fails:
:detergent.call("metadata.wsdl", "describeMetadata", ["37.0"], [{'sessionId',token.access_token}])
** (exit) an exception was raised:
** (FunctionClauseError) no function clause matching in :erlsom_write.processAnyAttributes/4
src/erlsom_write.erl:501: :erlsom_write.processAnyAttributes('ok', [], [{:ns, 'http://schemas.xmlsoap.org/soap/envelope/', 'soap', :unqualified}, {:ns, 'http://soap.sforce.com/2006/04/metadata', 'p', :qualified}, {:ns, 'http://www.w3.org/2001/XMLSchema', 'xsd', :qualified}], {[{'soap', 'http://schemas.xmlsoap.org/soap/envelope/'}], 0})
src/erlsom_write.erl:325: :erlsom_write.processAlternativeValue/8
What is the expected format of the header syntax to pass token?
You are using detergent.call/4 that expects the last parameter to be a #call_opts. You are passing a list [consisting of single tuple] and the function clause could not be matched.
I am not sure about what exactly you are to pass there (see the #call_opts definition,) but I believe something like the below should do the trick:
:detergent.call(
"metadata.wsdl",
"describeMetadata",
["37.0"],
#call_opts{http_client_options=[{'sessionId',token.access_token}]}
)
Related
I have different structs for the query in the REST request. I'd like to return HTTP 400: BAD REQUEST when the query string contains an unexpected parameter than my struct.
type FilterData struct {
Filter1 string `form:"filter_1"`
Filter2 string `form:"filter_2"`
Filter3 string `form:"filter_3"`
}
The expected request request is localhost:8000/testing?filter_1=123456&filter_2=test&filter_3=golang
But if the is request like localhost:8000/users?FILTER1=123456&filter_2=test&filter_3=golang or any extra parameter than my expected struct I want to return bad request.
Go gin.Context has c.ShouldBindQuery(&filterData) but this returns the filter_1 as an empty string, indeed in my case that's a bad request.
How would I do an extra check with a common function to all requests?
PS. some values in this struct can be optional.
It is pretty standard in apis to ignore unknown query parameters. If you require some parameters to always have value, use binding:"required" property in your struct tags.
https://github.com/gin-gonic/gin#model-binding-and-validation
If you want to throw back a 400 on unknown query params, you must check contents of c.Request.URL.Query().
In the same way we can have
nullableClassInstance?.method(blah)
Is there a way to do
nullableFunctionInstance?(blah)
In other words, is there an operator that checks whether a function instance is not null, if so, invoke the function all in one line?
Using the call method, you can achieve what you want with:
nullableFunctionInstance?.call(blah)
There's also the apply method if you want to pass arguments.
If you have a Function Object , you can use the call method and send all the parameters to that which works exactly as calling the function. Here , you can use the null aware member access operator.
void myFun(int a , int b){...}
var myVar = myFun ;
call
The function myVar will only get called if its not null as shown below.
myVar?.call( arg1 , arg2 );
apply
If your function is dynamic or you wish to control which function is being called at run time , you can use the apply static method of Function like so :
Function.apply(myVar , [arg1 , arg2]);
apply takes the function and a List of parameters that will be sent to the function.
Read more about call and apply :
I'm implementing a unittest to check if certain strings in an application start with a legal prefix. For example as a test function body I now have:
strings_to_check = ['ID_PRIMARY','ID_FOREIGN','OBJ_NAME', 'SOMETHING_ELSE']
for s in strings_to_check:
assert s.startswith('ID_') or\
s.startswith('OBJ_')
But the AssertionError that is returned is quite verbose (the real code has more legal prefix option). I found this in the documentation, but that focusses on assertion between (custom) objects. Is there a way to write you own custom assertion function that returns a easier to read message?
You could do something like this:
def test_myex1(myfixture):
myfixture.append(1)
strings_to_check = ['ID_PRIMARY','ID_FOREIGN','OBJ_NAME', 'SOMETHING_ELSE']
for s in strings_to_check:
failing_string = f'variable s: {s} does not start with valid string'
assert s.startswith('ID_') or s.startswith('OBJ_'), failing_string
Which produces a traceback like:
> assert s.startswith('ID_') or s.startswith('OBJ_'), failing_string
E AssertionError: variable s: SOMETHING_ELSE does not start with valid string
raisetest.py:6: AssertionError
I am using Sinatra.
-I am receiving webhooks from a 3rd party.
-The fields sent form the webhook vary from post to post.
-I am using the syntax ["field"] rather than [:field] for the par in my model due to it being a Sinatra app.
Model
def self.fields_hash_from_data(d)
{
field1: d["payload"]["some-field"]["that-appeared-in-this-webhook"]
field2: d["payload"]["some-field"]["that-did-not-appear-in-this-webhook"]
}
end
Controller
def method
json = request.body.read
data = JSON.parse(json)
new_values = data.map do |d|
Model.fields_hash_from_data(d)
end
Model.create(new_values_for_telematics)
end
-I cannot use .try with this syntax- ["field"] because all the fields appear as nil, even when they have values.
-If i do not use .try, undefined method `[]' for nil:NilClass appears for the empty fields
Is there an alternative to .try I can use in this case?
I understand that the interface to OpenCPU is RESTful. Nevertheless, I would like to save data between function calls, if possible.
I naively created the following package:
vals <- c()
fnInit <- function() {
vals <<- c('a','b','c')
}
but I got the error: cannot change value of locked binding for 'vals' when I called the fnInit function. I understand why this is happening.
I then tried:
fnBoth <- local({
vals <- c('a','b','c')
function(which) {
if (which == 0) {
vals
} else if (which == 1) {
vals <<- c(vals,'d')
vals
}
}
})
but every time I POST to the fnBoth function with which = 1, I get the same response:
[1] "a" "b" "c" "d"
If I call the function again, I get the same answer. So, it would seem that the value vals is being reset each time.
My question is: Can data be saved between function calls? The above attempts are not meant to be exhaustive - maybe there's another technique? Or, should I simply save the value to disk?
Thanks
It is not completely clear to me what you are trying to accomplish, perhaps you can elaborate a bit on the type of application you wish to build.
OpenCPU supports chaining of function calls to calculate e.g. f(g(x), h(y)). This is done by passing the session ID of a completed call as an argument to a subsequent one. Have a look at the docs about argument formats: https://public.opencpu.org/api.html#api-arguments. It includes an example that illustrates this by calculating summary(read.csv("mydata.csv")):
#upload local file mydata.csv
curl https://public.opencpu.org/ocpu/library/utils/R/read.csv -F "file=#mydata.csv"
#replace session id with returned one above
curl https://public.opencpu.org/ocpu/tmp/x067b4172/R/.val/print
curl https://public.opencpu.org/ocpu/library/base/R/summary -d 'object=x067b4172'
The first request calls the read.csv function which returns a dataframe. In the last line, we call the summary function where we set the object argument equal to the output of the previous call (i.e. the data frame) by passing the session ID.