Permalink
Browse files

update count.ly sdk and expose suspend resume functions

  • Loading branch information...
1 parent 1909862 commit 41efcfaeb7b14540fc3119518e01ea5e215a8a81 euforic committed Aug 23, 2012
View
@@ -5,6 +5,7 @@
* and licensed under the Apache Public License (version 2)
*/
#import "TiModule.h"
+#import "Countly.h"
@interface CountLyModule : TiModule
{
View
@@ -8,7 +8,59 @@
#import "TiBase.h"
#import "TiHost.h"
#import "TiUtils.h"
-#import "Countly.h"
+
+
+/// Tool to decoded urld encoded string that Count.ly uses to send metrics
+/// Utilities for encoding and decoding URL arguments.
+/// This code is from the project google-toolbox-for-mac
+@interface NSString (GTMNSStringURLArgumentsAdditions)
+
+/// Returns a string that is escaped properly to be a URL argument.
+//
+/// This differs from stringByAddingPercentEscapesUsingEncoding: in that it
+/// will escape all the reserved characters (per RFC 3986
+/// <http://www.ietf.org/rfc/rfc3986.txt>) which
+/// stringByAddingPercentEscapesUsingEncoding would leave.
+///
+/// This will also escape '%', so this should not be used on a string that has
+/// already been escaped unless double-escaping is the desired result.
+- (NSString*)gtm_stringByEscapingForURLArgument;
+
+/// Returns the unescaped version of a URL argument
+//
+/// This has the same behavior as stringByReplacingPercentEscapesUsingEncoding:,
+/// except that it will also convert '+' to space.
+- (NSString*)gtm_stringByUnescapingFromURLArgument;
+
+@end
+
+#define GTMNSMakeCollectable(cf) ((id)(cf))
+#define GTMCFAutorelease(cf) ([GTMNSMakeCollectable(cf) autorelease])
+
+@implementation NSString (GTMNSStringURLArgumentsAdditions)
+
+- (NSString*)gtm_stringByEscapingForURLArgument {
+ // Encode all the reserved characters, per RFC 3986
+ // (<http://www.ietf.org/rfc/rfc3986.txt>)
+ CFStringRef escaped =
+ CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
+ (CFStringRef)self,
+ NULL,
+ (CFStringRef)@"!*'();:@&=+$,/?%#[]",
+ kCFStringEncodingUTF8);
+ return GTMCFAutorelease(escaped);
+}
+
+- (NSString*)gtm_stringByUnescapingFromURLArgument {
+ NSMutableString *resultString = [NSMutableString stringWithString:self];
+ [resultString replaceOccurrencesOfString:@"+"
+ withString:@" "
+ options:NSLiteralSearch
+ range:NSMakeRange(0, [resultString length])];
+ return [resultString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+}
+
+@end
@implementation CountLyModule
@@ -41,12 +93,12 @@ -(void)shutdown:(id)sender
// this method is called when the module is being unloaded
// typically this is during shutdown. make sure you don't do too
// much processing here or the app will be quit forceably
-
+
// you *must* call the superclass
[super shutdown:sender];
}
-#pragma mark Cleanup
+#pragma mark Cleanup
-(void)dealloc
{
@@ -69,7 +121,7 @@ -(void)_listenerAdded:(NSString *)type count:(int)count
{
if (count == 1 && [type isEqualToString:@"my_event"])
{
- // the first (of potentially many) listener is being added
+ // the first (of potentially many) listener is being added
// for event named 'my_event'
}
}
@@ -94,51 +146,67 @@ -(void)start:(id)args
TiThreadPerformOnMainThread(^{[[Countly sharedInstance] start:apikey withHost:apiHost];}, NO);
}
--(id)udid
+-(void)resume:(id)args
+{
+ [[Countly sharedInstance] resume];
+}
+
+-(void)suspend:(id)args
+{
+ [[Countly sharedInstance] suspend];
+
+}
+
+-(void)exit:(id)args
+{
+ [[Countly sharedInstance] exit];
+
+}
+
+-(NSNumber*)isSuspended
+{
+ return NUMBOOL([[Countly sharedInstance] isSuspended]);
+}
+
+-(NSString*)udid
{
NSString *udid = [DeviceInfo udid];
return udid;
}
--(id)device
+-(NSString*)device
{
NSString *device = [DeviceInfo device];
return device;
}
--(id)osVersion
+-(NSString*)osVersion
{
NSString *osVersion = [DeviceInfo osVersion];
return osVersion;
}
--(id)carrier
+-(NSString*)carrier
{
NSString *carrier = [DeviceInfo carrier];
return carrier;
}
--(id)resolution
+-(NSString*)resolution
{
NSString *resolution = [DeviceInfo resolution];
return resolution;
}
-(id)locale
{
- NSString *locale = [DeviceInfo locale];
+ NSLocale *locale = [DeviceInfo locale];
return locale;
}
--(id)platform
-{
- NSString *platform = [DeviceInfo platform];
- return platform;
-}
-
--(id)metrics
+-(NSString*)metrics
{
- NSString *metrics = [DeviceInfo platform];
+ NSString *metrics = [[DeviceInfo metrics] gtm_stringByUnescapingFromURLArgument];
return metrics;
}
View
23 LICENSE
@@ -1 +1,22 @@
-TODO: place your license here and we'll include it in the module distribution
+(The MIT License)
+
+Copyright (c) 2012 Christian Sullivan &lt;cs@euforic.co&gt;
+
+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.
View
@@ -10,6 +10,24 @@ Other Countly SDK repositories;
- [Countly Android SDK (countly-sdk-android)](https://github.com/Countly/countly-sdk-android)
+# Install
+
+```
+$ git clone https://github.com/euforic/Ti-Count.ly.git
+$ cd Ti-Count.ly
+$ cp count.ly-iphone-0.1.1.zip /Library/Application Support/Titanium/
+```
+Register your module with your application by editing `tiapp.xml` and adding your module.
+```
+<modules>
+ <module version="0.1.1">count.ly</module>
+</modules>
+```
+Require you module in whatever js file you plan to use it in
+```
+var my_module = require('count.ly');
+```
+
## Usage
```
@@ -28,6 +46,27 @@ Ti.API.info(countly.platform);
Ti.API.info(countly.metrics);
```
-## TODO
+## License
+
+(The MIT License)
+
+Copyright (c) 2012 Christian Sullivan &lt;cs@euforic.co&gt;
+
+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.
-Write a real readme
+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.
View
@@ -16,13 +16,17 @@ win.open();
var countly = require('count.ly');
countly.start('APP_KEY','http://API_HOST.com');
-label.text = JSON.parse(countly.metrics);
+var metrics = JSON.parse(countly.metrics);
+
+metrics.udid = countly.udid;
+metrics.carrier = countly.carrier || 'Simulator';
+metrics.isSuspended = countly.isSuspended;
+label.text = metrics;
Ti.API.info(countly.udid);
Ti.API.info(countly.device);
Ti.API.info(countly.osVersion);
Ti.API.info(countly.carrier);
Ti.API.info(countly.resolution);
Ti.API.info(countly.locale);
-Ti.API.info(countly.platform);
Ti.API.info(countly.metrics);
View
@@ -2,7 +2,7 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
-version: 0.1
+version: 0.1.1
apiversion: 2
description: Count.ly SDK Module
author: Christian Sullivan <cs@euforic.co>
@@ -15,4 +15,4 @@ name: count.ly
moduleid: count.ly
guid: ad1ce2b6-9511-403b-b5de-50c40542c433
platform: iphone
-minsdk: 2.1.0.v20120604151821
+minsdk: 2.1.1.GA
View
@@ -1,26 +1,12 @@
// Countly.h
-//
+//
// This code is provided under the MIT License.
-//
+//
// Please visit www.count.ly for more information.
#import <Foundation/Foundation.h>
-#import <UIKit/UIKit.h>
-@interface DeviceInfo : NSObject {
-
-}
-
-+ (NSString *)udid;
-+ (NSString *)device;
-+ (NSString *)osVersion;
-+ (NSString *)carrier;
-+ (NSString *)resolution;
-+ (NSString *)locale;
-+ (NSString *)platform;
-
-@end
@interface Countly : NSObject {
double unsentSessionLength;
@@ -30,8 +16,22 @@
}
+ (Countly *)sharedInstance;
-
- (void)start:(NSString *)appKey withHost:(NSString *)appHost;
+- (BOOL)isSuspended;
+- (void)resume;
+- (void)suspend;
+- (void)exit;
+@end
+@interface DeviceInfo : NSObject{
+}
-@end
++ (NSString *)udid;
++ (NSString *)device;
++ (NSString *)osVersion;
++ (NSString *)carrier;
++ (NSString *)resolution;
++ (NSLocale *)locale;
++ (NSString *)appVersion;
++ (NSString *)metrics;
+@end
Oops, something went wrong.

0 comments on commit 41efcfa

Please sign in to comment.