Git Product home page Git Product logo

createsend-objectivec's Introduction

CreateSend Objective-C

CreateSend Objective-C is a library for talking to the Campaign Monitor API from Cocoa & Cocoa Touch applications. It supports iOS 5.0+ & Mac OS X 10.7+.

Build Status

Installation

If you use CocoaPods in your project, you can include the CreateSend pod in your Podfile:

pod 'CreateSend', '~> X.Y.Z'

Otherwise, just grab the latest version of CreateSend.xcodeproj and add it as a dependency in your own project.

Features

  • Implements the complete functionality of the API.
  • Provides a drop-in UI for adding new subscribers to your lists, with custom field support.

Sample Project

A sample project is included in $SRCROOT/Example/CreateSendExample/CreateSendExample.xcodeproj. With the help of IBAForms by the friendly folks at Itty Bitty Apps, CreateSendExample demonstrates presenting a form for subscribing to a Campaign Monitor list.

You will need to specify your API key in CSExampleAppDelegate.m before building & running CreateSendExample.

The provided CSSubscriptionFormViewController class can present a simple form with name & email address, or it can display the custom fields configured for the subscription list. Set the customFieldBehavior variable in CSExampleAppDelegate.m to any of the values specified in CSExampleAppCustomFieldBehavior to configure the form in fixed-fields or dynamic-fields mode.

Basic API Wrapper Usage Examples

If you prefer to build your own custom UI, you can simply use the API wrapper directly. For full documentation of the API wrapper, see the class documentation is available in Documentation/html/index.html (generated with rake docs:generate).

Here's a some examples to get you started.

Authenticating using OAuth 2

The Campaign Monitor API supports authenticating using either OAuth 2 or an API key over basic authentication. Using OAuth 2 is recommended. For full details see the API documentation.

Here's the recommended approach for authenticating using OAuth 2 from this library.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    API = [[CSAPI alloc] initWithClientID:@"CLIENT_ID" clientSecret:@"CLIENT_SECRET" scope:@[CSAPIClientScopeManageLists, CSAPIClientScopeImportSubscribers]];
    if (!API.isAuthorized) {
        [API authorize];    
    }
}

Once authorized, your app will be launched with the URL scheme csapiCLIENT_ID. The easiest way to register for this scheme is right-click on your app's plist file and select Open As โ†’ Source Code, and add the following code below the first <dict> tag, substituting CLIENT_ID with your app's client id:

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>csapiCLIENT_ID</string>
        </array>
    </dict>
</array>

Now that your app is registered for the correct scheme, you need to add the following code to your application delegate in order to complete the authorization flow:

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    if ([API handleOpenURL:url]) {
        if (API.isAuthorized) {
            NSLog(@"App has been authorized successfully!");
            // At this point you can start making API calls
        }
        return YES;
    }
    // Add whatever other url handling code your app requires here
    return NO;
}

Getting an API key

As an alternative to using OAuth 2 for authentication, you can also use an API key.

Here's how you get an API key using this library.

CSAPI *API = [[CSAPI alloc] init];
    
[API getAPIKeyWithSiteURL:@"http://yoursite.createsend.com/" username:@"yourusername" password:@"yourpassword" completionHandler:^(NSString *APIKey) {
    NSLog(@"Your API key is %@", APIKey);
} errorHandler:^(NSError *error) {
    NSLog(@"Something went wrong: %@", error);
}];

Subscribing to a list

Here's an example of how to subscribe to a list (authenticating with API key rather than OAuth).

CSAPI *API = [[CSAPI alloc] initWithAPIKey:@"ab6b0598d32fecd63485b18abb4f0ad7"];
    
NSArray *customFields = @[
    [CSCustomField customFieldWithKey:@"AddressStreet" value:@"1 Infinite Loop"],
    [CSCustomField customFieldWithKey:@"AddressSuburb" value:@"Cupertino"]
];

[API subscribeToListWithID:@"66f889ae2e1981157285b4f76f2e02ad"
              emailAddress:@"[email protected]"
                      name:@"Johnny Appleseed"
         shouldResubscribe:YES
              customFields:customFields
         completionHandler:^(NSString *subscribedAddress) {
            NSLog(@"Successfully subscribed %@", subscribedAddress);
         } errorHandler:^(NSError *error) {
            NSLog(@"Something went wrong: %@", error);
         }];

Contributing

Please check the guidelines for contributing to this repository.

Releasing

Please check the instructions for releasing this library.

createsend-objectivec's People

Contributors

atnan avatar daikini avatar henrys-cm avatar jdennes avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.