Permalink
Browse files

added JSON-framework setting and dmg

  • Loading branch information...
1 parent d818660 commit 22c1db23ad2b56e43f53e734841a4c512c680e01 @sschroed committed Jan 19, 2009
View
@@ -0,0 +1,20 @@
+//
+// Connector.h
+// iProtect
+//
+// Created by Sam Schroeder on 9/3/08.
+// Copyright 2008 Proton Microsystems, LLC. All rights reserved.
+//
+// The sole responsibility of the Connector is to communicate with to the iProtect web service.
+// It passes on data sent to it from the application or web server. It does no direct processing
+// on the data.
+
+@interface Connector : NSObject
+
++ (NSMutableURLRequest *)jsonURLRequest:(NSString *)url;
++ (NSMutableURLRequest *)jsonURLRequest:(NSString *)url withDictionary:(NSDictionary *)dictionary;
+
++ (NSString *) getJSONFromURL:(NSString *)url; // issue a GET request
++ (NSString *) getJSONFromURL:(NSString *)url withDictionary:(NSDictionary *)dictionary; // issues a POST request
+
+@end
View
@@ -0,0 +1,85 @@
+//
+// Connector.m
+// iProtect
+//
+// Created by Sam Schroeder on 9/3/08.
+// Copyright 2008 Proton Microsystems, LLC. All rights reserved.
+//
+// The sole responsibility of the Connector is to communicate with to the iProtect web service.
+// It passes on data sent to it from the application or web server. It does no direct processing
+// on the data.
+
+#import "Connector.h"
+
+@implementation Connector
+
+#pragma mark -
+#pragma mark Class Methods
+
++ (NSMutableURLRequest *)jsonURLRequest:(NSString *)url {
+ NSMutableURLRequest *jsonRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]
+ cachePolicy:NSURLRequestUseProtocolCachePolicy
+ timeoutInterval:30.0];
+ // Set request params for sending JSON
+ [jsonRequest setHTTPMethod:@"GET"];
+ [jsonRequest setValue:@"application/json" forHTTPHeaderField:@"Accept"];
+ [jsonRequest setValue:@"application/json" forHTTPHeaderField:@"Content-type"];
+
+ return jsonRequest;
+}
+
++ (NSMutableURLRequest *)jsonURLRequest:(NSString *)url withDictionary:(NSDictionary *)dictionary {
+ NSMutableURLRequest *jsonRequest = [self jsonURLRequest:url];
+
+ // Set request params for sending JSON
+ [jsonRequest setHTTPMethod:@"POST"];
+
+ // Change dictionary into JSON data.
+ // Rails webservice expects all post JSON to be wrapped in a "data" param.
+ NSDictionary *dataDictionary = [NSDictionary dictionaryWithObjectsAndKeys: [dictionary JSONRepresentation], @"data", nil];
+ NSString *jsonString = [NSString stringWithString: [dataDictionary JSONRepresentation]];
+
+ NSData *jsonBody = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
+ [jsonRequest setHTTPBody:jsonBody];
+
+ return jsonRequest;
+}
+
+// Send a GET to the server, return JSON string.
++ (NSString *) getJSONFromURL:(NSString *)url {
+ NSMutableURLRequest *req = [self jsonURLRequest:url];
+ NSData *urlData;
+ NSURLResponse *response;
+ NSError *error = nil;
+
+ NSLog(@"Retrieving JSON from URL: %@", url);
+
+ urlData = [NSURLConnection sendSynchronousRequest:req returningResponse:&response error:&error];
+
+ NSString *str = [[[NSString alloc] initWithData:urlData encoding:NSUTF8StringEncoding] autorelease];
+
+ DevLog3(@"Retrieved JSON from URL: %@ \n%@", url, str);
+
+ return str;
+
+}
+
+// Sent a POST to the server with the attached JSON dictionary, return JSON string.
++ (NSString *) getJSONFromURL:(NSString *)url withDictionary:(NSDictionary *)dictionary {
+
+ DevLog3(@"Sending JSON to %@: %@", url, [dictionary JSONRepresentation]);
+
+ NSMutableURLRequest *req = [self jsonURLRequest:url withDictionary:dictionary];
+ NSData *urlData;
+ NSURLResponse *response;
+ NSError *error = nil;
+
+ urlData = [NSURLConnection sendSynchronousRequest:req returningResponse:&response error:&error];
+
+ NSString *resp = [[[NSString alloc] initWithData:urlData encoding:NSUTF8StringEncoding] autorelease];
+ DevLog3(@"Received JSON from URL: %@\n%@", url, resp);
+ return resp;
+
+}
+
+@end
@@ -7,7 +7,6 @@
//
#import "LoginViewController.h"
-#import "Models.h"
@implementation LoginViewController
@@ -11,7 +11,6 @@
#import "ConnectivityController.h"
#import "ApplicationErrorViewController.h"
#import "LoginViewController.h"
-#import "Models.h"
@interface git_phoneAppDelegate()
- (void) showError:(NSString *)errorMessage;
View
0 README
No changes.
View
@@ -0,0 +1,15 @@
+# GitPhone: An iPhone app to stay connected with GitHub on the go.
+
+## Required frame-works
+
+This project uses the [json-framwork](http://code.google.com/p/json-framework/) for easy json parsing.
+Installation directions are [here](http://iphone.zcentric.com/2008/08/05/install-jsonframewor/).
+
+## Author
+
+Samuel Schroeder
+
+* samuelschroeder@gmail.com
+* [http://samuelschroeder.com](http://samuelschroeder.com)
+* Managing Consultant <:> Proton Microsystems, LLC <:> iPhone/Rails Development
+* twitter - [@SamSchroeder](http://twitter.com/SamSchroeder)
@@ -20,6 +20,7 @@
22E17C1E0F22467200D2853B /* LoginViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 22E17C1D0F22467200D2853B /* LoginViewController.m */; };
22E17C3B0F22490800D2853B /* Login.xib in Resources */ = {isa = PBXBuildFile; fileRef = 22E17C3A0F22490800D2853B /* Login.xib */; };
22E17C410F224A5700D2853B /* octocat_large.png in Resources */ = {isa = PBXBuildFile; fileRef = 22E17C400F224A5700D2853B /* octocat_large.png */; };
+ 22E17D0D0F24F08C00D2853B /* Connector.m in Sources */ = {isa = PBXBuildFile; fileRef = 22E17D0C0F24F08C00D2853B /* Connector.m */; };
22FA50040F212ED300709123 /* Settings.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 22FA50030F212ED300709123 /* Settings.bundle */; };
22FA502E0F21374300709123 /* octocat.png in Resources */ = {isa = PBXBuildFile; fileRef = 22FA502D0F21374300709123 /* octocat.png */; };
22FA50CE0F21463D00709123 /* Config.m in Sources */ = {isa = PBXBuildFile; fileRef = 22FA50CD0F21463D00709123 /* Config.m */; };
@@ -48,6 +49,8 @@
22E17C1D0F22467200D2853B /* LoginViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LoginViewController.m; sourceTree = "<group>"; };
22E17C3A0F22490800D2853B /* Login.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = Login.xib; sourceTree = "<group>"; };
22E17C400F224A5700D2853B /* octocat_large.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = octocat_large.png; path = images/octocat_large.png; sourceTree = "<group>"; };
+ 22E17D0B0F24F08C00D2853B /* Connector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Connector.h; sourceTree = "<group>"; };
+ 22E17D0C0F24F08C00D2853B /* Connector.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Connector.m; sourceTree = "<group>"; };
22FA50030F212ED300709123 /* Settings.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = Settings.bundle; sourceTree = "<group>"; };
22FA502D0F21374300709123 /* octocat.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = octocat.png; path = images/octocat.png; sourceTree = "<group>"; };
22FA50CC0F21463D00709123 /* Config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Config.h; path = Classes/Config.h; sourceTree = "<group>"; };
@@ -141,6 +144,8 @@
22FA50C70F2144F800709123 /* Networking */ = {
isa = PBXGroup;
children = (
+ 22E17D0B0F24F08C00D2853B /* Connector.h */,
+ 22E17D0C0F24F08C00D2853B /* Connector.m */,
22E17B640F22334300D2853B /* Reachability.h */,
22E17B650F22334300D2853B /* Reachability.m */,
22E17B8D0F22357F00D2853B /* Controllers */,
@@ -273,6 +278,7 @@
22E17B910F22361B00D2853B /* ConnectivityController.m in Sources */,
22E17B9D0F223AA600D2853B /* ApplicationErrorViewController.m in Sources */,
22E17C1E0F22467200D2853B /* LoginViewController.m in Sources */,
+ 22E17D0D0F24F08C00D2853B /* Connector.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -308,6 +314,7 @@
C01FCF4F08A954540054247B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ ADDITIONAL_SDKS = "$HOME/Library/SDKs/JSON/$(PLATFORM_NAME).sdk";
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
GCC_C_LANGUAGE_STANDARD = c99;
@@ -318,6 +325,10 @@
"-D",
__DEBUG__,
);
+ OTHER_LDFLAGS = (
+ "-ObjC",
+ "-ljson",
+ );
PREBINDING = NO;
SDKROOT = iphonesimulator2.2;
};
View
@@ -7,6 +7,9 @@
#import <UIKit/UIKit.h>
#endif
+#import <JSON/JSON.h>
+#import "Models.h"
+
// -----------------------------------------------------------------------------
#pragma mark -
#pragma mark Development Logging
View
Binary file not shown.

0 comments on commit 22c1db2

Please sign in to comment.