Skip to content

Commit

Permalink
Merge pull request #2 from jjideenschmiede/development
Browse files Browse the repository at this point in the history
Fixing contacts pages bug
  • Loading branch information
gowizzard committed Oct 17, 2021
2 parents c4a521e + 71d81bc commit ed1a1fa
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 29 deletions.
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type Request struct {
}

// Send is to send a new request
func (r *Request) Send() (*http.Response, error) {
func (r Request) Send() (*http.Response, error) {

// Set url
url := resourceUrl + r.Path
Expand Down
49 changes: 26 additions & 23 deletions contacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ package goplacetel
import (
"encoding/json"
"fmt"
"time"
)

// ContactBody is to build a new contact
Expand Down Expand Up @@ -43,7 +44,7 @@ type ContactBody struct {
type ContactReturn struct {
Id int `json:"id"`
UserId int `json:"user_id"`
Speeddail interface{} `json:"speeddail"`
Speeddial interface{} `json:"speeddial"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
Email string `json:"email"`
Expand All @@ -62,8 +63,8 @@ type ContactReturn struct {
XingUrl string `json:"xing_url"`
TwitterAccount string `json:"twitter_account"`
Blocked bool `json:"blocked"`
UpdatedAt string `json:"updated_at"`
CreatedAt string `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
CreatedAt time.Time `json:"created_at"`
}

// DeleteContactReturn is to decode the json data
Expand Down Expand Up @@ -103,7 +104,7 @@ type DeleteContactReturn struct {
}

// Contacts is to get all contacts from the api
func Contacts(token string) (*[]ContactReturn, error) {
func Contacts(token string) ([]ContactReturn, error) {

// To decode the json data
var contacts []ContactReturn
Expand Down Expand Up @@ -142,25 +143,27 @@ func Contacts(token string) (*[]ContactReturn, error) {
// Check length & break the loop
if len(decode) < 25 {
break
} else {
page++
}

}

// Return data
return &contacts, nil
return contacts, nil

}

// Contact is to get a contact by id
func Contact(id string, token string) (*ContactReturn, error) {
func Contact(id string, token string) (ContactReturn, error) {

// Set config for new request
r := Request{"/contacts/" + id, "GET", token, nil}

// Send new request
response, err := r.Send()
if err != nil {
return nil, err
return ContactReturn{}, err
}

// Close response body after function ends
Expand All @@ -171,21 +174,21 @@ func Contact(id string, token string) (*ContactReturn, error) {

err = json.NewDecoder(response.Body).Decode(&decode)
if err != nil {
return nil, err
return ContactReturn{}, err
}

// Return data
return &decode, nil
return decode, nil

}

// AddContact is to add a new contact
func AddContact(body *ContactBody, token string) (*ContactReturn, error) {
func AddContact(body *ContactBody, token string) (ContactReturn, error) {

// Convert data
convert, err := json.Marshal(body)
if err != nil {
return nil, err
return ContactReturn{}, err
}

// Set config for new request
Expand All @@ -194,7 +197,7 @@ func AddContact(body *ContactBody, token string) (*ContactReturn, error) {
// Send new request
response, err := r.Send()
if err != nil {
return nil, err
return ContactReturn{}, err
}

// Close response body after function ends
Expand All @@ -205,21 +208,21 @@ func AddContact(body *ContactBody, token string) (*ContactReturn, error) {

err = json.NewDecoder(response.Body).Decode(&decode)
if err != nil {
return nil, err
return ContactReturn{}, err
}

// Return data
return &decode, nil
return decode, nil

}

// UpdateContact is to add a new contact
func UpdateContact(body *ContactBody, token string) (*ContactReturn, error) {
func UpdateContact(body ContactBody, token string) (ContactReturn, error) {

// Convert data
convert, err := json.Marshal(body)
if err != nil {
return nil, err
return ContactReturn{}, err
}

// Set config for new request
Expand All @@ -228,7 +231,7 @@ func UpdateContact(body *ContactBody, token string) (*ContactReturn, error) {
// Send new request
response, err := r.Send()
if err != nil {
return nil, err
return ContactReturn{}, err
}

// Close response body after function ends
Expand All @@ -239,24 +242,24 @@ func UpdateContact(body *ContactBody, token string) (*ContactReturn, error) {

err = json.NewDecoder(response.Body).Decode(&decode)
if err != nil {
return nil, err
return ContactReturn{}, err
}

// Return data
return &decode, nil
return decode, nil

}

// DeleteContact is to add a new contact
func DeleteContact(id string, token string) (*DeleteContactReturn, error) {
func DeleteContact(id string, token string) (DeleteContactReturn, error) {

// Set config for new request
r := Request{"/contacts/" + id, "DELETE", token, nil}

// Send new request
response, err := r.Send()
if err != nil {
return nil, err
return DeleteContactReturn{}, err
}

// Close response body after function ends
Expand All @@ -267,10 +270,10 @@ func DeleteContact(id string, token string) (*DeleteContactReturn, error) {

err = json.NewDecoder(response.Body).Decode(&decode)
if err != nil {
return nil, err
return DeleteContactReturn{}, err
}

// Return data
return &decode, nil
return decode, nil

}
10 changes: 5 additions & 5 deletions sms.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ type SendSmsReturn struct {
}

// SendSms is to send a sms via the placetel api
func SendSms(body *SendSmsBody, token string) (*SendSmsReturn, error) {
func SendSms(body SendSmsBody, token string) (SendSmsReturn, error) {

// Convert body
convert, err := json.Marshal(body)
if err != nil {
return nil, err
return SendSmsReturn{}, err
}

// Set config for new request
Expand All @@ -41,7 +41,7 @@ func SendSms(body *SendSmsBody, token string) (*SendSmsReturn, error) {
// Send new request
response, err := r.Send()
if err != nil {
return nil, err
return SendSmsReturn{}, err
}

// Close response body after function ends
Expand All @@ -52,10 +52,10 @@ func SendSms(body *SendSmsBody, token string) (*SendSmsReturn, error) {

err = json.NewDecoder(response.Body).Decode(&decode)
if err != nil {
return nil, err
return SendSmsReturn{}, err
}

// Return data
return &decode, nil
return decode, nil

}

0 comments on commit ed1a1fa

Please sign in to comment.