/Mobile/iPhone/StoffiRemote/StoffiRemote/OAuthTestViewController.m

http://yet-another-music-application.googlecode.com/ · Objective C · 112 lines · 64 code · 21 blank · 27 comment · 5 complexity · 2dd3299df5b4326857096f51afa9b762 MD5 · raw file

  1. //
  2. // OAuthTestViewController.m
  3. // StoffiRemote
  4. //
  5. // Created by Fredrik Gadnell on 9/19/11.
  6. // Copyright 2011 __MyCompanyName__. All rights reserved.
  7. //
  8. #import "OAuthTestViewController.h"
  9. @implementation OAuthTestViewController
  10. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  11. {
  12. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  13. if (self) {
  14. self.view.backgroundColor = [UIColor darkGrayColor];
  15. UIButton *loginButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  16. loginButton.frame = CGRectMake(100, 100, 80, 40);
  17. [loginButton setTitle:@"Login" forState:UIControlStateNormal];
  18. [loginButton addTarget:self action:@selector(loginButtonPressed) forControlEvents:UIControlEventTouchUpInside];
  19. UIButton *requestButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  20. requestButton.frame = CGRectMake(100, 160, 80, 40);
  21. [requestButton setTitle:@"Request" forState:UIControlStateNormal];
  22. [requestButton addTarget:self action:@selector(requestButtonPressed) forControlEvents:UIControlEventTouchUpInside];
  23. [self.view addSubview:loginButton];
  24. [self.view addSubview:requestButton];
  25. }
  26. return self;
  27. }
  28. - (void)loginButtonPressed {
  29. [[StoffiOAuthManager sharedManager] signInToStoffiWithDelegate:self];
  30. }
  31. - (void)requestButtonPressed {
  32. RESTRequest *request = [[RESTClient sharedClient] get:@"/share" delegate:self];
  33. request.shouldLog = YES;
  34. }
  35. - (void)restRequestDidFail {
  36. NSLog(@"OAuthTestVC: Did receive callback from RestRequest: Request failed");
  37. }
  38. - (void)restRequestDidLoadResult:(id)jsonObject {
  39. NSLog(@"OAuthTestVC: Did receive callbak from RestRequest: %@", jsonObject);
  40. }
  41. - (void)viewController:(GTMOAuthViewControllerTouch *)viewController
  42. finishedWithAuth:(GTMOAuthAuthentication *)auth
  43. error:(NSError *)error
  44. {
  45. if (error != nil) {
  46. // Authentication failed
  47. NSLog(@"Auth failed");
  48. } else {
  49. // Authentication succeeded
  50. NSLog(@"Auth succeeded");
  51. }
  52. }
  53. - (void)didLogin {
  54. NSLog(@"OAuthTestViewController did login!");
  55. }
  56. - (void)dealloc
  57. {
  58. [super dealloc];
  59. }
  60. - (void)didReceiveMemoryWarning
  61. {
  62. // Releases the view if it doesn't have a superview.
  63. [super didReceiveMemoryWarning];
  64. // Release any cached data, images, etc that aren't in use.
  65. }
  66. #pragma mark - View lifecycle
  67. /*
  68. // Implement loadView to create a view hierarchy programmatically, without using a nib.
  69. - (void)loadView
  70. {
  71. }
  72. */
  73. /*
  74. // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
  75. - (void)viewDidLoad
  76. {
  77. [super viewDidLoad];
  78. }
  79. */
  80. - (void)viewDidUnload
  81. {
  82. [super viewDidUnload];
  83. // Release any retained subviews of the main view.
  84. // e.g. self.myOutlet = nil;
  85. }
  86. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  87. {
  88. // Return YES for supported orientations
  89. return (interfaceOrientation == UIInterfaceOrientationPortrait);
  90. }
  91. @end