forked from dlively1/SugarSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
435 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -154,3 +154,7 @@ $RECYCLE.BIN/ | |
|
||
# Mac desktop service store files | ||
.DS_Store | ||
|
||
#nuget | ||
packages/* | ||
!packages/repositories.config |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
SugarSharp | ||
========== | ||
|
||
Sugar7 C# Rest Client |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 2012 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SugarRest", "SugarRest\SugarRest.csproj", "{B01ABC51-484C-4E10-98F5-F86CA42E6F41}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{B01ABC51-484C-4E10-98F5-F86CA42E6F41}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{B01ABC51-484C-4E10-98F5-F86CA42E6F41}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{B01ABC51-484C-4E10-98F5-F86CA42E6F41}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{B01ABC51-484C-4E10-98F5-F86CA42E6F41}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System; | ||
using System.Text; | ||
using RestSharp; | ||
using RestSharp.Extensions; | ||
using RestSharp.Deserializers; | ||
using SugarRest.Model; | ||
|
||
namespace SugarRest | ||
{ | ||
public partial class SugarClient | ||
{ | ||
/// <summary> | ||
/// Retrieve list of Accounts | ||
/// </summary> | ||
/// <returns></returns> | ||
public AccountResult GetAccount() | ||
{ | ||
var request = new RestRequest("Accounts", Method.GET); | ||
IRestResponse<AccountResult> response = client.Execute<AccountResult>(request); | ||
return response.Data; | ||
} | ||
|
||
/// <summary> | ||
/// Retrieve a given Account | ||
/// </summary> | ||
/// <param name="id">string ID of the Account</param> | ||
/// <returns>Account Bean</returns> | ||
public Account GetAccount(string id) | ||
{ | ||
var request = new RestRequest("Accounts/{id}", Method.GET); | ||
request.AddUrlSegment("id", id); | ||
IRestResponse<Account> response = client.Execute<Account>(request); | ||
return response.Data; | ||
} | ||
|
||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace SugarRest.Model | ||
{ | ||
public class Account : Bean | ||
{ | ||
#region Account Properties | ||
|
||
public string account_type { get; set; } | ||
public string industry { get; set; } | ||
public string annual_revenue { get; set; } //@todo might be int | ||
public string rating { get; set; } | ||
public string ownership { get; set; } | ||
public string employees { get; set; } //@todo - check datatype | ||
public string ticker_symbol { get; set; } | ||
public List<EmailAddress> email { get; set; } | ||
public string email1 { get; set; } | ||
public string parent_id { get; set; } | ||
public string sic_code { get; set; } | ||
public bool email_opt_out { get; set; } | ||
public bool invalid_email { get; set; } | ||
public string campaign_id { get; set; } | ||
|
||
#endregion | ||
|
||
//@todo - check if these are in the company base class | ||
public string phone_fax { get; set; } | ||
public string billing_address_street { get; set; } | ||
public string billing_address_street_2 { get; set; } | ||
public string billing_address_street_3 { get; set; } | ||
public string billing_address_street_4 { get; set; } | ||
public string billing_address_city { get; set; } | ||
public string billing_address_state { get; set; } | ||
public string billing_address_postalcode { get; set; } | ||
public string billing_address_country { get; set; } | ||
public string phone_office { get; set; } | ||
public string phone_alternate { get; set; } | ||
public string website { get; set; } | ||
public string shipping_address_street { get; set; } | ||
public string shipping_address_street_2 { get; set; } | ||
public string shipping_address_street_3 { get; set; } | ||
public string shipping_address_street_4 { get; set; } | ||
public string shipping_address_city { get; set; } | ||
public string shipping_address_state { get; set; } | ||
public string shipping_address_postalcode { get; set; } | ||
public string shipping_address_country { get; set; } | ||
|
||
|
||
|
||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace SugarRest.Model | ||
{ | ||
public class AccountResult : BeanListBase | ||
{ | ||
public List<Account> records { get; set; } | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace SugarRest.Model | ||
{ | ||
public class BeanListBase | ||
{ | ||
public int next_offset { get; set; } | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace SugarRest.Model | ||
{ | ||
public class Bean | ||
{ | ||
public string id { get; set; } | ||
public string name { get; set; } | ||
public DateTime date_entered { get; set; } | ||
public DateTime date_modified { get; set; } | ||
public string modified_user_id { get; set; } | ||
public string modified_by_name { get; set; } | ||
public string created_by { get; set; } | ||
public string created_by_name { get; set; } | ||
public string description { get; set; } | ||
public bool deleted { get; set; } | ||
public string assigned_user_id { get; set; } | ||
public string assigned_user_name { get; set; } | ||
public List<Team> team_name { get; set; } | ||
|
||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace SugarRest.Model | ||
{ | ||
public class BeanResponse : BeanListBase | ||
{ | ||
public List<Bean> records { get; set; } | ||
} | ||
|
||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace SugarRest.Model | ||
{ | ||
public class EmailAddress | ||
{ | ||
public string email_address { get; set; } | ||
public string opt_out { get; set; } | ||
public string invalid_email { get; set; } | ||
public string primary_address { get; set; } | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
|
||
namespace SugarRest.Model | ||
{ | ||
public class Team | ||
{ | ||
public string id { get; set; } | ||
public string name { get; set; } | ||
public string name_2 { get; set; } | ||
public bool primary { get; set; } | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace SugarRest.Model | ||
{ | ||
public class TokenResponse | ||
{ | ||
|
||
public string access_token { get; set; } | ||
public int expires_in { get; set; } | ||
public string token_type { get; set; } | ||
public string scope { get; set; } | ||
public string refresh_token { get; set; } | ||
|
||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("SugarRest")] | ||
[assembly: AssemblyDescription("API wrapper for SugarCRM REST API")] | ||
[assembly: AssemblyConfiguration("")] | ||
|
||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("10095340-7f3c-4e9a-85bc-9ba986277a52")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
using System; | ||
using System.Text; | ||
using RestSharp; | ||
using RestSharp.Extensions; | ||
using RestSharp.Deserializers; | ||
using SugarRest.Model; | ||
|
||
namespace SugarRest | ||
{ | ||
public partial class SugarClient | ||
{ | ||
/// <summary> | ||
/// BaseURL of SugarCRM Instance | ||
/// </summary> | ||
public string BaseUrl { get; private set; } | ||
|
||
/// <summary> | ||
/// SugarCRM Username | ||
/// </summary> | ||
private string Username { get; set; } | ||
|
||
/// <summary> | ||
/// SugarCRM Password | ||
/// </summary> | ||
private string Password { get; set; } | ||
|
||
/// <summary> | ||
/// Oauth Token for authentication on requests to the SugarCRM API | ||
/// </summary> | ||
private string Token { get; set; } | ||
|
||
/// <summary> | ||
/// RestClient to handle API interactions | ||
/// </summary> | ||
private RestClient client; | ||
|
||
/// <summary> | ||
/// Constructor to create new API Client | ||
/// </summary> | ||
/// <param name="url">URL to rest end point</param> | ||
/// <param name="username">SugarCRM Username</param> | ||
/// <param name="password">SugarCRM Password</param> | ||
public SugarClient(string url, string username, string password) | ||
{ | ||
BaseUrl = url; | ||
Username = username; | ||
Password = password; | ||
|
||
client = new RestClient(); | ||
client.UserAgent = "SugarSharp"; | ||
client.BaseUrl = BaseUrl; | ||
|
||
var request = new RestRequest("oauth2/token", Method.POST); | ||
request.AddParameter("grant_type", "password"); | ||
request.AddParameter("client_id", "sugar"); | ||
request.AddParameter("username", Username); | ||
request.AddParameter("password", Password); | ||
|
||
IRestResponse<TokenResponse> tokenResponse = client.Execute<TokenResponse>(request); | ||
|
||
if(string.IsNullOrEmpty(tokenResponse.Data.access_token)) | ||
{ | ||
//@todo - handle exception here | ||
} | ||
|
||
Token = tokenResponse.Data.access_token; | ||
client.AddDefaultHeader("OAuth-Token",Token); | ||
|
||
} | ||
|
||
/// <summary> | ||
/// Sample API endpoint, good for testing | ||
/// </summary> | ||
/// <returns>String "pong"</returns> | ||
public string GetPing() | ||
{ | ||
var request = new RestRequest("ping", Method.GET); | ||
IRestResponse response = client.Execute(request); | ||
return response.Content; | ||
} | ||
|
||
/// <summary> | ||
/// Retrieves collection of basic bean properties for the given module | ||
/// </summary> | ||
/// <param name="module">Name of the module ex. ("Accounts")</param> | ||
/// <returns>List of Bean records</returns> | ||
public BeanResponse GetBean(string module) | ||
{ | ||
var request = new RestRequest(module, Method.GET); | ||
IRestResponse<BeanResponse> response = client.Execute<BeanResponse>(request); | ||
return response.Data; | ||
} | ||
|
||
/// <summary> | ||
/// Gets generic bean properties for a given ID | ||
/// </summary> | ||
/// <param name="module">Name of the module ex. ("Accounts")</param> | ||
/// <param name="id">string ID</param> | ||
/// <returns>SugarBean</returns> | ||
public Bean GetBean(string module, string id) | ||
{ | ||
var request = new RestRequest("{module}/{id}", Method.GET); | ||
request.AddUrlSegment("module", module); | ||
request.AddUrlSegment("id", id); | ||
IRestResponse<Bean> response = client.Execute<Bean>(request); | ||
return response.Data; | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.