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

Add membership openapi #426

Closed
wants to merge 3 commits into from
Closed
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/line/line-bot-sdk-go/v8/linebot/liff"
"github.com/line/line-bot-sdk-go/v8/linebot/manage_audience"
"github.com/line/line-bot-sdk-go/v8/linebot/messaging_api"
"github.com/line/line-bot-sdk-go/v8/linebot/membership"
"github.com/line/line-bot-sdk-go/v8/linebot/module"
"github.com/line/line-bot-sdk-go/v8/linebot/module_attach"
"github.com/line/line-bot-sdk-go/v8/linebot/shop"
Expand Down
1 change: 1 addition & 0 deletions generate-code.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def generate_clients():
"module-attach.yml",
"module.yml",
"messaging-api.yml",
"membership.yml",
]

for sourceYaml in components:
Expand Down
23 changes: 23 additions & 0 deletions linebot/membership/.openapi-generator-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
8 changes: 8 additions & 0 deletions linebot/membership/.openapi-generator/FILES
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
api_membership.go
model_error_response.go
model_get_membership_subscription_response.go
model_membership.go
model_membership_list_response.go
model_membership_meta.go
model_membership_user.go
model_subscription.go
1 change: 1 addition & 0 deletions linebot/membership/.openapi-generator/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.0.0
237 changes: 237 additions & 0 deletions linebot/membership/api_membership.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
/**
* Membership API
* This document describes LINE Official Account Membership API.
*
* The version of the OpenAPI document: 0.0.1
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/

/**
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/

//go:generate python3 ../../generate-code.py

package membership

import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
"net/url"
"path"
"strings"

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

type MembershipAPI struct {
httpClient *http.Client
endpoint *url.URL
channelToken string
ctx context.Context
}

// MembershipAPIOption type
type MembershipAPIOption func(*MembershipAPI) error

// New returns a new bot client instance.
func NewMembershipAPI(channelToken string, options ...MembershipAPIOption) (*MembershipAPI, error) {
if channelToken == "" {
return nil, errors.New("missing channel access token")
}

c := &MembershipAPI{
channelToken: channelToken,
httpClient: http.DefaultClient,
}

u, err := url.ParseRequestURI("https://api.line.me")
if err != nil {
return nil, err
}
c.endpoint = u

for _, option := range options {
err := option(c)
if err != nil {
return nil, err
}
}
return c, nil
}

// WithContext method
func (call *MembershipAPI) WithContext(ctx context.Context) *MembershipAPI {
call.ctx = ctx
return call
}

func (client *MembershipAPI) Do(req *http.Request) (*http.Response, error) {
if client.channelToken != "" {
req.Header.Set("Authorization", "Bearer "+client.channelToken)
}
req.Header.Set("User-Agent", "LINE-BotSDK-Go/"+linebot.GetVersion())
if client.ctx != nil {
req = req.WithContext(client.ctx)
}
return client.httpClient.Do(req)
}

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

// WithHTTPClient function
func WithHTTPClient(c *http.Client) MembershipAPIOption {
return func(client *MembershipAPI) error {
client.httpClient = c
return nil
}
}

// WithEndpointClient function
func WithEndpoint(endpoint string) MembershipAPIOption {
return func(client *MembershipAPI) error {
u, err := url.ParseRequestURI(endpoint)
if err != nil {
return err
}
client.endpoint = u
return nil
}
}

// GetMembershipList
//
// Get a list of memberships.
// Parameters:

// https://developers.line.biz/en/reference/messaging-api/#get-membership-plans
func (client *MembershipAPI) GetMembershipList() (*MembershipListResponse, error) {
_, body, error := client.GetMembershipListWithHttpInfo()
return body, error
}

// GetMembershipList
// If you want to take advantage of the HTTPResponse object for status codes and headers, use this signature.
//
// Get a list of memberships.
// Parameters:

// https://developers.line.biz/en/reference/messaging-api/#get-membership-plans
func (client *MembershipAPI) GetMembershipListWithHttpInfo() (*http.Response, *MembershipListResponse, error) {
path := "/membership/v1/list"

req, err := http.NewRequest(http.MethodGet, client.Url(path), nil)
if err != nil {
return nil, nil, err
}

res, err := client.Do(req)

if err != nil {
return res, nil, err
}

if res.StatusCode/100 != 2 {
bodyBytes, err := io.ReadAll(res.Body)
bodyReader := bytes.NewReader(bodyBytes)
if err != nil {
return res, nil, fmt.Errorf("failed to read response body: %w", err)
}
res.Body = io.NopCloser(bodyReader)
return res, nil, fmt.Errorf("unexpected status code: %d, %s", res.StatusCode, string(bodyBytes))
}

defer res.Body.Close()

decoder := json.NewDecoder(res.Body)
result := MembershipListResponse{}
if err := decoder.Decode(&result); err != nil {
return res, nil, fmt.Errorf("failed to decode JSON: %w", err)
}
return res, &result, nil

}

// GetMembershipSubscription
//
// Get a user's membership subscription.
// Parameters:
// userId User ID

// https://developers.line.biz/en/reference/messaging-api/#get-a-users-membership-subscription-status
func (client *MembershipAPI) GetMembershipSubscription(

userId string,

) (*GetMembershipSubscriptionResponse, error) {
_, body, error := client.GetMembershipSubscriptionWithHttpInfo(

userId,
)
return body, error
}

// GetMembershipSubscription
// If you want to take advantage of the HTTPResponse object for status codes and headers, use this signature.
//
// Get a user's membership subscription.
// Parameters:
// userId User ID

// https://developers.line.biz/en/reference/messaging-api/#get-a-users-membership-subscription-status
func (client *MembershipAPI) GetMembershipSubscriptionWithHttpInfo(

userId string,

) (*http.Response, *GetMembershipSubscriptionResponse, error) {
path := "/membership/v1/subscription/{userId}"

path = strings.Replace(path, "{userId}", userId, -1)

req, err := http.NewRequest(http.MethodGet, client.Url(path), nil)
if err != nil {
return nil, nil, err
}

res, err := client.Do(req)

if err != nil {
return res, nil, err
}

if res.StatusCode/100 != 2 {
bodyBytes, err := io.ReadAll(res.Body)
bodyReader := bytes.NewReader(bodyBytes)
if err != nil {
return res, nil, fmt.Errorf("failed to read response body: %w", err)
}
res.Body = io.NopCloser(bodyReader)
return res, nil, fmt.Errorf("unexpected status code: %d, %s", res.StatusCode, string(bodyBytes))
}

defer res.Body.Close()

decoder := json.NewDecoder(res.Body)
result := GetMembershipSubscriptionResponse{}
if err := decoder.Decode(&result); err != nil {
return res, nil, fmt.Errorf("failed to decode JSON: %w", err)
}
return res, &result, nil

}
36 changes: 36 additions & 0 deletions linebot/membership/model_error_response.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Membership API
* This document describes LINE Official Account Membership API.
*
* The version of the OpenAPI document: 0.0.1
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/

/**
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/

//go:generate python3 ../../generate-code.py
package membership

// ErrorResponse
// ErrorResponse

type ErrorResponse struct {

/**
* Error message (Required)
*/
Message string `json:"message"`

/**
* Get Details
*/
Details []string `json:"details"`
}
31 changes: 31 additions & 0 deletions linebot/membership/model_get_membership_subscription_response.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Membership API
* This document describes LINE Official Account Membership API.
*
* The version of the OpenAPI document: 0.0.1
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/

/**
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/

//go:generate python3 ../../generate-code.py
package membership

// GetMembershipSubscriptionResponse
// A user's membership subscription status
// https://developers.line.biz/en/reference/messaging-api/#get-a-users-membership-subscription-status
type GetMembershipSubscriptionResponse struct {

/**
* List of subscription information (Required)
*/
Subscriptions []Subscription `json:"subscriptions"`
}
Loading
Loading