Skip to content
This repository has been archived by the owner on Dec 21, 2017. It is now read-only.

Commit

Permalink
update count.ly sdk and expose suspend resume functions
Browse files Browse the repository at this point in the history
  • Loading branch information
euforic committed Aug 23, 2012
1 parent 1909862 commit 41efcfa
Show file tree
Hide file tree
Showing 12 changed files with 375 additions and 161 deletions.
1 change: 1 addition & 0 deletions Classes/CountLyModule.h
Expand Up @@ -5,6 +5,7 @@
* and licensed under the Apache Public License (version 2)
*/
#import "TiModule.h"
#import "Countly.h"

@interface CountLyModule : TiModule
{
Expand Down
104 changes: 86 additions & 18 deletions Classes/CountLyModule.m
Expand Up @@ -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

Expand Down Expand Up @@ -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
{
Expand All @@ -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'
}
}
Expand All @@ -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;
}

Expand Down
23 changes: 22 additions & 1 deletion 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.
43 changes: 41 additions & 2 deletions README.md
Expand Up @@ -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

```
Expand All @@ -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.
Binary file not shown.
8 changes: 6 additions & 2 deletions example/app.js
Expand Up @@ -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);
4 changes: 2 additions & 2 deletions manifest
Expand Up @@ -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>
Expand All @@ -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
36 changes: 18 additions & 18 deletions sdk/Countly.h
@@ -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;
Expand All @@ -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

0 comments on commit 41efcfa

Please sign in to comment.