Permalink
Browse files

First commit.

  • Loading branch information...
0 parents commit 3196a44708a895ba6407652e96242a1d5cef59ac @yatsu committed Jun 10, 2012
Showing with 3,887 additions and 0 deletions.
  1. +20 −0 LICENSE.txt
  2. +63 −0 README.md
  3. +11 −0 ios/.gitignore
  4. +1 −0 ios/.rvmrc
  5. +447 −0 ios/Bestmix.xcodeproj/project.pbxproj
  6. +7 −0 ios/Bestmix.xcodeproj/project.xcworkspace/contents.xcworkspacedata
  7. +7 −0 ios/Bestmix/AppDelegate.h
  8. +55 −0 ios/Bestmix/AppDelegate.m
  9. +49 −0 ios/Bestmix/Bestmix-Info.plist
  10. +14 −0 ios/Bestmix/Bestmix-Prefix.pch
  11. +6 −0 ios/Bestmix/Config.h.example
  12. +6 −0 ios/Bestmix/PrivateTasksViewController.h
  13. +105 −0 ios/Bestmix/PrivateTasksViewController.m
  14. +6 −0 ios/Bestmix/PublicTasksViewController.h
  15. +82 −0 ios/Bestmix/PublicTasksViewController.m
  16. +7 −0 ios/Bestmix/TasksApiClient.h
  17. +27 −0 ios/Bestmix/TasksApiClient.m
  18. +26 −0 ios/Bestmix/TasksViewController.h
  19. +176 −0 ios/Bestmix/TasksViewController.m
  20. +2 −0 ios/Bestmix/en.lproj/InfoPlist.strings
  21. +134 −0 ios/Bestmix/en.lproj/MainStoryboard_iPad.storyboard
  22. +147 −0 ios/Bestmix/en.lproj/MainStoryboard_iPhone.storyboard
  23. BIN ios/Bestmix/first.png
  24. BIN ios/Bestmix/first@2x.png
  25. +10 −0 ios/Bestmix/main.m
  26. BIN ios/Bestmix/second.png
  27. BIN ios/Bestmix/second@2x.png
  28. +5 −0 ios/Categories/NSDictionary+ObjectForKeyOrNil.h
  29. +14 −0 ios/Categories/NSDictionary+ObjectForKeyOrNil.m
  30. +5 −0 ios/Categories/UIColor+Hex.h
  31. +13 −0 ios/Categories/UIColor+Hex.m
  32. +8 −0 ios/DataModel/Bestmix.xcdatamodeld/.xccurrentversion
  33. +13 −0 ios/DataModel/Bestmix.xcdatamodeld/Bestmix.xcdatamodel/contents
  34. +16 −0 ios/DataModel/BestmixDataModel.h
  35. +104 −0 ios/DataModel/BestmixDataModel.m
  36. +7 −0 ios/DataModel/Task.h
  37. +29 −0 ios/DataModel/Task.m
  38. +135 −0 ios/DataModel/_Task.h
  39. +139 −0 ios/DataModel/_Task.m
  40. +12 −0 ios/Podfile
  41. +23 −0 ios/Podfile.lock
  42. +21 −0 server/.gitignore
  43. +1 −0 server/.rvmrc
  44. +57 −0 server/Gemfile
  45. +206 −0 server/Gemfile.lock
  46. +7 −0 server/Rakefile
  47. +3 −0 server/app/admin/access_grants.rb
  48. +3 −0 server/app/admin/access_tokens.rb
  49. +44 −0 server/app/admin/dashboards.rb
  50. +3 −0 server/app/admin/tasks.rb
  51. +3 −0 server/app/admin/users.rb
  52. BIN server/app/assets/images/rails.png
  53. +1 −0 server/app/assets/javascripts/active_admin.js
  54. +3 −0 server/app/assets/javascripts/api/tasks.js.coffee
  55. +14 −0 server/app/assets/javascripts/application.js
  56. +3 −0 server/app/assets/javascripts/main.js.coffee
  57. +3 −0 server/app/assets/javascripts/tasks.js.coffee
  58. +6 −0 server/app/assets/stylesheets/active_admin.css.scss
  59. +3 −0 server/app/assets/stylesheets/api/tasks.css.scss
  60. +14 −0 server/app/assets/stylesheets/application.css.scss
  61. +3 −0 server/app/assets/stylesheets/main.css.scss
  62. +56 −0 server/app/assets/stylesheets/scaffolds.css.scss
  63. +15 −0 server/app/assets/stylesheets/tasks.css.scss
  64. +11 −0 server/app/controllers/api/api_controller.rb
  65. +18 −0 server/app/controllers/api/v1/tasks_controller.rb
  66. +3 −0 server/app/controllers/application_controller.rb
  67. +10 −0 server/app/controllers/main_controller.rb
  68. +13 −0 server/app/controllers/tasks_controller.rb
  69. +2 −0 server/app/helpers/api/tasks_helper.rb
  70. +2 −0 server/app/helpers/application_helper.rb
  71. +2 −0 server/app/helpers/main_helper.rb
  72. +2 −0 server/app/helpers/tasks_helper.rb
  73. 0 server/app/mailers/.gitkeep
  74. 0 server/app/models/.gitkeep
  75. +10 −0 server/app/models/admin_user.rb
  76. +13 −0 server/app/models/task.rb
  77. +15 −0 server/app/models/user.rb
  78. +9 −0 server/app/views/api/v1/tasks/my.json.rabl
  79. +9 −0 server/app/views/api/v1/tasks/public.json.rabl
  80. +10 −0 server/app/views/api/v1/tasks/show.json.rabl
  81. +3 −0 server/app/views/api/v1/users/show.json.rabl
  82. +21 −0 server/app/views/layouts/application.html.haml
  83. +19 −0 server/app/views/main/index.html.haml
  84. +22 −0 server/app/views/tasks/_form.html.haml
  85. +4 −0 server/app/views/tasks/_task.html.haml
  86. +7 −0 server/app/views/tasks/edit.html.haml
  87. +21 −0 server/app/views/tasks/index.html.haml
  88. +5 −0 server/app/views/tasks/new.html.haml
  89. +13 −0 server/app/views/tasks/show.html.haml
  90. +33 −0 server/client/client.thor
  91. +4 −0 server/config.ru
  92. +65 −0 server/config/application.rb
  93. +6 −0 server/config/boot.rb
  94. +42 −0 server/config/database.yml.example
  95. +5 −0 server/config/environment.rb
  96. +37 −0 server/config/environments/development.rb
  97. +67 −0 server/config/environments/production.rb
  98. +37 −0 server/config/environments/test.rb
  99. +129 −0 server/config/initializers/active_admin.rb
  100. +7 −0 server/config/initializers/backtrace_silencers.rb
  101. +223 −0 server/config/initializers/devise.rb.example
  102. +42 −0 server/config/initializers/doorkeeper.rb
  103. +5 −0 server/config/initializers/fablication.rb
  104. +15 −0 server/config/initializers/inflections.rb
  105. +5 −0 server/config/initializers/mime_types.rb
  106. +19 −0 server/config/initializers/rabl_init.rb
  107. +7 −0 server/config/initializers/secret_token.rb
  108. +8 −0 server/config/initializers/session_store.rb
  109. +14 −0 server/config/initializers/wrap_parameters.rb
  110. +57 −0 server/config/locales/devise.en.yml
  111. +23 −0 server/config/locales/doorkeeper.en.yml
  112. +5 −0 server/config/locales/en.yml
  113. +80 −0 server/config/routes.rb
  114. +7 −0 server/data/fabricators/task_fabricator.rb
  115. +9 −0 server/db/migrate/20120525135258_create_tasks.rb
  116. +42 −0 server/db/migrate/20120526055304_create_doorkeeper_tables.rb
  117. +52 −0 server/db/migrate/20120526061155_devise_create_admin_users.rb
  118. +17 −0 server/db/migrate/20120526151202_create_admin_notes.rb
  119. +25 −0 server/db/migrate/20120526151203_move_admin_notes_to_comments.rb
  120. +49 −0 server/db/migrate/20120526151204_devise_create_users.rb
  121. +9 −0 server/db/migrate/20120527051437_add_user_id_to_tasks.rb
  122. +7 −0 server/db/seeds.rb
  123. 0 server/lib/assets/.gitkeep
  124. 0 server/lib/tasks/.gitkeep
  125. +26 −0 server/public/404.html
  126. +26 −0 server/public/422.html
  127. +25 −0 server/public/500.html
  128. 0 server/public/favicon.ico
  129. +5 −0 server/public/robots.txt
  130. +3 −0 server/script/generate_tasks.rb
  131. +6 −0 server/script/rails
  132. 0 server/vendor/assets/javascripts/.gitkeep
  133. 0 server/vendor/assets/stylesheets/.gitkeep
  134. 0 server/vendor/plugins/.gitkeep
@@ -0,0 +1,20 @@
+Copyright (c) 2012 Masaki Yatsu
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,63 @@
+Bestmix
+=======
+
+__NOTE: Bestmix is under development. It works currently without authentication and caching.__
+
+Bestmix is a set of boilerplate to build both Rails-based web app and iOS app integrated with each other.
+They are connected with JSON REST API supporting authentication, pagination and caching.
+You can build your own server-side and client-side quickly by extending it.
+
+Libraries
+---------
+
+Bestmix uses following libraries and frameworks.
+
+### Server-side
+
+* [Ruby on Rails](http://rubyonrails.org/ ) - Web Framework
+* [Devise](https://github.com/plataformatec/devise ) - Authentication
+* [RABL](https://github.com/nesquena/rabl ) - JSON Generation
+* [Doorkeeper](https://github.com/applicake/doorkeeper ) - OAuth2 Provider
+* [versionist](https://github.com/bploetz/versionist ) - API Versioning
+* [Kaminari](https://github.com/amatsuda/kaminari ) - Pagination
+* [Active Admin](http://activeadmin.info/) - Admin Interface
+
+See [Gemfile](http://github.com/yatsu/bestmix/blob/master/server/Gemfile ) for more details
+
+### iOS App
+
+* [CocoaPods](http://cocoapods.org/ ) - Library Management
+* [AFNetworking](https://github.com/AFNetworking/AFNetworking ) - Networking Framework
+* [JSONKit](https://github.com/johnezang/JSONKit ) - JSON Parser
+* [MBProgressHUD](https://github.com/jdg/MBProgressHUD ) - Progress HUD
+* [SVPullToRefresh](https://github.com/samvermette/SVPullToRefresh ) - Pull-to-Refresh
+* [Reachability](https://github.com/tonymillion/Reachability ) - Network Reachability
+
+See [Podfile](http://github.com/yatsu/bestmix/blob/master/ios/Podfile ) for more details.
+
+Setup
+-----
+
+### Server-side
+
+1. Install [Ruby on Rails](http://rubyonrails.org/ ) and [RVM](https://rvm.io/ ) if you don't have them.
+2. Copy server/config/database.yml.example to server/config/database.yml and modify it.
+3. Copy server/config/initializers/devise.rb.example to server/config/initializers/devise.rb and modify it (See [Devise](https://github.com/plataformatec/devise ) for details).
+4. cd server; rails db:setup
+5. rails s (or you can setup your web server like Apache, nginx, etc.)
+
+### iOS App
+
+1. Install [CocoaPods](http://cocoapods.org/ ) if you don't have it.
+2. Copy ios/Bestmix/Config.h.example to ios/Bestmix/Config.h and modify it.
+3. cd ios; pod install Bestmix.xcodeproj
+4. Open Bestmix.xcworkspace and build the app
+
+License
+-------
+
+Bestmix itself is provided under
+[MIT License](http://github.com/yatsu/bestmix/blob/master/LICENSE.txt )
+and it uses many other libraries.
+See [Gemfile](http://github.com/yatsu/bestmix/blob/master/server/Gemfile ) and
+[Podfile](http://github.com/yatsu/bestmix/blob/master/ios/Podfile ).
@@ -0,0 +1,11 @@
+*.xcodeproj/project.xcworkspace/xcuserdata/*.xcuserdatad
+*.xcodeproj/xcuserdata/*.xcuserdatad/
+*.xcodeproj/*.pbxuser
+*.xcodeproj/*.mode*
+build/Debug-*
+build/Release-*
+build/*.build
+DerivedData
+Bestmix.xcworkspace
+Pods
+/Bestmix/Config.h
@@ -0,0 +1 @@
+rvm 1.9.3
Oops, something went wrong.
Oops, something went wrong.
@@ -0,0 +1,7 @@
+#import <UIKit/UIKit.h>
+
+@interface AppDelegate : UIResponder <UIApplicationDelegate>
+
+@property (strong, nonatomic) UIWindow *window;
+
+@end
@@ -0,0 +1,55 @@
+#import <CoreData/CoreData.h>
+#import "AppDelegate.h"
+#import "Config.h"
+#import "BestmixDataModel.h"
+#import "Task.h"
+
+@implementation AppDelegate
+
+@synthesize window = _window;
+
+- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
+{
+ /*
+ NSManagedObjectContext *context = [[BestmixDataModel sharedDataModel] mainContext];
+ if (context) {
+ NSLog(@"context: %@", context);
+ Task *task = [Task insertInManagedObjectContext:context];
+ task.name = @"test a";
+ NSLog(@"task: %@", task);
+ [context save:nil];
+ }
+ */
+ [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent];
+
+ return YES;
+}
+
+- (void)applicationWillResignActive:(UIApplication *)application
+{
+ // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
+ // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
+}
+
+- (void)applicationDidEnterBackground:(UIApplication *)application
+{
+ // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
+ // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
+}
+
+- (void)applicationWillEnterForeground:(UIApplication *)application
+{
+ // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
+}
+
+- (void)applicationDidBecomeActive:(UIApplication *)application
+{
+ // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
+}
+
+- (void)applicationWillTerminate:(UIApplication *)application
+{
+ // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
+}
+
+@end
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>en</string>
+ <key>CFBundleDisplayName</key>
+ <string>${PRODUCT_NAME}</string>
+ <key>CFBundleExecutable</key>
+ <string>${EXECUTABLE_NAME}</string>
+ <key>CFBundleIdentifier</key>
+ <string>com.valleyport.${PRODUCT_NAME:rfc1034identifier}</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>${PRODUCT_NAME}</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleShortVersionString</key>
+ <string>1.0</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>1.0</string>
+ <key>LSRequiresIPhoneOS</key>
+ <true/>
+ <key>UIMainStoryboardFile</key>
+ <string>MainStoryboard_iPhone</string>
+ <key>UIMainStoryboardFile~ipad</key>
+ <string>MainStoryboard_iPad</string>
+ <key>UIRequiredDeviceCapabilities</key>
+ <array>
+ <string>armv7</string>
+ </array>
+ <key>UISupportedInterfaceOrientations</key>
+ <array>
+ <string>UIInterfaceOrientationPortrait</string>
+ <string>UIInterfaceOrientationLandscapeLeft</string>
+ <string>UIInterfaceOrientationLandscapeRight</string>
+ </array>
+ <key>UISupportedInterfaceOrientations~ipad</key>
+ <array>
+ <string>UIInterfaceOrientationPortrait</string>
+ <string>UIInterfaceOrientationPortraitUpsideDown</string>
+ <string>UIInterfaceOrientationLandscapeLeft</string>
+ <string>UIInterfaceOrientationLandscapeRight</string>
+ </array>
+</dict>
+</plist>
@@ -0,0 +1,14 @@
+//
+// Prefix header for all source files of the 'Bestmix' target in the 'Bestmix' project
+//
+
+#import <Availability.h>
+
+#ifndef __IPHONE_5_0
+#warning "This project uses features only available in iOS SDK 5.0 and later."
+#endif
+
+#ifdef __OBJC__
+ #import <UIKit/UIKit.h>
+ #import <Foundation/Foundation.h>
+#endif
@@ -0,0 +1,6 @@
+#define WebApiUrl @"http://localhost:3000/api/v1/"
+
+#define AuthBaseURL @"http://localhost:3000/"
+#define ClientID @"---client id---""
+#define ClientSecret @"---client secret---""
+#define RedirectURL @"bestmix://auth"
@@ -0,0 +1,6 @@
+#import <UIKit/UIKit.h>
+#import "TasksViewController.h"
+
+@interface PrivateTasksViewController : TasksViewController
+
+@end
@@ -0,0 +1,105 @@
+#import <CoreData/CoreData.h>
+#import "PrivateTasksViewController.h"
+#import "Config.h"
+#import "Task.h"
+#import "UIColor+Hex.h"
+#import "MBProgressHUD.h"
+#import "TasksApiClient.h"
+#import "SVPullToRefresh.h"
+#import "AFOAuth2Client.h"
+
+@interface PrivateTasksViewController ()
+{
+ BOOL _loggedIn;
+}
+
+- (void)fetchTasks;
+- (void)login;
+
+@end
+
+@implementation PrivateTasksViewController
+
+#pragma mark TaskViewController
+
+- (void)fetch
+{
+ if (!_loggedIn) {
+ [self login];
+ } else {
+ [self fetchTasks];
+ }
+}
+
+- (void)becomeReachable
+{
+ NSLog(@"reachable");
+ [self fetch];
+}
+
+- (void)becomeUnreachable
+{
+ NSLog(@"unreachable");
+}
+
+#pragma mark Local Methods
+
+- (void)fetchTasks
+{
+ if (!_reachable) {
+ NSLog(@"unable to fetch");
+ return;
+ }
+
+ if (_tasks.count == 0) {
+ MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
+ hud.labelText = @"Loading...";
+ }
+
+ TasksApiClient *client = [TasksApiClient sharedClient];
+
+ NSMutableDictionary *params = [NSMutableDictionary dictionary];
+ [params setObject:[NSNumber numberWithInteger:_currentPage] forKey:@"page"];
+
+ [client getPath:@"tasks/public"
+ parameters:params
+ success:^(AFHTTPRequestOperation *operation, id response) {
+ NSLog(@"response: %@", response);
+ id elem = [response objectForKey:@"num_pages"];
+ if (elem && [elem isKindOfClass:[NSNumber class]])
+ _totalPages = [elem integerValue];
+ elem = [response objectForKey:@"total_count"];
+ if (elem && [elem isKindOfClass:[NSNumber class]])
+ _totalCount = [elem integerValue];
+ NSLog(@"currentPage: %d totalPages: %d totalCount: %d", _currentPage, _totalPages, _totalCount);
+
+ elem = [response objectForKey:@"tasks"];
+ if (elem && [elem isKindOfClass:[NSArray class]]) {
+ for (id dict in elem) {
+ if (dict && [dict isKindOfClass:[NSDictionary class]]) {
+ Task *task = [Task taskWithDictionary:dict];
+ // NSLog(@"task: %@", task);
+ [_tasks addObject:task];
+ }
+ }
+ }
+
+ [self.tableView reloadData];
+
+ [MBProgressHUD hideHUDForView:self.view animated:YES];
+
+ [self.tableView.pullToRefreshView stopAnimating];
+ }
+ failure:^(AFHTTPRequestOperation *operation, NSError *error) {
+ NSLog(@"error %@", error);
+
+ [MBProgressHUD hideHUDForView:self.view animated:YES];
+ }];
+}
+
+- (void)login
+{
+ [self getAccessToken];
+}
+
+@end
@@ -0,0 +1,6 @@
+#import <UIKit/UIKit.h>
+#import "TasksViewController.h"
+
+@interface PublicTasksViewController : TasksViewController
+
+@end
Oops, something went wrong.

0 comments on commit 3196a44

Please sign in to comment.