· 5 years ago · May 07, 2020, 12:08 PM
1;{- Code Header
2; ==- Basic Info -================================
3; Name: Pastebin.pbi
4; Version: 0.0.1
5; Author: Herwin Bozet
6; Create date: 5 May 2020, 17:35:36
7; Description: ???
8;
9; ==- Compatibility -=============================
10; Compiler version: PureBasic 5.70 (x64) (Other versions untested)
11; Operating system: Windows (Other platforms untested)
12;
13; ==- Links & License -===========================
14; Github: https://github.com/aziascreations/PB-Utils
15; Doc.: https://github.com/aziascreations/PB-Utils/Documentation/Pastebin
16; License: WTFPL
17;
18;}
19
20;
21;- Compiler Options
22;{
23
24; The following line is only use to see if it works with it and for debugging
25EnableExplicit
26
27;}
28;- Constants
29;{
30
31#Pastebin_URL_Post$ = "https://pastebin.com/api/api_post.php"
32
33#Pastebin_API_Option_Post$ = "post"
34#Pastebin_API_Option_List$ = "list"
35#Pastebin_API_Option_Delete$ = "delete"
36#Pastebin_API_Option_UserDetails$ = "userdetails"
37#Pastebin_API_Option_RawPrivate$ = "show_paste"
38
39#Pastebin_Option_Expire_Never$ = "N"
40#Pastebin_Option_Expire_10Min$ = "10M"
41#Pastebin_Option_Expire_1Hour$ = "1H"
42#Pastebin_Option_Expire_1Week$ = "1W"
43#Pastebin_Option_Expire_2Weeks$ = "2W"
44#Pastebin_Option_Expire_1Month$ = "1M"
45#Pastebin_Option_Expire_6Months$ = "6M"
46#Pastebin_Option_Expire_1Year$ = "1Y"
47
48
49#Pastebin_Option_Privacy_Public = 0
50#Pastebin_Option_Privacy_Unlisted = 1
51#Pastebin_Option_Privacy_Private = 2
52
53
54#Pastebin_Option_Format_4CS$ = "4cs"
55#Pastebin_Option_Format_6502ACME$ = "6502acme"
56#Pastebin_Option_Format_6502KICKASS$ = "6502kickass"
57#Pastebin_Option_Format_6502TASM$ = "6502tasm"
58#Pastebin_Option_Format_ABAP$ = "abap"
59
60#Pastebin_Option_Format_PureBasic$ = "purebasic"
61
62#Pastebin_Option_Format_VB$ = "vb"
63#Pastebin_Option_Format_VisualBasic$ = #Pastebin_Option_Format_VB$
64#Pastebin_Option_Format_VisualFoxPro$ = "visualfoxpro"
65#Pastebin_Option_Format_WhiteSpace$ = "whitespace"
66#Pastebin_Option_Format_WHOIS$ = "whois"
67#Pastebin_Option_Format_Winbatch$ = "winbatch"
68
69;}
70;- Procedures
71;{
72
73Procedure.s PostPastebin(DevKey$ = "", UserKey$ = "", UserPassword$ ="", PasteName$ = "", PasteText$ = "",
74 ExpireTime$ = #Pastebin_Option_Expire_10Min$, PastePrivacy = #Pastebin_Option_Privacy_Unlisted,
75 PasteLanguage$ = #Pastebin_Option_Format_PureBasic$)
76 Protected HTTPRequest, PostFields$, Response$ = #Null$
77
78 If Trim(DevKey$, " ") = #Null$
79 DebuggerWarning("No dev key was given to 'PostPastebin()' !")
80 ProcedureReturn #Null$
81 EndIf
82
83 If Trim(PasteText$, " ") = #Null$
84 DebuggerWarning("No text was given to 'PostPastebin()' !")
85 ProcedureReturn #Null$
86 EndIf
87
88 PostFields$ = "api_option=paste&"
89
90 If UserKey$ <> #Null$
91 PostFields$ = PostFields$ + "api_user_key="+UserKey$+"&"
92 EndIf
93
94 PostFields$ = PostFields$ + "api_paste_private="+Str(PastePrivacy)+"&"
95 PostFields$ = PostFields$ + "api_paste_name="+URLEncoder(PasteName$)+"&"
96 PostFields$ = PostFields$ + "api_paste_expire_date="+ExpireTime$+"&"
97 PostFields$ = PostFields$ + "api_paste_format="+PasteLanguage$+"&"
98 PostFields$ = PostFields$ + "api_dev_key="+DevKey$+"&"
99 PostFields$ = PostFields$ + "api_paste_code="+URLEncoder(PasteText$)
100
101 HTTPRequest = HTTPRequest(#PB_HTTP_Post, #Pastebin_URL_Post$, PostFields$)
102 If HttpRequest
103 Response$ = HTTPInfo(HTTPRequest, #PB_HTTP_Response)
104
105 FinishHTTP(HTTPRequest)
106 EndIf
107
108 ProcedureReturn Response$
109EndProcedure
110
111
112Procedure.s PostAnonymousPastebin(DevKey$ = "", PasteName$ = "", PasteText$ = "", ExpireTime$ = #Pastebin_Option_Expire_10Min$,
113 PastePrivacy = #Pastebin_Option_Privacy_Unlisted, PasteLanguage$ = #Pastebin_Option_Format_PureBasic$)
114 ProcedureReturn PostPastebin(DevKey$, #Null$, #Null$, PasteName$, PasteText$, ExpireTime$, PastePrivacy, PasteLanguage$)
115EndProcedure
116
117;}
118;- Tests
119;{
120
121CompilerIf #PB_Compiler_IsMainFile
122 Debug "Pastebin compilerif test:"
123
124 Debug "Loading devkey..."
125 Define DevKey$
126
127 If Not ReadFile(0, "./pastebin-dev.key")
128 Debug "Key file not found -> ./pastebin-dev.key"
129 EndIf
130
131 DevKey$ = ReadString(0)
132
133 CloseFile(0)
134
135 Debug PostAnonymousPastebin(DevKey$, "API Test call 5", "Debug Str(42)", #Pastebin_Option_Expire_10Min$, #Pastebin_Option_Privacy_Public)
136
137CompilerEndIf
138
139;}