Skip to content

Commit 5403ca9

Browse files
committed
Initial commit
0 parents  commit 5403ca9

File tree

8 files changed

+263
-0
lines changed

8 files changed

+263
-0
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# APIpp
2+

api++.cbp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
2+
<CodeBlocks_project_file>
3+
<FileVersion major="1" minor="6" />
4+
<Project>
5+
<Option title="api++" />
6+
<Option pch_mode="2" />
7+
<Option compiler="tdm64-gcc_64-bit_compiler" />
8+
<Build>
9+
<Target title="Debug">
10+
<Option output="bin/Debug/api++" prefix_auto="1" extension_auto="1" />
11+
<Option object_output="obj/Debug/" />
12+
<Option type="1" />
13+
<Option compiler="tdm64-gcc_64-bit_compiler" />
14+
<Compiler>
15+
<Add option="-g" />
16+
</Compiler>
17+
</Target>
18+
<Target title="Release">
19+
<Option output="bin/Release/api++" prefix_auto="1" extension_auto="1" />
20+
<Option object_output="obj/Release/" />
21+
<Option type="1" />
22+
<Option compiler="tdm64-gcc_64-bit_compiler" />
23+
<Compiler>
24+
<Add option="-O2" />
25+
</Compiler>
26+
<Linker>
27+
<Add option="-s" />
28+
</Linker>
29+
</Target>
30+
</Build>
31+
<Compiler>
32+
<Add option="-Wall" />
33+
<Add option="-fexceptions" />
34+
</Compiler>
35+
<Unit filename="main.cpp" />
36+
<Extensions>
37+
<code_completion />
38+
<envvars />
39+
<debugger />
40+
</Extensions>
41+
</Project>
42+
</CodeBlocks_project_file>

api++.depend

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# depslib dependency file v1.0
2+
1585702678 source:c:\code\api++\main.cpp
3+
<iostream>
4+

api++.layout

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
2+
<CodeBlocks_layout_file>
3+
<FileVersion major="1" minor="0" />
4+
<ActiveTarget name="Debug" />
5+
<File name="main.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
6+
<Cursor>
7+
<Cursor1 position="4477" topLine="105" />
8+
</Cursor>
9+
</File>
10+
</CodeBlocks_layout_file>

bin/Debug/api++.exe

2.64 MB
Binary file not shown.

main.cpp

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
#include <iostream>
2+
#include <string>
3+
#include <fstream>
4+
5+
using namespace std;
6+
7+
string newApiOp;
8+
string fileType;
9+
bool javascriptFile;
10+
string repoSearchType;
11+
12+
string singleRepoOwner;
13+
string singleRepoName;
14+
string singleUrl;
15+
16+
string repoName;
17+
string repoFullName;
18+
string repoDesc;
19+
string repoHtmlUrl;
20+
21+
string fileName = "newApi++File";
22+
string filePath = "C:\\code\\api++";
23+
string fullFilePath;
24+
string fullFilePathConfirm;
25+
26+
string fileIdValue = "apiresultsapi++";
27+
28+
string fileTitleLink;
29+
string fileTitleLinkCustom = "#";
30+
string fileTitleClassName;
31+
32+
string fileFullNameClassName;
33+
34+
int main()
35+
{
36+
int apiSys();
37+
cout << "api++ starting..." << endl;
38+
cout << "Reading prefs file...(FUTURE FEATURE)" << endl;
39+
cout << "Start new api operation? [Y/N] ";
40+
cin >> newApiOp;
41+
if (newApiOp == "y" || newApiOp == "Y") {
42+
cout << "Embed the code directly into a HTML file or put it in a JavaScript file? [H (HTML)/J (JavaScript)] ";
43+
cin >> fileType;
44+
if (fileType == "h" || fileType == "H") {
45+
cout << "api++ will embed the code into a HTML file." << endl;
46+
javascriptFile = false;
47+
return apiSys();
48+
}
49+
else if (fileType == "j" || fileType == "J") {
50+
cout << "api++ will put the code into a .js file." << endl;
51+
javascriptFile = true;
52+
return apiSys();
53+
}
54+
}
55+
else {
56+
cout << "exiting..." << endl;
57+
system("pause");
58+
return 0;
59+
}
60+
return 0;
61+
}
62+
int apiSys() {
63+
int fileSys();
64+
cout << "This application currently only supports GitHub's API system." << endl;
65+
cout << "For your own reference the base URL is https://api.github.com/" << endl;
66+
cout << "Choose whether you would like to embed a single repository or a list (found using filters). [R (single repo)/L (list of repos) ";
67+
cin >> repoSearchType;
68+
if (repoSearchType == "R" || repoSearchType == "r") {
69+
cout << "Please type the owner of the repository you are trying to embed: ";
70+
cin >> singleRepoOwner;
71+
cout << "Please type the name of the repository you are trying to embed: ";
72+
cin >> singleRepoName;
73+
singleUrl = "https://api.github.com/repos/" + singleRepoOwner + "/" + singleRepoName;
74+
cout << "This is the URL api++ will be using: " << singleUrl << endl;
75+
cout << "Here is the repo HTML URL (the URL a user would go to view the repo.)" << endl;
76+
repoHtmlUrl = "https://github.com/" + singleRepoOwner + "/" + singleRepoName;
77+
cout << repoHtmlUrl << endl;
78+
79+
cout << "api++ needs to know what parts of the repo you will want to be displayed." << endl;
80+
cout << "Include title? [Y/N] ";
81+
cin >> repoName;
82+
cout << "Include the full name? [Y/N] ";
83+
cin >> repoFullName;
84+
cout << "Include the description? [Y/N] ";
85+
cin >> repoDesc;
86+
return fileSys();
87+
}
88+
}
89+
int fileSys() {
90+
ofstream file;
91+
//get file info
92+
if (javascriptFile == true) {
93+
cout << "What should the JavaScript file be named? (no spaces) ";
94+
cin >> fileName;
95+
}
96+
else if (javascriptFile == false) {
97+
cout << "What should the HTML file be named? (no spaces) ";
98+
cin >> fileName;
99+
}
100+
cout << "Where should the file be placed? (no spaces) ";
101+
cin >> filePath;
102+
if (javascriptFile == true) {
103+
fullFilePath = filePath + "\\\\" + fileName + ".js";
104+
}
105+
else if (javascriptFile == false) {
106+
fullFilePath = filePath + "\\\\" + fileName + ".html";
107+
}
108+
cout << "Is this good? [Y/N]" << endl;
109+
cout << fullFilePath << endl;
110+
cin >> fullFilePathConfirm;
111+
112+
if (fullFilePathConfirm == "Y" || fullFilePathConfirm == "y") {
113+
ofstream file((fullFilePath).c_str());
114+
if (javascriptFile == false) {
115+
file << "<!DOCTYPE html>" << endl;
116+
file << "<html>" << endl;
117+
file << "<head>" << endl;
118+
file << "<title>api++ auto generated file</title>" << endl;
119+
file << "</head>" << endl;
120+
file << "<body>" << endl;
121+
file << "<script>" << endl;
122+
}
123+
file << "//JavaScript code generated by API++" << endl;
124+
file << "//API++ by Piccolowen" << endl;
125+
file << "window.onload = apifunc();" << endl;
126+
file << "async function apifunc() {" << endl;
127+
if (repoSearchType == "R" || repoSearchType == "r") {
128+
file << "const url = '" << singleUrl << "';" << endl;
129+
}
130+
file << "const response = await fetch(url);" << endl;
131+
file << "const result = await response.json();" << endl;
132+
133+
cout << "For this code to work the code needs to place the results in a HTML element with a certain ID value. What should that value be? (no spaces) ";
134+
cin >> fileIdValue;
135+
cout << "ID value: " << fileIdValue << endl;
136+
137+
file << "const apiresult = document.getElementById('" << fileIdValue << "');" << endl;
138+
file << "console.log('api++ system working...')" << endl;
139+
file << "console.log('api++ system by Piccolowen https://github.com/Piccolowen')" << endl;
140+
file << "console.log('api++ result:');" << endl;
141+
file << "console.log(result);" << endl;
142+
143+
//repo title
144+
if (repoName == "Y" || repoName == "y") {
145+
file << "console.log('name result: ' + result.name)" << endl;
146+
cout << "Should the title element have link? [C (custom link)/R (repo link)/N (no)" << endl;
147+
cin >> fileTitleLink;
148+
if (fileTitleLink == "R" || fileTitleLink == "r") {
149+
file << "const title = document.createElement('a')" << endl;
150+
file << "title.href = result.html_url" << endl;
151+
}
152+
else if (fileTitleLink == "C" || fileTitleLink == "c") {
153+
cout << "Custom URL: ";
154+
cin >> fileTitleLinkCustom;
155+
file << "const title = document.createElement('a')" << endl;
156+
file << "title.href = '" << fileTitleLinkCustom << "'" << endl;
157+
}
158+
else {
159+
file << "const title = document.createElement('p')" << endl;
160+
}
161+
file << "title.target = '_blank'" << endl;
162+
cout << "What should the class value be for the title? (the class name allows styling with CSS) [no spaces] ";
163+
cin >> fileTitleClassName;
164+
cout << "Class name: " << fileTitleClassName << endl;
165+
file << "title.className = '" << fileTitleClassName << "'" << endl;
166+
file << "title.textContent = result.name" << endl;
167+
file << "apiresult.appendChild(title)" << endl;
168+
}
169+
//repo fullname
170+
if (repoFullName == "Y" || repoFullName == "y") {
171+
file << "console.log('full name result: ' + result.full_name)" << endl;
172+
file << "const fullname = document.createElement('p')" << endl;
173+
cout << "What should the class value be for the full name? (the class name allows styling with CSS) [no spaces] ";
174+
cin >> fileFullNameClassName;
175+
cout << "Class name: " << fileFullNameClassName << endl;
176+
file << "fullname.className = '" << fileFullNameClassName << "'" << endl;
177+
file << "fullname.textContent = result.full_name" << endl;
178+
file << "apiresult.appendChild(fullname)" << endl;
179+
}
180+
//repo desc
181+
if (repoDesc == "Y" || repoDesc == "y") {
182+
file << "console.log('desc result: ' + result.description)" << endl;
183+
file << "const desc = document.createElement('p')" << endl;
184+
cout << "What should the class value be for the description? (the class name allows styling with CSS) [no spaces] ";
185+
cin >> fileFullNameClassName;
186+
cout << "Class name: " << fileFullNameClassName << endl;
187+
file << "desc.className = '" << fileFullNameClassName << "'" << endl;
188+
file << "desc.textContent = result.description" << endl;
189+
file << "apiresult.appendChild(desc)" << endl;
190+
}
191+
file << "}" << endl;
192+
193+
if (javascriptFile == false) {
194+
file << "</script>" << endl;
195+
file << "</body>" << endl;
196+
file << "</html>" << endl;
197+
cout << "Make sure to add an element with ID value: " << fileIdValue << "!" << endl;
198+
}
199+
}
200+
else {
201+
return fileSys();
202+
}
203+
}

obj/Debug/main.o

72.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)