New Example Work

This commit is contained in:
Jeremy Ellison
2011-01-12 14:38:00 -05:00
parent 90c85e632f
commit 38d5b3cbd7
18 changed files with 150 additions and 20 deletions

1
.gitignore vendored
View File

@@ -15,3 +15,4 @@ Build
*.pbxuser
*.perspectivev3
Examples/RKDiscussionBoardExample/discussion_board_backend/public/system/attachments/*

View File

@@ -75,7 +75,7 @@
[items addObject:[TTTableImageItem itemWithText:@"Tap to Replace Image" imageURL:@"" defaultImage:_newAttachment URL:@"db://updateAttachment"]];
} else if (![[_post attachmentPath] isWhitespaceAndNewlines]) {
// Has existing attachment. allow replace
NSString* url = [NSString stringWithFormat:@"%@%@", [RKObjectManager sharedManager].client.baseURL, _post.attachmentPath];
NSString* url = _post.attachmentPath;
[items addObject:[TTTableImageItem itemWithText:@"Tap to Replace Image" imageURL:url defaultImage:nil URL:@"db://updateAttachment"]];
} else {
// has no attachment. allow new one.
@@ -83,7 +83,7 @@
}
} else {
[items addObject:[TTTableLongTextItem itemWithText:_post.body]];
NSString* url = [NSString stringWithFormat:@"%@%@", [RKObjectManager sharedManager].client.baseURL, _post.attachmentPath];
NSString* url = _post.attachmentPath;
[items addObject:[TTTableImageItem itemWithText:@"" imageURL:url URL:nil]];
}
@@ -130,6 +130,7 @@
[[RKObjectManager sharedManager] postObject:_post delegate:self];
}
- (void)updateButtonWasPressed:(id)sender {
_post.body = _bodyTextEditor.text;
_post.newAttachment = _newAttachment;

View File

@@ -71,18 +71,19 @@
for(DBPost* post in model.objects) {
NSString* url = [NSString stringWithFormat:@"db://posts/%@", post.postID];
NSString* imageURL = [NSString stringWithFormat:@"%@%@", [RKObjectManager sharedManager].client.baseURL,
post.attachmentPath];
NSString* imageURL = post.attachmentPath;
TTTableImageItem* item = [TTTableImageItem itemWithText:post.body
imageURL:imageURL
URL:url];
[postItems addObject:item];
}
self.dataSource = [TTSectionedDataSource dataSourceWithArrays:@"Topic",
TTSectionedDataSource* dataSource = [TTSectionedDataSource dataSourceWithArrays:@"Topic",
topicItems,
@"Posts",
postItems, nil];
dataSource.model = model;
self.dataSource = dataSource;
}
}

View File

@@ -59,6 +59,7 @@
}
- (void)didLoadModel:(BOOL)firstTime {
[super didLoadModel:firstTime];
if ([self.model isKindOfClass:[RKRequestTTModel class]]) {
RKRequestTTModel* model = (RKRequestTTModel*)self.model;

View File

@@ -0,0 +1,14 @@
//
// UIViewController+RKLoading.h
// DiscussionBoard
//
// Created by Jeremy Ellison on 1/12/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <RestKit/RestKit.h>
@interface UIViewController (RKLoading) <RKRequestDelegate>
@end

View File

@@ -0,0 +1,44 @@
//
// UIViewController+RKLoading.m
// DiscussionBoard
//
// Created by Jeremy Ellison on 1/12/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "UIViewController+RKLoading.h"
@implementation UIViewController (RKLoading)
- (void)requestDidStartLoad:(RKRequest*)request {
UIView* overlayView = [self.view viewWithTag:66];
UIView* progressView = [self.view viewWithTag:67];
if (overlayView == nil && progressView == nil) {
overlayView = [[UIView alloc] initWithFrame:self.view.bounds];
overlayView.backgroundColor = [UIColor blackColor];
overlayView.alpha = 0.5;
overlayView.tag = 66;
progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(10, 100, 300, 20)];
progressView.tag = 67;
[self.view addSubview:overlayView];
[self.view addSubview:progressView];
}
}
- (void)request:(RKRequest*)request didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite {
UIProgressView* progressView = (UIProgressView*)[self.view viewWithTag:67];
progressView.progress = totalBytesWritten / (float)totalBytesExpectedToWrite;
}
- (void)request:(RKRequest*)request didLoadResponse:(RKResponse*)response {
UIView* overlayView = [self.view viewWithTag:66];
UIView* progressView = [self.view viewWithTag:67];
[overlayView removeFromSuperview];
[overlayView release];
[progressView removeFromSuperview];
[progressView release];
}
@end

View File

@@ -8,8 +8,8 @@
#import "DBEnvironment.h"
NSString* const kDBBaseURLString = @"http://localhost:3000";
//NSString* const kDBBaseURLString = @"http://discussionboard.heroku.com";
//NSString* const kDBBaseURLString = @"http://localhost:3000";
NSString* const kDBBaseURLString = @"http://discussionboard.heroku.com";
NSString* const kCurrentUserIDKey = @"currentUserKey";

View File

@@ -13,14 +13,6 @@
@implementation DBManagedObjectCache
- (NSArray*)fetchRequestsForResourcePath:(NSString*)resourcePath {
// Don't return anything from the cache if we are online..
// If we return cached objects, RestKit assumes they are up to date
// and does not hit the server.
// if ([[RKObjectManager sharedManager] isOnline]) {
// return nil;
// }
if ([resourcePath isEqualToString:@"/topics"]) {
NSFetchRequest* request = [DBTopic fetchRequest];
NSSortDescriptor* sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"createdAt" ascending:YES];

View File

@@ -22,7 +22,7 @@
#import "DBUser.h"
#import "DBPostTableViewController.h"
static NSString* const kAccessTokenHeaderField = @"HTTP_USER_ACCESS_TOKEN";
static NSString* const kAccessTokenHeaderField = @"X-USER-ACCESS-TOKEN";
@implementation DiscussionBoardAppDelegate
@@ -82,6 +82,8 @@ static NSString* const kAccessTokenHeaderField = @"HTTP_USER_ACCESS_TOKEN";
[map from:@"*" toViewController:[TTWebController class]];
[[TTURLRequestQueue mainQueue] setMaxContentLength:0]; // Don't limit content length.
TTOpenURL(@"db://topics");
[[TTNavigator navigator].window makeKeyAndVisible];

View File

@@ -0,0 +1,14 @@
//
// RKRequestTTModel+Loading.h
// DiscussionBoard
//
// Created by Jeremy Ellison on 1/12/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <RestKit/Three20/Three20.h>
@interface RKRequestTTModel (Loading)
@end

View File

@@ -0,0 +1,26 @@
//
// RKRequestTTModel+Loading.m
// DiscussionBoard
//
// Created by Jeremy Ellison on 1/12/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "RKRequestTTModel+Loading.h"
@implementation RKRequestTTModel (Loading)
- (void)requestDidStartLoad:(RKRequest*)request {
NSLog(@"Request Start Load");
}
- (void)request:(RKRequest*)request didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite {
NSLog(@"Request Did Send Body Data");
}
- (void)request:(RKRequest*)request didLoadResponse:(RKResponse*)response {
NSLog(@"Request Did Load Response");
}
@end

View File

@@ -11,7 +11,7 @@
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>com.yourcompany.${PRODUCT_NAME:rfc1034identifier}</string>
<string>com.twotoasters.${PRODUCT_NAME:rfc1034identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>

View File

@@ -12,6 +12,7 @@
1D60589F0D05DD5A006BFB54 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; };
1DF5F4E00D08C38300B7A737 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */; };
288765FD0DF74451002DB57D /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 288765FC0DF74451002DB57D /* CoreGraphics.framework */; };
3F22448812DDFCB30002559D /* UIViewController+RKLoading.m in Sources */ = {isa = PBXBuildFile; fileRef = 3F22448712DDFCB30002559D /* UIViewController+RKLoading.m */; };
3F255A9712DB5F9200AFD2D1 /* DBManagedObjectCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 3F255A9612DB5F9200AFD2D1 /* DBManagedObjectCache.m */; };
3F255C9812DB70E200AFD2D1 /* DBPostsTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3F255C9312DB70E200AFD2D1 /* DBPostsTableViewController.m */; };
3F255C9912DB70E200AFD2D1 /* DBResourceListTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3F255C9512DB70E200AFD2D1 /* DBResourceListTableViewController.m */; };
@@ -35,6 +36,7 @@
3F4562D012D7E50A00BE25AD /* libThree20Style-Xcode3.2.5.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3F45625A12D7E47000BE25AD /* libThree20Style-Xcode3.2.5.a */; };
3F4562D112D7E50C00BE25AD /* libThree20UI-Xcode3.2.5.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3F45629012D7E47000BE25AD /* libThree20UI-Xcode3.2.5.a */; };
3F4562D212D7E50F00BE25AD /* libThree20UICommon-Xcode3.2.5.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3F45626C12D7E47000BE25AD /* libThree20UICommon-Xcode3.2.5.a */; };
3F49C15B12DE1D9900FDE614 /* RKRequestTTModel+Loading.m in Sources */ = {isa = PBXBuildFile; fileRef = 3F49C15A12DE1D9900FDE614 /* RKRequestTTModel+Loading.m */; };
3F76BBD612D7DA9D001562DC /* DataModel.xcdatamodel in Sources */ = {isa = PBXBuildFile; fileRef = 3F76BBD512D7DA9D001562DC /* DataModel.xcdatamodel */; };
A7A2D33A12D780DD00683D6F /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A7A2D33912D780DD00683D6F /* QuartzCore.framework */; };
A7A2D3C412D7829E00683D6F /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A7A2D3C312D7829E00683D6F /* CFNetwork.framework */; };
@@ -476,6 +478,8 @@
288765FC0DF74451002DB57D /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
32CA4F630368D1EE00C91783 /* DiscussionBoard_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DiscussionBoard_Prefix.pch; sourceTree = "<group>"; };
3F22448612DDFCB30002559D /* UIViewController+RKLoading.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIViewController+RKLoading.h"; sourceTree = "<group>"; };
3F22448712DDFCB30002559D /* UIViewController+RKLoading.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIViewController+RKLoading.m"; sourceTree = "<group>"; };
3F255A9512DB5F9200AFD2D1 /* DBManagedObjectCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DBManagedObjectCache.h; sourceTree = "<group>"; };
3F255A9612DB5F9200AFD2D1 /* DBManagedObjectCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DBManagedObjectCache.m; sourceTree = "<group>"; };
3F255C9212DB70E200AFD2D1 /* DBPostsTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DBPostsTableViewController.h; sourceTree = "<group>"; };
@@ -505,6 +509,8 @@
3F45622412D7E46F00BE25AD /* Three20UINavigator.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Three20UINavigator.xcodeproj; path = ../../../../three20/src/Three20UINavigator/Three20UINavigator.xcodeproj; sourceTree = SOURCE_ROOT; };
3F45622712D7E46F00BE25AD /* Three20UI.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Three20UI.xcodeproj; path = ../../../../three20/src/Three20UI/Three20UI.xcodeproj; sourceTree = SOURCE_ROOT; };
3F45622A12D7E46F00BE25AD /* Three20.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Three20.xcodeproj; path = ../../../../three20/src/Three20/Three20.xcodeproj; sourceTree = SOURCE_ROOT; };
3F49C15912DE1D9900FDE614 /* RKRequestTTModel+Loading.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "RKRequestTTModel+Loading.h"; sourceTree = "<group>"; };
3F49C15A12DE1D9900FDE614 /* RKRequestTTModel+Loading.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "RKRequestTTModel+Loading.m"; sourceTree = "<group>"; };
3F76BBD512D7DA9D001562DC /* DataModel.xcdatamodel */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = wrapper.xcdatamodel; path = DataModel.xcdatamodel; sourceTree = "<group>"; };
8D1107310486CEB800E47090 /* DiscussionBoard-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "DiscussionBoard-Info.plist"; plistStructureDefinitionIdentifier = "com.apple.xcode.plist.structure-definition.iphone.info-plist"; sourceTree = "<group>"; };
A7A2D33912D780DD00683D6F /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
@@ -634,6 +640,8 @@
3F3239E012DBB9C600AB2F6E /* DBPostTableViewController.m */,
3F3239EB12DBBA8D00AB2F6E /* DBAuthenticatedTableViewController.h */,
3F3239EC12DBBA8D00AB2F6E /* DBAuthenticatedTableViewController.m */,
3F22448612DDFCB30002559D /* UIViewController+RKLoading.h */,
3F22448712DDFCB30002559D /* UIViewController+RKLoading.m */,
);
path = Controllers;
sourceTree = "<group>";
@@ -647,6 +655,8 @@
3F255C9F12DB70E700AFD2D1 /* DBTopic.m */,
3F255CA612DB711900AFD2D1 /* DBUser.h */,
3F255CA712DB711900AFD2D1 /* DBUser.m */,
3F49C15912DE1D9900FDE614 /* RKRequestTTModel+Loading.h */,
3F49C15A12DE1D9900FDE614 /* RKRequestTTModel+Loading.m */,
);
path = Models;
sourceTree = "<group>";
@@ -1243,6 +1253,8 @@
3F255D1E12DB779B00AFD2D1 /* DBLoginViewController.m in Sources */,
3F3239E112DBB9C600AB2F6E /* DBPostTableViewController.m in Sources */,
3F3239ED12DBBA8D00AB2F6E /* DBAuthenticatedTableViewController.m in Sources */,
3F22448812DDFCB30002559D /* UIViewController+RKLoading.m in Sources */,
3F49C15B12DE1D9900FDE614 /* RKRequestTTModel+Loading.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1318,6 +1330,7 @@
../../../../three20/Build/Products/three20,
);
INFOPLIST_FILE = "DiscussionBoard-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 4.0;
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"\"$(SRCROOT)\"",
@@ -1340,6 +1353,7 @@
../../../../three20/Build/Products/three20,
);
INFOPLIST_FILE = "DiscussionBoard-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 4.0;
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"\"$(SRCROOT)\"",

View File

@@ -31,4 +31,5 @@ gem 'ruby-debug'
# end
gem 'authlogic', '2.1.6', :require => 'authlogic'
gem 'aws-s3'
gem 'paperclip'

View File

@@ -31,6 +31,10 @@ GEM
arel (2.0.6)
authlogic (2.1.6)
activesupport
aws-s3 (0.5.1)
builder
mime-types
xml-simple
builder (2.1.2)
columnize (0.3.2)
erubis (2.6.6)
@@ -66,6 +70,9 @@ GEM
rake (>= 0.8.7)
thor (~> 0.14.4)
rake (0.8.7)
right_aws (1.10.0)
right_http_connection (>= 1.2.4)
right_http_connection (1.2.4)
ruby-debug (0.10.4)
columnize (>= 0.1)
ruby-debug-base (~> 0.10.4.0)
@@ -76,13 +83,16 @@ GEM
treetop (1.4.9)
polyglot (>= 0.3.1)
tzinfo (0.3.23)
xml-simple (1.0.12)
PLATFORMS
ruby
DEPENDENCIES
authlogic (= 2.1.6)
aws-s3
paperclip
rails (= 3.0.3)
right_aws
ruby-debug
sqlite3-ruby

View File

@@ -4,8 +4,9 @@ class ApplicationController < ActionController::Base
protected
def require_user
# Look for the correct headers
token = request.headers["HTTP_USER_ACCESS_TOKEN"]
# Look for the correct headers.
token = request.headers["HTTP_X_USER_ACCESS_TOKEN"]
token ||= request.headers["HTTP_USER_ACCESS_TOKEN"]
@user = User.find_by_single_access_token(token)
if @user.nil?
render :json => {:error => "Invalid Access Token"}, :status => 401

View File

@@ -1,5 +1,11 @@
class Post < ActiveRecord::Base
has_attached_file :attachment, :default_url => "" # no default attachment.
@paperclip_options = Rails.env.production? ? {:storage => :s3,
:path => ":attachment/:id/:style/:basename.:extension",
:url => ":attachment/:id/:style/:basename.:extension",
:s3_credentials => "#{ Rails.root }/config/s3.yml",
:bucket => 'DiscussionBoard'} : {}
has_attached_file :attachment, { :default_url => "" }.merge(@paperclip_options)
belongs_to :user
belongs_to :topic

View File

@@ -0,0 +1,2 @@
access_key_id: AKIAICXIY3OHEMRFIY5A
secret_access_key: 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