Adding installation parameters to a contentful App - contentful

Struggling to find a working example or a document that explains how to set contentful app installation params. I can see how to get them from the SDK but settings them i cant.
any help is much appreciated.

Most likely your app has a Config Location which means you are building UI that will be shown to the user during and after installation of your app. In this location, there is an SDK method called sdk.app.onConfigure. This method takes a function which will return an object which is called targetState.
targetState documentation can be found here.
Let's take a React Config app as an example where we will set {foo: 'bar'} as our installation parameters:
export default class Config extends Component<ConfigProps, ConfigState> {
constructor(props: ConfigProps) {
super(props);
// letting the SDK know we have a configuration function which will
// return `targetState`
props.sdk.app.onConfigure(() => this.onConfigure());
}
// This method will be called when a user clicks on "Install"
// or "Save" on the configuration screen.
onConfigure = async () => {
// the object returned here is what Contentful calls `targetState`.
// it is simply a configuration object set when the app is installed or updated
return {
parameters: { installation: { foo: 'bar' } }
};
};
In the example above, when a user hits "Install" or "Save" on the app's Config location, the installation parameter object of {foo: 'bar'} will be saved and can then be accessed in other app locations via the SDK.
On the off chance you are purely using the API to create or modify an AppInstallation, you can use the Content Management API to update the app's parameters as described in the documentation here.

Late answer but i also struggled with it. I found a tutorial here:
https://dev.to/wiommi/how-i-built-a-contentful-app-combined-with-commerce-js-iii-33fo
They are added manually in ConfigScreen.tsx
You need to add them to your interface
export interface AppInstallationParameters {}
fx:
export interface AppInstallationParameters {
apiKey?: string;
projectId?: string;
}
And then set them manually with fx.
setParameters({ ...parameters, [PARAMETERNAME]: [PARAMETERVALUE] });

Related

Access Playfab data with Azure functions

How can I access to read/write/modify/delete Playfab data with Azure functions?
Below Steps will help you in accessing the azure functions with Playfab
Create Azure Function in VS Code
Deploy the azure function to portal and register your function with cloud script
Below is the sample example code for calling cloud script using azure functions from your playfab.
//This snippet assumes that your game client is already logged into PlayFab.
using PlayFab;
using PlayFab.CloudScriptModels;
private void CallCSharpExecuteFunction()
{
PlayFabCloudScriptAPI.ExecuteFunction(new ExecuteFunctionRequest()
{
Entity = new PlayFab.CloudScriptModels.EntityKey()
{
Id = PlayFabSettings.staticPlayer.EntityId, //Get this from when you logged in,
Type = PlayFabSettings.staticPlayer.EntityType, //Get this from when you logged in
},
FunctionName = "HelloWorld", //This should be the name of your Azure Function that you created.
FunctionParameter = new Dictionary<string, object>() { { "inputValue", "Test" } }, //This is the data that you would want to pass into your function.
GeneratePlayStreamEvent = false //Set this to true if you would like this call to show up in PlayStream
}, (ExecuteFunctionResult result) =>
{
if (result.FunctionResultTooLarge ?? false)
{
Debug.Log("This can happen if you exceed the limit that can be returned from an Azure Function, See PlayFab Limits Page for details.");
return;
}
Debug.Log($"The {result.FunctionName} function took {result.ExecutionTimeMilliseconds} to complete");
Debug.Log($"Result: {result.FunctionResult.ToString()}");
}, (PlayFabError error) =>
{
Debug.Log($"Opps Something went wrong: {error.GenerateErrorReport()}");
});
}
PlayFab CloudScript Context, Variables and Server SDKs
You will need to install the PlayFab SDK via Package Manager. To do this open Terminal or CMD Console in Visual Studio Code and type: dotnet add package PlayFabAllSDK
We have created some helpers that will ship with the cSharpSDK.
You need to edit your .csproj file and include <DefineConstants>NETCOREAPP2_0</DefineConstants> in your default PropertyGroup or NETCOREAPP3_1 if you are using the latest.
Execution of a script can occur through several methods (APIs, Scheduled Tasks, PlayStream Event, Segment Entering and Exit method). The context of the execution is important to implement your CloudScript. See the Using CloudScript context models tutorial for details on how to use the context of the script.
For further information check Cloud Script Using Azure Functions and Playfab Cloud Script

Add Custom Endpoint For Service ( Feathersjs )

I am new to NodeJS world.
I found FeatherJS is a awesome tools/framework to build API service with very less Coding
I need to add a custom service endpoint (like : localhost/servicename/custom-end-point ). I also need to grab data from user in those end-point (could be a get request or post).
I have already gone through followings links, but nothing is clearly mention there,
https://docs.feathersjs.com/guides/basics/services.html
https://docs.feathersjs.com/api/services.html
Install feathers-cli using the following command: npm install -g #feathersjs/cli.
To create a service, navigate to your project directory and run this command feathers generate service. It will ask some questions like service name.
If you don't already have an app then run this command to create one: feathers generate app.
Thats it!
Update:
Lets assume you have a service named organizations and you want to create a custom endpoint like custom-organization. Now, create a file inside services > organizations named custom-organizations.class.js. Add the following line in your organizations.service.js file.
// Import custom class
const { CustomOrganizations } = require('./custom-organizations.class');
// Initialize custom endpoint
app.use('/custom-organizations', new CustomOrganizations(options, app));
Add the following code in your custom-organizations.class.js file.
const { Service } = require('feathers-mongoose');
exports.CustomOrganizations = class CustomOrganizations extends Service {
constructor(options, app) {
super(options);
}
async find() {
return 'Test data';
}
};
Now, if you send a get request to /custom-organizations endpoint then you should get Test data.
Hope it helps.
Wrote an article about it here.

Events not tracked in App Center

I am trying new Visual Studio App Center platform for mobile apps. It gives me the crashes and the installed versions OK, so the app secret and SDK are configured OK.
But when I try to track custom Events, according to this tutorial I get "No events found" in the Mobile Center dashboard. I try with my app in release and debug mode, without results.
My code (Xamarin.Forms):
public MyClass()
{
InitializeComponent();
Analytics.SetEnabledAsync(true);
Analytics.TrackEvent("Video clicked", new Dictionary<string, string> {
{ "Category", "Music" },
{ "FileName", "favorite.avi"}
});
}
There is the constructor, so I am sure that these lines are executed.
MobileCenter.Start needs to be called before Analytics.TrackEvent or Analytics.SetEnabledAsync.
If you are using constructor, then you need to move MobileCenter.Start to constructor as well.
Your solution is working probably because you made that code execute later (and thus after MobileCenter.Start) with async but you don't need to do that (and you don't need to call SetEnabledAsync at all, it's true by default and persisted).
Solved. I need to execute the lines in an async method, not in the constructor.

Using hooks to trigger a process

I am trying to work out how to use the Hooks and just can't seem to get the syntax correct.
I have built a site using PirahnaCMS that has a blog component and am extending it to call some social plugins and auto post to FB, Twitter etc.
I just can't seem to get the syntax correct though. My app is MVC and I have looked at this section
1.2 ASP.NET MVC
If you're using ASP.NET MVC hooks should be attached in you Global.asax.cs in the Application_Start method, or any other place where you keep you startup code. You attach you hooks with the followin syntax:
protected void Application_Start() {
Piranha.WebPages.Hooks.Menu.RenderItemLink = (ui, str, title, url) => {
str.Append(String.Format("<span>{1}</span>", url, title)) ;
} ;
}
The Hook I believe I want to use is Piranha.WebPages.Hooks.Manager.PostEditModelAfterSave but for the life of me I can't seem to work it out.
All of the hooks are just static delegates that you can attach methods to. In the above example an anonymous method has been assigned to the hook with the syntax:
delegate += (parameters) => { method body }
You could also assign a previously declared method.
delegate += MyMethod
Example skeletons for attaching hooks should be available in the Docs at the official site. If not you can find the hooks in the file:
~/WebPages/Hooks.cs
And all delegates in:
~/Delegates.cs
I hope these URL:s are correct as I'm typing from memory :)
Regards

How to navigate in Gradle API documentation?

This could be a unusual question. I have a problem with navigating in gradle groovy api doc. For example see following code,
uploadArchives {
repositories {
ivy {
credentials {
username "username"
password "pw"
}
url "http://repo.mycompany.com"
}
}
}
In above code how can i find what goes into "credentials" closure in api documentaion ?
Thanks
I'm quite new to Gradle myself, but this is what I would do:
Start from Project as the build script is always executed against a Project instance
Look for repositories { }
It mentions RepositoryHandler, so look for ivy { } there
ivy() returns a IvyArtifactRepository, so I guess the closure will be executed against that
However there is no credentials { } defined on IvyArtifactRepository
Jump to its API doc to check its superclasses (link on the top of the page)
You can see there that credentials is defined on AuthenticationSupported
PasswordCredentials is mentioned there, and finally you see that it only has username and password properties
It's not always very intuitive, and I miss code completion a lot, but once you get the hang of it, it becomes easier to find your way through the documentation.

Resources