手工书 1.0.0

手工书 1.0.0

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布上次发布2014年12月

Muhammad Ibrahim 维护。



 
依赖
AFNetworking~> 2.2
Stripe~> 1.1
 

手工书 1.0.0

Handybook iOS Cocoapod

作者:Muhammad Ibrahim(@0ibrahim)和Jayant Sani(@jsani0102

描述

Handybook Cocoapod是对Handybook API的Objective-C包装,为第三方开发者提供了访问Handybook服务的接口(例如预约清洁、各类维修等)。使用这些文件,您可以将Handybook API的功能集成到自己的应用中,并使用Handybook进行预约。

例如,一个帮助人们计划派对的App可以利用Handybook Cocoapod提供预约次日清洁的服务。

如何获取API密钥?

您要与Handybook API接口,需要API密钥。请通过电子邮件申请API密钥:[email protected]

入门指引

按照以下步骤开始使用此Pod:
1. 在您的Podfile中添加pod 'Handybook', '1.0'
2. 在项目目录中,使用命令行执行pod install
3. 在HBAPI.m文件中添加您的API_KEY和API_SECRET
4. 添加适当的API头文件到源文件中,例如:要使用预约方法,添加#import <Handybook/HBAPIBooking.h>

5. 使用例如[[HBAPI sharedInstance] createBooking:];访问单例方法

测试环境

默认情况下,Pod将连接到handybook的测试服务器,以便开发者测试他们的代码。一旦您的应用程序通过了审查,您将会得到您的生产密钥和密钥,这将允许您进行真实预约。

要启用生产预约,通过在HBAPI.m中更改baseURL替换s-handybook.hbinternal.com为www.handybook.com

制作Handbook预订的流程如下
  1. 创建预订对象,填写必要的预订信息
  2. 通过网络调用进行预订 - createBooking:successBlock:failureBlock:
  3. 支付预订费用(如下所示为选项)

  • 现有用户支付
    • 所有用户信息都必须包含在HBBooking对象的HBUser属性中
    • 调用合适的支付方法 - payForBookingWithExistingUser
  • 非现有用户支付
    • HBBooking对象的HBUser属性应为nil
    • 生成新的Stripe令牌以关联用户 - stripeTokenWithCard:expirationMonth:expirationYear:cvc:
    • 调用合适的支付方法 - payForBooking:WithStripeToken:firstName:lastName:address:aptNumber:phoneNumber:
    • 提示输入密码,在服务器的用户端持久化用户 - getConfirmationForBooking:password:
    /**
     * Use this method to get a quote for a booking that you want to make. Returns 
     * the price, hours and timings of booking as a JSON object.
     *
     * @params
     * booking - HBBooking object filled in with booking information  
     **/

    - (void)createBooking:(HBBooking *)booking
         successBlock:(void(^)(NSDictionary *responseObject))successBlock
         failureBlock:(void(^)(NSError *error))failureBlock
    /**
     * Use this method to get a quote when you have a voucher code. Return the 
     * discounted price, hours and timings of the booking quote.
     *
     * @params
     * booking - HBBooking object filled in with booking info
     * voucher - voucher code that is to be applied to the booking for discount
     **/

    - (void)createBooking:(HBBooking *)booking
              WithVoucher:(NSString *)voucher
             successBlock:(void(^)(NSDictionary *responseObject))successBlock
             failureBlock:(void(^)(NSError *error))failureBlock
    /**
     * Use this method to pay for a booking when there is an existing user. 
     * The booking object must have a user property of type HBUser. This 
     * completes the booking and returns a confirmation with time of booking 
     * and price.
     *
     * @params
     * booking - HBBooking object filled in with booking info
     **/

    - (void)payForBookingWithExistingUser:(HBBooking *)booking
                         successBlock:(void(^)(NSDictionary *responseObject))successBlock
                         failureBlock:(void(^)(NSError *error))failureBlock
    /**
     * Use this method to pay for a booking when there is no user.
     * 
     * @params
     * booking - HBBooking object filled in with booking info
     * stripeToken - get stripeToken from stripeToken generator by passing credit card info.
     * firstName - first name of user
     * lastName - last name of user
     * address - address of the user
     * aptNumber - address line 2
     * phoneNumber - phone number of the user
     *
     **/

    - (void)payForBooking:(HBBooking *)booking
          WithStripeToken:(NSString *)stripeToken
                firstName:(NSString *)firstName
                 lastName:(NSString *)lastName
                  address:(NSString *)address
                aptNumber:(NSString *)aptNumber
              phoneNumber:(NSString *)phone
             successBlock:(void(^)(NSDictionary *responseObject))successBlock
             failureBlock:(void(^)(NSError *error))failureBlock
    /**
     * User this method to set a new booking date for bookings where you have made the 
     * quote but not completed the payment.
     *
     * @params
     * booking - HBBooking object filled with booking info
     * Date - date to be set for new booking (yyyy-MM-dd HH:mm)
     **/

    - (void)setNewBooking:(HBBooking *)booking
                     Date:(NSString*)date
             successBlock:(void(^)(NSDictionary *responseObject))successBlock
             failureBlock:(void(^)(NSError *error))failureBlock
    /**
     * Cancel a booking that has already been paid for.
     *
     * @params
     * booking - HBBooking object filled in with booking info
     * cancellationReason - number representing the reason from preCancellationInfoForBooking (1 - 5)
     **/

    - (void)cancelBooking:(HBBooking *)booking
       cancellationReason:(NSNumber *)cancellationReason
             successBlock:(void(^)(NSDictionary *responseObject)) successBlock
             failureBlock:(void(^)(NSError *error))failureBlock
    /**
     * Reschedule an existing booking. This operation differs from setting a new
     * booking date because a booking can only be rescheduled after it has been 
     * paid for. A new date can only be set if the booking has not been paid yet.
     *
     * @params
     * booking - the HBBooking object that contains all the booking information
     * date - the date that the booking should be rescheduled for. ([yyyy-MM-dd HH:mm])
     * @optional rescheduleAll - if this is a recurring booking and all future bookings
     * should be rescheduled, set to "1". If only a one-time occurrence, set to "0".
     **/

    - (void)rescheduleBooking:(HBBooking *)booking
                      forDate:(NSString *)date
                rescheduleAll:(NSString *)rescheduleAll
                 successBlock:(void(^)(NSDictionary *responseObject))successBlock
                 failureBlock:(void(^)(NSError *error))failureBlock
    /**
     * Replicate an existing booking. Creates a new booking with exactly
     * the same characteristics as the booking that is being duplicated.
     *
     * @params
     * booking - the HBBooking object that contains all the booking informations
     **/

    - (void)duplicateBooking:(HBBooking *)booking
                successBlock:(void(^)(NSDictionary *responseObject))successBlock
                failureBlock:(void(^)(NSError *error))failureBlock
    /**
     * Validates a zipcode for a specific booking, checking if the particular service
     * is available in a certain zipcode. A promo code can also be passed to see if
     * the code is available in a certain area, as some promos are region-specific.
     *
     * @params
     * booking - the HBBooking object that contains all the booking information
     * @optional promo - the promo code, pass nil if not applicable
     **/

    - (void)checkZipcodeforBooking:(HBBooking *)booking
                WithPromoIfPresent:(NSString *)promo
                      successBlock:(void(^)(NSDictionary *responseObject))successBlock
                      failureBlock:(void(^)(NSError *error))failureBlock
    /**
     * Displays the precancelation info for a specific booking. The precancelation info
     * is presented before a user cancels their booking, listing the reasons for why
     * the booking might be cancelled. The user must specify a reason when cancelling.
     *
     * @params
     * booking - the HBBooking object that contains the booking information
     **/

    - (void)getPrecancelationInfoForBooking:(HBBooking *)booking
                               successBlock:(void(^)(NSDictionary *responseObject))successBlock
                               failureBlock:(void(^)(NSError *error))failureBlock
    /**
     * Part of the post-booking flow, this method confirms that a booking quote has been
     * created an that the booking has been paid. In addition, a password parameter can be
     * passed into the method to create and persist a user if the user did not previously
     * exist.
     *
     **/

    - (void)getConfirmationForBooking:(HBBooking *)booking
                             password:(NSString *)password
                         successBlock:(void(^)(NSDictionary *responseObject))successBlock
                         failureBlock:(void(^)(NSError *error))failureBlock
    /**
     * Enter a promo code in order to receive a discount price before the booking flow. 
     *
     * @params
     * promoCode - the promo code to be applied
     **/

    - (void)getPrebookingPromo:(NSString *)promoCode
                  successBlock:(void(^)(NSDictionary *responseObject))successBlock
                  failureBlock:(void(^)(NSError *error))failureBlock
    /**
     * Apply a coupon to a booking for a discounted price.
     * 
     * @params
     * coupon - the coupon code to apply to the booking
     * booking - the HBBooking object that contains the booking information
     **/

    - (void)applyCoupon:(NSString *)coupon
              toBooking:(HBBooking *)booking
           successBlock:(void(^)(NSDictionary *responseObject))successBlock
           failureBlock:(void(^)(NSError *error))failureBlock
    /**
     * Remove a coupon from a booking. The booking must already have a coupon applied to it.
     *
     * @params
     * booking - the HBBooking object that contains the booking information
     **/

    - (void)removeCouponFromBooking:(HBBooking *)booking
                       successBlock:(void(^)(NSDictionary *responseObject))successBlock
                       failureBlock:(void(^)(NSError *error))failureBlock 

用户 - HBAPIUser.h

    /**
     * Create a session by logging in a user. The responseObject for this API
     * call contains the user_id and auth_token, which will be needed in
     * subsequent calls.
     *
     * @params
     * email - the user's email
     * password - the password for the user's account
     **/

    - (void)loginWithEmail:(NSString *)email
               andPassword:(NSString *)password
              successBlock:(void(^)(NSDictionary *responseObject))successBlock
              failureBlock:(void(^)(NSError *error))failureBlock
    /**
     * Get all the bookings associated with a user.
     *
     * @params
     * user - the HBUser object that contains the user's information
     **/

    - (void)getBookingsForUser:(HBUser *)user
                  successBlock:(void(^)(NSDictionary *responseObject))successBlock
                  failureBlock:(void(^)(NSError *error))failureBlock
    /**
     * Get the user's information, which includes their addresses and bookings,
     * among other information.
     *
     * @params
     * user - the HBUser object that contains the user's information
     **/

    - (void)getInfoForUser:(HBUser *)user
              successBlock:(void(^)(NSDictionary *responseObject))successBlock
              failureBlock:(void(^)(NSError *error))failureBlock
    /**
     * Share the user's information. Retrieve a promo code to give to friends
     * to get discounts on bookings. The user can share the code through
     * social media.
     *
     * @params
     * user - the HBUser object that contains the user's information
     **/

     - (void)shareInfoForUser:(HBUser *)user
            successBlock:(void(^)(NSDictionary *responseObject))successBlock
            failureBlock:(void(^)(NSError *error))failureBlock
    /**
     * Make modifications to the user's personal information. Input different
     * information than the user's confirmation in order to change it. For
     * example, if the user's current listed name is "Bill," but the user wants
     * to change it to "William," pass in "William" as the firstName parameter
     * to change the user's first name to "William" on our servers.
     * @Note - the password parameters are optional. They are only needed if
     * the user wants to change their password. Otherwise, pass in nil.
     *
     * @params
     * user - the HBUser object that contains the user's information
     * firstName - the user's desired first name
     * lastName - the user's desired last name
     * email - the user's desired email
     * phoneNumber - the user's desired phone number
     * @optional - the following parameters are only needed if the user wants to change their password:
     * currentPassword - the user's current password
     * newPassword - the user's desired new password
     * passwordConfirmation - to confirm the password, must match the new password
     **/

    - (void)editUserInfo:(HBUser *)user
           WithFirstName:(NSString *)firstName
                lastName:(NSString *)lastName
                   email:(NSString *)email
             phoneNumber:(NSString *)phoneNumber
         currentPassword:(NSString *)currentPassword
             newPassword:(NSString *)newPassword
    passwordConfirmation:(NSString *)passwordConfirmation
            successBlock:(void(^)(NSDictionary *responseObject))successBlock
            failureBlock:(void(^)(NSError *error))failureBlock

服务 - HBAPIServices.h

    /**
     * Retrieves all the home services that Handybook offers. Returns a 
     * dictionary that maps a particular service's name to its service ID in 
     * the success block.
     *
     * @params - none
     **/

    - (void)getAllServices:(void(^)(NSDictionary *responseObject))successBlock
              failureBlock:(void(^)(NSError *error))failureBlock

服务属性 - HBAPIServiceAttributes.h

    /**
     * Retrieves the service attributes for a certain serviceID. Returns an 
     * array of HBServiceAttributes objects that must be filled in before
     * creating a booking in the success block.
     *
     * @params
     * serviceID - the numerical ID of a specific services 
     * (ex. home cleaning's service ID is 3)
     **/

    - (void)getServiceAttributesForService:(NSNumber *)serviceID
                              successBlock:(void(^)(NSArray *responseObject))successBlock
                              failureBlock:(void(^)(NSError *error))failureBlock

Stripe令牌生成器 - HBStripeTokenGenerator.h

    /**
     * Generates a stripe token for a new user
     * 
     * @params
     * cardNumber - the user's credit card number
     * month - the credit card's expiration month
     * year - the credit card's expiration year
     * cvc - the credit card's cvc number (3 digits)
     **/

    + (void)stripeTokenWithCard:(NSString *)cardNumber
                expirationMonth:(NSNumber *)month
                 expirationYear:(NSNumber *)year
                            cvc:(NSString *)cvc
                   successBlock:(void(^)(NSString *stripeToken))successBlock
                        failure:(void(^)(NSError *error))failureBlock