Search in sources :

Example 6 with ShareOpenGraphAction

use of com.facebook.share.model.ShareOpenGraphAction in project facebook-android-sdk by facebook.

the class ShareContentValidationTest method testItValidatesShareOpenGraphWithPreviewPropertyNameByMessage.

@Test(expected = FacebookException.class)
public void testItValidatesShareOpenGraphWithPreviewPropertyNameByMessage() {
    ShareOpenGraphAction shareOpenGraphAction = new ShareOpenGraphAction.Builder().setActionType("foo").build();
    ShareOpenGraphContent shareOpenGraphContent = new ShareOpenGraphContent.Builder().setAction(shareOpenGraphAction).build();
    ShareContentValidation.validateForMessage(shareOpenGraphContent);
}
Also used : ShareOpenGraphAction(com.facebook.share.model.ShareOpenGraphAction) ShareOpenGraphContent(com.facebook.share.model.ShareOpenGraphContent) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 7 with ShareOpenGraphAction

use of com.facebook.share.model.ShareOpenGraphAction in project facebook-android-sdk by facebook.

the class ShareContentValidationTest method testItValidateShareOpenGraphWithNoTypeByMessage.

@Test(expected = FacebookException.class)
public void testItValidateShareOpenGraphWithNoTypeByMessage() {
    ShareOpenGraphAction shareOpenGraphAction = new ShareOpenGraphAction.Builder().setActionType(null).build();
    ShareOpenGraphContent shareOpenGraphContent = new ShareOpenGraphContent.Builder().setAction(shareOpenGraphAction).build();
    ShareContentValidation.validateForMessage(shareOpenGraphContent);
}
Also used : ShareOpenGraphAction(com.facebook.share.model.ShareOpenGraphAction) ShareOpenGraphContent(com.facebook.share.model.ShareOpenGraphContent) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 8 with ShareOpenGraphAction

use of com.facebook.share.model.ShareOpenGraphAction in project facebook-android-sdk by facebook.

the class ShareContentValidationTest method testItAcceptsShareOpenGraphContent.

@Test
public void testItAcceptsShareOpenGraphContent() {
    String actionKey = "foo";
    String actionValue = "fooValue";
    ShareOpenGraphAction shareOpenGraphAction = new ShareOpenGraphAction.Builder().putString(actionKey, actionValue).setActionType(actionKey).build();
    ShareOpenGraphContent shareOpenGraphContent = new ShareOpenGraphContent.Builder().setPreviewPropertyName(actionKey).setAction(shareOpenGraphAction).build();
    ShareContentValidation.validateForMessage(shareOpenGraphContent);
    ShareContentValidation.validateForNativeShare(shareOpenGraphContent);
    ShareContentValidation.validateForApiShare(shareOpenGraphContent);
    ShareContentValidation.validateForWebShare(shareOpenGraphContent);
}
Also used : ShareOpenGraphAction(com.facebook.share.model.ShareOpenGraphAction) ShareOpenGraphContent(com.facebook.share.model.ShareOpenGraphContent) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 9 with ShareOpenGraphAction

use of com.facebook.share.model.ShareOpenGraphAction in project react-native-fbsdk by facebook.

the class Utility method buildShareOpenGraphAction.

public static ShareOpenGraphAction buildShareOpenGraphAction(ReadableMap shareOpenGraphActionMap) {
    ShareOpenGraphAction.Builder contentBuilder = new ShareOpenGraphAction.Builder();
    contentBuilder.setActionType(shareOpenGraphActionMap.getString("actionType"));
    ReadableMap properties = shareOpenGraphActionMap.getMap("_properties");
    ReadableMapKeySetIterator keySetIterator = properties.keySetIterator();
    while (keySetIterator.hasNextKey()) {
        String key = keySetIterator.nextKey();
        ReadableMap entry = properties.getMap(key);
        contentBuilder.putObject(key, buildShareOpenGraphObject(entry.getMap("value")));
    }
    return contentBuilder.build();
}
Also used : ReadableMapKeySetIterator(com.facebook.react.bridge.ReadableMapKeySetIterator) ShareOpenGraphAction(com.facebook.share.model.ShareOpenGraphAction) ReadableMap(com.facebook.react.bridge.ReadableMap)

Example 10 with ShareOpenGraphAction

use of com.facebook.share.model.ShareOpenGraphAction in project facebook-android-sdk by facebook.

the class RequestTests method testShareOpenGraphContent.

@LargeTest
public void testShareOpenGraphContent() throws Exception {
    ShareOpenGraphObject ogObject = new ShareOpenGraphObject.Builder().putString("og:title", "a title").putString("og:type", TEST_OG_OBJECT_TYPE).putString("og:description", "a description").build();
    ShareOpenGraphAction ogAction = new ShareOpenGraphAction.Builder().setActionType(TEST_OG_ACTION_TYPE).putObject("test", ogObject).build();
    ShareOpenGraphContent content = new ShareOpenGraphContent.Builder().setAction(ogAction).setPreviewPropertyName("test").build();
    final ShareApi shareApi = new ShareApi(content);
    final AtomicReference<String> actionId = new AtomicReference<>(null);
    getActivity().runOnUiThread(new Runnable() {

        @Override
        public void run() {
            shareApi.share(new FacebookCallback<Sharer.Result>() {

                @Override
                public void onSuccess(Sharer.Result result) {
                    actionId.set(result.getPostId());
                    notifyShareFinished();
                }

                @Override
                public void onCancel() {
                    notifyShareFinished();
                }

                @Override
                public void onError(FacebookException error) {
                    notifyShareFinished();
                }

                private void notifyShareFinished() {
                    synchronized (shareApi) {
                        shareApi.notifyAll();
                    }
                }
            });
        }
    });
    synchronized (shareApi) {
        shareApi.wait(REQUEST_TIMEOUT_MILLIS);
    }
    assertNotNull(actionId.get());
}
Also used : ShareOpenGraphAction(com.facebook.share.model.ShareOpenGraphAction) ShareOpenGraphObject(com.facebook.share.model.ShareOpenGraphObject) AtomicReference(java.util.concurrent.atomic.AtomicReference) ShareOpenGraphContent(com.facebook.share.model.ShareOpenGraphContent) Sharer(com.facebook.share.Sharer) ShareApi(com.facebook.share.ShareApi) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Aggregations

ShareOpenGraphAction (com.facebook.share.model.ShareOpenGraphAction)10 ShareOpenGraphContent (com.facebook.share.model.ShareOpenGraphContent)7 ShareOpenGraphObject (com.facebook.share.model.ShareOpenGraphObject)4 Sharer (com.facebook.share.Sharer)3 SharePhoto (com.facebook.share.model.SharePhoto)3 Test (org.junit.Test)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 Bitmap (android.graphics.Bitmap)2 LargeTest (android.test.suitebuilder.annotation.LargeTest)2 ShareApi (com.facebook.share.ShareApi)2 ArrayList (java.util.ArrayList)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 FacebookException (com.facebook.FacebookException)1 LoginResult (com.facebook.login.LoginResult)1 ReadableMap (com.facebook.react.bridge.ReadableMap)1 ReadableMapKeySetIterator (com.facebook.react.bridge.ReadableMapKeySetIterator)1 ShareLinkContent (com.facebook.share.model.ShareLinkContent)1 Photo (com.kickstarter.models.Photo)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1