예제 #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 getAccountFleetData() {
   ApiRequest req =
       new ApiRequest(
           Office.getApiUrl() + "/passenger/v1/accounts/fleetdata",
           TDApplication.getSessionManager().getAccessToken());
   return doGetRequest(req);
 }
예제 #3
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);
  }
예제 #4
0
 public ApiResponse getAccountProfile() {
   ApiRequest req =
       new ApiRequest(
           Office.getApiUrl() + "/passenger/v1/accounts/preferences",
           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);
  }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

      View view = convertView;
      if (view == null) {
        int layoutId = R.layout.search_address_row;

        LayoutInflater li =
            (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = li.inflate(layoutId, null);

        WebnetTools.setCustomFonts(TDApplication.getAppContext(), (ViewGroup) view);
      }

      WebnetTools.setText(view, R.id.item_address, mItems.get(position).getAddress());
      view.setTag(R.id.tag_key_position, position);
      view.setOnClickListener(mOnClickListener);

      return (view);
    }
예제 #15
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);
  }
    @Override
    protected Integer doInBackground(String... params) {

      String queryString = params[0];

      try {
        ApiHelper api = ApiHelper.getInstance(TDApplication.getAppContext());

        ApiResponse response = api.locationSearch(queryString, 10, false);
        if (response.getErrorCode() == Const.ErrorCode.OK) {
          mPredictionsArray = new ArrayList<LocationData>();

          JSONArray locations = JsonTools.getJSONArray(response.getJSONObject(), "locations");
          for (int i = 0; i < locations.length(); i++) {
            LocationData loc = new LocationData((JSONObject) locations.get(i));
            mPredictionsArray.add(loc);
          }
        }
      } catch (Exception e) {
        e.printStackTrace();
      }

      return 0;
    }
예제 #17
0
/*
 ******************************************************************************
 *
 * Copyright 2013 Webnet Marcin Orłowski
 *
 * Licensed under the GPL License, Version 3.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.gnu.org/licenses/gpl-3.0.html
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 ******************************************************************************
 *
 * @author Marcin Orlowski <*****@*****.**>
 *
 ******************************************************************************
 */
public final class WebnetLog {
  // FIXME - we shall make this class abstract and put TAG in extending class!
  protected static final String TAG = "Passenger";

  protected static final Boolean ENABLED = TDApplication.isDebuggable();

  protected static final Boolean ENABLE_I = (ENABLED == false) ? false : true;
  protected static final Boolean ENABLE_W = (ENABLED == false) ? false : true;
  protected static final Boolean ENABLE_E = (ENABLED == false) ? false : true;
  protected static final Boolean ENABLE_D = (ENABLED == false) ? false : true;

  // NOTE: it's important to understand what we got on stack and NOT
  // call this method directly or the output will be WRONG!
  //
  // 0: getCallerTrace() (this)
  // 1: formatMessage()
  // 2: one of local calling methods (i.e. WebnetLog.i())
  // 3: caller class and method
  //
  // FIXME we could work that out by analyzing stack and skipping all invocation from
  // this class but as for now it's not done, so beware!

  protected static String getCallerTrace() {
    return getCallerTrace(4);
  }

  protected static String getCallerTrace(int depth) {
    Throwable throwable = new Throwable();
    StackTraceElement[] stackTrace = throwable.getStackTrace();

    String callerMethod = stackTrace[depth].getMethodName();
    String callerClass = stackTrace[depth].getClassName();
    int lineNumber = stackTrace[depth].getLineNumber();

    String[] nameParts = callerClass.split("\\.");
    callerClass = nameParts[nameParts.length - 1];

    //		Log.i("TA", callerMethod: " + callerMethod + ", callerClass: " + callerClass );

    return (callerClass + "/" + callerMethod + "()[+" + lineNumber + "]");
  }

  protected static String formatMessage() {
    return (WebnetLog.getCallerTrace());
  }

  protected static String formatMessage(String message) {
    return (WebnetLog.getCallerTrace() + ": " + message);
  }

  protected static String formatMessage(String tag, String message) {
    return (tag + ": " + WebnetLog.getCallerTrace() + ": " + message);
  }

  public static void i() {
    _i(WebnetLog.TAG, WebnetLog.formatMessage());
  }

  public static void i(int message) {
    i("(int): " + message);
  }

  public static void i(String message) {
    _i(WebnetLog.TAG, WebnetLog.formatMessage(message));
  }

  public static void i(String tag, String message) {
    Log.i(WebnetLog.TAG, WebnetLog.formatMessage(tag, message));
  }

  public static void i(String message, Throwable tr) {
    _i(WebnetLog.TAG, WebnetLog.formatMessage(message + " " + tr.getMessage()));
  }

  public static void i(String tag, String message, Throwable tr) {
    _i(WebnetLog.TAG, WebnetLog.formatMessage(tag, message + " " + tr.getMessage()));
  }

  protected static void _i(String tag, String msg) {
    if (ENABLE_I) {
      Log.i(tag, msg);
    }
  }

  public static void w() {
    _w(WebnetLog.TAG, WebnetLog.formatMessage());
  }

  public static void w(String message) {
    _w(WebnetLog.TAG, WebnetLog.formatMessage(message));
  }

  public static void w(String tag, String message) {
    _w(WebnetLog.TAG, WebnetLog.formatMessage(tag, message));
  }

  public static void w(String message, Throwable tr) {
    _w(WebnetLog.TAG, WebnetLog.formatMessage(message + " " + tr.getMessage()));
  }

  public static void w(String tag, String message, Throwable tr) {
    _w(WebnetLog.TAG, WebnetLog.formatMessage(tag, message + " " + tr.getMessage()));
  }

  protected static void _w(String tag, String msg) {
    if (ENABLE_W) {
      Log.w(tag, msg);
    }
  }

  public static void e() {
    _e(WebnetLog.TAG, WebnetLog.formatMessage());
  }

  public static void e(String message) {
    _e(WebnetLog.TAG, WebnetLog.formatMessage(message));
  }

  public static void e(String tag, String message) {
    _e(WebnetLog.TAG, WebnetLog.formatMessage(tag, message));
  }

  public static void e(String message, Throwable tr) {
    _e(WebnetLog.TAG, WebnetLog.formatMessage(message + " " + tr.getMessage()));
  }

  public static void e(String tag, String message, Throwable tr) {
    _e(WebnetLog.TAG, WebnetLog.formatMessage(tag, message + " " + tr.getMessage()));
  }

  protected static void _e(String tag, String msg) {
    if (ENABLE_E) {
      Log.e(tag, msg);
    }
  }

  public static void d() {
    _d(WebnetLog.TAG, WebnetLog.formatMessage());
  }

  public static void d(String message) {
    _d(WebnetLog.TAG, WebnetLog.formatMessage(message));
  }

  public static void d(String tag, String message) {
    _d(WebnetLog.TAG, WebnetLog.formatMessage(tag, message));
  }

  public static void d(String message, Throwable tr) {
    _d(WebnetLog.TAG, WebnetLog.formatMessage(message + " " + tr.getMessage()));
  }

  public static void d(String tag, String message, Throwable tr) {
    _d(WebnetLog.TAG, WebnetLog.formatMessage(tag, message + " " + tr.getMessage()));
  }

  protected static void _d(String tag, String msg) {
    if (ENABLE_D) {
      Log.d(tag, msg);
    }
  }
} // end of class