Search in sources :

Example 1 with Plan

use of org.wordpress.android.ui.plans.models.Plan in project WordPress-Android by wordpress-mobile.

the class RemoteTests method testSitePlans.

public void testSitePlans() throws Exception {
    PlansRestRequestAbstractListener listener = new PlansRestRequestAbstractListener() {

        @Override
        void parseResponse(JSONObject response) throws JSONException {
            List<Plan> plans = new ArrayList<>();
            JSONArray plansArray = response.getJSONArray("originalResponse");
            for (int i = 0; i < plansArray.length(); i++) {
                JSONObject currentPlanJSON = plansArray.getJSONObject(i);
                Plan currentPlan = new Plan(currentPlanJSON);
                plans.add(currentPlan);
            }
            assertEquals(3, plans.size());
            Plan currentPlan = plans.get(0);
            assertEquals(currentPlan.getDescription(), "Get a free blog and be on your way to publishing your first post in less than five minutes.");
            assertEquals(currentPlan.getProductID(), 1L);
            assertEquals(currentPlan.getProductName(), "WordPress.com Free");
            assertEquals(currentPlan.getBillPeriod(), -1);
            assertEquals(currentPlan.getRawPrice(), 0);
            assertEquals(currentPlan.getCost(), 0);
            assertEquals(currentPlan.isAvailable(), true);
            currentPlan = plans.get(1);
            assertEquals(currentPlan.isFreeTrial(), false);
            assertEquals(currentPlan.getBundleSubscriptionID(), "5683566");
            assertEquals(currentPlan.getExpiry(), "2017-03-07");
            assertEquals(currentPlan.getUserFacingExpiry(), "2017-03-04");
            assertEquals(currentPlan.getSubscribedDate(), "2016-03-07 08:56:13");
            currentPlan = plans.get(2);
            assertEquals(currentPlan.getDescription(), "Everything included with Premium, as well as live chat support, and unlimited access to our premium themes.");
            assertEquals(currentPlan.getProductID(), 1008L);
            assertEquals(currentPlan.getProductName(), "WordPress.com Business");
            assertEquals(currentPlan.getBillPeriod(), 365);
            assertEquals(currentPlan.getRawPrice(), 199);
            assertEquals(currentPlan.getCost(), 199);
            assertEquals(currentPlan.isAvailable(), true);
        }
    };
    mRestClientV1_2.makeRequest(Request.Method.POST, "https://public-api.wordpress.com/rest/v1.2/sites/123456/plans", null, listener, errListener);
}
Also used : JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) Plan(org.wordpress.android.ui.plans.models.Plan)

Example 2 with Plan

use of org.wordpress.android.ui.plans.models.Plan in project WordPress-Android by wordpress-mobile.

the class PlanUpdateService method downloadAvailablePlansForSite.

/*
     * download plans for the specific site
     */
private void downloadAvailablePlansForSite() {
    // This should live in a PlanStore (FluxC side)
    long remoteBlogId = mSite.getSiteId();
    WordPress.getRestClientUtilsV1_2().get("sites/" + remoteBlogId + "/plans", RestClientUtils.getRestLocaleParams(PlanUpdateService.this), null, new RestRequest.Listener() {

        @Override
        public void onResponse(JSONObject response) {
            if (response == null) {
                AppLog.w(AppLog.T.PLANS, "Unexpected empty response from server");
                requestFailed();
                return;
            }
            AppLog.d(AppLog.T.PLANS, response.toString());
            mSitePlans.clear();
            try {
                JSONArray plansArray = response.getJSONArray("originalResponse");
                for (int i = 0; i < plansArray.length(); i++) {
                    JSONObject currentPlanJSON = plansArray.getJSONObject(i);
                    Plan currentPlan = new Plan(currentPlanJSON);
                    mSitePlans.add(currentPlan);
                }
                requestCompleted();
            } catch (JSONException e) {
                AppLog.e(AppLog.T.PLANS, "Can't parse the plans list returned from the server", e);
                requestFailed();
            }
        }
    }, new RestRequest.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError volleyError) {
            AppLog.e(AppLog.T.UTILS, "Error downloading site plans", volleyError);
            requestFailed();
        }
    });
}
Also used : VolleyError(com.android.volley.VolleyError) RestRequest(com.wordpress.rest.RestRequest) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) Plan(org.wordpress.android.ui.plans.models.Plan)

Example 3 with Plan

use of org.wordpress.android.ui.plans.models.Plan in project WordPress-Android by wordpress-mobile.

the class PlansActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ((WordPress) getApplication()).component().inject(this);
    setContentView(R.layout.plans_activity);
    if (savedInstanceState != null) {
        mSelectedSite = (SiteModel) savedInstanceState.getSerializable(WordPress.SITE);
        Serializable serializable = savedInstanceState.getSerializable(ARG_LOCAL_AVAILABLE_PLANS);
        if (serializable instanceof Plan[]) {
            mAvailablePlans = (Plan[]) serializable;
        }
    } else if (getIntent() != null && getIntent().getExtras() != null) {
        mSelectedSite = (SiteModel) getIntent().getExtras().getSerializable(WordPress.SITE);
    }
    if (mSelectedSite == null) {
        AppLog.e(T.PLANS, "Selected site is null");
        Toast.makeText(this, R.string.plans_loading_error, Toast.LENGTH_LONG).show();
        finish();
        return;
    }
    mViewPager = (WPViewPager) findViewById(R.id.viewpager);
    mTabLayout = (TabLayout) findViewById(R.id.tab_layout);
    mManageBar = (ViewGroup) findViewById(R.id.frame_manage);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            onBackPressed();
        }
    });
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        // Shadow removed on Activities with a tab toolbar
        actionBar.setTitle(getString(R.string.plans));
        actionBar.setElevation(0.0f);
        actionBar.setDisplayShowTitleEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    // Download plans if not already available
    if (mAvailablePlans == null) {
        if (!NetworkUtils.checkConnection(this)) {
            finish();
            return;
        }
        showProgress();
        PlanUpdateService.startService(this, mSelectedSite);
    } else {
        setupPlansUI();
    }
    // navigate to the "manage plans" page for this blog when the user clicks the manage bar
    mManageBar.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            String domain = UrlUtils.getHost(mSelectedSite.getUrl());
            String managePlansUrl = "https://wordpress.com/plans/" + domain;
            ReaderActivityLauncher.openUrl(view.getContext(), managePlansUrl, OpenUrlType.EXTERNAL);
        }
    });
}
Also used : Serializable(java.io.Serializable) SiteModel(org.wordpress.android.fluxc.model.SiteModel) Plan(org.wordpress.android.ui.plans.models.Plan) View(android.view.View) ActionBar(android.support.v7.app.ActionBar) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

Plan (org.wordpress.android.ui.plans.models.Plan)3 JSONArray (org.json.JSONArray)2 JSONObject (org.json.JSONObject)2 ActionBar (android.support.v7.app.ActionBar)1 Toolbar (android.support.v7.widget.Toolbar)1 View (android.view.View)1 VolleyError (com.android.volley.VolleyError)1 RestRequest (com.wordpress.rest.RestRequest)1 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 JSONException (org.json.JSONException)1 SiteModel (org.wordpress.android.fluxc.model.SiteModel)1