Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify endpoint URL generation in Url function #397

Merged
merged 2 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ func (client *{{ classname }}) Do(req *http.Request) (*http.Response, error) {
}

func (client *{{ classname }}) Url(endpointPath string) string {
u := client.endpoint
u.Path = path.Join(u.Path, endpointPath)
newPath := path.Join(client.endpoint.Path, endpointPath)
u := *client.endpoint
u.Path = newPath
return u.String()
}

Expand Down
5 changes: 3 additions & 2 deletions linebot/channel_access_token/api_channel_access_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ func (client *ChannelAccessTokenAPI) Do(req *http.Request) (*http.Response, erro
}

func (client *ChannelAccessTokenAPI) Url(endpointPath string) string {
u := client.endpoint
u.Path = path.Join(u.Path, endpointPath)
newPath := path.Join(client.endpoint.Path, endpointPath)
u := *client.endpoint
u.Path = newPath
return u.String()
}

Expand Down
5 changes: 3 additions & 2 deletions linebot/insight/api_insight.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ func (client *InsightAPI) Do(req *http.Request) (*http.Response, error) {
}

func (client *InsightAPI) Url(endpointPath string) string {
u := client.endpoint
u.Path = path.Join(u.Path, endpointPath)
newPath := path.Join(client.endpoint.Path, endpointPath)
u := *client.endpoint
u.Path = newPath
return u.String()
}

Expand Down
5 changes: 3 additions & 2 deletions linebot/liff/api_liff.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ func (client *LiffAPI) Do(req *http.Request) (*http.Response, error) {
}

func (client *LiffAPI) Url(endpointPath string) string {
u := client.endpoint
u.Path = path.Join(u.Path, endpointPath)
newPath := path.Join(client.endpoint.Path, endpointPath)
u := *client.endpoint
u.Path = newPath
return u.String()
}

Expand Down
5 changes: 3 additions & 2 deletions linebot/manage_audience/api_manage_audience.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ func (client *ManageAudienceAPI) Do(req *http.Request) (*http.Response, error) {
}

func (client *ManageAudienceAPI) Url(endpointPath string) string {
u := client.endpoint
u.Path = path.Join(u.Path, endpointPath)
newPath := path.Join(client.endpoint.Path, endpointPath)
u := *client.endpoint
u.Path = newPath
return u.String()
}

Expand Down
5 changes: 3 additions & 2 deletions linebot/manage_audience/api_manage_audience_blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ func (client *ManageAudienceBlobAPI) Do(req *http.Request) (*http.Response, erro
}

func (client *ManageAudienceBlobAPI) Url(endpointPath string) string {
u := client.endpoint
u.Path = path.Join(u.Path, endpointPath)
newPath := path.Join(client.endpoint.Path, endpointPath)
u := *client.endpoint
u.Path = newPath
return u.String()
}

Expand Down
5 changes: 3 additions & 2 deletions linebot/messaging_api/api_messaging_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ func (client *MessagingApiAPI) Do(req *http.Request) (*http.Response, error) {
}

func (client *MessagingApiAPI) Url(endpointPath string) string {
u := client.endpoint
u.Path = path.Join(u.Path, endpointPath)
newPath := path.Join(client.endpoint.Path, endpointPath)
u := *client.endpoint
u.Path = newPath
return u.String()
}

Expand Down
5 changes: 3 additions & 2 deletions linebot/messaging_api/api_messaging_api_blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ func (client *MessagingApiBlobAPI) Do(req *http.Request) (*http.Response, error)
}

func (client *MessagingApiBlobAPI) Url(endpointPath string) string {
u := client.endpoint
u.Path = path.Join(u.Path, endpointPath)
newPath := path.Join(client.endpoint.Path, endpointPath)
u := *client.endpoint
u.Path = newPath
return u.String()
}

Expand Down
50 changes: 50 additions & 0 deletions linebot/messaging_api/tests/handwritten/calling_api_twice_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package tests

import (
"net/http"
"net/http/httptest"
"testing"

"github.com/line/line-bot-sdk-go/v8/linebot/messaging_api"
)

func TestCallingAPITwice(t *testing.T) {
server := httptest.NewServer(
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/v2/bot/message/push" {
t.Errorf("Expected path '/v2/bot/message/push', but got '%s'", r.URL.Path)
}
w.Header().Add("X-Line-Request-Id", "1234567890")
w.Write([]byte(`{}`))
}),
)
client, err := messaging_api.NewMessagingApiAPI(
"channelToken",
messaging_api.WithEndpoint(server.URL),
)
if err != nil {
t.Fatalf("Failed to create client: %v", err)
}
_, err = client.PushMessage(&messaging_api.PushMessageRequest{
Messages: []messaging_api.MessageInterface{
&messaging_api.TextMessage{
Text: "Hello, world",
},
},
}, "")
if err != nil {
t.Fatalf("Failed to get response: %v", err)
}

// call again
_, err = client.PushMessage(&messaging_api.PushMessageRequest{
Messages: []messaging_api.MessageInterface{
&messaging_api.TextMessage{
Text: "Hello, world",
},
},
}, "")
if err != nil {
t.Fatalf("Failed to get response: %v", err)
}
}
5 changes: 3 additions & 2 deletions linebot/module/api_line_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ func (client *LineModuleAPI) Do(req *http.Request) (*http.Response, error) {
}

func (client *LineModuleAPI) Url(endpointPath string) string {
u := client.endpoint
u.Path = path.Join(u.Path, endpointPath)
newPath := path.Join(client.endpoint.Path, endpointPath)
u := *client.endpoint
u.Path = newPath
return u.String()
}

Expand Down
5 changes: 3 additions & 2 deletions linebot/module_attach/api_line_module_attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ func (client *LineModuleAttachAPI) Do(req *http.Request) (*http.Response, error)
}

func (client *LineModuleAttachAPI) Url(endpointPath string) string {
u := client.endpoint
u.Path = path.Join(u.Path, endpointPath)
newPath := path.Join(client.endpoint.Path, endpointPath)
u := *client.endpoint
u.Path = newPath
return u.String()
}

Expand Down
5 changes: 3 additions & 2 deletions linebot/shop/api_shop.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ func (client *ShopAPI) Do(req *http.Request) (*http.Response, error) {
}

func (client *ShopAPI) Url(endpointPath string) string {
u := client.endpoint
u.Path = path.Join(u.Path, endpointPath)
newPath := path.Join(client.endpoint.Path, endpointPath)
u := *client.endpoint
u.Path = newPath
return u.String()
}

Expand Down