Skip to content

Commit

Permalink
Merge pull request #18 from amco/demo_project
Browse files Browse the repository at this point in the history
Demo project added. Demo excluded in podspec. Resolves #14.
  • Loading branch information
adamyanalunas committed Oct 7, 2013
2 parents 4cbe09c + e65154f commit ad788b5
Show file tree
Hide file tree
Showing 18 changed files with 1,011 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Demo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Xcode
.DS_Store
*.xcuserstate
*.xcbkptlist
*.xcuserstate
*/build/*
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
*.xcworkspace
!default.xcworkspace
xcuserdata
profile
*.moved-aside
DerivedData
.idea/
*.hmap
*.xcuserstate
*.xcbkptlist

# cocoapods
Pods
Podfile.lock
3 changes: 3 additions & 0 deletions Demo/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
platform :ios, '6.0'

pod 'librato-iOS', :path => '../librato-iOS.podspec'
17 changes: 17 additions & 0 deletions Demo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# librato-iOS Demo

This simple but direct project showcases some simple uses of the `librato-iOS` library.

# Usage

Because this demo project uses the `podspec` in the main library you'll need to grab the entire repo.

* Clone the `librato-iOS` repo (`$ git clone [email protected]:amco/librato-iOS.git`)
* Navigate into the Demo directory and install the Pods (`cd librato-iOS/Demo && pod install`)
* Open the workspace (`open librato-iOS\ Demo.xcworkspace`)
* Open `LibratoDemoAppDelegate.m` to select which demos to run
* Open `LibratoDemoEventTracker.m` to see how each demo is created

# Copyright

Copyright (c) 2013 Amco International Education Services, LLC. See LICENSE for more details.
510 changes: 510 additions & 0 deletions Demo/librato-iOS Demo.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "29x29",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "40x40",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"scale" : "2x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"images" : [
{
"orientation" : "portrait",
"idiom" : "iphone",
"extent" : "full-screen",
"minimum-system-version" : "7.0",
"scale" : "2x"
},
{
"orientation" : "portrait",
"idiom" : "iphone",
"subtype" : "retina4",
"extent" : "full-screen",
"minimum-system-version" : "7.0",
"scale" : "2x"
},
{
"orientation" : "portrait",
"idiom" : "ipad",
"extent" : "full-screen",
"minimum-system-version" : "7.0",
"scale" : "1x"
},
{
"orientation" : "landscape",
"idiom" : "ipad",
"extent" : "full-screen",
"minimum-system-version" : "7.0",
"scale" : "1x"
},
{
"orientation" : "portrait",
"idiom" : "ipad",
"extent" : "full-screen",
"minimum-system-version" : "7.0",
"scale" : "2x"
},
{
"orientation" : "landscape",
"idiom" : "ipad",
"extent" : "full-screen",
"minimum-system-version" : "7.0",
"scale" : "2x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
15 changes: 15 additions & 0 deletions Demo/librato-iOS Demo/LibratoDemoAppDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// LibratoDemoAppDelegate.h
// librato-iOS Demo
//
// Created by Adam Yanalunas on 10/7/13.
// Copyright (c) 2013 Amco International Education Services, LLC. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface LibratoDemoAppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end
57 changes: 57 additions & 0 deletions Demo/librato-iOS Demo/LibratoDemoAppDelegate.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// LibratoDemoAppDelegate.m
// librato-iOS Demo
//
// Created by Adam Yanalunas on 10/7/13.
// Copyright (c) 2013 Amco International Education Services, LLC. All rights reserved.
//

#import "LibratoDemoAppDelegate.h"
#import "LibratoDemoEventTracker.h"

@implementation LibratoDemoAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];

LibratoDemoEventTracker *eventTracker = LibratoDemoEventTracker.new;
[eventTracker counterMetricExample];
[eventTracker multipleMetricSubmissionExample];
[eventTracker dictionaryCreationExample];
[eventTracker gaugeMetricExample];

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
24 changes: 24 additions & 0 deletions Demo/librato-iOS Demo/LibratoDemoEventTracker.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// LibratoDemoEventTracker.h
// librato-iOS Demo
//
// Created by Adam Yanalunas on 10/7/13.
// Copyright (c) 2013 Amco International Education Services, LLC. All rights reserved.
//

#import <Foundation/Foundation.h>


@class Librato;


@interface LibratoDemoEventTracker : NSObject

+ (Librato *)sharedInstance;

- (void)counterMetricExample;
- (void)multipleMetricSubmissionExample;
- (void)dictionaryCreationExample;
- (void)gaugeMetricExample;

@end
113 changes: 113 additions & 0 deletions Demo/librato-iOS Demo/LibratoDemoEventTracker.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
//
// LibratoDemoEventTracker.m
// librato-iOS Demo
//
// Created by Adam Yanalunas on 10/7/13.
// Copyright (c) 2013 Amco International Education Services, LLC. All rights reserved.
//

#import "LibratoDemoEventTracker.h"
#import "Librato.h"


NSString *const libratoEmail = @"<Librato email>";
NSString *const libratoToken = @"<Librato token>";
NSString *const libratoPrefix = @"demo";


@interface LibratoDemoEventTracker ()

- (NSNumber *)randomNumber;

@end


@implementation LibratoDemoEventTracker


#pragma mark - Lifecycle
/*
Simple non-threadsafe singleton creator
*/
+ (Librato *)sharedInstance
{
static dispatch_once_t onceToken;
static Librato *_librato;

dispatch_once(&onceToken, ^{
_librato = [Librato.alloc initWithEmail:libratoEmail token:libratoToken prefix:libratoPrefix];
});

return _librato;
}


#pragma mark - Examples
/*
Creates a "counter" metric and shows that you can change values via the options or with property accessors
*/
- (void)counterMetricExample
{
LibratoMetric *simpleMetric = [LibratoMetric metricNamed:@"works" valued:self.randomNumber options:@{@"source": @"demo app"}];
simpleMetric.measureTime = [NSDate dateWithTimeIntervalSinceNow:-(3600 * 24)];

NSLog(@"%@", simpleMetric);

[LibratoDemoEventTracker.sharedInstance submit:simpleMetric];
}


/*
Creates two different metrics but submits them simultaneously
*/
- (void)multipleMetricSubmissionExample
{
LibratoMetric *memoryMetric = [LibratoMetric metricNamed:@"memory.available" valued:self.randomNumber options:nil];
LibratoMetric *storageMetric = [LibratoMetric metricNamed:@"storage.available" valued:self.randomNumber options:nil];

NSLog(@"%@", memoryMetric);
NSLog(@"%@", storageMetric);

[LibratoDemoEventTracker.sharedInstance submit:@[memoryMetric, storageMetric]];
}


/*
Creates and auto-submits two counter metrics: "meaning" and "plutonium", the latter using an NSDictionary to set the value and source simultaneously
*/
- (void)dictionaryCreationExample
{
[LibratoDemoEventTracker.sharedInstance submit:@{@"meaning": self.randomNumber, @"plutonium": @{@"value": @238, @"source": @"Russia, with love"}}];
}


/*
Creates a series of counter measurements and submits them as a gague metric
*/
- (void)gaugeMetricExample
{
LibratoMetric *metric1 = [LibratoMetric metricNamed:@"bagels" valued:self.randomNumber options:nil];
LibratoMetric *metric2 = [LibratoMetric metricNamed:@"bagels" valued:self.randomNumber options:nil];
LibratoMetric *metric3 = [LibratoMetric metricNamed:@"bagels" valued:self.randomNumber options:nil];
LibratoMetric *metric4 = [LibratoMetric metricNamed:@"bagels" valued:self.randomNumber options:nil];
LibratoMetric *metric5 = [LibratoMetric metricNamed:@"bagels" valued:self.randomNumber options:nil];
LibratoMetric *metric6 = [LibratoMetric metricNamed:@"bagels" valued:self.randomNumber options:nil];
LibratoMetric *metric7 = [LibratoMetric metricNamed:@"bagels" valued:self.randomNumber options:nil];
LibratoMetric *metric8 = [LibratoMetric metricNamed:@"bagels" valued:@0 options:nil];

NSArray *bagels = @[metric1, metric2, metric3, metric4, metric5, metric6, metric7, metric8];
NSLog(@"%@", bagels);
LibratoGaugeMetric *bagelGuage = [LibratoGaugeMetric metricNamed:@"bagel_guage" measurements:bagels];

[LibratoDemoEventTracker.sharedInstance submit:bagelGuage];
}


#pragma mark - Helpers
- (NSNumber *)randomNumber
{
return @(abs(rand() % 100));
}


@end
2 changes: 2 additions & 0 deletions Demo/librato-iOS Demo/en.lproj/InfoPlist.strings
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* Localized versions of Info.plist keys */

Loading

0 comments on commit ad788b5

Please sign in to comment.