-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Starting to get some kind of structure..
- Loading branch information
Showing
12 changed files
with
268 additions
and
65 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 |
---|---|---|
@@ -1,38 +1,123 @@ | ||
using GithubSharp.Core.Services; | ||
|
||
namespace GithubSharp.Core.API | ||
{ | ||
public class Gist : Base.BaseAPI | ||
{ | ||
public Gist(ICacheProvider CacheProvider, ILogProvider LogProvider) : base(CacheProvider, LogProvider) { } | ||
//http://github.com/mattikus/pygist/blob/master/pygist.py | ||
//http://github.com/miyagawa/gistp/blob/master/gistp | ||
//http://github.com/defunkt/gist/blob/master/gist.rb | ||
//http://gist.github.com/4277 | ||
|
||
//http://gist.github.com/api/v1/xml/search/gist | ||
//http://gist.github.com/api/v1/xml/new | ||
|
||
//Delete | ||
//http://gist.github.com/delete/:id | ||
// _method = delete ,authenticity_token, | ||
|
||
//Edit | ||
//http://gist.github.com/gists/:id/edit | ||
// _method = put, authenticity_token, file_ext[fileN.ext] , file_contents[fileN.ext], file_name[fileN.ext] | ||
|
||
//Get all gists for user | ||
//http://gist.github.com/api/v1/xml/gists/erikzaadi | ||
|
||
//Download | ||
// /gists/:id/download | ||
|
||
//Raw | ||
//http://gist.github.com/{repo}.txt | ||
|
||
//format - Parse to get the syntax highlighted html | ||
//http://gist.github.com/291158.json | ||
|
||
//http://gist.github.com/291158.js | ||
} | ||
} | ||
using GithubSharp.Core.Services; | ||
using System.Collections.Generic; | ||
|
||
namespace GithubSharp.Core.API | ||
{ | ||
public class Gist : Base.GithubApiBase | ||
{ | ||
public Gist( | ||
ILogProvider logProvider, | ||
ICacheProvider cacheProvider, | ||
IAuthProvider authProvider) | ||
: base( | ||
logProvider, | ||
cacheProvider, | ||
authProvider) { } | ||
|
||
public IEnumerable<Models.Gist> UserGists(string username) | ||
{ | ||
return base.Get<IEnumerable<Models.Gist>>( | ||
string.Format( | ||
"users/{0}/gists", | ||
username), | ||
"GET").Result; | ||
} | ||
public IEnumerable<Models.Gist> CurrentUserGists() | ||
{ | ||
return base.Get<IEnumerable<Models.Gist>>( | ||
string.Format( | ||
"users/{0}/gists", | ||
base.AuthProvider.Username), | ||
"GET").Result; | ||
} | ||
|
||
public IEnumerable<Models.Gist> PublicGists() | ||
{ | ||
return base.Get<IEnumerable<Models.Gist>>( | ||
"gists/public", | ||
"GET").Result; | ||
} | ||
|
||
public IEnumerable<Models.Gist> StarredGists() | ||
{ | ||
return base.Get<IEnumerable<Models.Gist>>( | ||
"gists/starred", | ||
"GET").Result; | ||
} | ||
|
||
public Models.Gist Get(string id) | ||
{ | ||
return base.Get<Models.Gist>( | ||
string.Format( | ||
"gists/{0}", | ||
id), | ||
"GET").Result; | ||
} | ||
|
||
public Models.Gist Create(Models.GistToCreateOrEdit gist) | ||
{ | ||
return base.Get<Models.Gist, Models.GistToCreateOrEdit>( | ||
"gists", | ||
"POST", | ||
gist).Result; | ||
} | ||
|
||
public Models.Gist Edit(string id, Models.GistToCreateOrEdit gist) | ||
{ | ||
return base.Get<Models.Gist, Models.GistToCreateOrEdit>( | ||
string.Format( | ||
"gists/{0}", | ||
id), | ||
"PATCH", | ||
gist).Result; | ||
} | ||
|
||
public void StarGist(string id) | ||
{ | ||
base.Get( | ||
string.Format( | ||
"gists/{0}/star", | ||
id), | ||
"PUT"); | ||
} | ||
|
||
public void UnstarGist(string id) | ||
{ | ||
base.Get( | ||
string.Format( | ||
"gists/{0}/star", | ||
id), | ||
"DELETE"); | ||
} | ||
|
||
public bool IsGistStarred(string id) | ||
{ | ||
return base.Get( | ||
string.Format( | ||
"gists/{0}/star", | ||
id), | ||
"GET" | ||
).StatusCode == 204; | ||
} | ||
|
||
public Models.Gist Fork(string id) | ||
{ | ||
return base.Get<Models.Gist>( | ||
string.Format( | ||
"gists/{0}/fork", | ||
id), | ||
"POST").Result; | ||
} | ||
|
||
public void Delete(string id) | ||
{ | ||
base.Get( | ||
string.Format( | ||
"gists/{0}", | ||
id), | ||
"DELETE"); | ||
|
||
} | ||
|
||
} | ||
} |
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,64 @@ | ||
using System; | ||
|
||
namespace GithubSharp.Core.Base | ||
{ | ||
public class GithubApiBase | ||
{ | ||
public GithubApiBase ( | ||
Services.ILogProvider logProvider, | ||
Services.ICacheProvider cacheProvider, | ||
Services.IAuthProvider authProvider) | ||
{ | ||
LogProvider = logProvider; | ||
CacheProvider = cacheProvider; | ||
AuthProvider = authProvider; | ||
} | ||
|
||
public Services.ILogProvider LogProvider { get;set;} | ||
public Services.ICacheProvider CacheProvider { get;set;} | ||
public Services.IAuthProvider AuthProvider { get;set;} | ||
|
||
protected IGithubResponse Get( | ||
string Path, | ||
string Method) | ||
{ | ||
return new GithubRequest( | ||
LogProvider, | ||
CacheProvider, | ||
AuthProvider, | ||
Path, | ||
Method).GetResponse(); | ||
} | ||
|
||
protected IGithubResponseWithReturnType<TReturnType> Get<TReturnType>( | ||
string Path, | ||
string Method) | ||
where TReturnType : class | ||
{ | ||
return new GithubRequestWithReturnType<TReturnType>( | ||
LogProvider, | ||
CacheProvider, | ||
AuthProvider, | ||
Path, | ||
Method) | ||
.GetResponseWithReturnType(); | ||
} | ||
|
||
protected IGithubResponseWithReturnType<TReturnType> Get<TReturnType, TInputType>( | ||
string Path, | ||
string Method, | ||
TInputType ToSend) | ||
where TReturnType : class | ||
{ | ||
return new GithubRequestWithInputAndReturnType<TInputType, TReturnType>( | ||
LogProvider, | ||
CacheProvider, | ||
AuthProvider, | ||
Path, | ||
Method, | ||
ToSend) | ||
.GetResponseWithReturnType(); | ||
} | ||
} | ||
} | ||
|
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
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
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
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
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
Test Creation + Deletion of Gist to see that GithubRequestWithInput works | ||
|
||
Think of a better way to inherit between GithubRequestWithInput and GithubRequestWithInputAndReturnType | ||
Add pagination defaults to base api class | ||
Continue to implement models to understand the needs of the base api class | ||
Add attribute for an api method that needs authentication? | ||
Add a simple parameterized string format for methods? | ||
Add raw url helper methods - with content types? |
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
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
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
Oops, something went wrong.