Created
August 23, 2016 20:17
-
-
Save JogoShugh/e2c3aa4d5935e1ed1da48c10bbe0c767 to your computer and use it in GitHub Desktop.
Utilizing Meta's power for maximum flexibility and maximum leverage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using VersionOne.SDK.APIClient; | |
using static System.Console; | |
namespace CreateLinkInVersionOneStory | |
{ | |
public class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
MaximumFlexibility(); // Currently supported approach | |
MaximumLeverage(); // Coming improvements | |
} | |
// This way provides the most flexibility, but it requires more typing | |
public static void MaximumFlexibility() | |
{ | |
var connector = V1Connector | |
.WithInstanceUrl("https://www14.v1host.com/v1sdktesting") | |
.WithUserAgentHeader("CreateLinkOnStory", "0.01") | |
.WithUsernameAndPassword("admin", "admin") | |
.Build(); | |
var services = new Services(connector); | |
var linkMeta = services.Meta.GetAssetType("Link"); | |
var link = services.New(linkMeta, null); | |
var urlAttrib = linkMeta.GetAttributeDefinition("URL"); | |
var nameAttrib = linkMeta.GetAttributeDefinition("Name"); | |
var onMenuAttrib = linkMeta.GetAttributeDefinition("OnMenu"); | |
var assetAttrib = linkMeta.GetAttributeDefinition("Asset"); | |
link.SetAttributeValue(urlAttrib, "http://www.versionone.com"); | |
link.SetAttributeValue(nameAttrib, "Link to VersionOne"); | |
link.SetAttributeValue(onMenuAttrib, false); | |
link.SetAttributeValue(assetAttrib, "Story:90295"); | |
services.Save(link); | |
WriteLine(link.Oid.Token); | |
} | |
// This way provides less flexibility, but reduces typing for the most common cases | |
public static void MaximumLeverage() | |
{ | |
var client = V1Client | |
.WithInstanceUrl("https://www14.v1host.com/v1sdktesting") | |
.WithUserAgentHeader("CreateLinkOnStory", "0.01") | |
.WithUsernameAndPassword("admin", "admin") | |
.Build(); | |
var asset = client.Create("Link", new | |
{ | |
Asset = "Story:90295", | |
URL = "http://www.versionone.com", | |
Name = "This is the link to VersionOne", | |
OnMenu = false | |
}); | |
WriteLine(asset.OidToken); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment