rest

package
v0.0.0-...-e633676 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 3, 2020 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	APIScheme = "https"
	APIHost   = "api.ardich.com"
	APIPath   = "api/v3/"
)

Const is

View Source
const (
	ResponseOK       = "200 OK"
	ResponseCreated  = "201 Created"
	ResponseNotFound = "404 Not Found"
	ResponseNil      = "Null Value"
)

These constants are used throughout the program. It has been used to make variable types more meaningful. ResponseOK: This constant is used to check if we have a question when we are back positive, ie "200 OK". ResponseNotFound: This constant is used to check if we have a negative response, ie "404 Not Found" when we make a query. ResponseCreated: This constant is used to check if "201 Created" is coming back when we made a query. ResponseNil: This constant is used to return a blank when we have a question.

View Source
const (
	ResponseOKCode            = 200
	ResponseCreatedCode       = 201
	ResponseBadRequestCode    = 400
	ResponseUnauthorizedCode  = 401
	ResponseForbiddenCode     = 403
	ResponseNotFoundCode      = 404
	ResponseServerProblemCode = 500
)

Response Code

View Source
const (
	POST   = "POST"
	GET    = "GET"
	PUT    = "PUT"
	DELETE = "DELETE"
)

Query Type

View Source
const (
	Visible   = true
	Invisible = false
	OKMarshal = true
	NOMarshal = false
)

These constants are used throughout the program. They have functions such as displaying yawning values. Visible: Show the user without processing the incoming json value. Invisible: The incoming json value does not represent the user. OKMarshal: Processes automatically when data arrives. However, since this process is address-based, there may be data overlap. This is why it is necessary to pay attention. NOMarshal: If this option is selected, the data will be sent directly without processing. The incoming value is processed in the returned field.

View Source
const (
	Online  = "ONLINE"
	Offline = "OFFLINE"
)

This section is the online - offline status check of the Presence value taken from the device.

View Source
const (
	NoApplication = "NOAPPLICATION"
	Running       = "RUNNING"
	NotRunning    = "NOTRUNNING"
	Blocked       = "BLOCKED"
	NotBlocked    = "NOTBLOCKED"
	UnKnow        = "UNKNOW"
)

Variables

View Source
var (
	ErrorResponseBadRequestCode400   = errors.New("Request is 400 Bad Request. Please check your request")
	ErrorResponseUnauthorizedCode401 = errors.New("Request is 401 Unauthorized. Please check the login information")
	ErrorResponseForbiddenCode403    = errors.New("Request is 403 Forbidden. You are not authorized for this query")
	ErrorNotFound404                 = errors.New("Request is 404 Not Found. Please check variables, queries, links and other parameters")
	ErrorServerProblemCode500        = errors.New("Request is 500 Server Problem. There is a server problem. Please try later")
	ErrorElseProblem                 = errors.New("No problem could be detected. Please check the information. If the problem is not resolved, consult the program owner")
	ErrorResponseNil                 = errors.New("Null Response Message")
	ErrorResponseNilRequest          = errors.New("Null Response Request Message")
)

Errors

Functions

func Connect

func Connect(userName string, password string) (bool, error)

Connect is In order to use the Connect Rest APIs, it performs login util to "Tenant". It takes two parameters;

1: userName:
      UserName, IoT - You are logged in to the Ignite platform.
2: password:
      Password, IoT - prompts you for the password information that you have registered
      for the Ignite platform.

This process performs the Post method. Information from the user is sent to the method post section. The header section is important here. This is given as a constant. This function returns "true" if the Connect operation has been performed. Sends "false" if the message is empty and "false" if it gets an error.

func GetAPITemplate

func GetAPITemplate() url.URL

GetAPITemplate is

func GetAccessToken

func GetAccessToken() string

GetAccessToken is; After the Connect is done, it sends back the Acces Token value. All subsequent query util will use this value. Anyone who wishes to know about Connect can take this value with the help of this function.

func GetRefreshToken

func GetRefreshToken() string

GetRefreshToken is ; There is a period of Acces Token. When this time expires, the automatically executed util are interrupted and the program fails. You need to do the Connect again. But the Connect operation also gives us the Reflesh Token value. This value is used to automatically submit a new Access Token when the time expires. This function is used to rotate the desired value.

func SetHost

func SetHost(hst string)

SetHost is

func SetPath

func SetPath(pth string)

SetPath is

func SetScheme

func SetScheme(schm string)

SetScheme is

Types

type Query

type Query struct{}

Query is performs query util. These util are "Post", "Get", "Put". With this class, it makes a stable query everywhere. Retrieve values by query type. These values will be explained in the description of each questionnaire. The queries were taken from https://api.ardich.com/api/v3/apidoc/ The queries return two values.

1: [] byte:
       If the incoming data is meaningful, that is, "Status" as the response,
       if "200 OK" is reached, the data that you read is sent as a byte array to the querying function.
       If the message is empty or is problem, it returns the value "nil".
2: error:
       If it encounters an error during the query, it sends back an error.

func (Query) DeleteQuery

func (q Query) DeleteQuery(setQueryAddress string, setBody string, setHeader map[string]string, visualFlag bool) ([]byte, error)

DeleteQuery is used to perform an event. For example turning off the device, running the application etc. . You need to be careful when using this query. Because it can make changes for many devices in the wrong steps. You need to send the parameters correctly. Otherwise, unwanted situations may occur. First test it on a test device in your hand. This query takes 4 parameters.

1: "setQueryAdress":
       This query will show the address to be made.
2: "setBody":
       This will show the parameters to be added to the body part of the address to be sent.
3: "setHeader":
       Shows the portion of the address to be sent. The example access token is sent in this way.
4: "vasualFlag":
       The task is visual. If it is not 0, the value is only processed and not shown to the user.
       But if it is 1, the incoming message is seen by the first user and then processed.

func (Query) GetQuery

func (q Query) GetQuery(setQueryAddress string, visualFlag bool) ([]byte, error)

GetQuery is the type of query that does not capture information. It will not do operation. Only gets the existing information. Take two parameters.

  1. "setQueryAdress": The name of this query. This adrese request is sent.
  2. "vasualFlag": The task is visual. If it is sent as 0, the value is only processed but not shown to the user. But if it is 1, the incoming message is seen by the first user and then processed.

func (Query) PostQuery

func (q Query) PostQuery(setQueryAddress string, setBody string, setHeader map[string]string, visualFlag bool) ([]byte, error)

PostQuery is used to perform an event. For example turning off the device, running the application etc. . You need to be careful when using this query. Because it can make changes for many devices in the wrong steps. You need to send the parameters correctly. Otherwise, unwanted situations may occur. First test it on a test device in your hand. This query takes 4 parameters.

1: "setQueryAdress":
       This query will show the address to be made.
2: "setBody":
       This will show the parameters to be added to the body part of the address to be sent.
3: "setHeader":
       Shows the portion of the address to be sent. The example access token is sent in this way.
4: "vasualFlag":
       The task is visual. If it is not 0, the value is only processed and not shown to the user.
       But if it is 1, the incoming message is seen by the first user and then processed.

func (Query) PutQuery

func (q Query) PutQuery(setQueryAddress string, setBody string, setHeader map[string]string, visualFlag bool) ([]byte, error)

PutQuery is used to perform an event. For example turning off the device, running the application etc. . You need to be careful when using this query. Because it can make changes for many devices in the wrong steps. You need to send the parameters correctly. Otherwise, unwanted situations may occur. First test it on a test device in your hand. This query takes 4 parameters.

1: "setQueryAdress":
       This query will show the address to be made.
2: "setBody":
       This will show the parameters to be added to the body part of the address to be sent.
3: "setHeader":
       Shows the portion of the address to be sent. The example access token is sent in this way.
4: "vasualFlag":
       The task is visual. If it is not 0, the value is only processed and not shown to the user.
       But if it is 1, the incoming message is seen by the first user and then processed.

type QueryMessage

type QueryMessage struct {
	RequestParameter requestParameter `json:"requestParameter"`
	ResponseMessage  response         `json:"response"`
}

QueryMessage is used to push query parameters and return value to log

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL