-
Notifications
You must be signed in to change notification settings - Fork 18
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
upgrade ver 0.1.0 (beta release) #35
Conversation
a372bdd
to
83127b1
Compare
b, _ := ioutil.ReadAll(req.Body) | ||
s := string(b) | ||
t.Body = &s | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
util.goのテストではなく、単体テストのヘルパーファイルなため、ファイル名を変更。
このヘルパー自体はgithub.com/jarcoal/httpmock
を使った方がモダンでリッチなことができるが、現状の単体テストに限れば上の修正で十分なため、外部ライブラリの使用は一旦見送る。
} | ||
defer resp.Body.Close() | ||
return ioutil.ReadAll(resp.Body) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
client.goに移した。
意味はないのだが、この関数がこのutilが扱ってる内容の中で浮いていたため。
8d3468c
to
f3ea442
Compare
@@ -42,32 +40,21 @@ type Plan struct { | |||
// | |||
// また、支払いの実行日を指定すると、支払い日の固定されたプランを生成することができます。 | |||
func (p PlanService) Create(plan Plan) (*PlanResponse, error) { | |||
var errors []string | |||
if plan.Amount < 50 || plan.Amount > 9999999 { | |||
errors = append(errors, fmt.Sprintf("Amount should be between 50 and 9,999,999, but %d.", plan.Amount)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
本題と関係ない修正。
基本的にSDKでバリデーションは、日付など普遍的なもの以外はしないよう改修。
リクエスト自体はさせて、サーバーからのエラーメッセージに任せる。
加盟店によっては50円未満決済可能であるし、将来金額上限やCurrencyが増える可能性もあるため。
この変更は既存ユーザーに影響しない。
v1/client.go
Outdated
continue | ||
} | ||
fieldV := v.Field(i) | ||
// if fieldV.Kind() != reflect.Ptr || fieldV.IsZero() { // todo golang >= 1.13 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
本当は使いたいけれどcompile only supportができなくなる。
https://pkg.go.dev/reflect#Value.IsZero
@@ -25,7 +22,7 @@ const ( | |||
SubscriptionPaused | |||
) | |||
|
|||
func (s SubscriptionStatus) status() interface{} { | |||
func (s SubscriptionStatus) String() string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UnmarshalJSONでも似た判定してるので統一したいですね。
Lines 394 to 403 in 744614f
switch raw.Status { | |
case "active": | |
s.Status = SubscriptionActive | |
case "trial": | |
s.Status = SubscriptionTrial | |
case "canceled": | |
s.Status = SubscriptionCanceled | |
case "paused": | |
s.Status = SubscriptionPaused | |
} |
軽微なので無視でいいんですが
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
- name: Execute Test | ||
run: go test -v ./v1 | ||
- name: Compile | ||
run: go build ./... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これの意味がよく分からないんですが… go build ./v1/*.go
ではないんですか
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
goにおけるワイルドカードのようです。カレントディレクトリ以下を再帰します。
v1/examplesなども含んで欲しいのでこちらにしています。
@@ -6,8 +6,8 @@ import ( | |||
"net/http" | |||
) | |||
|
|||
func NewMockClient(status int, response []byte) (*http.Client, *MockTransport) { | |||
transport := &MockTransport{ | |||
func newMockClient(status int, response []byte) (*http.Client, *mockTransport) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これprivate化しちゃって大丈夫ですかね?
これ使ってテスト書いちゃってるところとかないかな
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
それならテストこけそう。外の人って意味だと、元々公開前提ではないはずだし考慮しない(後方互換性ない)で良さそう
if service.APIBase() != "https://api.pay.jp/v2" { | ||
t.Errorf(`ApiBase should be "https://api.pay.jp/v2", but "%s"`, service.APIBase()) | ||
func TestRequests(t *testing.T) { | ||
mock, transport := newMockClient(400, errorJSON) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
v1/payjperror_test.goのerrorJSONに依存してるのがびっくりしますね。
errorJSONはtesthelpersに移動して良さそう
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
v1/client.go
Outdated
request.Header.Add("Authorization", s.apiKey) | ||
|
||
_, err = parseResponseError(s.Client.Do(request)) | ||
_, err = parseError(body) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parseErrorがここでしか使われないならここに中身書いてしまったらどうでしょう。
parseErrorという名前からは汎用的なエラーレスポンスのパースに使われそうで本来各リソースのUnmarshalJSON内でエラーを取り出す処理等にも使われるべきに思えますが、そこまでしないなら逆に違和感がありました。
同じロジック消してparseErrorで共通化するのがより良いとは思いますが、修正をこれ以上大きくするのもまぁためらわれるので…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
汎用化done
v1/examples/subscription/main.go
Outdated
@@ -3,38 +3,151 @@ package main | |||
import ( | |||
"fmt" | |||
"github.com/payjp/payjp-go/v1" | |||
"time" | |||
|
|||
//"time" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
要らなそう
// Update はプラン情報を更新します。 | ||
func (p PlanService) Update(id, name string) (*PlanResponse, error) { | ||
body, err := p.update(id, name) | ||
func (p PlanService) Update(id string, plan Plan) (*PlanResponse, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここは後方互換性のない変更。一応利用状況を確認する?
07106a4
to
04b204c
Compare
80c3329
to
66db653
Compare
66db653
to
43e2537
Compare
Until: Int(1455500895), | ||
}, | ||
} | ||
params.Offset = Int(0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
paramsの初期化はListParamsと一段深くなる。けれど初期化後はListParamsというクッションはなくなる。go struct embeddingのルール。
どちらで指定してもらっても構わない。
(一応、他社SDKに揃えるためにこうしたが、そもそもListParamsはいらないかも)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
バージョンに関してのところを特に相談したい
v1/client.go
Outdated
if err != nil { | ||
return nil, err | ||
} | ||
request.Header.Add("Authorization", s.apiKey) | ||
request.Header.Add("X-Payjp-Client-User-Agent", "payjp-go("+runtime.Version()+",os:"+runtime.GOOS+",arch:"+runtime.GOARCH+")") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sdkのリリースバージョンを定義したい…
request.Header.Add("X-Payjp-Client-User-Agent", "payjp-go("+runtime.Version()+",os:"+runtime.GOOS+",arch:"+runtime.GOARCH+")") | |
request.Header.Add("User-Agent", "payjp-go-http-client/v1.0.0") | |
request.Header.Add("X-Payjp-Client-User-Agent", "payjp-go(sdk-version:1.0.0,go-version:"+runtime.Version()+",os:"+runtime.GOOS+",arch:"+runtime.GOARCH+")") |
上記にして今回リリースしたらv1.0.0のtagきってリリース作るのはどうすかね。
このPRもただの修正PRではなくタイトルをv1.0.0とかにしていいと思う
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
User-Agentは一旦上書きしないで(これまでと同じ検索ができるようにして)おきます。
func (s Service) queryListAll(resourcePath string, limit, offset, since, until, sinceSheduledDate, untilSheduledDate int, callbacks ...func(*url.Values) bool) ([]byte, error) { | ||
if limit < 0 || limit > 100 { | ||
return nil, fmt.Errorf("method Limit() should be between 1 and 100, but %d", limit) | ||
func (s Service) makeEncoder(v reflect.Value, values url.Values) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
何の関数か説明を追記して欲しいです。渡されたパラメータをquerystring形式のstringに変換してる?
if callback(&values) { | ||
hasParam = true | ||
// 引数の構造体はメンバが全てポインタ型である必要があります | ||
func (s Service) getQuery(c interface{}) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これも。何の関数か説明を追記して欲しいです
v1/customer.go
Outdated
return c.caller.All(&c.CardListParams) | ||
} | ||
|
||
func (c *CustomerResponse) All(params ...*CardListParams) ([]*CardResponse, bool, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
顧客のカードリスト取得はAllCardとかにしたいです
v1/examples/plan/main.go
Outdated
fmt.Println(" LiveMode:", plan.LiveMode) | ||
fmt.Println(" Name:", plan.Name) | ||
fmt.Println(" TrialDays:", plan.TrialDays) | ||
plans, _, _ := payjpService.Plan.List().Limit(1).Do() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
plans, _, _ := payjpService.Plan.List().Limit(1).Do() | |
plans, _, _ := payjpService.Plan.All(&payjp.PlanListParams{ | |
ListParams: payjp.ListParams{ | |
Limit: payjp.Int(1), | |
}, | |
}) |
transferのexampleにListを使ってるのが残ってるのでそれも消したい
@@ -4,8 +4,6 @@ import ( | |||
"bytes" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
このファイルの実装全部client.goに移植でもいい気はする
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
一旦このまま(見送り)で!
} | ||
|
||
// Delete メソッドは顧客に登録されているカードを削除します | ||
// Customer情報から得られるカードでしか削除はできません | ||
func (c *CardResponse) Delete() error { | ||
if c.customerID == "" { | ||
return errors.New("Token's card doens't support Delete()") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
新linterにより。後方互換無くなるが影響極小と判断。
if err != nil { | ||
return nil, err | ||
} | ||
request.Header.Add("Authorization", s.apiKey) | ||
request.Header.Add("X-Payjp-Client-User-Agent", "payjp-go/"+Version+"("+runtime.Version()+",os:"+runtime.GOOS+",arch:"+runtime.GOARCH+")") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
request.Header.Add("X-Payjp-Client-User-Agent", "payjp-go/"+Version+"("+runtime.Version()+",os:"+runtime.GOOS+",arch:"+runtime.GOARCH+")") | |
request.Header.Add("User-Agent", "Go-http-client/payjp-"+Version) | |
request.Header.Add("X-Payjp-Client-User-Agent", "payjp-go/"+Version+"("+runtime.Version()+",os:"+runtime.GOOS+",arch:"+runtime.GOARCH+")") |
assert.Equal(t, "https://api.pay.jp/v1/test", transport.URL) | ||
assert.Equal(t, "POST", transport.Method) | ||
assert.Equal(t, "Basic YXBpLWtleTo=", transport.Header.Get("Authorization")) | ||
assert.Regexp(t, "^payjp-go/v[0-9.]+\\(go[0-9.]+,os\\:.+,arch\\:.+\\)$", transport.Header.Get("X-Payjp-Client-User-Agent")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert.Regexp(t, "^payjp-go/v[0-9.]+\\(go[0-9.]+,os\\:.+,arch\\:.+\\)$", transport.Header.Get("X-Payjp-Client-User-Agent")) | |
assert.Regexp(t, "^Go-http-client/payjp-v[0-9.]+$", transport.Header.Get("User-Agent")) | |
assert.Regexp(t, "^payjp-go/v[0-9.]+\\(go[0-9.]+,os\\:.+,arch\\:.+\\)$", transport.Header.Get("X-Payjp-Client-User-Agent")) |
594a170
to
c5e58b7
Compare
c5e58b7
to
5c822df
Compare
対応箇所と修正方針
XXX
がstring
型ならRawXXX
という*string
型を用意).List().Limit().Do()
のようなチェーンでの使用法をdeprecatedとする.All(params)
を用意し、params
にlimitやsubscription_idなどそれぞれで必要な引数を渡してもらう.List(params)
にしたかったが後方互換性のため断念(上のdeprecatedが完了したら.List(params)
も用意したい)go
欄を新設する)他細かい箇所
fmt.Print()
した際に自動で数値型ではなく文字列型となる。後方互換性を意識するなら関数名を変えても良い後方互換性のない箇所
いずれもニーズ・使用例が極端に低いであろう箇所のみ
fmt.Print()
した際に数値型ではなく文字列型となる