ClutchMobileAPI 0.1.0

ClutchMobileAPI 0.1.0

lhgravendeel维护。



  • Clutch

ClutchMobileAPI

Version License Platform

示例

要运行示例项目,请先克隆仓库,然后从示例目录中首先运行pod install

安装

ClutchMobileAPI通过CocoaPods提供。安装它,只需将以下行添加到您的Podfile中:

pod 'ClutchMobileAPI'

配置

在您的项目的Info.plist文件中,将您的Clutch App Key和Secret添加到ClutchMobAppKeyClutchMobAppSecret中。

用法

要获取对共享客户端的访问权限,请使用

#import <ClutchMobileAPI/ClutchMobClient.h>

id client = [ClutchMobClient sharedClient];

使用此客户端,您可以立即执行品牌级别的调用,例如

[client listSubscriptionLists:^(ClutchMobListSubscriptionListsResponse * _Nonnull serverResponse) {
  NSLog(@"Subscription list count: %lu", [serverResponse.subscriptionLists count]);
} failure:nil];

要执行针对特定用户操作的步骤,您需要获取用户令牌。用户令牌可以通过注册新的Clutch卡或通过知道卡号和PIN访问现有的Clutch卡来获取。

获取用户令牌的第一步是让用户完成一个验证码图片。首先获取验证码ID,下载验证码图片并展示给用户。用户输入被认为验证码“的秘密”。

验证码ID与验证码秘密可以用于一个注册或“为现有卡获取令牌”调用。如果调用失败,需要新的验证码。

为了获取验证码ID和渲染验证码图片

[client getCaptchaIDWithSuccess:^(ClutchMobCaptchaResponse * _Nonnull serverResponse) {
  self.captchaID = [NSString stringWithString:serverResponse.captchaId];
  
  NSString *url = [NSString stringWithFormat:@"https://mobile-api.clutch.com/captcha/show/%@", serverResponse.captchaId];
  [self.captchaViewController setImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:url]]]];

} failure:nil];

要注册新卡,请确保指定Clutch品牌配置中标记为“必需”的所有字段

NSMutableDictionary *primaryFields = [[NSMutableDictionary alloc] init];
[primaryFields setValue:@"John" forKey:@"firstName"];
[primaryFields setValue:@"Doe" forKey:@"lastName"];
[primaryFields setValue:@"[email protected]" forKey:@"email"];

NSMutableDictionary *customFields = [[NSMutableDictionary alloc] init];

[client registerNewCardWithPrimaryFields:primaryFields andCustomFields:customFields withCaptchaID:self.captchaID andCaptchaSecret:captchaSecret withSuccess:^(ClutchMobRegisterResponse *serverResponse) {
  NSLog(@"Registered, user token: %@, Created Clutch card number: %@ with PIN %@", serverResponse.token, serverResponse.cardNumber, serverResponse.pin);
  // The token from serverResponse.token should be stored
} failure:nil];

为现有卡获取用户令牌

[client getTokenForCard:cardNumber withPin:pin
  withCaptchaID: captchaID andCaptchaSecret: captchaSecret
  withSuccess:^(ClutchMobGetTokenResponse *serverResponse) {
    // The token from serverResponse.token should be stored
  } failure:nil];

一旦您获取了用户令牌,重要的是将其存储起来,以便在应用程序需要访问用户的Clutch卡数据时使用。

为了有效地“注销”,请使用 [client releaseToken:token withSuccess:nil failure:nil];

使用令牌,您可以执行以下操作

  • 获取用户配置文件,返回余额(忠诚度、礼物和自定义)、人口统计学、电子邮件许可状态、段成员资格
  • 更新人口统计学(仅在您的Clutch品牌配置中指定为“可编辑”的字段)
  • 更改电子邮件许可状态,无论是全局的还是针对个别订阅列表的
  • 注册事件
  • 为与Clutch活动的推送通知集成提供APNS令牌

ClutchMobClient.h 以获取可用的签名。

作者

Clutch,[email protected]

许可

ClutchMobileAPI在MIT许可下可用。有关更多信息,请参阅LICENSE文件。

注意

在示例中打开 'ClutchMobileAPI/Example/ClutchMobileAPI.xcworkspace',然后运行 pod install