Skip to content
This repository has been archived by the owner on Sep 17, 2019. It is now read-only.

Commit

Permalink
First commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
yatsu committed Jun 10, 2012
0 parents commit 3196a44
Show file tree
Hide file tree
Showing 134 changed files with 3,887 additions and 0 deletions.
20 changes: 20 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -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.
63 changes: 63 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 ).
11 changes: 11 additions & 0 deletions ios/.gitignore
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions ios/.rvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rvm 1.9.3
447 changes: 447 additions & 0 deletions ios/Bestmix.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions ios/Bestmix/AppDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end
55 changes: 55 additions & 0 deletions ios/Bestmix/AppDelegate.m
Original file line number Diff line number Diff line change
@@ -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
49 changes: 49 additions & 0 deletions ios/Bestmix/Bestmix-Info.plist
Original file line number Diff line number Diff line change
@@ -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>
14 changes: 14 additions & 0 deletions ios/Bestmix/Bestmix-Prefix.pch
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions ios/Bestmix/Config.h.example
Original file line number Diff line number Diff line change
@@ -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"
6 changes: 6 additions & 0 deletions ios/Bestmix/PrivateTasksViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#import <UIKit/UIKit.h>
#import "TasksViewController.h"

@interface PrivateTasksViewController : TasksViewController

@end
105 changes: 105 additions & 0 deletions ios/Bestmix/PrivateTasksViewController.m
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions ios/Bestmix/PublicTasksViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#import <UIKit/UIKit.h>
#import "TasksViewController.h"

@interface PublicTasksViewController : TasksViewController

@end
Loading

0 comments on commit 3196a44

Please sign in to comment.