How to make a post request using the gogearbox framework - api

I am currently stuck because I do not know how to complete my Post request for a project I am doing. I am using a framework called gearbox (I wanted to try something new). The main problem is I don't know how to bind the json to the new variable. So can anyone help me with this issue. For the info I can post the GitHub package. It's "github.com/gogearbox/gearbox" , Please help me.
I did try to look up the documentation,and I did try a few different functions but it didn't work so if anyone can help me please.

You should provide some code even if it doesn't work. It's usually a good starting point. This way we can avoid trying things you already tested out. I've briefly read the doc and didn't test the code below but you may try to look at the ParseBody function:
type Payload struct{
FirstName string `json:"firstname"`
LastName string `json:"lastname"`
}
requestHandler := func(ctx *fasthttp.RequestCtx) {
var payload *Payload
err := ctx.ParseBody(&payload)
if err!= nil {
ctx.Status(gearbox.StatusInternalServerError).SendString("Something went wrong when parsing your payload!")
}
// do something with your payload
}
reference here

Related

Looking for a "legit" way to be able to log a Selector's function chain

I find that I often want to be able to log out what a Selector was looking for at various times during execution. I couldn't find a "legit" way to do this so I worked around it by creating the following function:
function printSelector(selector) {
console.log(selector[Object.getOwnPropertySymbols(selector)[0]].options.apiFnChain.join(""));
}
// And with this, if you have something like:
let mySelector = Selector('button').withText('foo').with({ visibilityCheck: true });
// You can run:
printSelector(mySelector);
// and get: Selector('button').withText('foo').with({ visibilityCheck: true })
My question is: is there some better way that doesn't require using the internal apiFnChain to find / log this info?
Thanks
TestCafe does not allow you to log Selectors if there were no Selector errors. However, the approach we use is similar to yours.
You can continue using your approach. However, please note that this is private API and it can be changed in the future.

Problem with Prefix in Discord.js (including .toUpperCase())

Basically, I've been developing a bot for several weeks now using the discord.js library and recently encountered a small but crucial issue. Essentially when I declare my argument, I also made it so that the message content (message.content) would be capitalized using .toUpperCase(). Essentially in doing so regardless of the type of prefix you would enter (symbol wise) it would all be read by the program as valid.
For example only: !help - should work, however if I would enter .help, it would also be read as valid.
In any case, here's the code. I appreciate all the help!
bot.on('message', message =>{
let args = message.content.toUpperCase().substring(PREFIX.length).split(" ");
const sender = message.member;
switch(args[0])
{
case 'HELP':
message.reply("I've sent you some documentation on all the commands that you can use...").then(d_msg => {d_msg.delete(3000); });
message.delete(3000);
const attachment = new Attachment('./UtilityBot_Documentation.txt')
message.author.send('[Education] Bot - Documentation');
message.author.send(attachment);
break;
}
})
The discord.js tutorial covers an extremely similar problem to what you're trying to do. I recommend you check it out. The page I linked in specific is doing a very similar thing to you, but it's worth giving the whole thing a read through if you haven't done so already. In general, I would include the following line just above where you established args.
if (!message.content.startsWith(PREFIX)) return;
What I'm doing here is saying if the message does not start with the prefix, stop running until a new message is sent. I might be missing something, but certainly check out the tutorial. It's really well written.
https://discordjs.guide/creating-your-bot/commands-with-user-input.html#basic-arguments

Update metadata of object in Google Cloud Storare with Java/Kotlin gives NullPoinerException

I have created a function to update metadata of an object in Google Cloud Storage.
fun updateUserMetadata(objectName: String, userMetadata: Map<String, String>) {
val blobId = BlobId.of(bucketName, basePath + objectName)
val blobInfo: BlobInfo = BlobInfo.newBuilder(blobId)
.setMetadata(userMetadata)
.build()
storage.update(blobInfo)
}
Somehow this function always gives me the following exception:
java.lang.NullPointerException
at com.google.cloud.storage.BlobId.fromPb(BlobId.java:119)
at com.google.cloud.storage.BlobInfo.fromPb(BlobInfo.java:1029)
at com.google.cloud.storage.Blob.fromPb(Blob.java:918)
at com.google.cloud.storage.StorageImpl.update(StorageImpl.java:428)
at com.google.cloud.storage.StorageImpl.update(StorageImpl.java:447)
at com.peerke.outdoorpuzzlegame.backend.common.gcp.cloudstorage.CloudStorageBase.updateUserMetadata(CloudStorageBase.kt:88)
at com.peerke.outdoorpuzzlegame.backend.common.gcp.cloudstorage.CloudStorageBaseTest.testUpdateUserMetadata(CloudStorageBaseTest.kt:71)
In the function above non of the variables are null.
Is this a bug or am I doing something wrong?
I've been looking into how you are passing things and I first did not see anything directly wrong. What I found though makes total sense and I hope helps you in finding a solution is this:
gsObjectName - the object name of this Blob, if it is stored on Google Cloud Storage, null otherwise.
I'm inclining towards it being a pathing issue on how you are pointing to the GCS object. It not being able to reach where you are pointing would explain why a nullpointer is raised.
I would recommend revising the way you are pointing to the path of the GCS object.
Hope this helps.
EDIT:
I've found another thing that might help you solve the issue. This is a similar way of doing what you are attempting to do and the different perspective might help you out.
Have a look here

Magento SOAP API: Error in retrieving catalogCategoryTree

Currently I'm using Magento 1.9.01 and PHP 5.3.28. In ASP .NET I'm trying to retrieve the catalog tree by using the SOAP API using the following code:
var magentoService = new MagentoService.Mage_Api_Model_Server_Wsi_HandlerPortTypeClient();
var sessionId = magentoService.login(userName, apiKey);
var categoryTree = magentoService.catalogCategoryTree(sessionId, "", "");
The errror I get is "Internal Error. Please see log for details."
And in the logs I can see the following:
Argument 1 passed to Mage_Catalog_Model_Category_Api::_nodeToArray() must be an instance of Varien_Data_Tree_Node, null given
From what I've read it can be a bug with PHP 5.4 or greater, but not the version I'm using... So if someone has any idea how to solve this, it will be greatly appreaciated.
Seems pretty straight forward, though the error thrown suggests a much bigger problem. First make sure that the variables are exactly as you specified in your Magento installation (pay attention to caps). Second you can't pass empty strings, instead try "Null".
Good luck

Backbone using GET instead of PUT or POST

I'm having some issues with a Backbone project that I am working on.
I have the following model:
class App.Models.Purchaseorder extends Backbone.Model
url: ->
base = 'api/purchaseorders'
if this.isNew()
base
else
base + '/' + this.id;
urlRoot: 'api/purchaseorders'
When I run the following in the console:
po = new App.Models.Purchaseorders;
po.set({'po_number': '1234', 'locale': 'Home', 'po_date': '3/22/2012'});
it appears to set the attributes correctly. However, if I run
po.save()
I would expect it to do a POST request to the api/purchaseorders URL. When I debug through the save() and sync() functions in the Backbone JS, it looks like it is indeed running a POST, but at the last minute, it looks as if it is really doing a GET http://i.imgur.com/dQK88.png
I am a little confused as to why this would be happening. I am having similar issues when trying to do an update -- which should be doing a PUT. I am assuming something is funky in the model, but I have no clue what it could be.
Any help would be greatly appreciated.
Thanks!
I tested the code you have in the question (had to call new App.Models.Purchaseorder, without the s, though FYI) and it does a POST as expected.
What version of Backbone and Underscore are you using?
Here's a fiddle.