YouscribeNet

YouScribe REST client for .NET to manage accounts and publications


Project maintained by Youscribe Hosted on GitHub Pages — Theme by mattgraham

YouScribeNet

YouScribeNet is a .NET REST client to manage accounts and publications

Getting Started

Easy installing using nuget

Exemples

Publish new document

To publish a new document, you need to be registered.
See the register exemple
You can publish a document with different formats

                    
var client = new YouScribeClient();
//need to be authorized to publish a document
if (client.Authorize("user_name", "password") == true)
{
    var productRequest = client.CreateProductRequest();
    
    //Publish the document named "my document" using a pdf and an epub file
    var product = productRequest.PublishDocument(
        new YouScribe.Rest.Models.Products.ProductModel 
        {
            Title = "my document",
            AllowDownload = true,
            AllowStreaming = true,
            Public = true
        },
        new[] {
            new YouScribe.Rest.Models.FileModel { 
                Content = File.OpenRead(pdf_file), 
                ContentType = "application/pdf", 
                FileName= "my document.pdf"  },
            new YouScribe.Rest.Models.FileModel { 
                Content = File.OpenRead(epub_file),
                ContentType = "application/epub+zip",
                FileName= "my document.epub"  }
        }
    );

    //Publish the document named "my document 2" using a pdf link
    var product2 = productRequest.PublishDocument(
        new YouScribe.Rest.Models.Products.ProductModel 
        {
            Title = "my document 2",
            AllowDownload = true,
            AllowStreaming = true,
            Public = true
        },
        new[] {
            new Uri("http://mysite.com/my_document.pdf")
        }
    );
}
                    
                

The PublishDocument method returns the product published

Update a document

You can update all the publications related to you.
You can update the documents of your publication.
You cannot set publication as free if it's not free or not free if it's free.

                    
var client = new YouScribeClient();
//need to be authorized to update a document
if (client.Authorize("user_name", "password") == true)
{
    var productRequest = client.CreateProductRequest();
    
    //Update a product to private and upload a new pdf file
    //productId represent the id of the product published (ProductModel.Id)
    var ok = productRequest.UpdateDocument(productId,
        new YouScribe.Rest.Models.Products.ProductUpdateModel
        {
            Public = false
        },
        new[] { new YouScribe.Rest.Models.FileModel { 
            Content = File.OpenRead(updateFile),
            ContentType = "application/pdf", 
            FileName = "my document2.pdf" } }
    );
}
                

Update the document thumbnail

You can update the document thumbnail using a local image, an url image or a page in the document

                    
var client = new YouScribeClient();
//need to be authorized to update the thumbnail
if (client.Authorize("user_name", "password") == true)
{
    var productRequest = client.CreateProductRequest();
    
    // update the document thumbnail using the page 4 of the document
    productRequest.UpdateDocumentThumbnail(123, 4);
    // update the document thumbnail using the uri http://exemple.com/thumbnail.png
    productRequest.UpdateDocumentThumbnail(123, new Uri("http://exemple.com/thumbnail.png"));
    // update the document thumbnail using a local file
    productRequest.UpdateDocumentThumbnail(123,
        new YouScribe.Rest.Models.FileModel
        {
            Content = System.IO.File.OpenRead("my thumbnail"),
            ContentType = "image/jpg",
            FileName = "my_thumbnail.png"
        }
    );
}
                

Generate the embed code for a document

You can generate the embed code for a private or a public document.
To generate the embed code for a private document, you need to be connected with your account.
To generate an embed code you need the document id, you can find this id in the url. It's the last integer of the url :
http://en.youscribe.com/catalogue/manuals-and-practical-information-sheets/practical-life/tutorial-embed-the-youscribe-reader-in-your-blog-or-website-1016405
The document id is 1016405

Generate the embed code for a public document:

You can specify the width, height, start page and the display mode of the embed using the class EmbedGenerateModel.
There are two display mode: Embed mode using a scroll bar and Double mode using two pages.

                    
var client = new YouScribeClient();

var embedRequest = client.CreateEmbedRequest();

var embedCode = embedRequest.GenerateIframeTag(1016405);

var embedCode2 = embedRequest.GenerateIframeTag(1016405,
    new YouScribe.Rest.Models.Products.EmbedGenerateModel
    {
        Width = 620,
        Height = 438,
        DisplayMode = YouScribe.Rest.Models.Products.EmbedDisplayMode.Double
    }
);
                    
                
Generate the embed code for a private document:
If you published a private document, you can embed it. The users cannot find the document on YouScribe but it can be embed in your blog / site.
Like a public document, you can specify the width, height, start page and the display mode.

You can also specify an access period, after this period, the embed will not be accessible. You can define this period using the following formats:
  • minute fomart: xm - x represents the number of minutes
  • hour fomart: xh - x represents the number of hours
  • day fomart: xd - x represents the number of days
  • month fomart: xM - x represents the number of months
  • year fomart: xy - x represents the number of years
  • units of ticks format: x - x represents the number of ticks
                    
var client = new YouScribeClient();
// need to be authorized to generate the code for a private document
if (client.Authorize("user_name", "password") == true)
{
    var embedRequest = client.CreateEmbedRequest();
    
    int privateDocumentId = 123;

    // generate the embed code for a private document
    var embedCode = embedRequest.GeneratePrivateIframeTag(privateDocumentId);

    // generate the embed code for a private document, the embed is available for 4 days
    var embedCode2 = embedRequest.GeneratePrivateIframeTag(privateDocumentId,
        new YouScribe.Rest.Models.Products.PrivateEmbedGenerateModel
        {
            AccessPeriod = "4d"
        }
    );

    // generate the embed code for a private document, the embed is available for 90 minutes
    var embedCode3 = embedRequest.GeneratePrivateIframeTag(privateDocumentId,
        new YouScribe.Rest.Models.Products.PrivateEmbedGenerateModel
        {
            AccessPeriod = TimeSpan.FromMinutes(90).Ticks.ToString()
        }
    );
);
                    
                

Register new account

To register an account we need a valid email, a user name and a password.
The user name has to be an alphanumeric string with no space.
The characters '.', '_' and '-' are allowed.

                    
var client = new YouScribeClient();
var accountRequest = client.CreateAccountRequest();
var account = accountRequest.Create(
    new YouScribe.Rest.Models.Accounts.AccountModel
    {
        UserName = "user_name",
        Email = "your@email.com",
        Password = "****"
    }
);
                

The Create method returns the account created if successful.

Update an account

You can update all your information

                    
var client = new YouScribeClient();
//need to be authorized to update an account
if (client.Authorize("user_name", "password") == true)
{
    var accountRequest = client.CreateAccountRequest();

    // Update the city, firstname and the lastname
    accountRequest.Update(new YouScribe.Rest.Models.Accounts.AccountModel
    {
        City = "Paris",
        FirstName = "firstname",
        LastName = "lastname",
    });
}