Skip to content

Commit

Permalink
add tasks module
Browse files Browse the repository at this point in the history
  • Loading branch information
andrepinto committed Aug 12, 2016
1 parent 3b72f1d commit b67ede2
Show file tree
Hide file tree
Showing 10 changed files with 432 additions and 48 deletions.
1 change: 1 addition & 0 deletions .idea/libraries/GOPATH__mrs_service_go_sdk_.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

241 changes: 196 additions & 45 deletions .idea/workspace.xml

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"errors"
)

func NewClient(endpoint string, organization string, application string) (*Client, error){
func NewClient(endpoint string, organization string, application string, appId string) (*Client, error){
if(organization == "" || application == ""){
return &Client{}, errors.New("ORGANIZATION_OR_APPLICATION_IS_EMPTY")
}
Expand All @@ -22,6 +22,7 @@ func NewClient(endpoint string, organization string, application string) (*Clie
application,
endpoint,
nil,
appId,
}, nil
}

Expand Down
4 changes: 2 additions & 2 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import (


func TestNewClient(t *testing.T) {
_, err := NewClient("", "", "")
_, err := NewClient("", "", "","")
if err == nil {
t.Errorf("All arguments are required in NewClient()")
} else {
fmt.Println(err.Error())
}

_, err = NewClient("http://52.50.91.:9999","tlantic", "customer")
_, err = NewClient("http://52.50.91.27","tlantic", "customer","")
if err != nil {
t.Errorf( err.Error())
}
Expand Down
7 changes: 7 additions & 0 deletions error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package mrs_service_go_sdk

type ApiError struct {
Status int `json:"status"`
Error string `json:"error"`
Message interface{} `json:"message"`
}
110 changes: 110 additions & 0 deletions task.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package mrs_service_go_sdk

type TaskSummary struct {
Status string `json:"status"`
Result struct {
PriceAudit struct {
Total int `json:"total"`
} `json:"priceAudit"`
StockCount struct {
Total int `json:"total"`
} `json:"stockCount"`
StockOut struct {
Total int `json:"total"`
} `json:"stockOut"`
Replenish struct {
Total int `json:"total"`
} `json:"replenish"`
QueueBust struct {
Total int `json:"total"`
} `json:"queueBust"`
Checklist struct {
Total int `json:"total"`
} `json:"checklist"`
Shrinkage struct {
Total int `json:"total"`
} `json:"shrinkage"`
Planogram struct {
Total int `json:"total"`
} `json:"planogram"`
Markdown struct {
Total int `json:"total"`
} `json:"markdown"`
QualClas struct {
Total int `json:"total"`
} `json:"qualClas"`
RecepDir struct {
Total int `json:"total"`
} `json:"recepDir"`
RecepCen struct {
Total int `json:"total"`
} `json:"recepCen"`
RecepTsf struct {
Total int `json:"total"`
} `json:"recepTsf"`
PriceChang struct {
Total int `json:"total"`
} `json:"priceChang"`
RecepCS struct {
Total int `json:"total"`
} `json:"recepCS"`
ReplenPrep struct {
Total int `json:"total"`
} `json:"replenPrep"`
ReplenConf struct {
Total int `json:"total"`
} `json:"replenConf"`
StockOutFA struct {
Total int `json:"total"`
} `json:"stockOutFA"`
} `json:"result"`
}

type TasksRequest struct {
Status string `json:"status"`
Result []Task `json:"result"`
}


type Task struct {
Status string `json:"status"`
OwnerID string `json:"ownerId"`
LastUpdateUser string `json:"lastUpdateUser"`
TaskType string `json:"taskType"`
Counter int `json:"counter"`
SetupID string `json:"setupId"`
TaskName string `json:"taskName"`
Description string `json:"description"`
ProfileID string `json:"profileId"`
DeviceID string `json:"deviceId"`
StoreID string `json:"storeId"`
Priority int `json:"priority"`
Shared bool `json:"shared"`
DocumentID string `json:"documentId"`
ScheduledDate int64 `json:"scheduledDate"`
ApplicationID string `json:"applicationId"`
Type string `json:"_type"`
UID string `json:"_uId"`
UpdateDate int `json:"_updateDate"`
CreateDate int `json:"_createDate"`
UpdateUser string `json:"_updateUser"`
CreateUser string `json:"_createUser"`
Items []TaskItem `json:"items"`
}



type TaskItem struct {
ItemID string `json:"itemId"`
Status string `json:"status"`
TaskID string `json:"taskId"`
Type string `json:"type,omitempty"`
ApplicationID string `json:"applicationId"`
_Type string `json:"_type"`
UID string `json:"_uId"`
UpdateDate int `json:"_updateDate"`
CreateDate int `json:"_createDate"`
UpdateUser string `json:"_updateUser,omitempty"`
CreateUser string `json:"_createUser,omitempty"`
ItemEan string `json:"itemEan,omitempty"`
}
57 changes: 57 additions & 0 deletions tasks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package mrs_service_go_sdk


import (
"net/http"
"fmt"
)

const TASKS_MODULE_NAME = "tasks"

func (c *Client) Summary() (*TaskSummary, error) {
p := TaskSummary{}

url := fmt.Sprintf("%s/%s", c.BaseApi, createPath(c.Organization, c.Application,"summary"))

req, err := http.NewRequest("GET", url , nil)
req.Header.Set("mrs-application-id", c.AppId)

if err != nil {
return &p, err
}

err = c.Send(req, &p)
if err != nil {
return &p, err
}


return &p, nil
}


func (c *Client) GetTasks(items bool) (*TasksRequest, error) {
p := TasksRequest{}

url := fmt.Sprintf("%s/%s", c.BaseApi, createPath(c.Organization, c.Application, fmt.Sprintf("?items=%t", items)))

req, err := http.NewRequest("GET", url , nil)
req.Header.Set("mrs-application-id", c.AppId)

if err != nil {
return &p, err
}

err = c.Send(req, &p)
if err != nil {
return &p, err
}


return &p, nil
}

func createPath(org, app, extra string) string{
return fmt.Sprintf("%s/orgs/%s/apps/%s/%s/%s", TASKS_MODULE_NAME, org, app, TASKS_MODULE_NAME, extra)
}

50 changes: 50 additions & 0 deletions tasks_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package mrs_service_go_sdk

import (
"testing"
)


func TestTaskSummary(t *testing.T) {

cl, err := NewClient("http://52.50.91.27:8067","tlantic", "instore", "489a598e-259c-4e25-974e-5de00b29f707")
if err != nil {
t.Errorf( err.Error())
}

summary, err := cl.Summary()

if err != nil{
t.Errorf( err.Error())
}

t.Log(summary.Result.PriceChang.Total)


}


func TestGetTasks(t *testing.T) {

cl, err := NewClient("http://52.50.91.27:8067","tlantic", "instore", "489a598e-259c-4e25-974e-5de00b29f707")
if err != nil {
t.Errorf( err.Error())
}

tasks, err := cl.GetTasks(true)

if err != nil{
t.Errorf( err.Error())
}

t.Log(tasks.Result)

if(len(tasks.Result)>0){
task := tasks.Result[0]
t.Log(task.TaskName)
t.Log(task.Items)
}


}

1 change: 1 addition & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type Client struct {
Application string
BaseApi string
Log io.Writer
AppId string
}

type TokenResponse struct {
Expand Down

0 comments on commit b67ede2

Please sign in to comment.