generated from NdoleStudio/go-http-client
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a39bcba
commit ddf9490
Showing
14 changed files
with
225 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,16 @@ | ||
package client | ||
package httpsms | ||
|
||
import "net/http" | ||
|
||
type clientConfig struct { | ||
httpClient *http.Client | ||
delay int | ||
apiKey string | ||
baseURL string | ||
} | ||
|
||
func defaultClientConfig() *clientConfig { | ||
return &clientConfig{ | ||
httpClient: http.DefaultClient, | ||
delay: 0, | ||
baseURL: "https://httpstat.us", | ||
baseURL: "https://api.httpsms.com", | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module github.com/NdoleStudio/go-http-client | ||
module github.com/NdoleStudio/httpsms-go | ||
|
||
go 1.17 | ||
|
||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package stubs | ||
|
||
// MessagesSendResponse response from the /v1/messages/send endpoint | ||
func MessagesSendResponse() []byte { | ||
return []byte(` | ||
{ | ||
"data": { | ||
"contact": "+18005550100", | ||
"content": "This is a sample text message", | ||
"created_at": "2022-06-05T14:26:02.302718+03:00", | ||
"failure_reason": "", | ||
"id": "32343a19-da5e-4b1b-a767-3298a73703cb", | ||
"last_attempted_at": "2022-06-05T14:26:09.527976+03:00", | ||
"order_timestamp": "2022-06-05T14:26:09.527976+03:00", | ||
"owner": "+18005550199", | ||
"received_at": "2022-06-05T14:26:09.527976+03:00", | ||
"request_received_at": "2022-06-05T14:26:01.520828+03:00", | ||
"send_time": 133414, | ||
"sent_at": "2022-06-05T14:26:09.527976+03:00", | ||
"status": "pending", | ||
"type": "mobile-terminated", | ||
"updated_at": "2022-06-05T14:26:10.303278+03:00", | ||
"user_id": "WB7DRDWrJZRGbYrv2CKGkqbzvqdC" | ||
}, | ||
"message": "message created successfully", | ||
"status": "success" | ||
} | ||
`) | ||
} | ||
|
||
// MessagesSendErrorResponse internal error response | ||
func MessagesSendErrorResponse() []byte { | ||
return []byte(` | ||
{ | ||
"message": "We ran into an internal error while handling the request.", | ||
"status": "error" | ||
} | ||
`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package httpsms | ||
|
||
import "time" | ||
|
||
// MessageSendParams is the request payload for sending a message | ||
type MessageSendParams struct { | ||
Content string `json:"content"` | ||
From string `json:"from"` | ||
To string `json:"to"` | ||
} | ||
|
||
// MessageResponse is the response gotten with a message content | ||
type MessageResponse struct { | ||
Data Message `json:"data"` | ||
Message string `json:"message"` | ||
Status string `json:"status"` | ||
} | ||
|
||
// Message represents and incoming or outgoing SMS message | ||
type Message struct { | ||
Contact string `json:"contact"` | ||
Content string `json:"content"` | ||
CreatedAt time.Time `json:"created_at"` | ||
FailureReason string `json:"failure_reason"` | ||
ID string `json:"id"` | ||
LastAttemptedAt time.Time `json:"last_attempted_at"` | ||
OrderTimestamp time.Time `json:"order_timestamp"` | ||
Owner string `json:"owner"` | ||
ReceivedAt time.Time `json:"received_at"` | ||
RequestReceivedAt time.Time `json:"request_received_at"` | ||
SendTime int `json:"send_time"` | ||
SentAt time.Time `json:"sent_at"` | ||
Status string `json:"status"` | ||
Type string `json:"type"` | ||
UpdatedAt time.Time `json:"updated_at"` | ||
UserID string `json:"user_id"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package httpsms | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"net/http" | ||
) | ||
|
||
// messagesService is the API client for the `/` endpoint | ||
type messagesService service | ||
|
||
// Send adds a new SMS message to be sent by the android phone | ||
// | ||
// API Docs: https://api.httpsms.com/index.html#/Messages/post_messages_send | ||
func (service *messagesService) Send(ctx context.Context, params *MessageSendParams) (*MessageResponse, *Response, error) { | ||
request, err := service.client.newRequest(ctx, http.MethodPost, "/v1/messages/send", params) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
response, err := service.client.do(request) | ||
if err != nil { | ||
return nil, response, err | ||
} | ||
|
||
message := new(MessageResponse) | ||
if err = json.Unmarshal(*response.Body, message); err != nil { | ||
return nil, response, err | ||
} | ||
|
||
return message, response, nil | ||
} |
Oops, something went wrong.