Пример #1
0
 public ApiResponse getAccountProfile() {
   ApiRequest req =
       new ApiRequest(
           Office.getApiUrl() + "/passenger/v1/accounts/preferences",
           TDApplication.getSessionManager().getAccessToken());
   return doGetRequest(req);
 }
Пример #2
0
  public ApiResponse braintreeWrapperCardCreate(
      String userPk,
      String holdrName,
      String cardNumber,
      String cardCvv,
      String cardExpirationMonth,
      String cardExpirationYear) {

    Braintree bt = new Braintree(Office.getBraintreeEncryptionKey());

    ApiRequest req =
        new ApiRequest(
            Office.getBraintreeWrapperUrl(), TDApplication.getSessionManager().getAccessToken());

    req.addGetParam("cmd", "card-create");
    req.addGetParam("version", BRAINTREE_WRAPPER_MIN_VERSION);

    req.addPostParam("customer_pk", userPk);
    req.addPostParam("card_holder_name", holdrName);
    req.addPostParam("card_number", bt.encrypt(cardNumber));
    req.addPostParam("card_expiration_month", bt.encrypt(String.valueOf(cardExpirationMonth)));
    req.addPostParam("card_expiration_year", bt.encrypt(String.valueOf(cardExpirationYear)));

    if (cardCvv != null) {
      req.addPostParam("card_cvv", bt.encrypt(cardCvv));
    }

    return doPostRequest(req);
  }
Пример #3
0
 /**
  * [ vehicles
  * ]****************************************************************************************************
  */
 public ApiResponse getVehicleTypes() {
   ApiRequest req =
       new ApiRequest(
           Office.getApiUrl() + "/passenger/v1/vehicletypes",
           TDApplication.getSessionManager().getAccessToken());
   return doGetRequest(req);
 }
Пример #4
0
 public ApiResponse getAccountFleetData() {
   ApiRequest req =
       new ApiRequest(
           Office.getApiUrl() + "/passenger/v1/accounts/fleetdata",
           TDApplication.getSessionManager().getAccessToken());
   return doGetRequest(req);
 }
Пример #5
0
 public ApiResponse bookingsTrackBooking(JSONArray bookingPks) {
   ApiRequest req =
       new ApiRequest(
           Office.getApiUrl() + "/passenger/v1/bookings/track",
           TDApplication.getSessionManager().getAccessToken());
   req.addRequestParam("booking_pks", bookingPks);
   return doPostRequest(req);
 }
Пример #6
0
  public ApiResponse bookingsCancelBooking(String bookingPk, String reason) {
    String url = String.format(Office.getApiUrl() + "/passenger/v1/bookings/%s/cancel", bookingPk);
    ApiRequest req = new ApiRequest(url, TDApplication.getSessionManager().getAccessToken());

    if ((reason != null) && (reason.length() > 0)) {
      req.addRequestParam("description", reason);
    }

    return doPostRequest(req);
  }
Пример #7
0
  public ApiResponse bookingsNewBooking(JSONObject newBookingJson) {

    ApiRequest req =
        new ApiRequest(
            Office.getApiUrl() + "/passenger/v1/bookings",
            TDApplication.getSessionManager().getAccessToken());
    req.setRequestParameters(newBookingJson);

    return doPostRequest(req);
  }
Пример #8
0
  public ApiResponse braintreeWrapperCardList(String userPk) {
    ApiRequest req =
        new ApiRequest(
            Office.getBraintreeWrapperUrl(), TDApplication.getSessionManager().getAccessToken());
    req.addGetParam("cmd", "card-list");
    req.addGetParam("version", BRAINTREE_WRAPPER_MIN_VERSION);

    req.addPostParam("customer_pk", userPk);

    return doPostRequest(req);
  }
Пример #9
0
  public ApiResponse braintreeWrapperCardDelete(String cardToken) {
    ApiRequest req =
        new ApiRequest(
            Office.getBraintreeWrapperUrl(), TDApplication.getSessionManager().getAccessToken());

    req.addGetParam("cmd", "card-delete");
    req.addGetParam("version", BRAINTREE_WRAPPER_MIN_VERSION);

    req.addPostParam("card_token", cardToken);

    return doPostRequest(req);
  }
Пример #10
0
  public ApiResponse locationFare(
      LocationData from, LocationData to, Long pickupMillis, String vehiclePk, int paymentMethod) {
    ApiRequest req =
        new ApiRequest(
            Office.getApiUrl() + "/passenger/v1/locations/fare",
            TDApplication.getSessionManager().getAccessToken());

    try {
      JSONObject pickup = new JSONObject();
      pickup.put("lat", from.getLatitude());
      pickup.put("lng", from.getLongitude());
      req.addRequestParam("pickup_location", pickup);

      JSONObject dropoff = new JSONObject();
      dropoff.put("lat", to.getLatitude());
      dropoff.put("lng", to.getLongitude());
      req.addRequestParam("dropoff_location", dropoff);

      if (pickupMillis != null) {
        Time t = new Time();
        t.set(pickupMillis);
        String timeStr = t.format3339(false).replace(".000+", "+"); // FIXME API BUG
        req.addRequestParam("pickup_time", timeStr);
      }

      String method = PaymentMethod.CASH_STRING;
      switch (paymentMethod) {
        case PaymentMethod.ACCOUNT:
          method = PaymentMethod.ACCOUNT_STRING;
          break;

        case PaymentMethod.CARD:
          method = PaymentMethod.CARD_STRING;
          break;

        case PaymentMethod.CASH:
        default:
          method = PaymentMethod.CASH_STRING;
          break;
      }
      req.addRequestParam("payment_method", method);

      if (vehiclePk != null) {
        req.addRequestParam("car_type", vehiclePk);
      }

    } catch (Exception e) {
      e.printStackTrace();
    }

    return doPostRequest(req);
  }
Пример #11
0
  /**
   * [ bookings
   * ]****************************************************************************************************
   */
  public ApiResponse bookingsGetAll(String status) {
    ApiRequest req =
        new ApiRequest(
            Office.getApiUrl() + "/passenger/v1/bookings",
            TDApplication.getSessionManager().getAccessToken());

    req.addGetParam("order_by", "-pickup_time");
    req.addGetParam("status", status);
    req.addGetParam("limit", 20);
    req.addGetParam("offset", 0);

    return doGetRequest(req);
  }
Пример #12
0
  public ApiResponse locationSearch(String search, int limit, Boolean narrowToPickupOnly) {
    ApiRequest req =
        new ApiRequest(
            Office.getApiUrl() + "/passenger/v1/locations/search",
            TDApplication.getSessionManager().getAccessToken());

    req.addGetParam("q", search);
    req.addGetParam("limit", limit);
    if (narrowToPickupOnly) {
      req.addGetParam("type", "pickup");
    }

    return doGetRequest(req);
  }
Пример #13
0
  public ApiResponse braintreeWrapperTransactionCreate(BookingData booking, CardData card) {
    ApiRequest req =
        new ApiRequest(
            Office.getBraintreeWrapperUrl(), TDApplication.getSessionManager().getAccessToken());

    req.addGetParam("cmd", "transaction-create");
    req.addGetParam("version", BRAINTREE_WRAPPER_MIN_VERSION);

    req.addPostParam("booking_pk", booking.getPk());
    req.addPostParam("booking_key", booking.getBookingKey());
    req.addPostParam("card_token", card.getToken());
    req.addPostParam("amount", booking.getTotalCostValue());

    return doPostRequest(req);
  }
Пример #14
0
  /**
   * [ drivers
   * ]*****************************************************************************************************
   */
  public ApiResponse getNearbyDrivers(LatLng position) {
    ApiRequest req =
        new ApiRequest(
            Office.getApiUrl() + "/passenger/v1/drivers/nearby",
            TDApplication.getSessionManager().getAccessToken());

    req.addRequestParam("limit", 15); // #of cabs
    req.addRequestParam("radius", 10); // km

    try {
      JSONObject json = new JSONObject();
      json.put("lat", position.latitude);
      json.put("lng", position.longitude);

      req.addRequestParam("location", json);
    } catch (Exception e) {
      e.printStackTrace();
    }

    return doPostRequest(req);
  }