Welcome to mirror list, hosted at ThFree Co, Russian Federation.

BookmarkPaymentDataParser.java « bookmarks « maps « mapswithme « com « src « android - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8bc2e5718890b3a76969838161892e0f3497154c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package com.mapswithme.maps.bookmarks;

import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log;

import com.mapswithme.maps.bookmarks.data.PaymentData;
import com.mapswithme.util.CrashlyticsUtils;

class BookmarkPaymentDataParser implements PaymentDataParser
{
  private static final String TAG = BookmarkPaymentDataParser.class.getSimpleName();

  final static String SERVER_ID = "id";
  final static String PRODUCT_ID = "tier";
  final static String NAME = "name";
  final static String IMG_URL = "img";
  final static String AUTHOR_NAME = "author_name";

  @NonNull
  @Override
  public PaymentData parse(@NonNull String url)
  {
    Uri uri = Uri.parse(url);
    String serverId = getQueryRequiredParameter(uri, SERVER_ID);
    String productId = getQueryRequiredParameter(uri, PRODUCT_ID);
    String name = getQueryRequiredParameter(uri, NAME);
    String authorName = getQueryRequiredParameter(uri, AUTHOR_NAME);
    String imgUrl = uri.getQueryParameter(IMG_URL);
    return new PaymentData(serverId, productId, name, imgUrl, authorName);
  }

  @Nullable
  String getParameter(@NonNull String url, @NonNull String parameterName)
  {
    Uri uri = Uri.parse(url);
    return uri.getQueryParameter(parameterName);
  }

  @NonNull
  private static String getQueryRequiredParameter(@NonNull Uri uri, @NonNull String name)
  {
    String parameter = uri.getQueryParameter(name);
    if (TextUtils.isEmpty(parameter))
    {
      CrashlyticsUtils.logException(
        new IllegalArgumentException("'" + name + "' parameter is required! URI: " + uri));
      return "";
    }

    return parameter;
  }
}