Commit cf9d91ac authored by Morgan McMillian's avatar Morgan McMillian

renamed constants to conform to go standards

renamed package from peantus to woodstock
parent ecb429b3
package peanuts
package woodstock
import (
"net/url"
......@@ -35,7 +35,7 @@ func (c *Client) AccessToken(code string, redirectURI string) (result AccessToke
v.Set("redirect_uri", redirectURI)
v.Set("grant_type", "authorization_code")
response_ch := make(chan response)
c.queryQueue <- query{url: OAUTH_ACCESS_TOKEN_API, form: v, data: &result, method: "POST", response_ch: response_ch}
c.queryQueue <- query{url: OAuthAccessTokenAPI, form: v, data: &result, method: "POST", response_ch: response_ch}
return result, (<-response_ch).err
}
......@@ -50,6 +50,6 @@ func (c *Client) AccessTokenFromPassword(username string, password string, scope
v.Set("grant_type", "password")
v.Set("scope", strings.Join(scope, ","))
response_ch := make(chan response)
c.queryQueue <- query{url: OAUTH_ACCESS_TOKEN_API, form: v, data: &result, method: "POST", response_ch: response_ch}
c.queryQueue <- query{url: OAuthAccessTokenAPI, form: v, data: &result, method: "POST", response_ch: response_ch}
return result, (<-response_ch).err
}
package peanuts
package woodstock
import (
"net/http"
)
const (
AUTHENTICATE_URL = "https://pnut.io/oauth/authenticate"
API_BASE_URL = "https://api.pnut.io/v0/"
OAUTH_ACCESS_TOKEN_API = API_BASE_URL + "oauth/access_token"
POST_API = API_BASE_URL + "posts"
STREAM_BASE_URL = POST_API + "/" + "streams"
STREAM_ME_API = STREAM_BASE_URL + "/me"
STREAM_UNIFIED_API = STREAM_BASE_URL + "/unified"
STREAM_GLOBAL_API = STREAM_BASE_URL + "/global"
STREAM_TAG_BASE_URL = POST_API + "/" + "tag"
USER_API = API_BASE_URL + "users"
USER_ME_API = USER_API + "/me"
ME_CHANNELS_BASE_URL = USER_ME_API + "/channels"
UNREAD_PM_NUMBER_API = ME_CHANNELS_BASE_URL + "/num_unread/pm"
SUBSCRIBED_CHANNELS_API = ME_CHANNELS_BASE_URL + "/subscribed"
MUTED_CHANNELS_API = ME_CHANNELS_BASE_URL + "/muted"
ME_MESSAGES_API = USER_ME_API + "/messages"
CHANNEL_API = API_BASE_URL + "channels"
PRESENCE_API = API_BASE_URL + "presence"
CLIENT_API = API_BASE_URL + "clients"
MARKER_API = API_BASE_URL + "markers"
AuthenticateURL = "https://pnut.io/oauth/authenticate"
APIBasesURL = "https://api.pnut.io/v0/"
OAuthAccessTokenAPI = APIBasesURL + "oauth/access_token"
PostAPI = APIBasesURL + "posts"
StreamBaseURL = PostAPI + "/" + "streams"
StreamMeAPI = StreamBaseURL + "/me"
StreamUnifiedAPI = StreamBaseURL + "/unified"
StreamGlobalAPI = StreamBaseURL + "/global"
StreamTabBaseURL = PostAPI + "/" + "tag"
UserAPI = APIBasesURL + "users"
UserMeAPI = UserAPI + "/me"
MeChannelsBaseURL = UserMeAPI + "/channels"
UnreadPMNumberAPI = MeChannelsBaseURL + "/num_unread/pm"
SubscribedChannelsAPI = MeChannelsBaseURL + "/subscribed"
MutedChannelsAPI = MeChannelsBaseURL + "/muted"
MeMessagesAPI = UserMeAPI + "/messages"
ChannelAPI = APIBasesURL + "channels"
PresenceAPI = APIBasesURL + "presence"
ClientAPI = APIBasesURL + "clients"
MarkerAPI = APIBasesURL + "markers"
)
type Api struct {
type API struct {
accessToken string
HttpClient *http.Client
HTTPClient *http.Client
}
This diff is collapsed.
package peanuts
package woodstock
import (
"bytes"
......@@ -16,7 +16,7 @@ type Client struct {
clientSecret string
passwordGrantSecret string
queryQueue chan query
Api Api
Api API
}
func NewClient(clientId string, clientSecret string) *Client {
......@@ -43,16 +43,16 @@ type response struct {
}
func (c *Client) initialize() {
c.Api = *&Api{
c.Api = *&API{
accessToken: "",
HttpClient: http.DefaultClient,
HTTPClient: http.DefaultClient,
}
}
// Generate authorization url
// https://pnut.io/docs/authentication/web-flows
func (c *Client) AuthURL(redirectURI string, scope []string, responseType string) string {
return AUTHENTICATE_URL + "?client_id=" + c.clientId + "&redirect_uri=" + redirectURI + "&scope=" + strings.Join(scope, "%20") + "&response_type=" + responseType
return AuthenticateURL + "?client_id=" + c.clientId + "&redirect_uri=" + redirectURI + "&scope=" + strings.Join(scope, "%20") + "&response_type=" + responseType
}
// Set password grant secret
......@@ -148,7 +148,7 @@ func (c *Client) execQuery(url string, form url.Values, data interface{}, method
return fmt.Errorf(strconv.Itoa(res.StatusCode))
}
}
res, err := c.Api.HttpClient.Do(req)
res, err := c.Api.HTTPClient.Do(req)
if err != nil {
return err
}
......
package peanuts
package woodstock
type ClientInfoResult struct {
*CommonResponse
......@@ -9,6 +9,6 @@ type ClientInfoResult struct {
// https://pnut.io/docs/resources/clients#get-clients-id
func (c *Client) GetClient(id string) (result ClientInfosResult, err error) {
response_ch := make(chan response)
c.queryQueue <- query{url: CLIENT_API + "/" + id, data: &result, method: "GET", response_ch: response_ch}
c.queryQueue <- query{url: ClientAPI + "/" + id, data: &result, method: "GET", response_ch: response_ch}
return result, (<-response_ch).err
}
package peanuts
package woodstock
type Links struct {
Link string `json:"link"`
......
package peanuts
package woodstock
type Image struct {
Link string `json:"link"`
......
package peanuts
package woodstock
import (
"net/url"
......@@ -25,7 +25,7 @@ type ActionsResult struct {
// https://pnut.io/docs/resources/posts/lookup#get-posts-id
func (c *Client) GetPost(id string) (result PostResult, err error) {
response_ch := make(chan response)
c.queryQueue <- query{url: POST_API + "/" + id, data: &result, method: "GET", response_ch: response_ch}
c.queryQueue <- query{url: PostAPI + "/" + id, data: &result, method: "GET", response_ch: response_ch}
return result, (<-response_ch).err
}
......@@ -35,7 +35,7 @@ func (c *Client) GetPosts(ids []string) (result PostsResult, err error) {
v := url.Values{}
v.Set("ids", strings.Join(ids, ","))
response_ch := make(chan response)
c.queryQueue <- query{url: POST_API + "?" + v.Encode(), data: &result, method: "GET", response_ch: response_ch}
c.queryQueue <- query{url: PostAPI + "?" + v.Encode(), data: &result, method: "GET", response_ch: response_ch}
return result, (<-response_ch).err
}
......@@ -43,7 +43,7 @@ func (c *Client) GetPosts(ids []string) (result PostsResult, err error) {
// https://pnut.io/docs/resources/posts/lookup#get-posts-id-revisions
func (c *Client) GetPostRevisions(id string) (result PostsResult, err error) {
response_ch := make(chan response)
c.queryQueue <- query{url: POST_API + "/" + id + "/revisions", data: &result, method: "GET", response_ch: response_ch}
c.queryQueue <- query{url: PostAPI + "/" + id + "/revisions", data: &result, method: "GET", response_ch: response_ch}
return result, (<-response_ch).err
}
......@@ -51,7 +51,7 @@ func (c *Client) GetPostRevisions(id string) (result PostsResult, err error) {
// https://pnut.io/docs/resources/posts/lifecycle#post-posts
func (c *Client) Post(v url.Values) (result PostResult, err error) {
response_ch := make(chan response)
c.queryQueue <- query{url: POST_API, form: v, data: &result, method: "POST", response_ch: response_ch}
c.queryQueue <- query{url: PostAPI, form: v, data: &result, method: "POST", response_ch: response_ch}
return result, (<-response_ch).err
}
......@@ -59,7 +59,7 @@ func (c *Client) Post(v url.Values) (result PostResult, err error) {
// https://pnut.io/docs/resources/posts/lifecycle#put-posts-id
func (c *Client) RevisePost(id string, v url.Values) (result PostResult, err error) {
response_ch := make(chan response)
c.queryQueue <- query{url: POST_API + "/" + id, form: v, data: &result, method: "PUT", response_ch: response_ch}
c.queryQueue <- query{url: PostAPI + "/" + id, form: v, data: &result, method: "PUT", response_ch: response_ch}
return result, (<-response_ch).err
}
......@@ -67,7 +67,7 @@ func (c *Client) RevisePost(id string, v url.Values) (result PostResult, err err
// https://pnut.io/docs/resources/posts/lifecycle#delete-posts-id
func (c *Client) DeletePost(id string) (result PostResult, err error) {
response_ch := make(chan response)
c.queryQueue <- query{url: POST_API + "/" + id, data: &result, method: "DELETE", response_ch: response_ch}
c.queryQueue <- query{url: PostAPI + "/" + id, data: &result, method: "DELETE", response_ch: response_ch}
return result, (<-response_ch).err
}
......@@ -83,7 +83,7 @@ func (c *Client) MeStream(count ...int) (result PostsResult, err error) {
param = "?" + param
}
response_ch := make(chan response)
c.queryQueue <- query{url: STREAM_ME_API + param, data: &result, method: "GET", response_ch: response_ch}
c.queryQueue <- query{url: StreamMeAPI + param, data: &result, method: "GET", response_ch: response_ch}
return result, (<-response_ch).err
}
......@@ -99,7 +99,7 @@ func (c *Client) UnifiedStream(count ...int) (result PostsResult, err error) {
param = "?" + param
}
response_ch := make(chan response)
c.queryQueue <- query{url: STREAM_UNIFIED_API + param, data: &result, method: "GET", response_ch: response_ch}
c.queryQueue <- query{url: StreamUnifiedAPI + param, data: &result, method: "GET", response_ch: response_ch}
return result, (<-response_ch).err
}
......@@ -115,7 +115,7 @@ func (c *Client) GlobalStream(count ...int) (result PostsResult, err error) {
param = "?" + param
}
response_ch := make(chan response)
c.queryQueue <- query{url: STREAM_GLOBAL_API + param, data: &result, method: "GET", response_ch: response_ch}
c.queryQueue <- query{url: StreamGlobalAPI + param, data: &result, method: "GET", response_ch: response_ch}
return result, (<-response_ch).err
}
......@@ -131,7 +131,7 @@ func (c *Client) TagStream(tag string, count ...int) (result PostsResult, err er
param = "?" + param
}
response_ch := make(chan response)
c.queryQueue <- query{url: STREAM_TAG_BASE_URL + "/" + tag + param, data: &result, method: "GET", response_ch: response_ch}
c.queryQueue <- query{url: StreamTabBaseURL + "/" + tag + param, data: &result, method: "GET", response_ch: response_ch}
return result, (<-response_ch).err
}
......@@ -139,7 +139,7 @@ func (c *Client) TagStream(tag string, count ...int) (result PostsResult, err er
// https://pnut.io/docs/resources/posts/threads#get-posts-id-thread
func (c *Client) GetThread(id string) (result PostsResult, err error) {
response_ch := make(chan response)
c.queryQueue <- query{url: POST_API + "/" + id + "/thread", data: &result, method: "GET", response_ch: response_ch}
c.queryQueue <- query{url: PostAPI + "/" + id + "/thread", data: &result, method: "GET", response_ch: response_ch}
return result, (<-response_ch).err
}
......@@ -147,7 +147,7 @@ func (c *Client) GetThread(id string) (result PostsResult, err error) {
// https://pnut.io/docs/resources/posts/reposts#put-posts-id-repost
func (c *Client) Repost(id string) (result PostResult, err error) {
response_ch := make(chan response)
c.queryQueue <- query{url: POST_API + "/" + id + "/repost", data: &result, method: "PUT", response_ch: response_ch}
c.queryQueue <- query{url: PostAPI + "/" + id + "/repost", data: &result, method: "PUT", response_ch: response_ch}
return result, (<-response_ch).err
}
......@@ -155,7 +155,7 @@ func (c *Client) Repost(id string) (result PostResult, err error) {
// https://pnut.io/docs/resources/posts/reposts#delete-posts-id-repost
func (c *Client) UnRepost(id string) (result PostResult, err error) {
response_ch := make(chan response)
c.queryQueue <- query{url: POST_API + "/" + id + "/repost", data: &result, method: "DELETE", response_ch: response_ch}
c.queryQueue <- query{url: PostAPI + "/" + id + "/repost", data: &result, method: "DELETE", response_ch: response_ch}
return result, (<-response_ch).err
}
......@@ -163,7 +163,7 @@ func (c *Client) UnRepost(id string) (result PostResult, err error) {
// https://pnut.io/docs/resources/posts/bookmarks#put-posts-id-bookmark
func (c *Client) Bookmark(id string) (result PostResult, err error) {
response_ch := make(chan response)
c.queryQueue <- query{url: POST_API + "/" + id + "/bookmark", data: &result, method: "PUT", response_ch: response_ch}
c.queryQueue <- query{url: PostAPI + "/" + id + "/bookmark", data: &result, method: "PUT", response_ch: response_ch}
return result, (<-response_ch).err
}
......@@ -171,7 +171,7 @@ func (c *Client) Bookmark(id string) (result PostResult, err error) {
// https://pnut.io/docs/resources/posts/bookmarks#put-posts-id-bookmark
func (c *Client) UnBookmark(id string) (result PostResult, err error) {
response_ch := make(chan response)
c.queryQueue <- query{url: POST_API + "/" + id + "/bookmark", data: &result, method: "DELETE", response_ch: response_ch}
c.queryQueue <- query{url: PostAPI + "/" + id + "/bookmark", data: &result, method: "DELETE", response_ch: response_ch}
return result, (<-response_ch).err
}
......@@ -186,6 +186,6 @@ func (c *Client) GetActions(id string, v ...url.Values) (result ActionsResult, e
param = "?" + param
}
response_ch := make(chan response)
c.queryQueue <- query{url: POST_API + "/" + id + "/actions" + param, data: &result, method: "GET", response_ch: response_ch}
c.queryQueue <- query{url: PostAPI + "/" + id + "/actions" + param, data: &result, method: "GET", response_ch: response_ch}
return result, (<-response_ch).err
}
package peanuts
package woodstock
type PresencesResult struct {
*CommonResponse
......@@ -9,6 +9,6 @@ type PresencesResult struct {
// https://pnut.io/docs/resources/users/presence#get-presence
func (c *Client) GetPresences() (result PresencesResult, err error) {
response_ch := make(chan response)
c.queryQueue <- query{url: PRESENCE_API, data: &result, method: "GET", response_ch: response_ch}
c.queryQueue <- query{url: PresenceAPI, data: &result, method: "GET", response_ch: response_ch}
return result, (<-response_ch).err
}
package peanuts
package woodstock
type MarkersResult struct {
*CommonResponse
......@@ -11,6 +11,6 @@ type MarkersResult struct {
// https://pnut.io/docs/resources/stream-marker#post-markers
func (c *Client) SetMarker(json string) (result MarkersResult, err error) {
response_ch := make(chan response)
c.queryQueue <- query{url: MARKER_API, data: &result, method: "PUT", response_ch: response_ch, json: json}
c.queryQueue <- query{url: MarkerAPI, data: &result, method: "PUT", response_ch: response_ch, json: json}
return result, (<-response_ch).err
}
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment