Пример #1
0
 /**
  * [ vehicles
  * ]****************************************************************************************************
  */
 public ApiResponse getVehicleTypes() {
   ApiRequest req =
       new ApiRequest(
           Office.getApiUrl() + "/passenger/v1/vehicletypes",
           TDApplication.getSessionManager().getAccessToken());
   return doGetRequest(req);
 }
Пример #2
0
 public ApiResponse getAccountProfile() {
   ApiRequest req =
       new ApiRequest(
           Office.getApiUrl() + "/passenger/v1/accounts/preferences",
           TDApplication.getSessionManager().getAccessToken());
   return doGetRequest(req);
 }
Пример #3
0
 public ApiResponse getAccountFleetData() {
   ApiRequest req =
       new ApiRequest(
           Office.getApiUrl() + "/passenger/v1/accounts/fleetdata",
           TDApplication.getSessionManager().getAccessToken());
   return doGetRequest(req);
 }
Пример #4
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);
 }
Пример #5
0
  public ApiResponse refreshOAuthAccessToken(String refreshToken) {
    ApiRequest req = new ApiRequest(Office.getApiUrl() + "/passenger/oauth2/token");
    req.addPostParam("refresh_token", refreshToken);
    req.addPostParam("client_id", Office.getOAuthClientId());
    req.addPostParam("client_secret", Office.getOAuthSecret());
    req.addPostParam("grant_type", "refresh_token");

    return doPostRequest(req);
  }
Пример #6
0
  /**
   * [ helpers
   * ]******************************************************************************************
   */
  public ApiResponse getOAuthTokens(String tmpAuthCode) {
    ApiRequest req = new ApiRequest(Office.getApiUrl() + "/passenger/oauth2/token");
    req.addPostParam("code", tmpAuthCode);
    req.addPostParam("client_id", Office.getOAuthClientId());
    req.addPostParam("client_secret", Office.getOAuthSecret());
    req.addPostParam("redirect_url", "");
    req.addPostParam("grant_type", "authorization_code");

    return doPostRequest(req);
  }
Пример #7
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);
  }
Пример #8
0
  public ApiResponse bookingsNewBooking(JSONObject newBookingJson) {

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

    return doPostRequest(req);
  }
Пример #9
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);
  }
Пример #10
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);
  }
Пример #11
0
  // Accounts
  public ApiResponse accountCreate(AccountData account) {
    ApiRequest req = new ApiRequest(Office.getApiUrl() + "/passenger/v1/accounts");
    req.addGetParam("key", Office.getFleetApiKey());

    req.addRequestParam("first_name", account.getFirstName());
    req.addRequestParam("last_name", account.getLastName());
    req.addRequestParam("email", account.getEmail());
    req.addRequestParam("phone", account.getPhone());
    req.addRequestParam("password", account.getPassword());

    req.addRequestParam("client_id", Office.getOAuthClientId());

    return doPostRequest(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
  /**
   * [ 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);
  }