I am trying to use the GitHub API with the Delphi REST components to create a file in a repo. I have successfully done this from Python and a curl call, but after much effort, I can't seem to get it to work from Delphi using the provided REST components. I have successfully done GETs using the Delphi components. The curl command that works is:
curl -X PUT \
-H "Authorization: token ghp_xxxxxxxxxxxxxxxxxxxxxxxx"
https://api.github.com/repos/<user>/TestRepo/contents/test.txt \
-d '{"message": "Add File", "content": "bXkgbmV3IGZpbGUgY29udGVudHM="}'
I've swapped out the user name and hidden the token but this call works.
The equivalent Delphi code I used was:
procedure TfrmMain.addFile;
begin
RESTClient1.BaseURL := 'https://api.github.com';
RESTRequest1.Client := RESTClient1;
RESTRequest1.Resource := '/repos/<user>/TestRepo/contents/test.txt';
RESTRequest1.Method := rmPUT;
RESTRequest1.AddParameter('Authorization', 'ghp_xxxxxxxxxxxxxxxxx', pkHTTPHEADER);
RESTRequest1.AddParameter('message', 'Add File', pkREQUESTBODY);
RESTRequest1.AddParameter('content', 'bXkgbmV3IGZpbGUgY29udGVudHM=', pkREQUESTBODY);
RESTRequest1.Execute;
Memo1.text := RESTResponse1.JSONValue.ToString;
end;
The response I get is:
{"message":"Not
Found","documentation_url":"https:\/\/docs.github.com\/rest\/reference\/repos#create-or-
update-file-contents"}
I've also tried using the Delphi REST Debugger, and I get the same error message.
I tried changing
RESTRequest1.AddParameter('Authorization', 'ghp_xxxxxxxxxxxxxxxxx', pkHTTPHEADER);
to
RESTRequest1.AddParameter('Authorization', 'token ghp_xxxxxxxxxxxxxxxxx', pkHTTPHEADER);
just in case that was the issue but no difference. Any suggestions?
The use of AddParameter for the body is wrong. The resulting content will not automatically be JSON. Try it this way:
RESTClient1.BaseURL := 'https://api.github.com';
RESTRequest1.Client := RESTClient1;
RESTRequest1.Resource := 'repos/<user>/TestRepo/contents/test.txt';
RESTRequest1.Method := rmPUT;
RESTRequest1.AddAuthParameter('Authorization', 'token ghp_xxxxxxxxxxxxxxxxx', pkHTTPHEADER, [poDoNotEncode]);
RESTRequest1.AddBody(TJSONObject.Create.AddPair('message', 'Add File').AddPair('content', 'bXkgbmV3IGZpbGUgY29udGVudHM='), ooREST);
RESTRequest1.Execute;
Related
I was following this guide to learn HAL layer and framework layer in AOSP. I've managed to run the whole process. But there's one small issue. When I build the whole ROM/Android, hello.default.so won't be built/shown up in the following,
${output}/system/lib/hw
${output}/system/lib64/hw
${output}/vendor/lib/hw
${output}/vendor/lib64/hw
Only by manually executing mmm hardware/libhardware/modules/hello/, can I get the hello.default.so.
I have remember to append the module into PRODUCT_PACKAGES macro as following. Packages/Modules vim, hello-lkm-client have been successfully integrated. But not the hello.default module.
PRODUCT_PACKAGES += \
vim
PRODUCT_PACKAGES += \
hello-lkm-client
PRODUCT_PACKAGES += \
hello.default
Here's the Android.mk file for the hello HAL
include $(CLEAR_VARS)
LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_PROPRIETARY_MODULE := true
LOCAL_SHARED_LIBRARIES := liblog
#############
# I'm following $hw/modules/gralloc/Android.mk
#############
LOCAL_MODULE_TAGS := optional
LOCAL_PRELINK_MODULE := false
# LOCAL_C_INCLUDES := hardware/libhardware
LOCAL_SRC_FILES := hello.c
LOCAL_HEADER_LIBRARIES := libhardware_headers
LOCAL_MODULE := hello.default
# LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog
include $(BUILD_SHARED_LIBRARY)
Here's the complete hello HAL module.
OK, found it. I have to add the hello module in Android.mk of Module modules, just like the following.
chang#ryzen:~/bulk2/rockpi4-atv9-chang/hardware/libhardware$ git diff
diff --git a/modules/Android.mk b/modules/Android.mk
index a430a650..7bbeaeb9 100644
--- a/modules/Android.mk
+++ b/modules/Android.mk
## -2,5 +2,6 ## hardware_modules := \
camera \
gralloc \
sensors \
- hw_output
+ hw_output \
+ hello
I'm using windows 10 task view and need to open different instances of excel word and acrobat.
I can't seem to get acrobat working. I get error: 0x800401F3 - Invalid class string on the AcroApp := ComObjCreate("AcroExch.App") line.
Any suggestions?
^+n::
oWord := ComObjCreate("Word.Application")
oWord.Documents.Add
oWord.Visible := 1
oWord.Activate
xlApp := ComObjCreate("Excel.Application")
xlApp.Visible := true
xlApp.Workbooks.Add()
xlApp := ""
run notepad
run chrome
AcroApp := ComObjCreate("AcroExch.App"); Error when running
AcroApp.Visible := true
AcroApp.Open
return
While the COM approach seems cool, it seems really unnecessary.
I don't have Acrobat, but a quick Google search tells me they have a command line option to open a new instance, as I suspected (documented here).
So, a quick little run command should do the trick:
Run, % """C:\Path\To\Acrobat.exe"" /n"
Also, maybe this is why your COM approach didn't work?
I am trying to upload a file to a rest server from jenkins using http plugin. I have a jenkins pipelie where a step involves loading a file(type formData)
to a server using rest.
the server side method uses two parameters:
(#FormDataParam("file") InputStream file, #FormDataParam("fileName") String fileName)
I am using the below method
def filename = "${WORKSPACE}/Test.txt"
data="""{ \"fileName\" : \"Test.txt\" }"""
resp3 = httpRequest consoleLogResponseBody: true,url: "http://<url>",contentType:'APPLICATION_OCTETSTREAM',customHeaders:[[name:'Authorization', value:"Basic ${auth}"]],httpMode: 'POST',multipartName: 'Test.txt',uploadFile: "${filename}",requestBody:data,validResponseCodes: '200'
but when I run the status code is 400 and in the server logs the message is that no filestream and no filename is received i.e not able to get both the arguments.
Please let me know where it is getting wrong
Regards
You can try using curl instead of built-in Jenkins methods:
curl -XPOST http://<url> -H 'Content-Type: application/octet-stream' -H 'Authorization: Basic ${auth}' --data-binary '{\"fileName\" : \"Test.txt\" }'
You can debug it first from within shell. Once it's working, wrap it in sh directive:
sh "curl ..."
Since I was running on windows so bat + curl worked for me .With this workaround I was able to transfer files using jenkins and rest
However using httpRequest from jenkins inbuild library is still not working.
I'm launching build jobs on a local Jenkins with:
curl -X POST "http://UID:TOKEN#server:port/job/DevGate/build?delay=0sec&json=%7B%22parameter%22%3A+%7B%22name%22%3A+%22DEVGATE_PACKAGELIST%22%2C+%22value%22%3A+%2212345678%3A9%22%7D%2C+%22statusCode%22%3A+%22303%22%2C+%22redirectTo%22%3A+%22.%22%7D&Submit=Build"
which translates into
curl -X POST "http://UID:TOKEN#server:port/job/DevGate/build?delay=0sec&json={"parameter": {"name": "DEVGATE_PACKAGELIST", "value": "12345678:9"}, "statusCode": "303", "redirectTo": "."}&Submit=Build"
UID being userID. TOKEN being API Token given by Jenkins/REST API. And it works. Now, this command is launched inside of a VBScript that mainly gathers data for creation of aforementioned URL. No password needed, and I'd like to keep it that way. The problem: I'd like to avoid using curl and use just native VBScript functionality.
What I've tried so far:
Dim http: Set http = CreateObject("Microsoft.XMLHTTP")
Dim url: url = "http://server:port/job/DevGate/build"
Dim data: data = "delay=0sec&json=%7B%22parameter%22:+%7B%22name%22:+%22DEVGATE_PACKAGELIST%22,+%22value%22:+%22" + the rest of data
'string2try = Base64EncodeString("UID:TOKEN")
'string2try = Base64EncodeString("UID:PASSWORD")
With http
.Open "POST", url, False
Call .SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
Call .SetRequestHeader("oAuth", token)
.Send data
'Call .SetRequestHeader("X-Api-Key", token)
'Call .SetRequestHeader("Authorization", "Bearer " & token)
'Call .SetRequestHeader("X-Auth-Token", token or string2try)
'Call .SetRequestHeader("X-Parse-REST-API-Key", token)
End With
Every permutation of that code fails authentication. How to pass my token + uid properly in VBScript without using curl?
I'm trying to print an local image from my Go program using the Exec Package on Windows 7.
The following command line works fine when ran manually:
rundll32.exe shimgvw.dll ImageView_PrintTo /pt C:\Users\XXXXX\IMAGE.jpg "PRINTERNAME"
I tried:
res, err := exec.Command(
"cmd",
"/c",
"rundll32.exe",
"shimgvw.dll",
"ImageView_PrintTo",
"/pt",
"C:\\Users\\XXXXX\\IMAGE.jpg",
"\"PRINTERNAME\"",
).Output();
or
res, err := exec.Command(
"cmd",
"/c",
"rundll32.exe shimgvw.dll ImageView_PrintTo /pt C:\\Users\\XXXXX\\IMAGE.jpg \"PRINTERNAME\"",
).Output();
But in both cases, it just sends back an empty string as a result and no error.
And no effect on the printer tasks list.
I'm sure I'm missing something obvious (something to do with the system environnement when executing the script?). Ideas are welcome!
Thanks.