Skip to content
This repository has been archived by the owner on Jun 8, 2018. It is now read-only.

Commit

Permalink
😏 Jake Kaufman - Scuttle Town
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxim Lebedev committed Dec 28, 2016
1 parent ebc352c commit ad9acdc
Show file tree
Hide file tree
Showing 56 changed files with 843 additions and 821 deletions.
30 changes: 30 additions & 0 deletions AcceptTeamInvite.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package hitGox

import (
"errors"
"fmt"
"github.com/valyala/fasthttp"
"strconv"
)

// AcceptTeamInvite accept an invite from teamName.
func (account *Account) AcceptTeamInvite(teamName string, groupID interface{}) (*Status, error) {
var args fasthttp.Args
args.Add("authToken", account.AuthToken)
switch id := groupID.(type) {
case int:
args.Add("group_id", strconv.Itoa(id))
case string:
args.Add("group_id", id)
default:
return nil, errors.New("groupid can be only as string or int")
}

url := fmt.Sprintf(APIEndpoint, fmt.Sprint("/team/", teamName, "/", account.UserName))
resp, err := update(url, &args)
if err != nil {
return nil, err
}

return fixStatus(resp), nil
}
27 changes: 27 additions & 0 deletions ChatConnection.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package hitGox

import (
"bytes"
"encoding/json"
"fmt"
)

func GetChatServers() ([]string, error) {
url := fmt.Sprintf(APIEndpoint, "chat/servers")
resp, err := get(url, nil)
if err != nil {
return nil, err
}

var obj = []struct {
ServerIP string `json:"server_ip"`
}{}
json.NewDecoder(bytes.NewReader(resp)).Decode(&obj)

var servers []string
for i := range obj {
servers = append(servers, obj[i].ServerIP)
}

return servers, nil
}
21 changes: 2 additions & 19 deletions getChatSettings.go → ChatSettings.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package hitGox
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"github.com/valyala/fasthttp"
)
Expand All @@ -20,33 +19,17 @@ type ChatSettings struct {
//
// Moderators and Editors can view this API.
func (account *Account) GetChatSettings(channel string) (*ChatSettings, error) {
if err := checkGetChatSettings(account, channel); err != nil {
return nil, err
}

var args fasthttp.Args
args.Add("authToken", account.AuthToken)

url := fmt.Sprint(API, "/chat/settings/", channel)
url := fmt.Sprintf(APIEndpoint, fmt.Sprint("chat/settings/", channel))
resp, err := get(url, &args)
if err != nil {
return nil, err
}

var obj ChatSettings
if err = json.NewDecoder(bytes.NewReader(resp)).Decode(&obj); err != nil {
return nil, err
}
json.NewDecoder(bytes.NewReader(resp)).Decode(&obj)

return &obj, nil
}

func checkGetChatSettings(account *Account, channel string) error {
switch {
case account.AuthToken == "":
return errors.New("authtoken in account can not be empty")
case channel == "":
return errors.New("channel can not be empty")
}
return nil
}
21 changes: 2 additions & 19 deletions checkFollowingStatus.go → CheckFollowingStatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package hitGox
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"github.com/valyala/fasthttp"
)
Expand All @@ -19,33 +18,17 @@ type FollowingStatus struct {

// CheckFollowingStatus returns follower relationship from userName to channel.
func CheckFollowingStatus(channel string, userName string) (*FollowingStatus, error) {
if err := checkCheckFollowingStatus(channel, userName); err != nil {
return nil, err
}

var args fasthttp.Args
args.Add("user_name", userName)

url := fmt.Sprint(API, "/following/user/", channel)
url := fmt.Sprintf(APIEndpoint, fmt.Sprint("following/user/", channel))
resp, err := get(url, &args)
if err != nil {
return nil, err
}

var obj FollowingStatus
if err = json.NewDecoder(bytes.NewReader(resp)).Decode(&obj); err != nil {
return nil, err
}
json.NewDecoder(bytes.NewReader(resp)).Decode(&obj)

return &obj, nil
}

func checkCheckFollowingStatus(channel string, userName string) error {
switch {
case userName == "":
return errors.New("username can not be empty")
case channel == "":
return errors.New("channel can not be empty")
}
return nil
}
44 changes: 44 additions & 0 deletions CheckSubscriptionInfo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package hitGox

import (
"bytes"
"encoding/json"
"fmt"
"github.com/valyala/fasthttp"
)

// SubscriptionInfo is about user subscription status.
type SubscriptionInfo struct {
SubID string `json:"sub_id"`
SubDateAdded string `json:"sub_date_added"`
SubDateValid string `json:"sub_date_valid"`
SubPlanID string `json:"sub_plan_id"`
SubPaymentMethod string `json:"sub_payment_method"`
PlanCharge string `json:"plan_charge"`
PlanCurrency string `json:"plan_currency"`
PlanRecurring string `json:"plan_recurring"`
UserName string `json:"user_name"`
UserID string `json:"user_id"`
UserLogo string `json:"user_logo"`
UserLogoSmall string `json:"user_logo_small"`
Cancel string `json:"cancel"`
Benefits []string `json:"benefits"`
Resub bool `json:"resub"`
}

// CheckSubscriptionInfo retruns subscription information between :channel and :user
func (account *Account) CheckSubscriptionInfo(user string) (*SubscriptionInfo, error) {
var args fasthttp.Args
args.Add("authToken", account.AuthToken)

url := fmt.Sprintf(APIEndpoint, fmt.Sprint("subscription/", account.UserName, "/", user))
resp, err := get(url, &args)
if err != nil {
return nil, err
}

var obj SubscriptionInfo
json.NewDecoder(bytes.NewReader(resp)).Decode(&obj)

return &obj, nil
}
23 changes: 23 additions & 0 deletions CheckSubscriptionStatus.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package hitGox

import (
"bytes"
"encoding/json"
"fmt"
)

// CheckSubscriptionStatus rReturns subscription relationship between channel and auth.
func (account *Account) CheckSubscriptionStatus(channel string) (bool, error) {
url := fmt.Sprintf(APIEndpoint, fmt.Sprint("user/subscription/", channel, "/", account.AuthToken))
resp, err := get(url, nil)
if err != nil {
return false, err
}

var obj = struct {
IsSubscriber bool `json:"isSubscriber"`
}{}
json.NewDecoder(bytes.NewReader(resp)).Decode(&obj)

return obj.IsSubscriber, nil
}
20 changes: 20 additions & 0 deletions CheckToken.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package hitGox

import (
"fmt"
"github.com/valyala/fasthttp"
)

// CheckToken checks if the Token is valid.
func (app *OAuthApplication) CheckToken(authToken string) (*Status, error) {
var args fasthttp.Args
args.Add("token", authToken)

url := fmt.Sprintf(APIEndpoint, fmt.Sprint("auth/valid/", app.Name))
resp, err := get(url, &args)
if err != nil {
return nil, err
}

return fixStatus(resp), nil
}
11 changes: 2 additions & 9 deletions checkVerifiedEmail.go → CheckVerifiedEmail.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package hitGox
import (
"bytes"
"encoding/json"
"errors"
"fmt"
)

Expand All @@ -21,20 +20,14 @@ type VerifiedStatus struct {

// CheckVerifiedEmail check if user has validated their email address.
func CheckVerifiedEmail(userName string) (*VerifiedStatus, error) {
if userName == "" {
return nil, errors.New("username can not be empty")
}

url := fmt.Sprint(API, "/user/checkVerifiedEmail/", userName)
url := fmt.Sprintf(APIEndpoint, fmt.Sprint("user/checkVerifiedEmail/", userName))
resp, err := get(url, nil)
if err != nil {
return nil, err
}

var obj VerifiedStatus
if err = json.NewDecoder(bytes.NewReader(resp)).Decode(&obj); err != nil {
return nil, err
}
json.NewDecoder(bytes.NewReader(resp)).Decode(&obj)

return &obj, nil
}
28 changes: 2 additions & 26 deletions createOAuthApplication.go → CreateOAuthApplication.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@ package hitGox

import (
"encoding/json"
"errors"
"fmt"
"github.com/valyala/fasthttp"
)

// CreateOAuthApplication creates a OAuth Application.
func (account *Account) CreateOAuthApplication(name string, redirectURI string) (*Status, error) {
if err := checkCreateOAuthApplication(account, name, redirectURI); err != nil {
return nil, err
}

var changes = struct {
AuthToken string `json:"authToken"`
UserName string `json:"user_name"`
Expand All @@ -35,30 +30,11 @@ func (account *Account) CreateOAuthApplication(name string, redirectURI string)
var args fasthttp.Args
args.Add("authToken", account.AuthToken)

url := fmt.Sprint(API, "/oauthapps/", account.UserName)
url := fmt.Sprintf(APIEndpoint, fmt.Sprint("oauthapps/", account.UserName))
resp, err := post(dst, url, &args)
if err != nil {
return nil, err
}

status, err := fuckYouNeedDecodeStatusFirst(resp)
if err != nil {
return nil, err
}

return status, nil
}

func checkCreateOAuthApplication(account *Account, name string, redirectURI string) error {
switch {
case account.AuthToken == "":
return errors.New("authtoken in account can not be empty")
case account.UserName == "":
return errors.New("username in account can not be empty")
case name == "":
return errors.New("name can not be empty")
case redirectURI == "":
return errors.New("redirecturi can not be empty")
}
return nil
return fixStatus(resp), nil
}
30 changes: 2 additions & 28 deletions createTeam.go → CreateTeam.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package hitGox

import (
"encoding/json"
"errors"
"fmt"
"github.com/valyala/fasthttp"
)
Expand All @@ -11,10 +10,6 @@ import (
//
// displayName must match dame except casing.
func (account *Account) CreateTeam(name string, displayName string, text string) (*Status, error) {
if err := checkCreateTeam(account, name, displayName, text); err != nil {
return nil, err
}

var changes = struct {
AuthToken string `json:"authToken"`
GroupUserName string `json:"group_user_name"`
Expand All @@ -31,32 +26,11 @@ func (account *Account) CreateTeam(name string, displayName string, text string)
var args fasthttp.Args
args.Add("authToken", account.AuthToken)

url := fmt.Sprint(API, "/team")
url := fmt.Sprintf(APIEndpoint, "team")
resp, err := post(dst, url, &args)
if err != nil {
return nil, err
}

status, err := fuckYouNeedDecodeStatusFirst(resp)
if err != nil {
return nil, err
}

return status, nil
}

func checkCreateTeam(account *Account, name string, displayName string, text string) error {
switch {
case account.AuthToken == "":
return errors.New("authtoken in account can not be empty")
case account.UserName == "":
return errors.New("username in account can not be empty")
case name == "" || len(name) < 4:
return errors.New("name too short")
case text == "" || len(text) < 4:
return errors.New("text required")
case displayName == "":
return errors.New("invalid display name")
}
return nil
return fixStatus(resp), nil
}
Loading

0 comments on commit ad9acdc

Please sign in to comment.