Skip to content
Permalink
Browse files

Initial checkin of a primitive command line tool that downloads the f…

…irst page of issues using Github's JSON API and prints out some info from it.
  • Loading branch information...
uliwitness committed Jul 16, 2016
1 parent 3f8de77 commit c6a6c4aa981970128ed580f0463f8dd5724248d9
@@ -0,0 +1,27 @@
*.o
*.lo
*.la
*.al
.libs
*.so
*.so.[0-9]*
*.a
*.pyc
*.pyo
*.rej
*~
#*#
.#*
.*.swp
.DS_Store
*~.nib
*.pbxuser
*.mode1
*.pbxuser
*.mode1v3
build
xcuserdata
*.xcworkspacedata
*.xcworkspace
.idea
*.xcuserdata
@@ -0,0 +1,3 @@
[submodule "json11"]
path = json11
url = https://uliwitness@github.com/uliwitness/json11.git
@@ -8,6 +8,8 @@

/* Begin PBXBuildFile section */
554408B11D2A9336001EA2BC /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 554408B01D2A9336001EA2BC /* main.cpp */; };
554408B91D2AB1E3001EA2BC /* url_request.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 554408B71D2AB1E3001EA2BC /* url_request.cpp */; };
55614A781D3A431C0026B9A8 /* json11.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 55614A761D3A431C0026B9A8 /* json11.cpp */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
@@ -25,6 +27,10 @@
/* Begin PBXFileReference section */
554408AD1D2A9336001EA2BC /* bugmatic */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = bugmatic; sourceTree = BUILT_PRODUCTS_DIR; };
554408B01D2A9336001EA2BC /* main.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = "<group>"; };
554408B71D2AB1E3001EA2BC /* url_request.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = url_request.cpp; sourceTree = "<group>"; };
554408B81D2AB1E3001EA2BC /* url_request.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = url_request.hpp; sourceTree = "<group>"; };
55614A761D3A431C0026B9A8 /* json11.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = json11.cpp; path = json11/json11.cpp; sourceTree = SOURCE_ROOT; };
55614A771D3A431C0026B9A8 /* json11.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = json11.hpp; path = json11/json11.hpp; sourceTree = SOURCE_ROOT; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
@@ -58,6 +64,10 @@
isa = PBXGroup;
children = (
554408B01D2A9336001EA2BC /* main.cpp */,
554408B81D2AB1E3001EA2BC /* url_request.hpp */,
554408B71D2AB1E3001EA2BC /* url_request.cpp */,
55614A771D3A431C0026B9A8 /* json11.hpp */,
55614A761D3A431C0026B9A8 /* json11.cpp */,
);
path = bugmatic;
sourceTree = "<group>";
@@ -118,7 +128,9 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
55614A781D3A431C0026B9A8 /* json11.cpp in Sources */,
554408B11D2A9336001EA2BC /* main.cpp in Sources */,
554408B91D2AB1E3001EA2BC /* url_request.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -209,13 +221,15 @@
554408B51D2A9336001EA2BC /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
OTHER_LDFLAGS = "-lcurl";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Debug;
};
554408B61D2A9336001EA2BC /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
OTHER_LDFLAGS = "-lcurl";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
@@ -239,6 +253,7 @@
554408B61D2A9336001EA2BC /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "554408AC1D2A9336001EA2BC"
BuildableName = "bugmatic"
BlueprintName = "bugmatic"
ReferencedContainer = "container:bugmatic.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "554408AC1D2A9336001EA2BC"
BuildableName = "bugmatic"
BlueprintName = "bugmatic"
ReferencedContainer = "container:bugmatic.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "554408AC1D2A9336001EA2BC"
BuildableName = "bugmatic"
BlueprintName = "bugmatic"
ReferencedContainer = "container:bugmatic.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "554408AC1D2A9336001EA2BC"
BuildableName = "bugmatic"
BlueprintName = "bugmatic"
ReferencedContainer = "container:bugmatic.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

This file was deleted.

@@ -4,7 +4,7 @@
<dict>
<key>SchemeUserState</key>
<dict>
<key>bugmatic.xcscheme</key>
<key>bugmatic.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
@@ -6,10 +6,108 @@
// Copyright © 2016 Uli Kusterer. All rights reserved.
//

#include <curl/curl.h>
#include <iostream>
#include <string>
#include <vector>
#include "url_request.hpp"
#include "json11.hpp"
#include <fstream>

int main(int argc, const char * argv[]) {
// insert code here...
std::cout << "Hello, World!\n";
return 0;

using Json = json11::Json;
using namespace std;


int main( int argc, const char * argv[] )
{
try
{
ofstream logfile("bugmatic.log");

string replyData;
ifstream downloadedjson;
downloadedjson.open("downloaded.json");
if( downloadedjson.is_open() )
{
cout << "Using cached data from 'downloaded.json'." << endl;
while( true )
{
int currCh = downloadedjson.get();
if( currCh == EOF )
break;
replyData.append(1, currCh);
if( downloadedjson.eof() )
break;
}
}
else
{
url_request request;
url_reply reply;

request.add_header( "User-Agent: bugmatic/0.1" );

CURLcode errcode = request.load( "https://api.github.com/repos/uliwitness/Stacksmith/issues?state=all&sort=created&direction=asc", reply );
if( errcode == CURLE_OK )
{

logfile << "status: " << reply.status() << endl;
logfile << "type: " << reply.content_type() << endl;
vector<string> headers = reply.headers();

for(vector<string>::iterator it = headers.begin();
it != headers.end(); it++)
logfile << "Header: " << (*it) << endl;

ofstream jsonfile("downloaded.json");

replyData = reply.data();

}
else
cerr << "Curl Error: " << errcode << endl;
}

//logfile << "<<" << replyData << ">>" << endl;

string errMsg;
Json replyJson = Json::parse( replyData, errMsg );
if( errMsg.length() == 0 )
{
for( const Json& currItem : replyJson.array_items() )
{
int bugNumber = currItem["number"].int_value();
logfile << "#" << bugNumber << ": " << currItem["title"].string_value();
for( const Json& currLabel : currItem["labels"].array_items() )
{
logfile << " [" << currLabel["name"].string_value() << "]";
}
logfile << endl;

logfile << "----------" << endl;
}
}
else
{
logfile << errMsg << endl;
cerr << errMsg << endl;
}

logfile << "Done." << endl;

logfile.flush();
}
catch( const std::exception& err )
{
cerr << err.what() << endl;
}
catch( ... )
{
cerr << "Unknown exception" << endl;
}

cout << "Done." << endl;

return 0;
}

0 comments on commit c6a6c4a

Please sign in to comment.
You can’t perform that action at this time.