{"_id":"56c2bc1dde695a19009a4aa7","user":"56b98db7bb36440d0001f492","version":{"_id":"56bc8e689afb8b0d00d62dd2","project":"56bc8e679afb8b0d00d62dcf","__v":18,"createdAt":"2016-02-11T13:36:40.146Z","releaseDate":"2016-02-11T13:36:40.146Z","categories":["56bc8e689afb8b0d00d62dd3","56c3c837bc41330d009f25ed","56c3c83e521f350d00d348eb","56c3c8452d97560d00e23cd8","56c3c85234df460d00c2beb8","56c4180d70187b17005f43b4","56c418162d97560d00e23cf6","56c4181cc4796b0d007ef039","56c4182370187b17005f43b5","56c418292e75e01700986052","56c4183328bd680d005e7ac6","56c4183bbb64720d00552b88","56c418414040602b0064cea0","56c4184754b6030d00ec29a1","56c4184c28bd680d005e7ac7","56c4185370187b17005f43b6","56c4185b6063071700500cfc","582a98b6f8c0a0190053d7a5"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"__v":6,"category":{"_id":"56bc8e689afb8b0d00d62dd3","__v":6,"pages":["56bc8e699afb8b0d00d62dd5","56c2aadf46d27917009d0719","56c2bc123e1b8d2300fe4ca0","56c2bc1dde695a19009a4aa7","56c2bc2a46d27917009d0722","56c2bc398073830d00e42e6f"],"project":"56bc8e679afb8b0d00d62dcf","version":"56bc8e689afb8b0d00d62dd2","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-02-11T13:36:40.802Z","from_sync":false,"order":0,"slug":"documentation","title":"Getting Started"},"parentDoc":null,"project":"56bc8e679afb8b0d00d62dcf","githubsync":"","updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-02-16T06:05:17.839Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":3,"body":"## Overview\n\nThe Buddy Windows IoT Core (or the \".NET SDK\") helps you get up and running in seconds. \n\nFor the most part, the Buddy .NET SDK takes care of all the housekeeping of making requests against the Buddy REST API:\n\n* Building and formatting requests\n* Managing authentication\n* Parsing responses\n* Loading and saving credentials\n\nWith that handled, all you have to do is initialize the SDK and start making some calls!\n\n## Getting Started\n\nTo get started with the Buddy Platform SDK, please reference the _Getting Started_ series of documents at [docs.buddy.com](https://docs.buddy.com). You will need an application ID and key before you can use the SDK. The _Getting Started_ documents will walk you through obtaining everything you need and show you where to find the SDK for your platform.\n\nApplication IDs and keys are obtained at the Buddy Developer Dashboard at [buddyplatform.com](https://buddyplatform.com/login).\n\nFull documentation for Buddy's services are available at [docs.buddy.com](https://docs.buddy.com).\n\n### Prerequisites\n\n* Visual Studio 2013 or greater\n* Xamarin Studio 5.9.7 or greater (iOS and Android)\n\nThe Buddy .NET SDK can be accessed via [NuGet](http://nuget.org/). NuGet version of at least 2.8.6 is required to install the Buddy SDK and sample apps.\n\n### Getting Started\n\nThe Buddy .NET SDK is distributed via NuGet. Source code for the SDK can be cloned from [GitHub](https://github.com/BuddyPlatform/Buddy-DotNET-SDK).\n\n#### Install with NuGet\n\nWe recommend using NuGet to include the SDK in your project. It's fast and makes it much easier to keep up to date with the latest SDK release.\n\nTo include the Buddy .NET SDK in your project:\n* Right-click on your project in Visual Studio and select the \\\"Manage NuGet Packages...\\\" menu item.\n* Type \\\"BuddyPlatformSdk\\\" into the edit box in the upper-right-hand corner of the \\\"Manage NuGet Packages\\\" window.\n* Click \\\"Install\\\".\n\n#### Install from Source\n\nBuddy hosts our SDK source on GitHub. To access it, you need to have a GitHub account, and you will also need [Git](http://git-scm.com/download) installed. If you'd like to contribute SDK modifications or additions to Buddy, you'll want to [fork the repository](https://help.github.com/articles/fork-a-repo) so you can issue [pull requests](https://help.github.com/articles/be-social#pull-requests). See the \\\"Contributing Back\\\" section below for details.\n\n1) In a Terminal window run:\n\n git clone https://github.com/BuddyPlatform/Buddy-DotNET-SDK.git\n\nThis will clone the latest version of the SDK into a directory called **Buddy-DotNET-SDK**.\n\n2) Navigate to the **Buddy-DotNET-SDK** directory that was created when you cloned the Buddy GitHub repository.\n\nThe .NET source is in the **Buddy-DotNET-SDK\\\\Src** directory.\n\n##### Build the GitHub Source\n\nYou must add a reference to the Buddy SDK in order to use it in your application.\n* Open your project in Visual Studio\n* In the Solution Explorer, right-click on your project and select \\\"Add Reference...\\\" (about halfway down the menu)\n* In the Reference Manager, click the \\\"Browse...\\\" button in the lower-right-hand corner of the window\n* In the \\\"Select the files to reference...\\\" dialog, find the assembly file for your project type and click \\\"Add\\\"\n* Click \\\"OK\\\" in the \\\"Reference Manager\\\" window\n\nNow when you build your project, Visual Studio will build the SDK.\n\n## Using the .NET SDK\n\nVisit the [Buddy Dashboard](https://buddyplatform.com) to obtain your application ID and key.\n\n### Initialize the SDK\n\nTo reference the Buddy SDK in your source file, you need to put a 'using' keyword at the top of files that will contain code that calls Buddy:\n\n using BuddySDK;\n\nThe `Init` method should be called once at the start of your app; we recommend placing it in your project's application constructor.\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"public MyCoolApp()\\n{\\n // Don't forget to get your app ID and key from http://buddyplatform.com!\\n Buddy.Init(\\\\\\\"YOUR_APP_ID\\\\\\\", \\\\\\\"YOUR_APP_KEY\\\\\\\");\\n}\",\n \"language\": \"csharp\"\n }\n ]\n}\n[/block]\nReplace \\\"YOUR_APP_ID\\\" and \\\"YOUR_APP_KEY\\\" above with your Buddy app's ID and key from the [Buddy Dashboard](https://buddyplatform.com).\n\n### User Flow\n\nThe Buddy .NET SDK handles user creation, login, and logout. Here are some example calls.\n\n#### Create A User\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"// We recommend awaiting Buddy calls; see https://msdn.microsoft.com/en-us/library/hh191443.aspx for more details.\\nawait Buddy.CreateUserAsync(username, password);\",\n \"language\": \"csharp\"\n }\n ]\n}\n[/block]\n#### User Login\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"var result = await Buddy.LoginUserAsync(username, password);\\n// Obtain the user's userName with result.Value.userName;\",\n \"language\": \"csharp\"\n }\n ]\n}\n[/block]\n#### User Logout\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"await Buddy.LogoutUserAsync();\",\n \"language\": \"csharp\"\n }\n ]\n}\n[/block]\n#### User Authorization event handler\n\nYou can add an event handler to `AuthorizationNeedsUserLogin` that gets called whenever a Buddy call is made that requires a logged-in user. That way, you won't have to manage user login state. Here's an example:\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"Buddy.AuthorizationNeedsUserLogin += async (sender, args) =>\\n {\\n await Buddy.LoginUserAsync(\\\"testuser\\\", \\\"testpassword\\\");\\n };\",\n \"language\": \"csharp\"\n }\n ]\n}\n[/block]\n \n### REST Interface\n\nEach SDK provides general wrappers that make REST calls to Buddy.\n\n#### GET\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"// GET all checkins within a 5000 meter radius around the point 47.1, -122.3\\nvar result = await Buddy.GetAsync<PagedResult<Checkin>>(\\\"/checkins\\\", new { locationRange = \\\"47.1,-122.3,5000\\\" } );\",\n \"language\": \"csharp\"\n }\n ]\n}\n[/block]\n#### POST\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"var result = await Buddy.PostAsync<Checkin>(\\\"/checkins\\\", new {\\n location = new BuddyGeoLocation(47.1, -122.3),\\n comment = \\\"This place was awesome!\\\"\\n});\\n// POST results return similar responses to GET, use the result to check for success\",\n \"language\": \"csharp\"\n }\n ]\n}\n[/block]\n#### PUT/PATCH/DELETE\n\nEach remaining REST verb is available through the Buddy SDK using the same pattern as the POST and GET examples.\n\n### Working With Files\n\nBuddy offers support for binary files. The .NET SDK works with files through our REST interface similarly to other API calls.\n\n**Note:** Responses for files deviate from the standard Buddy response templates. See the [docs.buddy.com](https://docs.buddy.com) for more information.\n\n#### Upload A File\n\nHere we demonstrate uploading a picture. For all binary files (e.g. blobs and videos), the pattern is the same, but with a different path and different parameters.\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"// Create a new BuddyFile with the picture we want to upload\\nvar result = await Buddy.PostAsync<Picture> (\\\"/pictures\\\", new {\\n data = new BuddyFile (chosenImage.AsPNG().AsStream(), \\\"data\\\", \\\"image/png\\\"),\\n});\",\n \"language\": \"csharp\"\n }\n ]\n}\n[/block]\n#### Download A File\n\nOur download example uses pictures.\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"// Gets the photo bits, resized to 200x200\\nvar result = await Buddy.GetAsync<BuddyFile>(\\\"/pictures/\\\" + id + \\\"/file\\\", new {size=200});\\n\\nif (result.IsSuccess && result.Value != null) {\\n\\n // Load the image data from result.Value.Data\\n}\",\n \"language\": \"csharp\"\n }\n ]\n}\n[/block]\n### Advanced Usage\n\n#### Automatically report location for each Buddy call\n\nIf you set the current location in the Buddy client, each time a Buddy call is made that location will be passed in the call. Most calls that send data to Buddy have a location parameter; if a call is made that doesn't take location, the parameter will be ignored.\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"Buddy.LastLocation = new BuddyGeoLocation(42, -42);\",\n \"language\": \"csharp\"\n }\n ]\n}\n[/block]\n#### Multiple concurrent users\n\nIf you need to have multiple clients (for example if you need to interact with multiple users concurrently from your app), you can capture clients created from `Buddy.init` and use those clients individually:\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"var client1 = Buddy.Init(\\\"App ID 1\\\", \\\"App Password 1\\\");\\n\\nvar client2 = Buddy.Init(\\\"App ID 2\\\", \\\"App Password 2\\\");\\n\\nawait client1.LoginUserAsync(\\\"username1\\\", \\\"password1\\\");\\n\\nawait client2.LoginUserAsync(\\\"username2\\\", \\\"password2\\\");\",\n \"language\": \"csharp\"\n }\n ]\n}\n[/block]\n \n#### Handling connectivity\n\nYou can add an event handler to `ConnectivityLevelChanged` if you would like to be notified if your device loses and regains ability to communicate to the Buddy servers for whatever reason. Here's an example that notifies the user:\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"Buddy.ConnectivityLevelChanged += (object sender, ConnectivityLevelChangedArgs e) =>\\n{\\n MessageBox.Show(e.ConnectivityLevel == ConnectivityLevel.None ? \\\"No connectivty...\\\" : \\\"Connected!\\\";\\n};\",\n \"language\": \"csharp\"\n }\n ]\n}\n[/block]\n### Sample Apps\n\n#### PushSample (Windows Phone 8)\n\nA simple app that demonstrates user login\\\\logout and the push notification API.\n\n#### BuddySquare (Xamarin iOS)\n\nAn app that demonstrates user login\\\\logout\\\\creation and the checkin, pictures, and metrics APIs.\n\n## Contributing Back: Pull Requests\n\nWe'd love to have your help making the Buddy SDK as good as it can be!\n\nTo submit a change to the Buddy SDK please do the following:\n\n1. Create your own fork of the Buddy SDK\n2. Make the change to your fork\n3. Before creating your pull request, please sync your repository to the current state of the parent repository: `git pull origin master`\n4. Commit your changes, then [submit a pull request](https://help.github.com/articles/using-pull-requests) for just that commit\n\n## Questions or need help?\n\nThis should have given you the basics of how to work with the Buddy .NET SDK. If you have further questions or are stuck, send an email to support:::at:::buddy.com","excerpt":"","slug":"dotnet-sdk","type":"basic","title":"Windows IoT Core SDK"}

Checkins

Batching

Windows IoT Core SDK

## Overview
The Buddy Windows IoT Core (or the ".NET SDK") helps you get up and running in seconds.
For the most part, the Buddy .NET SDK takes care of all the housekeeping of making requests against the Buddy REST API:
* Building and formatting requests
* Managing authentication
* Parsing responses
* Loading and saving credentials
With that handled, all you have to do is initialize the SDK and start making some calls!
## Getting Started
To get started with the Buddy Platform SDK, please reference the _Getting Started_ series of documents at [docs.buddy.com](https://docs.buddy.com). You will need an application ID and key before you can use the SDK. The _Getting Started_ documents will walk you through obtaining everything you need and show you where to find the SDK for your platform.
Application IDs and keys are obtained at the Buddy Developer Dashboard at [buddyplatform.com](https://buddyplatform.com/login).
Full documentation for Buddy's services are available at [docs.buddy.com](https://docs.buddy.com).
### Prerequisites
* Visual Studio 2013 or greater
* Xamarin Studio 5.9.7 or greater (iOS and Android)
The Buddy .NET SDK can be accessed via [NuGet](http://nuget.org/). NuGet version of at least 2.8.6 is required to install the Buddy SDK and sample apps.
### Getting Started
The Buddy .NET SDK is distributed via NuGet. Source code for the SDK can be cloned from [GitHub](https://github.com/BuddyPlatform/Buddy-DotNET-SDK).
#### Install with NuGet
We recommend using NuGet to include the SDK in your project. It's fast and makes it much easier to keep up to date with the latest SDK release.
To include the Buddy .NET SDK in your project:
* Right-click on your project in Visual Studio and select the \"Manage NuGet Packages...\" menu item.
* Type \"BuddyPlatformSdk\" into the edit box in the upper-right-hand corner of the \"Manage NuGet Packages\" window.
* Click \"Install\".
#### Install from Source
Buddy hosts our SDK source on GitHub. To access it, you need to have a GitHub account, and you will also need [Git](http://git-scm.com/download) installed. If you'd like to contribute SDK modifications or additions to Buddy, you'll want to [fork the repository](https://help.github.com/articles/fork-a-repo) so you can issue [pull requests](https://help.github.com/articles/be-social#pull-requests). See the \"Contributing Back\" section below for details.
1) In a Terminal window run:
git clone https://github.com/BuddyPlatform/Buddy-DotNET-SDK.git
This will clone the latest version of the SDK into a directory called **Buddy-DotNET-SDK**.
2) Navigate to the **Buddy-DotNET-SDK** directory that was created when you cloned the Buddy GitHub repository.
The .NET source is in the **Buddy-DotNET-SDK\\Src** directory.
##### Build the GitHub Source
You must add a reference to the Buddy SDK in order to use it in your application.
* Open your project in Visual Studio
* In the Solution Explorer, right-click on your project and select \"Add Reference...\" (about halfway down the menu)
* In the Reference Manager, click the \"Browse...\" button in the lower-right-hand corner of the window
* In the \"Select the files to reference...\" dialog, find the assembly file for your project type and click \"Add\"
* Click \"OK\" in the \"Reference Manager\" window
Now when you build your project, Visual Studio will build the SDK.
## Using the .NET SDK
Visit the [Buddy Dashboard](https://buddyplatform.com) to obtain your application ID and key.
### Initialize the SDK
To reference the Buddy SDK in your source file, you need to put a 'using' keyword at the top of files that will contain code that calls Buddy:
using BuddySDK;
The `Init` method should be called once at the start of your app; we recommend placing it in your project's application constructor.
[block:code]
{
"codes": [
{
"code": "public MyCoolApp()\n{\n // Don't forget to get your app ID and key from http://buddyplatform.com!\n Buddy.Init(\\\"YOUR_APP_ID\\\", \\\"YOUR_APP_KEY\\\");\n}",
"language": "csharp"
}
]
}
[/block]
Replace \"YOUR_APP_ID\" and \"YOUR_APP_KEY\" above with your Buddy app's ID and key from the [Buddy Dashboard](https://buddyplatform.com).
### User Flow
The Buddy .NET SDK handles user creation, login, and logout. Here are some example calls.
#### Create A User
[block:code]
{
"codes": [
{
"code": "// We recommend awaiting Buddy calls; see https://msdn.microsoft.com/en-us/library/hh191443.aspx for more details.\nawait Buddy.CreateUserAsync(username, password);",
"language": "csharp"
}
]
}
[/block]
#### User Login
[block:code]
{
"codes": [
{
"code": "var result = await Buddy.LoginUserAsync(username, password);\n// Obtain the user's userName with result.Value.userName;",
"language": "csharp"
}
]
}
[/block]
#### User Logout
[block:code]
{
"codes": [
{
"code": "await Buddy.LogoutUserAsync();",
"language": "csharp"
}
]
}
[/block]
#### User Authorization event handler
You can add an event handler to `AuthorizationNeedsUserLogin` that gets called whenever a Buddy call is made that requires a logged-in user. That way, you won't have to manage user login state. Here's an example:
[block:code]
{
"codes": [
{
"code": "Buddy.AuthorizationNeedsUserLogin += async (sender, args) =>\n {\n await Buddy.LoginUserAsync(\"testuser\", \"testpassword\");\n };",
"language": "csharp"
}
]
}
[/block]
### REST Interface
Each SDK provides general wrappers that make REST calls to Buddy.
#### GET
[block:code]
{
"codes": [
{
"code": "// GET all checkins within a 5000 meter radius around the point 47.1, -122.3\nvar result = await Buddy.GetAsync<PagedResult<Checkin>>(\"/checkins\", new { locationRange = \"47.1,-122.3,5000\" } );",
"language": "csharp"
}
]
}
[/block]
#### POST
[block:code]
{
"codes": [
{
"code": "var result = await Buddy.PostAsync<Checkin>(\"/checkins\", new {\n location = new BuddyGeoLocation(47.1, -122.3),\n comment = \"This place was awesome!\"\n});\n// POST results return similar responses to GET, use the result to check for success",
"language": "csharp"
}
]
}
[/block]
#### PUT/PATCH/DELETE
Each remaining REST verb is available through the Buddy SDK using the same pattern as the POST and GET examples.
### Working With Files
Buddy offers support for binary files. The .NET SDK works with files through our REST interface similarly to other API calls.
**Note:** Responses for files deviate from the standard Buddy response templates. See the [docs.buddy.com](https://docs.buddy.com) for more information.
#### Upload A File
Here we demonstrate uploading a picture. For all binary files (e.g. blobs and videos), the pattern is the same, but with a different path and different parameters.
[block:code]
{
"codes": [
{
"code": "// Create a new BuddyFile with the picture we want to upload\nvar result = await Buddy.PostAsync<Picture> (\"/pictures\", new {\n data = new BuddyFile (chosenImage.AsPNG().AsStream(), \"data\", \"image/png\"),\n});",
"language": "csharp"
}
]
}
[/block]
#### Download A File
Our download example uses pictures.
[block:code]
{
"codes": [
{
"code": "// Gets the photo bits, resized to 200x200\nvar result = await Buddy.GetAsync<BuddyFile>(\"/pictures/\" + id + \"/file\", new {size=200});\n\nif (result.IsSuccess && result.Value != null) {\n\n // Load the image data from result.Value.Data\n}",
"language": "csharp"
}
]
}
[/block]
### Advanced Usage
#### Automatically report location for each Buddy call
If you set the current location in the Buddy client, each time a Buddy call is made that location will be passed in the call. Most calls that send data to Buddy have a location parameter; if a call is made that doesn't take location, the parameter will be ignored.
[block:code]
{
"codes": [
{
"code": "Buddy.LastLocation = new BuddyGeoLocation(42, -42);",
"language": "csharp"
}
]
}
[/block]
#### Multiple concurrent users
If you need to have multiple clients (for example if you need to interact with multiple users concurrently from your app), you can capture clients created from `Buddy.init` and use those clients individually:
[block:code]
{
"codes": [
{
"code": "var client1 = Buddy.Init(\"App ID 1\", \"App Password 1\");\n\nvar client2 = Buddy.Init(\"App ID 2\", \"App Password 2\");\n\nawait client1.LoginUserAsync(\"username1\", \"password1\");\n\nawait client2.LoginUserAsync(\"username2\", \"password2\");",
"language": "csharp"
}
]
}
[/block]
#### Handling connectivity
You can add an event handler to `ConnectivityLevelChanged` if you would like to be notified if your device loses and regains ability to communicate to the Buddy servers for whatever reason. Here's an example that notifies the user:
[block:code]
{
"codes": [
{
"code": "Buddy.ConnectivityLevelChanged += (object sender, ConnectivityLevelChangedArgs e) =>\n{\n MessageBox.Show(e.ConnectivityLevel == ConnectivityLevel.None ? \"No connectivty...\" : \"Connected!\";\n};",
"language": "csharp"
}
]
}
[/block]
### Sample Apps
#### PushSample (Windows Phone 8)
A simple app that demonstrates user login\\logout and the push notification API.
#### BuddySquare (Xamarin iOS)
An app that demonstrates user login\\logout\\creation and the checkin, pictures, and metrics APIs.
## Contributing Back: Pull Requests
We'd love to have your help making the Buddy SDK as good as it can be!
To submit a change to the Buddy SDK please do the following:
1. Create your own fork of the Buddy SDK
2. Make the change to your fork
3. Before creating your pull request, please sync your repository to the current state of the parent repository: `git pull origin master`
4. Commit your changes, then [submit a pull request](https://help.github.com/articles/using-pull-requests) for just that commit
## Questions or need help?
This should have given you the basics of how to work with the Buddy .NET SDK. If you have further questions or are stuck, send an email to [email protected]