Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 226bd99
Showing
30 changed files
with
2,877 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// Consumo_iOSAppDelegate.h | ||
// Consumo-iOS | ||
// | ||
// Created by Felipe Kellermann on 1/4/11. | ||
// Copyright 2011 Nyvra Software. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
#import "ScraperMonkey.h" | ||
|
||
@interface Consumo_iOSAppDelegate : NSObject <UIApplicationDelegate, ScraperMonkeyDelegate> | ||
{ | ||
UIWindow *window; | ||
UINavigationController *navigation; | ||
} | ||
|
||
@property (nonatomic, retain) IBOutlet UIWindow *window; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// | ||
// Consumo_iOSAppDelegate.m | ||
// Consumo-iOS | ||
// | ||
// Created by Felipe Kellermann on 1/4/11. | ||
// Copyright 2011 Nyvra Software. All rights reserved. | ||
// | ||
|
||
#import "Consumo_iOSAppDelegate.h" | ||
#import "AccountsViewController.h" | ||
#import "Accounts.h" | ||
#import "ScraperMonkey.h" | ||
|
||
@implementation Consumo_iOSAppDelegate | ||
|
||
@synthesize window; | ||
|
||
#pragma mark Application life-cycle | ||
|
||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | ||
{ | ||
[window setBackgroundColor:[UIColor blackColor]]; | ||
|
||
AccountsViewController *accountsView = [[[AccountsViewController alloc] init] autorelease]; | ||
navigation = [[UINavigationController alloc] initWithRootViewController:accountsView]; | ||
[navigation.navigationBar setTintColor:[UIColor colorWithRed:0.10 green:0.25 blue:0.70 alpha:1.0]]; | ||
[self.window addSubview:navigation.view]; | ||
|
||
[self.window makeKeyAndVisible]; | ||
|
||
return YES; | ||
} | ||
|
||
#pragma mark Memory management | ||
|
||
- (void)dealloc | ||
{ | ||
[navigation release]; | ||
[window release]; | ||
[super dealloc]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// Accounts.h | ||
// Consumo-iOS | ||
// | ||
// Created by Felipe Kellermann on 1/4/11. | ||
// Copyright 2011 Nyvra Software. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface Accounts : NSObject | ||
{ | ||
NSString *path; | ||
NSMutableArray *accounts; | ||
} | ||
|
||
+ (Accounts *)singleton; | ||
- (NSArray *)allAccounts; | ||
- (NSDictionary *)accountAtIndex:(NSInteger)index; | ||
- (NSDictionary *)accountWithUsername:(NSString *)username; | ||
- (NSDictionary *)newAccountWithLabel:(NSString *)label carrier:(NSString *)carrier username:(NSString *)username andPassword:(NSString *)password; | ||
- (void)removeAccount:(NSDictionary *)account; | ||
- (void)commit; | ||
|
||
@property (nonatomic, retain) NSString *path; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// | ||
// Accounts.m | ||
// Consumo-iOS | ||
// | ||
// Created by Felipe Kellermann on 1/4/11. | ||
// Copyright 2011 Nyvra Software. All rights reserved. | ||
// | ||
|
||
#import "Accounts.h" | ||
|
||
@implementation Accounts | ||
|
||
@synthesize path; | ||
|
||
- (id)init | ||
{ | ||
if (self = [super init]) { | ||
NSString *documents = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; | ||
path = [[documents stringByAppendingPathComponent:@"Accounts.plist"] retain]; | ||
|
||
if ([[NSFileManager defaultManager] fileExistsAtPath:path]) | ||
accounts = [[NSArray arrayWithContentsOfFile:path] mutableCopy]; | ||
else { | ||
accounts = [[NSMutableArray alloc] init]; | ||
[self commit]; | ||
} | ||
} | ||
|
||
return self; | ||
} | ||
|
||
+ (Accounts *)singleton | ||
{ | ||
static Accounts *instance = nil; | ||
|
||
@synchronized (self) { | ||
if (instance == nil) | ||
instance = [[Accounts alloc] init]; | ||
} | ||
|
||
return instance; | ||
} | ||
|
||
- (NSArray *)allAccounts | ||
{ | ||
return [[accounts copy] autorelease]; | ||
} | ||
|
||
- (NSDictionary *)accountAtIndex:(NSInteger)index | ||
{ | ||
return [[self allAccounts] objectAtIndex:index]; | ||
} | ||
|
||
- (NSDictionary *)accountWithUsername:(NSString *)username | ||
{ | ||
for (NSDictionary *account in accounts) { | ||
if ([[account objectForKey:@"Username"] isEqualToString:username]) | ||
return account; | ||
} | ||
|
||
return nil; | ||
} | ||
|
||
- (NSDictionary *)newAccountWithLabel:(NSString *)label carrier:(NSString *)carrier username:(NSString *)username andPassword:(NSString *)password | ||
{ | ||
NSMutableDictionary *account = [[NSMutableDictionary alloc] init]; | ||
[account setObject:carrier forKey:@"Carrier"]; | ||
[account setObject:username forKey:@"Username"]; | ||
[account setObject:password forKey:@"Password"]; | ||
if (label != nil) | ||
[account setObject:label forKey:@"Label"]; | ||
else | ||
[account setObject:@"" forKey:@"Label"]; | ||
|
||
|
||
[accounts addObject:account]; | ||
|
||
return account; | ||
} | ||
|
||
- (void)removeAccount:(NSDictionary *)account | ||
{ | ||
[accounts removeObject:account]; | ||
} | ||
|
||
- (void)commit | ||
{ | ||
[accounts writeToFile:path atomically:YES]; | ||
} | ||
|
||
- (void)dealloc | ||
{ | ||
[path release]; | ||
[accounts release]; | ||
[super dealloc]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// | ||
// Consumo.h | ||
// Consumo-iOS | ||
// | ||
// Created by Felipe Kellermann on 1/4/11. | ||
// Copyright 2011 Nyvra Software. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@class Consumo; | ||
|
||
@protocol ConsumoDelegate | ||
|
||
@required | ||
|
||
- (void)consumo:(Consumo *)consumo didFinishWithData:(NSDictionary *)data; | ||
|
||
@end | ||
|
||
@interface Consumo : NSObject | ||
{ | ||
NSDictionary *account; | ||
id<ConsumoDelegate> delegate; | ||
} | ||
|
||
- (id)initWithAccount:(NSDictionary *)anAccount; | ||
- (void)start; | ||
|
||
@property (nonatomic, retain) NSDictionary *account; | ||
@property (nonatomic, retain) id<ConsumoDelegate> delegate; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// | ||
// Consumo.m | ||
// Consumo-iOS | ||
// | ||
// Created by Felipe Kellermann on 1/4/11. | ||
// Copyright 2011 Nyvra Software. All rights reserved. | ||
// | ||
|
||
#import "Consumo.h" | ||
#import "JSON.h" | ||
|
||
@implementation Consumo | ||
|
||
@synthesize account; | ||
@synthesize delegate; | ||
|
||
- (id)initWithAccount:(NSDictionary *)anAccount | ||
{ | ||
if (self = [super init]) { | ||
self.account = anAccount; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
- (void)request | ||
{ | ||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | ||
NSURLResponse *response = nil; | ||
NSError *error = nil; | ||
NSDictionary *content = nil; | ||
|
||
NSString *url = [NSString stringWithFormat:@"http://nyvra.net/service/consumo/%@?username=%@&password=%@", | ||
[account objectForKey:@"Carrier"], [account objectForKey:@"Username"], [account objectForKey:@"Password"]]; | ||
|
||
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:url]]; | ||
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; | ||
[request release]; | ||
|
||
NSString *stringData = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease]; | ||
|
||
error = nil; | ||
SBJSON *parser = [[SBJSON alloc] init]; | ||
id object = [parser objectWithString:stringData error:&error]; | ||
|
||
[parser release]; | ||
|
||
if ([object isKindOfClass:[NSDictionary class]]) | ||
content = object; | ||
else { | ||
// TODO FEK: better report? | ||
} | ||
|
||
[delegate consumo:self didFinishWithData:content]; | ||
|
||
[pool release]; | ||
} | ||
|
||
- (void)start | ||
{ | ||
NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(request) object:nil]; | ||
[thread start]; | ||
[thread release]; | ||
} | ||
|
||
- (void)dealloc | ||
{ | ||
self.account = nil; | ||
self.delegate = nil; | ||
[super dealloc]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// Services.h | ||
// Consumo-iOS | ||
// | ||
// Created by Felipe Kellermann on 1/22/11. | ||
// Copyright 2011 Nyvra Software. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface Services : NSObject | ||
{ | ||
NSDictionary *services; | ||
NSMutableDictionary *serviceDefinition; | ||
} | ||
|
||
+ (Services *)singleton; | ||
- (void)definitionsLoad; | ||
- (NSDictionary *)serviceWithName:(NSString *)name; | ||
- (void)definitionsUpdate; | ||
- (NSArray *)allServices; | ||
|
||
@end |
Oops, something went wrong.