diff --git a/.openapi-generator-ignore b/.openapi-generator-ignore deleted file mode 100644 index 7484ee5..0000000 --- a/.openapi-generator-ignore +++ /dev/null @@ -1,23 +0,0 @@ -# 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 diff --git a/.openapi-generator/FILES b/.openapi-generator/FILES deleted file mode 100644 index b649627..0000000 --- a/.openapi-generator/FILES +++ /dev/null @@ -1,17 +0,0 @@ -.gitignore -.travis.yml -README.md -api\openapi.yaml -api_bca.go -client.go -configuration.go -docs\BCAApi.md -docs\InlineObject.md -docs\InlineObject1.md -git_push.sh -go.mod -go.sum -model_inline_object.go -model_inline_object_1.go -response.go -utils.go diff --git a/.openapi-generator/VERSION b/.openapi-generator/VERSION deleted file mode 100644 index 8836c81..0000000 --- a/.openapi-generator/VERSION +++ /dev/null @@ -1 +0,0 @@ -5.0.0-beta \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index f5cb2ce..0000000 --- a/.travis.yml +++ /dev/null @@ -1,8 +0,0 @@ -language: go - -install: - - go get -d -v . - -script: - - go build -v ./ - diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..427395e --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Ahmad Satryaji Aulia + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index ccbefcc..af9fce6 100644 --- a/README.md +++ b/README.md @@ -1,70 +1,42 @@ -# Go API client for bca +# bca-go -No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) +go-bca is the (unofficial) BCA SDK for the Go programming language. -## Overview -This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [OpenAPI-spec](https://www.openapis.org/) from a remote server, you can easily generate an API client. - -- API version: 1.0 -- Package version: 1.0.0 -- Build package: org.openapitools.codegen.languages.GoClientExperimentalCodegen +This SDK was kickstarted by the [OpenAPI Generator](https://openapi-generator.tech) project. ## Installation -Install the following dependencies: - ```shell -go get github.com/stretchr/testify/assert -go get golang.org/x/oauth2 -go get golang.org/x/net/context -``` - -Put the package under your project folder and add the following in import: - -```golang -import sw "./bca" -``` - -## Configuration of Server URL - -Default configuration comes with `Servers` field that contains server objects as defined in the OpenAPI specification. - -### Select Server Configuration - -For using other server than the one defined on index 0 set context value `sw.ContextServerIndex` of type `int`. - -```golang -ctx := context.WithValue(context.Background(), sw.ContextServerIndex, 1) +go get github.com/satraul/bca-go ``` -### Templated Server URL - -Templated server URL is formatted using default variables from configuration or from context value `sw.ContextServerVariables` of type `map[string]string`. +## Usage ```golang -ctx := context.WithValue(context.Background(), sw.ContextServerVariables, map[string]string{ - "basePath": "v2", -}) +import ( + bca "github.com/satraul/bca-go" +) + +func main() { + api := bca.NewAPIClient(bca.NewConfiguration()) + auth, err := api.Login(ctx, "username", "password", "1.2.3.4") + if err != nil { + panic(err) + } + + balance, err := api.BalanceInquiry(ctx, auth) + if err != nil { + panic(err) + } + log.Printf("%+v\n", balance) + + if err := api.Logout(ctx, auth); err != nil { + panic(err) + } +} ``` -Note, enum values are always validated and all unused variables are silently ignored. - -### URLs Configuration per Operation - -Each operation can use different server URL defined using `OperationServers` map in the `Configuration`. -An operation is uniquely identifield by `"{classname}Service.{nickname}"` string. -Similar rules for overriding default operation server index and variables applies by using `sw.ContextOperationServerIndices` and `sw.ContextOperationServerVariables` context maps. - -``` -ctx := context.WithValue(context.Background(), sw.ContextOperationServerIndices, map[string]int{ - "{classname}Service.{nickname}": 2, -}) -ctx = context.WithValue(context.Background(), sw.ContextOperationServerVariables, map[string]map[string]string{ - "{classname}Service.{nickname}": { - "port": "8443", - }, -}) -``` +See the a full example at [example/example.go](example/example.go). ## Documentation for API Endpoints @@ -76,37 +48,15 @@ Class | Method | HTTP request | Description *BCAApi* | [**BalanceInquiry**](docs/BCAApi.md#balanceinquiry) | **Post** /balanceinquiry.do | BalanceInquiry *BCAApi* | [**Login**](docs/BCAApi.md#login) | **Post** /authentication.do | Login *BCAApi* | [**Logout**](docs/BCAApi.md#logout) | **Get** /authentication.do?value(actions)=logout | Logout -*BCAApi* | [**Menu**](docs/BCAApi.md#menu) | **Post** /accountstmt.do?value(actions)=menu | Menu - - -## Documentation For Models - - - [InlineObject](docs/InlineObject.md) - - [InlineObject1](docs/InlineObject1.md) - ## Documentation For Authorization - Endpoints do not require authorization. - - -## Documentation for Utility Methods - -Due to the fact that model structure members are all pointers, this package contains -a number of utility functions to easily obtain pointers to values of basic types. -Each of these functions takes a value of the given basic type and returns a pointer to it: - -* `PtrBool` -* `PtrInt` -* `PtrInt32` -* `PtrInt64` -* `PtrFloat` -* `PtrFloat32` -* `PtrFloat64` -* `PtrString` -* `PtrTime` +[**Login**](docs/BCAApi.md#login) will return session cookies (`[]*Cookie`) that are used for auth in all other endpoints. -## Author +## Contributing +Pull requests are welcome. +## License +[MIT](LICENSE) \ No newline at end of file diff --git a/api/openapi.yaml b/api/openapi.yaml deleted file mode 100644 index dd12a05..0000000 --- a/api/openapi.yaml +++ /dev/null @@ -1,509 +0,0 @@ -openapi: 3.0.0 -info: - contact: {} - title: BCA - version: "1.0" -servers: -- url: https://m.klikbca.com -tags: -- name: BCA -paths: - /authentication.do?value(actions)=logout: - get: - deprecated: false - operationId: Logout - parameters: - - explode: false - in: header - name: User-Agent - required: true - schema: - enum: - - Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 - (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1 - example: Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 - (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1 - type: string - style: simple - - explode: false - in: header - name: Referer - required: true - schema: - enum: - - https://m.klikbca.com/accountstmt.do?value(actions)=acctstmtview - example: https://m.klikbca.com/accountstmt.do?value(actions)=acctstmtview - type: string - style: simple - - explode: true - in: query - name: value(actions) - required: true - schema: - enum: - - logout - example: logout - type: string - style: form - - explode: false - in: header - name: Cookie - required: true - schema: - type: string - style: simple - responses: - "200": - content: - text/plain: - schema: - type: object - summary: Logout - tags: - - BCA - /accountstmt.do?value(actions)=acctstmtview: - post: - deprecated: false - operationId: AccountStatementView - parameters: - - explode: false - in: header - name: Content-Type - required: true - schema: - example: application/x-www-form-urlencoded - type: string - style: simple - - explode: false - in: header - name: User-Agent - required: true - schema: - enum: - - Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 - (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1 - example: Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 - (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1 - type: string - style: simple - - explode: false - in: header - name: Referer - required: true - schema: - enum: - - https://m.klikbca.com/accountstmt.do?value(actions)=acct_stmt - example: https://m.klikbca.com/accountstmt.do?value(actions)=acct_stmt - type: string - style: simple - - explode: true - in: query - name: value(actions) - required: true - schema: - enum: - - acctstmtview - example: acctstmtview - type: string - style: form - - explode: false - in: header - name: Cookie - required: true - schema: - type: string - style: simple - - explode: false - in: header - name: Content-Length - required: true - schema: - example: "3495" - type: string - style: simple - requestBody: - $ref: '#/components/requestBodies/inline_object' - content: - application/x-www-form-urlencoded: - encoding: {} - schema: - properties: - r1: - example: "1" - type: string - value%28D1%29: - example: "0" - type: string - value%28startDt%29: - example: "14" - type: string - value%28startMt%29: - example: "8.0" - type: string - value%28startYr%29: - example: "2020" - type: string - value%28endDt%29: - example: "20" - type: string - value%28endMt%29: - example: "8.0" - type: string - value%28endYr%29: - example: "2020" - type: string - required: - - r1 - - value%28D1%29 - - value%28endDt%29 - - value%28endMt%29 - - value%28endYr%29 - - value%28startDt%29 - - value%28startMt%29 - - value%28startYr%29 - type: object - required: false - responses: - "200": - content: - text/plain: - schema: - type: object - summary: AccountStatementView - tags: - - BCA - /balanceinquiry.do: - post: - deprecated: false - operationId: BalanceInquiry - parameters: - - explode: false - in: header - name: Content-Type - required: true - schema: - enum: - - application/x-www-form-urlencoded - example: application/x-www-form-urlencoded - type: string - style: simple - - explode: false - in: header - name: User-Agent - required: true - schema: - enum: - - Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 - (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1 - example: Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 - (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1 - type: string - style: simple - - explode: false - in: header - name: Referer - required: true - schema: - enum: - - https://m.klikbca.com/accountstmt.do?value(actions)=menu - example: https://m.klikbca.com/accountstmt.do?value(actions)=menu - type: string - style: simple - - explode: false - in: header - name: Cookie - required: true - schema: - type: string - style: simple - - explode: false - in: header - name: Content-Length - required: true - schema: - enum: - - "0" - example: "0" - type: string - style: simple - responses: - "200": - content: - text/plain: - schema: - type: object - summary: BalanceInquiry - tags: - - BCA - /accountstmt.do?value(actions)=menu: - post: - deprecated: false - operationId: Menu - parameters: - - explode: false - in: header - name: Content-Type - required: true - schema: - enum: - - application/x-www-form-urlencoded - example: application/x-www-form-urlencoded - type: string - style: simple - - explode: false - in: header - name: User-Agent - required: true - schema: - enum: - - Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 - (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1 - example: Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 - (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1 - type: string - style: simple - - explode: false - in: header - name: Referer - required: true - schema: - enum: - - https://m.klikbca.com/authentication.do - example: https://m.klikbca.com/authentication.do - type: string - style: simple - - explode: true - in: query - name: value(actions) - required: true - schema: - enum: - - menu - example: menu - type: string - style: form - - explode: false - in: header - name: Cookie - required: true - schema: - type: string - style: simple - - explode: false - in: header - name: Content-Length - required: true - schema: - enum: - - "0" - example: "0" - type: string - style: simple - responses: - "200": - content: - text/plain: - schema: - type: object - summary: Menu - tags: - - BCA - /authentication.do: - post: - deprecated: false - operationId: Login - parameters: - - explode: false - in: header - name: Content-Type - required: true - schema: - enum: - - application/x-www-form-urlencoded - example: application/x-www-form-urlencoded - type: string - style: simple - - explode: false - in: header - name: User-Agent - required: true - schema: - enum: - - Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 - (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1 - example: Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 - (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1 - type: string - style: simple - - explode: false - in: header - name: Referer - required: true - schema: - enum: - - https://m.klikbca.com/login.jsp - example: https://m.klikbca.com/login.jsp - type: string - style: simple - - explode: false - in: header - name: Cookie - required: true - schema: - type: string - style: simple - - explode: true - in: query - name: Content-Length - required: true - schema: - example: 3495 - format: int32 - type: integer - style: form - requestBody: - $ref: '#/components/requestBodies/inline_object_1' - content: - application/x-www-form-urlencoded: - encoding: {} - schema: - properties: - value%28user_id%29: - example: username - type: string - value%28pswd%29: - example: "111111" - type: string - value%28Submit%29: - example: LOGIN - type: string - value%28actions%29: - example: login - type: string - value%28user_ip%29: - example: 1.1.1.1 - type: string - user_ip: - example: 1.1.1.1 - type: string - value%28mobile%29: - example: "true" - type: string - value%28browser_info%29: - example: Mozilla%2F5.0+%28iPhone%3B+CPU+iPhone+OS+10_3_1+like+Mac+OS+X%29+AppleWebKit%2F603.1.30+%28KHTML%2C+like+Gecko%29+Version%2F10.0+Mobile%2F14E304+Safari%2F602.1 - type: string - mobile: - example: "true" - type: string - required: - - mobile - - user_ip - - value%28Submit%29 - - value%28actions%29 - - value%28browser_info%29 - - value%28mobile%29 - - value%28pswd%29 - - value%28user_id%29 - - value%28user_ip%29 - type: object - required: false - responses: - "200": - content: - text/plain: - schema: - type: object - summary: Login - tags: - - BCA -components: - requestBodies: - inline_object_1: - content: - application/x-www-form-urlencoded: - schema: - $ref: '#/components/schemas/inline_object_1' - required: false - inline_object: - content: - application/x-www-form-urlencoded: - schema: - $ref: '#/components/schemas/inline_object' - required: false - schemas: - inline_object_1: - properties: - value%28user_id%29: - example: username - type: string - value%28pswd%29: - example: "111111" - type: string - value%28Submit%29: - example: LOGIN - type: string - value%28actions%29: - example: login - type: string - value%28user_ip%29: - example: 1.1.1.1 - type: string - user_ip: - example: 1.1.1.1 - type: string - value%28mobile%29: - example: "true" - type: string - value%28browser_info%29: - example: Mozilla%2F5.0+%28iPhone%3B+CPU+iPhone+OS+10_3_1+like+Mac+OS+X%29+AppleWebKit%2F603.1.30+%28KHTML%2C+like+Gecko%29+Version%2F10.0+Mobile%2F14E304+Safari%2F602.1 - type: string - mobile: - example: "true" - type: string - required: - - mobile - - user_ip - - value%28Submit%29 - - value%28actions%29 - - value%28browser_info%29 - - value%28mobile%29 - - value%28pswd%29 - - value%28user_id%29 - - value%28user_ip%29 - type: object - inline_object: - properties: - r1: - example: "1" - type: string - value%28D1%29: - example: "0" - type: string - value%28startDt%29: - example: "14" - type: string - value%28startMt%29: - example: "8.0" - type: string - value%28startYr%29: - example: "2020" - type: string - value%28endDt%29: - example: "20" - type: string - value%28endMt%29: - example: "8.0" - type: string - value%28endYr%29: - example: "2020" - type: string - required: - - r1 - - value%28D1%29 - - value%28endDt%29 - - value%28endMt%29 - - value%28endYr%29 - - value%28startDt%29 - - value%28startMt%29 - - value%28startYr%29 - type: object diff --git a/api_bca.go b/api_bca.go index 24dbf13..f7fbf47 100644 --- a/api_bca.go +++ b/api_bca.go @@ -11,9 +11,12 @@ package bca import ( _context "context" + "errors" _ioutil "io/ioutil" + "net/http" _nethttp "net/http" _neturl "net/url" + "time" ) // Linger please @@ -24,190 +27,52 @@ var ( // BCAApiService BCAApi service type BCAApiService service -type apiAccountStatementViewRequest struct { - ctx _context.Context - apiService *BCAApiService - contentType *string - userAgent *string - referer *string - valueActions *string - cookie *string - contentLength *string - r1 *string - value28D129 *string - value28startDt29 *string - value28startMt29 *string - value28startYr29 *string - value28endDt29 *string - value28endMt29 *string - value28endYr29 *string -} - - -func (r apiAccountStatementViewRequest) ContentType(contentType string) apiAccountStatementViewRequest { - r.contentType = &contentType - return r -} - -func (r apiAccountStatementViewRequest) UserAgent(userAgent string) apiAccountStatementViewRequest { - r.userAgent = &userAgent - return r -} - -func (r apiAccountStatementViewRequest) Referer(referer string) apiAccountStatementViewRequest { - r.referer = &referer - return r -} - -func (r apiAccountStatementViewRequest) ValueActions(valueActions string) apiAccountStatementViewRequest { - r.valueActions = &valueActions - return r -} - -func (r apiAccountStatementViewRequest) Cookie(cookie string) apiAccountStatementViewRequest { - r.cookie = &cookie - return r -} - -func (r apiAccountStatementViewRequest) ContentLength(contentLength string) apiAccountStatementViewRequest { - r.contentLength = &contentLength - return r -} - -func (r apiAccountStatementViewRequest) R1(r1 string) apiAccountStatementViewRequest { - r.r1 = &r1 - return r -} - -func (r apiAccountStatementViewRequest) Value28D129(value28D129 string) apiAccountStatementViewRequest { - r.value28D129 = &value28D129 - return r -} - -func (r apiAccountStatementViewRequest) Value28startDt29(value28startDt29 string) apiAccountStatementViewRequest { - r.value28startDt29 = &value28startDt29 - return r -} - -func (r apiAccountStatementViewRequest) Value28startMt29(value28startMt29 string) apiAccountStatementViewRequest { - r.value28startMt29 = &value28startMt29 - return r -} - -func (r apiAccountStatementViewRequest) Value28startYr29(value28startYr29 string) apiAccountStatementViewRequest { - r.value28startYr29 = &value28startYr29 - return r -} - -func (r apiAccountStatementViewRequest) Value28endDt29(value28endDt29 string) apiAccountStatementViewRequest { - r.value28endDt29 = &value28endDt29 - return r -} - -func (r apiAccountStatementViewRequest) Value28endMt29(value28endMt29 string) apiAccountStatementViewRequest { - r.value28endMt29 = &value28endMt29 - return r -} - -func (r apiAccountStatementViewRequest) Value28endYr29(value28endYr29 string) apiAccountStatementViewRequest { - r.value28endYr29 = &value28endYr29 - return r -} - /* AccountStatementView AccountStatementView * @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). -@return apiAccountStatementViewRequest -*/ -func (a *BCAApiService) AccountStatementView(ctx _context.Context) apiAccountStatementViewRequest { - return apiAccountStatementViewRequest{ - apiService: a, - ctx: ctx, - } -} - -/* -Execute executes the request - @return map[string]interface{} + * @param contentType + * @param userAgent + * @param referer + * @param valueActions + * @param cookie + * @param contentLength + * @param r1 + * @param value28D129 + * @param value28startDt29 + * @param value28startMt29 + * @param value28startYr29 + * @param value28endDt29 + * @param value28endMt29 + * @param value28endYr29 +@return map[string]interface{} */ -func (r apiAccountStatementViewRequest) Execute() (map[string]interface{}, *_nethttp.Response, error) { +func (a *BCAApiService) AccountStatementView(ctx _context.Context, startDate time.Time, endDate time.Time, cookies []*http.Cookie) ([]Entry, error) { var ( localVarHTTPMethod = _nethttp.MethodPost localVarPostBody interface{} localVarFormFileName string localVarFileName string localVarFileBytes []byte - localVarReturnValue map[string]interface{} + localVarReturnValue []Entry + localVarCookies []*http.Cookie ) - localBasePath, err := r.apiService.client.cfg.ServerURLWithContext(r.ctx, "BCAApiService.AccountStatementView") - if err != nil { - return localVarReturnValue, nil, GenericOpenAPIError{error: err.Error()} + // validate dates + if startDate.After(endDate) { + return localVarReturnValue, errors.New("date invalid: start date must be before end date") + } + if endDate.AddDate(0, 0, -7).Before(startDate) { + return localVarReturnValue, errors.New("date invalid: range must be less than 7 days") } - localVarPath := localBasePath + "/accountstmt.do?value(actions)=acctstmtview" - + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/accountstmt.do" localVarHeaderParams := make(map[string]string) localVarQueryParams := _neturl.Values{} localVarFormParams := _neturl.Values{} - - if r.contentType == nil { - return localVarReturnValue, nil, reportError("contentType is required and must be specified") - } - - if r.userAgent == nil { - return localVarReturnValue, nil, reportError("userAgent is required and must be specified") - } - - if r.referer == nil { - return localVarReturnValue, nil, reportError("referer is required and must be specified") - } - - if r.valueActions == nil { - return localVarReturnValue, nil, reportError("valueActions is required and must be specified") - } - - if r.cookie == nil { - return localVarReturnValue, nil, reportError("cookie is required and must be specified") - } - - if r.contentLength == nil { - return localVarReturnValue, nil, reportError("contentLength is required and must be specified") - } - - if r.r1 == nil { - return localVarReturnValue, nil, reportError("r1 is required and must be specified") - } - - if r.value28D129 == nil { - return localVarReturnValue, nil, reportError("value28D129 is required and must be specified") - } - - if r.value28startDt29 == nil { - return localVarReturnValue, nil, reportError("value28startDt29 is required and must be specified") - } - - if r.value28startMt29 == nil { - return localVarReturnValue, nil, reportError("value28startMt29 is required and must be specified") - } - - if r.value28startYr29 == nil { - return localVarReturnValue, nil, reportError("value28startYr29 is required and must be specified") - } - - if r.value28endDt29 == nil { - return localVarReturnValue, nil, reportError("value28endDt29 is required and must be specified") - } - - if r.value28endMt29 == nil { - return localVarReturnValue, nil, reportError("value28endMt29 is required and must be specified") - } - - if r.value28endYr29 == nil { - return localVarReturnValue, nil, reportError("value28endYr29 is required and must be specified") - } + localVarCookies = cookies - localVarQueryParams.Add("value(actions)", parameterToString(*r.valueActions, "")) + localVarQueryParams.Add("value(actions)", parameterToString("acctstmtview", "")) // to determine the Content-Type header localVarHTTPContentTypes := []string{"application/x-www-form-urlencoded"} @@ -218,40 +83,36 @@ func (r apiAccountStatementViewRequest) Execute() (map[string]interface{}, *_net } // to determine the Accept header - localVarHTTPHeaderAccepts := []string{"text/plain"} + localVarHTTPHeaderAccepts := []string{"*/*"} // set Accept header localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) if localVarHTTPHeaderAccept != "" { localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept } - localVarHeaderParams["Content-Type"] = parameterToString(*r.contentType, "") - localVarHeaderParams["User-Agent"] = parameterToString(*r.userAgent, "") - localVarHeaderParams["Referer"] = parameterToString(*r.referer, "") - localVarHeaderParams["Cookie"] = parameterToString(*r.cookie, "") - localVarHeaderParams["Content-Length"] = parameterToString(*r.contentLength, "") - localVarFormParams.Add("r1", parameterToString(*r.r1, "")) - localVarFormParams.Add("value%28D1%29", parameterToString(*r.value28D129, "")) - localVarFormParams.Add("value%28startDt%29", parameterToString(*r.value28startDt29, "")) - localVarFormParams.Add("value%28startMt%29", parameterToString(*r.value28startMt29, "")) - localVarFormParams.Add("value%28startYr%29", parameterToString(*r.value28startYr29, "")) - localVarFormParams.Add("value%28endDt%29", parameterToString(*r.value28endDt29, "")) - localVarFormParams.Add("value%28endMt%29", parameterToString(*r.value28endMt29, "")) - localVarFormParams.Add("value%28endYr%29", parameterToString(*r.value28endYr29, "")) - req, err := r.apiService.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFormFileName, localVarFileName, localVarFileBytes) + localVarHeaderParams["Referer"] = parameterToString("https://m.klikbca.com/accountstmt.do?value(actions)=acct_stmt", "") + localVarFormParams.Add("r1", parameterToString("1", "")) + localVarFormParams.Add("value(D1)", parameterToString("0", "")) + localVarFormParams.Add("value(startDt)", parameterToString(startDate.Day(), "")) + localVarFormParams.Add("value(startMt)", parameterToString(int(startDate.Month()), "")) + localVarFormParams.Add("value(startYr)", parameterToString(startDate.Year(), "")) + localVarFormParams.Add("value(endDt)", parameterToString(endDate.Day(), "")) + localVarFormParams.Add("value(endMt)", parameterToString(int(endDate.Month()), "")) + localVarFormParams.Add("value(endYr)", parameterToString(endDate.Year(), "")) + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFormFileName, localVarFileName, localVarFileBytes, localVarCookies) if err != nil { - return localVarReturnValue, nil, err + return localVarReturnValue, err } - localVarHTTPResponse, err := r.apiService.client.callAPI(req) + localVarHTTPResponse, err := a.client.callAPI(r) if err != nil || localVarHTTPResponse == nil { - return localVarReturnValue, localVarHTTPResponse, err + return localVarReturnValue, err } localVarBody, err := _ioutil.ReadAll(localVarHTTPResponse.Body) localVarHTTPResponse.Body.Close() if err != nil { - return localVarReturnValue, localVarHTTPResponse, err + return localVarReturnValue, err } if localVarHTTPResponse.StatusCode >= 300 { @@ -259,112 +120,48 @@ func (r apiAccountStatementViewRequest) Execute() (map[string]interface{}, *_net body: localVarBody, error: localVarHTTPResponse.Status, } - return localVarReturnValue, localVarHTTPResponse, newErr + return localVarReturnValue, newErr } - err = r.apiService.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) if err != nil { newErr := GenericOpenAPIError{ body: localVarBody, error: err.Error(), } - return localVarReturnValue, localVarHTTPResponse, newErr + return localVarReturnValue, newErr } - return localVarReturnValue, localVarHTTPResponse, nil -} -type apiBalanceInquiryRequest struct { - ctx _context.Context - apiService *BCAApiService - contentType *string - userAgent *string - referer *string - cookie *string - contentLength *string -} - - -func (r apiBalanceInquiryRequest) ContentType(contentType string) apiBalanceInquiryRequest { - r.contentType = &contentType - return r -} - -func (r apiBalanceInquiryRequest) UserAgent(userAgent string) apiBalanceInquiryRequest { - r.userAgent = &userAgent - return r -} - -func (r apiBalanceInquiryRequest) Referer(referer string) apiBalanceInquiryRequest { - r.referer = &referer - return r -} - -func (r apiBalanceInquiryRequest) Cookie(cookie string) apiBalanceInquiryRequest { - r.cookie = &cookie - return r -} - -func (r apiBalanceInquiryRequest) ContentLength(contentLength string) apiBalanceInquiryRequest { - r.contentLength = &contentLength - return r + return localVarReturnValue, nil } /* BalanceInquiry BalanceInquiry * @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). -@return apiBalanceInquiryRequest -*/ -func (a *BCAApiService) BalanceInquiry(ctx _context.Context) apiBalanceInquiryRequest { - return apiBalanceInquiryRequest{ - apiService: a, - ctx: ctx, - } -} - -/* -Execute executes the request - @return map[string]interface{} + * @param contentType + * @param userAgent + * @param referer + * @param cookie + * @param contentLength +@return map[string]interface{} */ -func (r apiBalanceInquiryRequest) Execute() (map[string]interface{}, *_nethttp.Response, error) { +func (a *BCAApiService) BalanceInquiry(ctx _context.Context, cookies []*http.Cookie) (Balance, error) { var ( localVarHTTPMethod = _nethttp.MethodPost localVarPostBody interface{} localVarFormFileName string localVarFileName string localVarFileBytes []byte - localVarReturnValue map[string]interface{} + localVarReturnValue Balance + localVarCookies []*http.Cookie ) - localBasePath, err := r.apiService.client.cfg.ServerURLWithContext(r.ctx, "BCAApiService.BalanceInquiry") - if err != nil { - return localVarReturnValue, nil, GenericOpenAPIError{error: err.Error()} - } - - localVarPath := localBasePath + "/balanceinquiry.do" - + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/balanceinquiry.do" localVarHeaderParams := make(map[string]string) localVarQueryParams := _neturl.Values{} localVarFormParams := _neturl.Values{} - - if r.contentType == nil { - return localVarReturnValue, nil, reportError("contentType is required and must be specified") - } - - if r.userAgent == nil { - return localVarReturnValue, nil, reportError("userAgent is required and must be specified") - } - - if r.referer == nil { - return localVarReturnValue, nil, reportError("referer is required and must be specified") - } - - if r.cookie == nil { - return localVarReturnValue, nil, reportError("cookie is required and must be specified") - } - - if r.contentLength == nil { - return localVarReturnValue, nil, reportError("contentLength is required and must be specified") - } + localVarCookies = cookies // to determine the Content-Type header localVarHTTPContentTypes := []string{} @@ -376,32 +173,28 @@ func (r apiBalanceInquiryRequest) Execute() (map[string]interface{}, *_nethttp.R } // to determine the Accept header - localVarHTTPHeaderAccepts := []string{"text/plain"} + localVarHTTPHeaderAccepts := []string{"*/*"} // set Accept header localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) if localVarHTTPHeaderAccept != "" { localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept } - localVarHeaderParams["Content-Type"] = parameterToString(*r.contentType, "") - localVarHeaderParams["User-Agent"] = parameterToString(*r.userAgent, "") - localVarHeaderParams["Referer"] = parameterToString(*r.referer, "") - localVarHeaderParams["Cookie"] = parameterToString(*r.cookie, "") - localVarHeaderParams["Content-Length"] = parameterToString(*r.contentLength, "") - req, err := r.apiService.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFormFileName, localVarFileName, localVarFileBytes) + localVarHeaderParams["Referer"] = parameterToString("https://m.klikbca.com/accountstmt.do?value(actions)=menu", "") + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFormFileName, localVarFileName, localVarFileBytes, localVarCookies) if err != nil { - return localVarReturnValue, nil, err + return localVarReturnValue, err } - localVarHTTPResponse, err := r.apiService.client.callAPI(req) + localVarHTTPResponse, err := a.client.callAPI(r) if err != nil || localVarHTTPResponse == nil { - return localVarReturnValue, localVarHTTPResponse, err + return localVarReturnValue, err } localVarBody, err := _ioutil.ReadAll(localVarHTTPResponse.Body) localVarHTTPResponse.Body.Close() if err != nil { - return localVarReturnValue, localVarHTTPResponse, err + return localVarReturnValue, err } if localVarHTTPResponse.StatusCode >= 300 { @@ -409,204 +202,45 @@ func (r apiBalanceInquiryRequest) Execute() (map[string]interface{}, *_nethttp.R body: localVarBody, error: localVarHTTPResponse.Status, } - return localVarReturnValue, localVarHTTPResponse, newErr + return localVarReturnValue, newErr } - err = r.apiService.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) if err != nil { newErr := GenericOpenAPIError{ body: localVarBody, error: err.Error(), } - return localVarReturnValue, localVarHTTPResponse, newErr + return localVarReturnValue, newErr } - return localVarReturnValue, localVarHTTPResponse, nil -} -type apiLoginRequest struct { - ctx _context.Context - apiService *BCAApiService - contentType *string - userAgent *string - referer *string - cookie *string - contentLength *int32 - value28userId29 *string - value28pswd29 *string - value28Submit29 *string - value28actions29 *string - value28userIp29 *string - userIp *string - value28mobile29 *string - value28browserInfo29 *string - mobile *string -} - - -func (r apiLoginRequest) ContentType(contentType string) apiLoginRequest { - r.contentType = &contentType - return r -} - -func (r apiLoginRequest) UserAgent(userAgent string) apiLoginRequest { - r.userAgent = &userAgent - return r -} - -func (r apiLoginRequest) Referer(referer string) apiLoginRequest { - r.referer = &referer - return r -} - -func (r apiLoginRequest) Cookie(cookie string) apiLoginRequest { - r.cookie = &cookie - return r -} - -func (r apiLoginRequest) ContentLength(contentLength int32) apiLoginRequest { - r.contentLength = &contentLength - return r -} - -func (r apiLoginRequest) Value28userId29(value28userId29 string) apiLoginRequest { - r.value28userId29 = &value28userId29 - return r -} - -func (r apiLoginRequest) Value28pswd29(value28pswd29 string) apiLoginRequest { - r.value28pswd29 = &value28pswd29 - return r -} - -func (r apiLoginRequest) Value28Submit29(value28Submit29 string) apiLoginRequest { - r.value28Submit29 = &value28Submit29 - return r -} - -func (r apiLoginRequest) Value28actions29(value28actions29 string) apiLoginRequest { - r.value28actions29 = &value28actions29 - return r -} - -func (r apiLoginRequest) Value28userIp29(value28userIp29 string) apiLoginRequest { - r.value28userIp29 = &value28userIp29 - return r -} - -func (r apiLoginRequest) UserIp(userIp string) apiLoginRequest { - r.userIp = &userIp - return r -} - -func (r apiLoginRequest) Value28mobile29(value28mobile29 string) apiLoginRequest { - r.value28mobile29 = &value28mobile29 - return r -} - -func (r apiLoginRequest) Value28browserInfo29(value28browserInfo29 string) apiLoginRequest { - r.value28browserInfo29 = &value28browserInfo29 - return r -} - -func (r apiLoginRequest) Mobile(mobile string) apiLoginRequest { - r.mobile = &mobile - return r + return localVarReturnValue, nil } /* Login Login * @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). -@return apiLoginRequest -*/ -func (a *BCAApiService) Login(ctx _context.Context) apiLoginRequest { - return apiLoginRequest{ - apiService: a, - ctx: ctx, - } -} - -/* -Execute executes the request - @return map[string]interface{} + * @param userID + * @param password + * @param userIP - Client's public IP +@return []*http.Cookie */ -func (r apiLoginRequest) Execute() (map[string]interface{}, *_nethttp.Response, error) { +func (a *BCAApiService) Login(ctx _context.Context, userID string, password string, userIP string) ([]*http.Cookie, error) { var ( localVarHTTPMethod = _nethttp.MethodPost localVarPostBody interface{} localVarFormFileName string localVarFileName string localVarFileBytes []byte - localVarReturnValue map[string]interface{} + localVarCookies []*http.Cookie ) - localBasePath, err := r.apiService.client.cfg.ServerURLWithContext(r.ctx, "BCAApiService.Login") - if err != nil { - return localVarReturnValue, nil, GenericOpenAPIError{error: err.Error()} - } - - localVarPath := localBasePath + "/authentication.do" - + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/authentication.do" localVarHeaderParams := make(map[string]string) localVarQueryParams := _neturl.Values{} localVarFormParams := _neturl.Values{} - - if r.contentType == nil { - return localVarReturnValue, nil, reportError("contentType is required and must be specified") - } - - if r.userAgent == nil { - return localVarReturnValue, nil, reportError("userAgent is required and must be specified") - } - - if r.referer == nil { - return localVarReturnValue, nil, reportError("referer is required and must be specified") - } - - if r.cookie == nil { - return localVarReturnValue, nil, reportError("cookie is required and must be specified") - } - - if r.contentLength == nil { - return localVarReturnValue, nil, reportError("contentLength is required and must be specified") - } - - if r.value28userId29 == nil { - return localVarReturnValue, nil, reportError("value28userId29 is required and must be specified") - } - - if r.value28pswd29 == nil { - return localVarReturnValue, nil, reportError("value28pswd29 is required and must be specified") - } - - if r.value28Submit29 == nil { - return localVarReturnValue, nil, reportError("value28Submit29 is required and must be specified") - } - - if r.value28actions29 == nil { - return localVarReturnValue, nil, reportError("value28actions29 is required and must be specified") - } - - if r.value28userIp29 == nil { - return localVarReturnValue, nil, reportError("value28userIp29 is required and must be specified") - } - - if r.userIp == nil { - return localVarReturnValue, nil, reportError("userIp is required and must be specified") - } - - if r.value28mobile29 == nil { - return localVarReturnValue, nil, reportError("value28mobile29 is required and must be specified") - } - - if r.value28browserInfo29 == nil { - return localVarReturnValue, nil, reportError("value28browserInfo29 is required and must be specified") - } - - if r.mobile == nil { - return localVarReturnValue, nil, reportError("mobile is required and must be specified") - } - localVarQueryParams.Add("Content-Length", parameterToString(*r.contentLength, "")) // to determine the Content-Type header localVarHTTPContentTypes := []string{"application/x-www-form-urlencoded"} @@ -617,40 +251,37 @@ func (r apiLoginRequest) Execute() (map[string]interface{}, *_nethttp.Response, } // to determine the Accept header - localVarHTTPHeaderAccepts := []string{"text/plain"} + localVarHTTPHeaderAccepts := []string{"*/*"} // set Accept header localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) if localVarHTTPHeaderAccept != "" { localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept } - localVarHeaderParams["Content-Type"] = parameterToString(*r.contentType, "") - localVarHeaderParams["User-Agent"] = parameterToString(*r.userAgent, "") - localVarHeaderParams["Referer"] = parameterToString(*r.referer, "") - localVarHeaderParams["Cookie"] = parameterToString(*r.cookie, "") - localVarFormParams.Add("value%28user_id%29", parameterToString(*r.value28userId29, "")) - localVarFormParams.Add("value%28pswd%29", parameterToString(*r.value28pswd29, "")) - localVarFormParams.Add("value%28Submit%29", parameterToString(*r.value28Submit29, "")) - localVarFormParams.Add("value%28actions%29", parameterToString(*r.value28actions29, "")) - localVarFormParams.Add("value%28user_ip%29", parameterToString(*r.value28userIp29, "")) - localVarFormParams.Add("user_ip", parameterToString(*r.userIp, "")) - localVarFormParams.Add("value%28mobile%29", parameterToString(*r.value28mobile29, "")) - localVarFormParams.Add("value%28browser_info%29", parameterToString(*r.value28browserInfo29, "")) - localVarFormParams.Add("mobile", parameterToString(*r.mobile, "")) - req, err := r.apiService.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFormFileName, localVarFileName, localVarFileBytes) + localVarHeaderParams["Referer"] = parameterToString("https://m.klikbca.com/login.jsp", "") + localVarFormParams.Add("value(user_id)", parameterToString(userID, "")) + localVarFormParams.Add("value(pswd)", parameterToString(password, "")) + localVarFormParams.Add("value(Submit)", parameterToString("LOGIN", "")) + localVarFormParams.Add("value(actions)", parameterToString("login", "")) + localVarFormParams.Add("value(user_ip)", parameterToString(userIP, "")) + localVarFormParams.Add("user_ip", parameterToString(userIP, "")) + localVarFormParams.Add("value(mobile)", parameterToString(true, "")) + localVarFormParams.Add("value(browser_info)", parameterToString(a.client.cfg.UserAgent, "")) + localVarFormParams.Add("mobile", parameterToString(true, "")) + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFormFileName, localVarFileName, localVarFileBytes, localVarCookies) if err != nil { - return localVarReturnValue, nil, err + return nil, err } - localVarHTTPResponse, err := r.apiService.client.callAPI(req) + localVarHTTPResponse, err := a.client.callAPI(r) if err != nil || localVarHTTPResponse == nil { - return localVarReturnValue, localVarHTTPResponse, err + return localVarHTTPResponse.Cookies(), err } localVarBody, err := _ioutil.ReadAll(localVarHTTPResponse.Body) localVarHTTPResponse.Body.Close() if err != nil { - return localVarReturnValue, localVarHTTPResponse, err + return localVarHTTPResponse.Cookies(), err } if localVarHTTPResponse.StatusCode >= 300 { @@ -658,263 +289,39 @@ func (r apiLoginRequest) Execute() (map[string]interface{}, *_nethttp.Response, body: localVarBody, error: localVarHTTPResponse.Status, } - return localVarReturnValue, localVarHTTPResponse, newErr - } - - err = r.apiService.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) - if err != nil { - newErr := GenericOpenAPIError{ - body: localVarBody, - error: err.Error(), - } - return localVarReturnValue, localVarHTTPResponse, newErr + return localVarHTTPResponse.Cookies(), newErr } - return localVarReturnValue, localVarHTTPResponse, nil -} -type apiLogoutRequest struct { - ctx _context.Context - apiService *BCAApiService - userAgent *string - referer *string - valueActions *string - cookie *string -} - - -func (r apiLogoutRequest) UserAgent(userAgent string) apiLogoutRequest { - r.userAgent = &userAgent - return r -} - -func (r apiLogoutRequest) Referer(referer string) apiLogoutRequest { - r.referer = &referer - return r -} - -func (r apiLogoutRequest) ValueActions(valueActions string) apiLogoutRequest { - r.valueActions = &valueActions - return r -} - -func (r apiLogoutRequest) Cookie(cookie string) apiLogoutRequest { - r.cookie = &cookie - return r + return localVarHTTPResponse.Cookies(), nil } /* Logout Logout * @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). -@return apiLogoutRequest -*/ -func (a *BCAApiService) Logout(ctx _context.Context) apiLogoutRequest { - return apiLogoutRequest{ - apiService: a, - ctx: ctx, - } -} - -/* -Execute executes the request - @return map[string]interface{} + * @param userAgent + * @param referer + * @param valueActions + * @param cookie +@return map[string]interface{} */ -func (r apiLogoutRequest) Execute() (map[string]interface{}, *_nethttp.Response, error) { +func (a *BCAApiService) Logout(ctx _context.Context, cookies []*http.Cookie) error { var ( localVarHTTPMethod = _nethttp.MethodGet localVarPostBody interface{} localVarFormFileName string localVarFileName string localVarFileBytes []byte - localVarReturnValue map[string]interface{} - ) - - localBasePath, err := r.apiService.client.cfg.ServerURLWithContext(r.ctx, "BCAApiService.Logout") - if err != nil { - return localVarReturnValue, nil, GenericOpenAPIError{error: err.Error()} - } - - localVarPath := localBasePath + "/authentication.do?value(actions)=logout" - - localVarHeaderParams := make(map[string]string) - localVarQueryParams := _neturl.Values{} - localVarFormParams := _neturl.Values{} - - if r.userAgent == nil { - return localVarReturnValue, nil, reportError("userAgent is required and must be specified") - } - - if r.referer == nil { - return localVarReturnValue, nil, reportError("referer is required and must be specified") - } - - if r.valueActions == nil { - return localVarReturnValue, nil, reportError("valueActions is required and must be specified") - } - - if r.cookie == nil { - return localVarReturnValue, nil, reportError("cookie is required and must be specified") - } - - localVarQueryParams.Add("value(actions)", parameterToString(*r.valueActions, "")) - // to determine the Content-Type header - localVarHTTPContentTypes := []string{} - - // set Content-Type header - localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) - if localVarHTTPContentType != "" { - localVarHeaderParams["Content-Type"] = localVarHTTPContentType - } - - // to determine the Accept header - localVarHTTPHeaderAccepts := []string{"text/plain"} - - // set Accept header - localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) - if localVarHTTPHeaderAccept != "" { - localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept - } - localVarHeaderParams["User-Agent"] = parameterToString(*r.userAgent, "") - localVarHeaderParams["Referer"] = parameterToString(*r.referer, "") - localVarHeaderParams["Cookie"] = parameterToString(*r.cookie, "") - req, err := r.apiService.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFormFileName, localVarFileName, localVarFileBytes) - if err != nil { - return localVarReturnValue, nil, err - } - - localVarHTTPResponse, err := r.apiService.client.callAPI(req) - if err != nil || localVarHTTPResponse == nil { - return localVarReturnValue, localVarHTTPResponse, err - } - - localVarBody, err := _ioutil.ReadAll(localVarHTTPResponse.Body) - localVarHTTPResponse.Body.Close() - if err != nil { - return localVarReturnValue, localVarHTTPResponse, err - } - - if localVarHTTPResponse.StatusCode >= 300 { - newErr := GenericOpenAPIError{ - body: localVarBody, - error: localVarHTTPResponse.Status, - } - return localVarReturnValue, localVarHTTPResponse, newErr - } - - err = r.apiService.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) - if err != nil { - newErr := GenericOpenAPIError{ - body: localVarBody, - error: err.Error(), - } - return localVarReturnValue, localVarHTTPResponse, newErr - } - - return localVarReturnValue, localVarHTTPResponse, nil -} -type apiMenuRequest struct { - ctx _context.Context - apiService *BCAApiService - contentType *string - userAgent *string - referer *string - valueActions *string - cookie *string - contentLength *string -} - - -func (r apiMenuRequest) ContentType(contentType string) apiMenuRequest { - r.contentType = &contentType - return r -} - -func (r apiMenuRequest) UserAgent(userAgent string) apiMenuRequest { - r.userAgent = &userAgent - return r -} - -func (r apiMenuRequest) Referer(referer string) apiMenuRequest { - r.referer = &referer - return r -} - -func (r apiMenuRequest) ValueActions(valueActions string) apiMenuRequest { - r.valueActions = &valueActions - return r -} - -func (r apiMenuRequest) Cookie(cookie string) apiMenuRequest { - r.cookie = &cookie - return r -} - -func (r apiMenuRequest) ContentLength(contentLength string) apiMenuRequest { - r.contentLength = &contentLength - return r -} - -/* -Menu Menu - * @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). -@return apiMenuRequest -*/ -func (a *BCAApiService) Menu(ctx _context.Context) apiMenuRequest { - return apiMenuRequest{ - apiService: a, - ctx: ctx, - } -} - -/* -Execute executes the request - @return map[string]interface{} -*/ -func (r apiMenuRequest) Execute() (map[string]interface{}, *_nethttp.Response, error) { - var ( - localVarHTTPMethod = _nethttp.MethodPost - localVarPostBody interface{} - localVarFormFileName string - localVarFileName string - localVarFileBytes []byte - localVarReturnValue map[string]interface{} + localVarCookies []*http.Cookie ) - localBasePath, err := r.apiService.client.cfg.ServerURLWithContext(r.ctx, "BCAApiService.Menu") - if err != nil { - return localVarReturnValue, nil, GenericOpenAPIError{error: err.Error()} - } - - localVarPath := localBasePath + "/accountstmt.do?value(actions)=menu" - + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/authentication.do" localVarHeaderParams := make(map[string]string) localVarQueryParams := _neturl.Values{} localVarFormParams := _neturl.Values{} - - if r.contentType == nil { - return localVarReturnValue, nil, reportError("contentType is required and must be specified") - } - - if r.userAgent == nil { - return localVarReturnValue, nil, reportError("userAgent is required and must be specified") - } - - if r.referer == nil { - return localVarReturnValue, nil, reportError("referer is required and must be specified") - } - - if r.valueActions == nil { - return localVarReturnValue, nil, reportError("valueActions is required and must be specified") - } - - if r.cookie == nil { - return localVarReturnValue, nil, reportError("cookie is required and must be specified") - } - - if r.contentLength == nil { - return localVarReturnValue, nil, reportError("contentLength is required and must be specified") - } + localVarCookies = cookies - localVarQueryParams.Add("value(actions)", parameterToString(*r.valueActions, "")) + localVarQueryParams.Add("value(actions)", parameterToString("logout", "")) // to determine the Content-Type header localVarHTTPContentTypes := []string{} @@ -925,32 +332,28 @@ func (r apiMenuRequest) Execute() (map[string]interface{}, *_nethttp.Response, e } // to determine the Accept header - localVarHTTPHeaderAccepts := []string{"text/plain"} + localVarHTTPHeaderAccepts := []string{"*/*"} // set Accept header localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) if localVarHTTPHeaderAccept != "" { localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept } - localVarHeaderParams["Content-Type"] = parameterToString(*r.contentType, "") - localVarHeaderParams["User-Agent"] = parameterToString(*r.userAgent, "") - localVarHeaderParams["Referer"] = parameterToString(*r.referer, "") - localVarHeaderParams["Cookie"] = parameterToString(*r.cookie, "") - localVarHeaderParams["Content-Length"] = parameterToString(*r.contentLength, "") - req, err := r.apiService.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFormFileName, localVarFileName, localVarFileBytes) + localVarHeaderParams["Referer"] = parameterToString("https://m.klikbca.com/accountstmt.do?value(actions)=acctstmtview", "") + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFormFileName, localVarFileName, localVarFileBytes, localVarCookies) if err != nil { - return localVarReturnValue, nil, err + return err } - localVarHTTPResponse, err := r.apiService.client.callAPI(req) + localVarHTTPResponse, err := a.client.callAPI(r) if err != nil || localVarHTTPResponse == nil { - return localVarReturnValue, localVarHTTPResponse, err + return err } localVarBody, err := _ioutil.ReadAll(localVarHTTPResponse.Body) localVarHTTPResponse.Body.Close() if err != nil { - return localVarReturnValue, localVarHTTPResponse, err + return err } if localVarHTTPResponse.StatusCode >= 300 { @@ -958,17 +361,8 @@ func (r apiMenuRequest) Execute() (map[string]interface{}, *_nethttp.Response, e body: localVarBody, error: localVarHTTPResponse.Status, } - return localVarReturnValue, localVarHTTPResponse, newErr - } - - err = r.apiService.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) - if err != nil { - newErr := GenericOpenAPIError{ - body: localVarBody, - error: err.Error(), - } - return localVarReturnValue, localVarHTTPResponse, newErr + return newErr } - return localVarReturnValue, localVarHTTPResponse, nil + return nil } diff --git a/client.go b/client.go index 6a679f0..d7413c0 100644 --- a/client.go +++ b/client.go @@ -17,6 +17,7 @@ import ( "errors" "fmt" "io" + "io/ioutil" "log" "mime/multipart" "net/http" @@ -37,6 +38,7 @@ import ( var ( jsonCheck = regexp.MustCompile(`(?i:(?:application|text)/(?:vnd\.[^;]+\+)?json)`) xmlCheck = regexp.MustCompile(`(?i:(?:application|text)/xml)`) + htmlCheck = regexp.MustCompile(`(?i:(?:application|text)/html)`) ) // APIClient manages communication with the BCA API v1.0 @@ -56,7 +58,7 @@ type service struct { // NewAPIClient creates a new API client. Requires a userAgent string describing your application. // optionally a custom http.Client to allow for advanced features such as caching. -func NewAPIClient(cfg *Configuration) *APIClient { +func NewAPIClient(cfg *Configuration) *BCAApiService { if cfg.HTTPClient == nil { cfg.HTTPClient = http.DefaultClient } @@ -68,7 +70,7 @@ func NewAPIClient(cfg *Configuration) *APIClient { // API Services c.BCAApi = (*BCAApiService)(&c.common) - return c + return c.BCAApi } func atoi(in string) (int, error) { @@ -156,7 +158,6 @@ func parameterToJson(obj interface{}) (string, error) { return string(jsonBuf), err } - // callAPI do the request. func (c *APIClient) callAPI(request *http.Request) (*http.Response, error) { if c.cfg.Debug { @@ -179,9 +180,15 @@ func (c *APIClient) callAPI(request *http.Request) (*http.Response, error) { } log.Printf("\n%s\n", string(dump)) } + return resp, err } +// ChangeBasePath changes base path to allow switching to mocks +func (c *APIClient) ChangeBasePath(path string) { + c.cfg.BasePath = path +} + // Allow modification of underlying config for alternate implementations and testing // Caution: modifying the configuration while live can cause data races and potentially unwanted behavior func (c *APIClient) GetConfig() *Configuration { @@ -198,7 +205,8 @@ func (c *APIClient) prepareRequest( formParams url.Values, formFileName string, fileName string, - fileBytes []byte) (localVarRequest *http.Request, err error) { + fileBytes []byte, + cookies []*http.Cookie) (localVarRequest *http.Request, err error) { var body *bytes.Buffer @@ -342,11 +350,18 @@ func (c *APIClient) prepareRequest( if auth, ok := ctx.Value(ContextAccessToken).(string); ok { localVarRequest.Header.Add("Authorization", "Bearer "+auth) } + + } + + // add cookies, if any + for _, cookie := range cookies { + localVarRequest.AddCookie(cookie) } for header, value := range c.cfg.DefaultHeader { localVarRequest.Header.Add(header, value) } + return localVarRequest, nil } @@ -358,6 +373,15 @@ func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err err *s = string(b) return nil } + if f, ok := v.(**os.File); ok { + *f, err = ioutil.TempFile("", "HttpClientFile") + if err != nil { + return + } + _, err = (*f).Write(b) + _, err = (*f).Seek(0, io.SeekStart) + return + } if xmlCheck.MatchString(contentType) { if err = xml.Unmarshal(b, v); err != nil { return err @@ -365,15 +389,13 @@ func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err err return nil } if jsonCheck.MatchString(contentType) { - if actualObj, ok := v.(interface{GetActualInstance() interface{}}); ok { // oneOf, anyOf schemas - if unmarshalObj, ok := actualObj.(interface{UnmarshalJSON([]byte) error}); ok { // make sure it has UnmarshalJSON defined - if err = unmarshalObj.UnmarshalJSON(b); err!= nil { - return err - } - } else { - errors.New("Unknown type with GetActualInstance but no unmarshalObj.UnmarshalJSON defined") - } - } else if err = json.Unmarshal(b, v); err != nil { // simple model + if err = json.Unmarshal(b, v); err != nil { + return err + } + return nil + } + if htmlCheck.MatchString(contentType) { + if err = extractHTML(b, v); err != nil { return err } return nil diff --git a/configuration.go b/configuration.go index 4651547..191d07d 100644 --- a/configuration.go +++ b/configuration.go @@ -10,7 +10,6 @@ package bca import ( - "context" "fmt" "net/http" "strings" @@ -36,23 +35,8 @@ var ( // ContextAccessToken takes a string oauth2 access token as authentication for the request. ContextAccessToken = contextKey("accesstoken") - // ContextAPIKeys takes a string apikey as authentication for the request - ContextAPIKeys = contextKey("apiKeys") - - // ContextHttpSignatureAuth takes HttpSignatureAuth as authentication for the request. - ContextHttpSignatureAuth = contextKey("httpsignature") - - // ContextServerIndex uses a server configuration from the index. - ContextServerIndex = contextKey("serverIndex") - - // ContextOperationServerIndices uses a server configuration from the index mapping. - ContextOperationServerIndices = contextKey("serverOperationIndices") - - // ContextServerVariables overrides a server configuration variables. - ContextServerVariables = contextKey("serverVariables") - - // ContextOperationServerVariables overrides a server configuration variables using operation specific values. - ContextOperationServerVariables = contextKey("serverOperationVariables") + // ContextAPIKey takes an APIKey as authentication for the request + ContextAPIKey = contextKey("apikey") ) // BasicAuth provides basic http authentication to a request passed via context using ContextBasicAuth @@ -76,40 +60,36 @@ type ServerVariable struct { // ServerConfiguration stores the information about a server type ServerConfiguration struct { - URL string + Url string Description string - Variables map[string]ServerVariable + Variables map[string]ServerVariable } -// ServerConfigurations stores multiple ServerConfiguration items -type ServerConfigurations []ServerConfiguration - // Configuration stores the configuration of the API client type Configuration struct { - Host string `json:"host,omitempty"` - Scheme string `json:"scheme,omitempty"` - DefaultHeader map[string]string `json:"defaultHeader,omitempty"` - UserAgent string `json:"userAgent,omitempty"` - Debug bool `json:"debug,omitempty"` - Servers ServerConfigurations - OperationServers map[string]ServerConfigurations - HTTPClient *http.Client + BasePath string `json:"basePath,omitempty"` + Host string `json:"host,omitempty"` + Scheme string `json:"scheme,omitempty"` + DefaultHeader map[string]string `json:"defaultHeader,omitempty"` + UserAgent string `json:"userAgent,omitempty"` + Debug bool `json:"debug,omitempty"` + Servers []ServerConfiguration + HTTPClient *http.Client } // NewConfiguration returns a new Configuration object func NewConfiguration() *Configuration { cfg := &Configuration{ - DefaultHeader: make(map[string]string), - UserAgent: "OpenAPI-Generator/1.0.0/go", - Debug: false, - Servers: ServerConfigurations{ + BasePath: "https://m.klikbca.com", + DefaultHeader: make(map[string]string), + UserAgent: "Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1", + Debug: false, + Servers: []ServerConfiguration{ { - URL: "https://m.klikbca.com", + Url: "https://m.klikbca.com", Description: "No description provided", }, }, - OperationServers: map[string]ServerConfigurations{ - }, } return cfg } @@ -119,13 +99,13 @@ func (c *Configuration) AddDefaultHeader(key string, value string) { c.DefaultHeader[key] = value } -// URL formats template on a index using given variables -func (sc ServerConfigurations) URL(index int, variables map[string]string) (string, error) { - if index < 0 || len(sc) <= index { - return "", fmt.Errorf("Index %v out of range %v", index, len(sc)-1) +// ServerUrl returns URL based on server settings +func (c *Configuration) ServerUrl(index int, variables map[string]string) (string, error) { + if index < 0 || len(c.Servers) <= index { + return "", fmt.Errorf("Index %v out of range %v", index, len(c.Servers)-1) } - server := sc[index] - url := server.URL + server := c.Servers[index] + url := server.Url // go through variables and replace placeholders for name, variable := range server.Variables { @@ -146,84 +126,3 @@ func (sc ServerConfigurations) URL(index int, variables map[string]string) (stri } return url, nil } - -// ServerURL returns URL based on server settings -func (c *Configuration) ServerURL(index int, variables map[string]string) (string, error) { - return c.Servers.URL(index, variables) -} - -func getServerIndex(ctx context.Context) (int, error) { - si := ctx.Value(ContextServerIndex) - if si != nil { - if index, ok := si.(int); ok { - return index, nil - } - return 0, reportError("Invalid type %T should be int", si) - } - return 0, nil -} - -func getServerOperationIndex(ctx context.Context, endpoint string) (int, error) { - osi := ctx.Value(ContextOperationServerIndices) - if osi != nil { - if operationIndices, ok := osi.(map[string]int); !ok { - return 0, reportError("Invalid type %T should be map[string]int", osi) - } else { - index, ok := operationIndices[endpoint] - if ok { - return index, nil - } - } - } - return getServerIndex(ctx) -} - -func getServerVariables(ctx context.Context) (map[string]string, error) { - sv := ctx.Value(ContextServerVariables) - if sv != nil { - if variables, ok := sv.(map[string]string); ok { - return variables, nil - } - return nil, reportError("ctx value of ContextServerVariables has invalid type %T should be map[string]string", sv) - } - return nil, nil -} - -func getServerOperationVariables(ctx context.Context, endpoint string) (map[string]string, error) { - osv := ctx.Value(ContextOperationServerVariables) - if osv != nil { - if operationVariables, ok := osv.(map[string]map[string]string); !ok { - return nil, reportError("ctx value of ContextOperationServerVariables has invalid type %T should be map[string]map[string]string", osv) - } else { - variables, ok := operationVariables[endpoint] - if ok { - return variables, nil - } - } - } - return getServerVariables(ctx) -} - -// ServerURLWithContext returns a new server URL given an endpoint -func (c *Configuration) ServerURLWithContext(ctx context.Context, endpoint string) (string, error) { - sc, ok := c.OperationServers[endpoint] - if !ok { - sc = c.Servers - } - - if ctx == nil { - return sc.URL(0, nil) - } - - index, err := getServerOperationIndex(ctx, endpoint) - if err != nil { - return "", err - } - - variables, err := getServerOperationVariables(ctx, endpoint) - if err != nil { - return "", err - } - - return sc.URL(index, variables) -} diff --git a/docs/BCAApi.md b/docs/BCAApi.md index f043eb6..2c91be6 100644 --- a/docs/BCAApi.md +++ b/docs/BCAApi.md @@ -8,81 +8,35 @@ Method | HTTP request | Description [**BalanceInquiry**](BCAApi.md#BalanceInquiry) | **Post** /balanceinquiry.do | BalanceInquiry [**Login**](BCAApi.md#Login) | **Post** /authentication.do | Login [**Logout**](BCAApi.md#Logout) | **Get** /authentication.do?value(actions)=logout | Logout -[**Menu**](BCAApi.md#Menu) | **Post** /accountstmt.do?value(actions)=menu | Menu ## AccountStatementView -> map[string]interface{} AccountStatementView(ctx).ContentType(contentType).UserAgent(userAgent).Referer(referer).ValueActions(valueActions).Cookie(cookie).ContentLength(contentLength).R1(r1).Value28D129(value28D129).Value28startDt29(value28startDt29).Value28startMt29(value28startMt29).Value28startYr29(value28startYr29).Value28endDt29(value28endDt29).Value28endMt29(value28endMt29).Value28endYr29(value28endYr29).Execute() +> map[string]interface{} AccountStatementView(ctx, contentType, userAgent, referer, valueActions, cookie, contentLength, r1, value28D129, value28startDt29, value28startMt29, value28startYr29, value28endDt29, value28endMt29, value28endYr29) AccountStatementView -### Example - -```go -package main - -import ( - "context" - "fmt" - "os" - openapiclient "./openapi" -) - -func main() { - contentType := "contentType_example" // string | - userAgent := "userAgent_example" // string | - referer := "referer_example" // string | - valueActions := "valueActions_example" // string | - cookie := "cookie_example" // string | - contentLength := "contentLength_example" // string | - r1 := "r1_example" // string | - value28D129 := "value28D129_example" // string | - value28startDt29 := "value28startDt29_example" // string | - value28startMt29 := "value28startMt29_example" // string | - value28startYr29 := "value28startYr29_example" // string | - value28endDt29 := "value28endDt29_example" // string | - value28endMt29 := "value28endMt29_example" // string | - value28endYr29 := "value28endYr29_example" // string | - - configuration := openapiclient.NewConfiguration() - api_client := openapiclient.NewAPIClient(configuration) - resp, r, err := api_client.BCAApi.AccountStatementView(context.Background(), contentType, userAgent, referer, valueActions, cookie, contentLength, r1, value28D129, value28startDt29, value28startMt29, value28startYr29, value28endDt29, value28endMt29, value28endYr29).Execute() - if err != nil { - fmt.Fprintf(os.Stderr, "Error when calling `BCAApi.AccountStatementView``: %v\n", err) - fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) - } - // response from `AccountStatementView`: map[string]interface{} - fmt.Fprintf(os.Stdout, "Response from `BCAApi.AccountStatementView`: %v\n", resp) -} -``` - -### Path Parameters - - - -### Other Parameters - -Other parameters are passed through a pointer to a apiAccountStatementViewRequest struct via the builder pattern +### Required Parameters Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **contentType** | **string** | | - **userAgent** | **string** | | - **referer** | **string** | | - **valueActions** | **string** | | - **cookie** | **string** | | - **contentLength** | **string** | | - **r1** | **string** | | - **value28D129** | **string** | | - **value28startDt29** | **string** | | - **value28startMt29** | **string** | | - **value28startYr29** | **string** | | - **value28endDt29** | **string** | | - **value28endMt29** | **string** | | - **value28endYr29** | **string** | | +**ctx** | **context.Context** | context for authentication, logging, cancellation, deadlines, tracing, etc. +**contentType** | **string**| | +**userAgent** | **string**| | +**referer** | **string**| | +**valueActions** | **string**| | +**cookie** | **string**| | +**contentLength** | **string**| | +**r1** | **string**| | +**value28D129** | **string**| | +**value28startDt29** | **string**| | +**value28startMt29** | **string**| | +**value28startYr29** | **string**| | +**value28endDt29** | **string**| | +**value28endMt29** | **string**| | +**value28endYr29** | **string**| | ### Return type @@ -104,57 +58,21 @@ No authorization required ## BalanceInquiry -> map[string]interface{} BalanceInquiry(ctx).ContentType(contentType).UserAgent(userAgent).Referer(referer).Cookie(cookie).ContentLength(contentLength).Execute() +> map[string]interface{} BalanceInquiry(ctx, contentType, userAgent, referer, cookie, contentLength) BalanceInquiry -### Example - -```go -package main - -import ( - "context" - "fmt" - "os" - openapiclient "./openapi" -) - -func main() { - contentType := "contentType_example" // string | - userAgent := "userAgent_example" // string | - referer := "referer_example" // string | - cookie := "cookie_example" // string | - contentLength := "contentLength_example" // string | - - configuration := openapiclient.NewConfiguration() - api_client := openapiclient.NewAPIClient(configuration) - resp, r, err := api_client.BCAApi.BalanceInquiry(context.Background(), contentType, userAgent, referer, cookie, contentLength).Execute() - if err != nil { - fmt.Fprintf(os.Stderr, "Error when calling `BCAApi.BalanceInquiry``: %v\n", err) - fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) - } - // response from `BalanceInquiry`: map[string]interface{} - fmt.Fprintf(os.Stdout, "Response from `BCAApi.BalanceInquiry`: %v\n", resp) -} -``` - -### Path Parameters - - - -### Other Parameters - -Other parameters are passed through a pointer to a apiBalanceInquiryRequest struct via the builder pattern +### Required Parameters Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **contentType** | **string** | | - **userAgent** | **string** | | - **referer** | **string** | | - **cookie** | **string** | | - **contentLength** | **string** | | +**ctx** | **context.Context** | context for authentication, logging, cancellation, deadlines, tracing, etc. +**contentType** | **string**| | +**userAgent** | **string**| | +**referer** | **string**| | +**cookie** | **string**| | +**contentLength** | **string**| | ### Return type @@ -176,75 +94,30 @@ No authorization required ## Login -> map[string]interface{} Login(ctx).ContentType(contentType).UserAgent(userAgent).Referer(referer).Cookie(cookie).ContentLength(contentLength).Value28userId29(value28userId29).Value28pswd29(value28pswd29).Value28Submit29(value28Submit29).Value28actions29(value28actions29).Value28userIp29(value28userIp29).UserIp(userIp).Value28mobile29(value28mobile29).Value28browserInfo29(value28browserInfo29).Mobile(mobile).Execute() +> map[string]interface{} Login(ctx, contentType, userAgent, referer, cookie, contentLength, value28userId29, value28pswd29, value28Submit29, value28actions29, value28userIp29, userIp, value28mobile29, value28browserInfo29, mobile) Login -### Example - -```go -package main - -import ( - "context" - "fmt" - "os" - openapiclient "./openapi" -) - -func main() { - contentType := "contentType_example" // string | - userAgent := "userAgent_example" // string | - referer := "referer_example" // string | - cookie := "cookie_example" // string | - contentLength := 987 // int32 | - value28userId29 := "value28userId29_example" // string | - value28pswd29 := "value28pswd29_example" // string | - value28Submit29 := "value28Submit29_example" // string | - value28actions29 := "value28actions29_example" // string | - value28userIp29 := "value28userIp29_example" // string | - userIp := "userIp_example" // string | - value28mobile29 := "value28mobile29_example" // string | - value28browserInfo29 := "value28browserInfo29_example" // string | - mobile := "mobile_example" // string | - - configuration := openapiclient.NewConfiguration() - api_client := openapiclient.NewAPIClient(configuration) - resp, r, err := api_client.BCAApi.Login(context.Background(), contentType, userAgent, referer, cookie, contentLength, value28userId29, value28pswd29, value28Submit29, value28actions29, value28userIp29, userIp, value28mobile29, value28browserInfo29, mobile).Execute() - if err != nil { - fmt.Fprintf(os.Stderr, "Error when calling `BCAApi.Login``: %v\n", err) - fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) - } - // response from `Login`: map[string]interface{} - fmt.Fprintf(os.Stdout, "Response from `BCAApi.Login`: %v\n", resp) -} -``` - -### Path Parameters - - - -### Other Parameters - -Other parameters are passed through a pointer to a apiLoginRequest struct via the builder pattern +### Required Parameters Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **contentType** | **string** | | - **userAgent** | **string** | | - **referer** | **string** | | - **cookie** | **string** | | - **contentLength** | **int32** | | - **value28userId29** | **string** | | - **value28pswd29** | **string** | | - **value28Submit29** | **string** | | - **value28actions29** | **string** | | - **value28userIp29** | **string** | | - **userIp** | **string** | | - **value28mobile29** | **string** | | - **value28browserInfo29** | **string** | | - **mobile** | **string** | | +**ctx** | **context.Context** | context for authentication, logging, cancellation, deadlines, tracing, etc. +**contentType** | **string**| | +**userAgent** | **string**| | +**referer** | **string**| | +**cookie** | **string**| | +**contentLength** | **int32**| | +**value28userId29** | **string**| | +**value28pswd29** | **string**| | +**value28Submit29** | **string**| | +**value28actions29** | **string**| | +**value28userIp29** | **string**| | +**userIp** | **string**| | +**value28mobile29** | **string**| | +**value28browserInfo29** | **string**| | +**mobile** | **string**| | ### Return type @@ -266,129 +139,20 @@ No authorization required ## Logout -> map[string]interface{} Logout(ctx).UserAgent(userAgent).Referer(referer).ValueActions(valueActions).Cookie(cookie).Execute() +> map[string]interface{} Logout(ctx, userAgent, referer, valueActions, cookie) Logout -### Example - -```go -package main - -import ( - "context" - "fmt" - "os" - openapiclient "./openapi" -) - -func main() { - userAgent := "userAgent_example" // string | - referer := "referer_example" // string | - valueActions := "valueActions_example" // string | - cookie := "cookie_example" // string | - - configuration := openapiclient.NewConfiguration() - api_client := openapiclient.NewAPIClient(configuration) - resp, r, err := api_client.BCAApi.Logout(context.Background(), userAgent, referer, valueActions, cookie).Execute() - if err != nil { - fmt.Fprintf(os.Stderr, "Error when calling `BCAApi.Logout``: %v\n", err) - fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) - } - // response from `Logout`: map[string]interface{} - fmt.Fprintf(os.Stdout, "Response from `BCAApi.Logout`: %v\n", resp) -} -``` - -### Path Parameters - - - -### Other Parameters - -Other parameters are passed through a pointer to a apiLogoutRequest struct via the builder pattern - - -Name | Type | Description | Notes -------------- | ------------- | ------------- | ------------- - **userAgent** | **string** | | - **referer** | **string** | | - **valueActions** | **string** | | - **cookie** | **string** | | - -### Return type - -**map[string]interface{}** - -### Authorization - -No authorization required - -### HTTP request headers - -- **Content-Type**: Not defined -- **Accept**: text/plain - -[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) -[[Back to Model list]](../README.md#documentation-for-models) -[[Back to README]](../README.md) - - -## Menu - -> map[string]interface{} Menu(ctx).ContentType(contentType).UserAgent(userAgent).Referer(referer).ValueActions(valueActions).Cookie(cookie).ContentLength(contentLength).Execute() - -Menu - -### Example - -```go -package main - -import ( - "context" - "fmt" - "os" - openapiclient "./openapi" -) - -func main() { - contentType := "contentType_example" // string | - userAgent := "userAgent_example" // string | - referer := "referer_example" // string | - valueActions := "valueActions_example" // string | - cookie := "cookie_example" // string | - contentLength := "contentLength_example" // string | - - configuration := openapiclient.NewConfiguration() - api_client := openapiclient.NewAPIClient(configuration) - resp, r, err := api_client.BCAApi.Menu(context.Background(), contentType, userAgent, referer, valueActions, cookie, contentLength).Execute() - if err != nil { - fmt.Fprintf(os.Stderr, "Error when calling `BCAApi.Menu``: %v\n", err) - fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) - } - // response from `Menu`: map[string]interface{} - fmt.Fprintf(os.Stdout, "Response from `BCAApi.Menu`: %v\n", resp) -} -``` - -### Path Parameters - - - -### Other Parameters - -Other parameters are passed through a pointer to a apiMenuRequest struct via the builder pattern +### Required Parameters Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **contentType** | **string** | | - **userAgent** | **string** | | - **referer** | **string** | | - **valueActions** | **string** | | - **cookie** | **string** | | - **contentLength** | **string** | | +**ctx** | **context.Context** | context for authentication, logging, cancellation, deadlines, tracing, etc. +**userAgent** | **string**| | +**referer** | **string**| | +**valueActions** | **string**| | +**cookie** | **string**| | ### Return type diff --git a/docs/InlineObject.md b/docs/InlineObject.md deleted file mode 100644 index ebf4a53..0000000 --- a/docs/InlineObject.md +++ /dev/null @@ -1,198 +0,0 @@ -# InlineObject - -## Properties - -Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- -**R1** | **string** | | -**Value28D129** | **string** | | -**Value28startDt29** | **string** | | -**Value28startMt29** | **string** | | -**Value28startYr29** | **string** | | -**Value28endDt29** | **string** | | -**Value28endMt29** | **string** | | -**Value28endYr29** | **string** | | - -## Methods - -### NewInlineObject - -`func NewInlineObject(r1 string, value28D129 string, value28startDt29 string, value28startMt29 string, value28startYr29 string, value28endDt29 string, value28endMt29 string, value28endYr29 string, ) *InlineObject` - -NewInlineObject instantiates a new InlineObject object -This constructor will assign default values to properties that have it defined, -and makes sure properties required by API are set, but the set of arguments -will change when the set of required properties is changed - -### NewInlineObjectWithDefaults - -`func NewInlineObjectWithDefaults() *InlineObject` - -NewInlineObjectWithDefaults instantiates a new InlineObject object -This constructor will only assign default values to properties that have it defined, -but it doesn't guarantee that properties required by API are set - -### GetR1 - -`func (o *InlineObject) GetR1() string` - -GetR1 returns the R1 field if non-nil, zero value otherwise. - -### GetR1Ok - -`func (o *InlineObject) GetR1Ok() (*string, bool)` - -GetR1Ok returns a tuple with the R1 field if it's non-nil, zero value otherwise -and a boolean to check if the value has been set. - -### SetR1 - -`func (o *InlineObject) SetR1(v string)` - -SetR1 sets R1 field to given value. - - -### GetValue28D129 - -`func (o *InlineObject) GetValue28D129() string` - -GetValue28D129 returns the Value28D129 field if non-nil, zero value otherwise. - -### GetValue28D129Ok - -`func (o *InlineObject) GetValue28D129Ok() (*string, bool)` - -GetValue28D129Ok returns a tuple with the Value28D129 field if it's non-nil, zero value otherwise -and a boolean to check if the value has been set. - -### SetValue28D129 - -`func (o *InlineObject) SetValue28D129(v string)` - -SetValue28D129 sets Value28D129 field to given value. - - -### GetValue28startDt29 - -`func (o *InlineObject) GetValue28startDt29() string` - -GetValue28startDt29 returns the Value28startDt29 field if non-nil, zero value otherwise. - -### GetValue28startDt29Ok - -`func (o *InlineObject) GetValue28startDt29Ok() (*string, bool)` - -GetValue28startDt29Ok returns a tuple with the Value28startDt29 field if it's non-nil, zero value otherwise -and a boolean to check if the value has been set. - -### SetValue28startDt29 - -`func (o *InlineObject) SetValue28startDt29(v string)` - -SetValue28startDt29 sets Value28startDt29 field to given value. - - -### GetValue28startMt29 - -`func (o *InlineObject) GetValue28startMt29() string` - -GetValue28startMt29 returns the Value28startMt29 field if non-nil, zero value otherwise. - -### GetValue28startMt29Ok - -`func (o *InlineObject) GetValue28startMt29Ok() (*string, bool)` - -GetValue28startMt29Ok returns a tuple with the Value28startMt29 field if it's non-nil, zero value otherwise -and a boolean to check if the value has been set. - -### SetValue28startMt29 - -`func (o *InlineObject) SetValue28startMt29(v string)` - -SetValue28startMt29 sets Value28startMt29 field to given value. - - -### GetValue28startYr29 - -`func (o *InlineObject) GetValue28startYr29() string` - -GetValue28startYr29 returns the Value28startYr29 field if non-nil, zero value otherwise. - -### GetValue28startYr29Ok - -`func (o *InlineObject) GetValue28startYr29Ok() (*string, bool)` - -GetValue28startYr29Ok returns a tuple with the Value28startYr29 field if it's non-nil, zero value otherwise -and a boolean to check if the value has been set. - -### SetValue28startYr29 - -`func (o *InlineObject) SetValue28startYr29(v string)` - -SetValue28startYr29 sets Value28startYr29 field to given value. - - -### GetValue28endDt29 - -`func (o *InlineObject) GetValue28endDt29() string` - -GetValue28endDt29 returns the Value28endDt29 field if non-nil, zero value otherwise. - -### GetValue28endDt29Ok - -`func (o *InlineObject) GetValue28endDt29Ok() (*string, bool)` - -GetValue28endDt29Ok returns a tuple with the Value28endDt29 field if it's non-nil, zero value otherwise -and a boolean to check if the value has been set. - -### SetValue28endDt29 - -`func (o *InlineObject) SetValue28endDt29(v string)` - -SetValue28endDt29 sets Value28endDt29 field to given value. - - -### GetValue28endMt29 - -`func (o *InlineObject) GetValue28endMt29() string` - -GetValue28endMt29 returns the Value28endMt29 field if non-nil, zero value otherwise. - -### GetValue28endMt29Ok - -`func (o *InlineObject) GetValue28endMt29Ok() (*string, bool)` - -GetValue28endMt29Ok returns a tuple with the Value28endMt29 field if it's non-nil, zero value otherwise -and a boolean to check if the value has been set. - -### SetValue28endMt29 - -`func (o *InlineObject) SetValue28endMt29(v string)` - -SetValue28endMt29 sets Value28endMt29 field to given value. - - -### GetValue28endYr29 - -`func (o *InlineObject) GetValue28endYr29() string` - -GetValue28endYr29 returns the Value28endYr29 field if non-nil, zero value otherwise. - -### GetValue28endYr29Ok - -`func (o *InlineObject) GetValue28endYr29Ok() (*string, bool)` - -GetValue28endYr29Ok returns a tuple with the Value28endYr29 field if it's non-nil, zero value otherwise -and a boolean to check if the value has been set. - -### SetValue28endYr29 - -`func (o *InlineObject) SetValue28endYr29(v string)` - -SetValue28endYr29 sets Value28endYr29 field to given value. - - - -[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) - - diff --git a/docs/InlineObject1.md b/docs/InlineObject1.md deleted file mode 100644 index e637cd8..0000000 --- a/docs/InlineObject1.md +++ /dev/null @@ -1,219 +0,0 @@ -# InlineObject1 - -## Properties - -Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- -**Value28userId29** | **string** | | -**Value28pswd29** | **string** | | -**Value28Submit29** | **string** | | -**Value28actions29** | **string** | | -**Value28userIp29** | **string** | | -**UserIp** | **string** | | -**Value28mobile29** | **string** | | -**Value28browserInfo29** | **string** | | -**Mobile** | **string** | | - -## Methods - -### NewInlineObject1 - -`func NewInlineObject1(value28userId29 string, value28pswd29 string, value28Submit29 string, value28actions29 string, value28userIp29 string, userIp string, value28mobile29 string, value28browserInfo29 string, mobile string, ) *InlineObject1` - -NewInlineObject1 instantiates a new InlineObject1 object -This constructor will assign default values to properties that have it defined, -and makes sure properties required by API are set, but the set of arguments -will change when the set of required properties is changed - -### NewInlineObject1WithDefaults - -`func NewInlineObject1WithDefaults() *InlineObject1` - -NewInlineObject1WithDefaults instantiates a new InlineObject1 object -This constructor will only assign default values to properties that have it defined, -but it doesn't guarantee that properties required by API are set - -### GetValue28userId29 - -`func (o *InlineObject1) GetValue28userId29() string` - -GetValue28userId29 returns the Value28userId29 field if non-nil, zero value otherwise. - -### GetValue28userId29Ok - -`func (o *InlineObject1) GetValue28userId29Ok() (*string, bool)` - -GetValue28userId29Ok returns a tuple with the Value28userId29 field if it's non-nil, zero value otherwise -and a boolean to check if the value has been set. - -### SetValue28userId29 - -`func (o *InlineObject1) SetValue28userId29(v string)` - -SetValue28userId29 sets Value28userId29 field to given value. - - -### GetValue28pswd29 - -`func (o *InlineObject1) GetValue28pswd29() string` - -GetValue28pswd29 returns the Value28pswd29 field if non-nil, zero value otherwise. - -### GetValue28pswd29Ok - -`func (o *InlineObject1) GetValue28pswd29Ok() (*string, bool)` - -GetValue28pswd29Ok returns a tuple with the Value28pswd29 field if it's non-nil, zero value otherwise -and a boolean to check if the value has been set. - -### SetValue28pswd29 - -`func (o *InlineObject1) SetValue28pswd29(v string)` - -SetValue28pswd29 sets Value28pswd29 field to given value. - - -### GetValue28Submit29 - -`func (o *InlineObject1) GetValue28Submit29() string` - -GetValue28Submit29 returns the Value28Submit29 field if non-nil, zero value otherwise. - -### GetValue28Submit29Ok - -`func (o *InlineObject1) GetValue28Submit29Ok() (*string, bool)` - -GetValue28Submit29Ok returns a tuple with the Value28Submit29 field if it's non-nil, zero value otherwise -and a boolean to check if the value has been set. - -### SetValue28Submit29 - -`func (o *InlineObject1) SetValue28Submit29(v string)` - -SetValue28Submit29 sets Value28Submit29 field to given value. - - -### GetValue28actions29 - -`func (o *InlineObject1) GetValue28actions29() string` - -GetValue28actions29 returns the Value28actions29 field if non-nil, zero value otherwise. - -### GetValue28actions29Ok - -`func (o *InlineObject1) GetValue28actions29Ok() (*string, bool)` - -GetValue28actions29Ok returns a tuple with the Value28actions29 field if it's non-nil, zero value otherwise -and a boolean to check if the value has been set. - -### SetValue28actions29 - -`func (o *InlineObject1) SetValue28actions29(v string)` - -SetValue28actions29 sets Value28actions29 field to given value. - - -### GetValue28userIp29 - -`func (o *InlineObject1) GetValue28userIp29() string` - -GetValue28userIp29 returns the Value28userIp29 field if non-nil, zero value otherwise. - -### GetValue28userIp29Ok - -`func (o *InlineObject1) GetValue28userIp29Ok() (*string, bool)` - -GetValue28userIp29Ok returns a tuple with the Value28userIp29 field if it's non-nil, zero value otherwise -and a boolean to check if the value has been set. - -### SetValue28userIp29 - -`func (o *InlineObject1) SetValue28userIp29(v string)` - -SetValue28userIp29 sets Value28userIp29 field to given value. - - -### GetUserIp - -`func (o *InlineObject1) GetUserIp() string` - -GetUserIp returns the UserIp field if non-nil, zero value otherwise. - -### GetUserIpOk - -`func (o *InlineObject1) GetUserIpOk() (*string, bool)` - -GetUserIpOk returns a tuple with the UserIp field if it's non-nil, zero value otherwise -and a boolean to check if the value has been set. - -### SetUserIp - -`func (o *InlineObject1) SetUserIp(v string)` - -SetUserIp sets UserIp field to given value. - - -### GetValue28mobile29 - -`func (o *InlineObject1) GetValue28mobile29() string` - -GetValue28mobile29 returns the Value28mobile29 field if non-nil, zero value otherwise. - -### GetValue28mobile29Ok - -`func (o *InlineObject1) GetValue28mobile29Ok() (*string, bool)` - -GetValue28mobile29Ok returns a tuple with the Value28mobile29 field if it's non-nil, zero value otherwise -and a boolean to check if the value has been set. - -### SetValue28mobile29 - -`func (o *InlineObject1) SetValue28mobile29(v string)` - -SetValue28mobile29 sets Value28mobile29 field to given value. - - -### GetValue28browserInfo29 - -`func (o *InlineObject1) GetValue28browserInfo29() string` - -GetValue28browserInfo29 returns the Value28browserInfo29 field if non-nil, zero value otherwise. - -### GetValue28browserInfo29Ok - -`func (o *InlineObject1) GetValue28browserInfo29Ok() (*string, bool)` - -GetValue28browserInfo29Ok returns a tuple with the Value28browserInfo29 field if it's non-nil, zero value otherwise -and a boolean to check if the value has been set. - -### SetValue28browserInfo29 - -`func (o *InlineObject1) SetValue28browserInfo29(v string)` - -SetValue28browserInfo29 sets Value28browserInfo29 field to given value. - - -### GetMobile - -`func (o *InlineObject1) GetMobile() string` - -GetMobile returns the Mobile field if non-nil, zero value otherwise. - -### GetMobileOk - -`func (o *InlineObject1) GetMobileOk() (*string, bool)` - -GetMobileOk returns a tuple with the Mobile field if it's non-nil, zero value otherwise -and a boolean to check if the value has been set. - -### SetMobile - -`func (o *InlineObject1) SetMobile(v string)` - -SetMobile sets Mobile field to given value. - - - -[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) - - diff --git a/example/example.go b/example/example.go new file mode 100644 index 0000000..f79a081 --- /dev/null +++ b/example/example.go @@ -0,0 +1,64 @@ +package main + +import ( + "context" + "io/ioutil" + "log" + "net/http" + "os" + "time" + + bca "github.com/satraul/bca-go" +) + +func main() { + retcode := 1 + defer func() { os.Exit(retcode) }() + + var ( + ctx = context.Background() + username = os.Getenv("BCA_USERNAME") + password = os.Getenv("BCA_PASSWORD") + ip = getPublicIP() + ) + + api := bca.NewAPIClient(bca.NewConfiguration()) + auth, err := api.Login(ctx, username, password, ip) + if err != nil { + log.Println(err) + return + } + defer api.Logout(ctx, auth) + + balance, err := api.BalanceInquiry(ctx, auth) + if err != nil { + log.Println(err) + return + } + log.Printf("%+v\n", balance) + + statement, err := api.AccountStatementView(ctx, time.Now().AddDate(0, 0, -7), time.Now(), auth) + if err != nil { + log.Fatal(err) + return + } + log.Printf("%+v\n", statement) + + retcode = 0 +} + +// https://gist.github.com/ankanch/8c8ec5aaf374039504946e7e2b2cdf7f +func getPublicIP() string { + url := "https://api.ipify.org?format=text" + + resp, err := http.Get(url) + if err != nil { + panic(err) + } + defer resp.Body.Close() + ip, err := ioutil.ReadAll(resp.Body) + if err != nil { + panic(err) + } + return string(ip) +} diff --git a/extract.go b/extract.go new file mode 100644 index 0000000..83f6d37 --- /dev/null +++ b/extract.go @@ -0,0 +1,127 @@ +package bca + +import ( + "bytes" + "encoding/json" + "errors" + "io/ioutil" + "regexp" + "time" + + "github.com/PuerkitoBio/goquery" + "github.com/shopspring/decimal" +) + +// Balance is data in balance inquiry +type Balance struct { + AccountNumber string `json:"accountNumber"` + Currency string `json:"currency"` + BalanceRaw string `json:"balanceRaw"` + Balance decimal.Decimal `json:"balance"` +} + +// Entry is a row in statement view +type Entry struct { + Date time.Time `json:"date"` + Description string `json:"description"` + Payee string `json:"payee"` + Type string `json:"type"` + AmountRaw string `json:"balanceRaw"` + Amount decimal.Decimal `json:"balance"` +} + +var ( + blncCheck = regexp.MustCompile("INFORMASI REKENING - INFORMASI SALDO") + stmtCheck = regexp.MustCompile("INFORMASI REKENING - MUTASI REKENING") + commas = regexp.MustCompile("[,]+") +) + +const ( + blncSlctr = "#pagebody > span > table:nth-child(2) > tbody > tr > td:nth-child(2) > table > tbody > tr:nth-child(2)" + stmtSlctr = "#pagebody > span > table:nth-child(2) > tbody > tr:nth-child(2) > td:nth-child(2) > table > tbody" +) + +func extractHTML(b []byte, v interface{}) (err error) { + reader := ioutil.NopCloser(bytes.NewBuffer(b)) + defer reader.Close() + + doc, err := goquery.NewDocumentFromReader(reader) + if err != nil { + return + } + + if blncCheck.Match(b) { + return store(extractBalanceInquiry(doc), v) + } + + if stmtCheck.Match(b) { + return store(extractStatement(doc), v) + } + + return errors.New("failed to extract HTML") +} + +func extractBalanceInquiry(doc *goquery.Document) *Balance { + selector := doc.Find(blncSlctr).Children() + + b := Balance{ + AccountNumber: selector.First().Text(), + Currency: selector.Next().First().Text(), + BalanceRaw: selector.Next().Next().First().Text(), + } + + b.Balance = convDec(b.BalanceRaw) + return &b +} + +func extractStatement(doc *goquery.Document) []Entry { + selector := doc.Find(stmtSlctr).Children().Next() + + entries := make([]Entry, 0) + selector.Each(func(i int, s *goquery.Selection) { + s = s.Children() + s = s.First() + + timeRaw := s.Text() + + s = s.Next() + desc := s.Contents().FilterFunction(func(i int, s *goquery.Selection) bool { + return !s.Is("br") + }) + amountRaw := desc.Get(desc.Size() - 1).Data + entries = append(entries, Entry{ + Date: convTime(timeRaw), + Description: desc.Slice(0, desc.Size()-3).Text(), + Payee: desc.Get(desc.Size() - 3).Data, + Type: s.Next().Text(), + AmountRaw: amountRaw, + Amount: convDec(amountRaw), + }) + }) + return entries +} + +func convDec(raw string) (d decimal.Decimal) { + d, err := decimal.NewFromString(commas.ReplaceAllString(raw, "")) + if err != nil { + return + } + return d +} + +func convTime(raw string) (t time.Time) { + // May have timezone issues + t, err := time.ParseInLocation("02/01", raw, time.Local) + if err != nil { + return + } + return t.AddDate(time.Now().Year(), 0, 0) +} + +func store(data interface{}, v interface{}) error { + b, err := json.Marshal(data) + if err != nil { + return err + } + return json.Unmarshal(b, v) +} diff --git a/git_push.sh b/git_push.sh deleted file mode 100644 index ced3be2..0000000 --- a/git_push.sh +++ /dev/null @@ -1,58 +0,0 @@ -#!/bin/sh -# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ -# -# Usage example: /bin/sh ./git_push.sh wing328 openapi-pestore-perl "minor update" "gitlab.com" - -git_user_id=$1 -git_repo_id=$2 -release_note=$3 -git_host=$4 - -if [ "$git_host" = "" ]; then - git_host="github.com" - echo "[INFO] No command line input provided. Set \$git_host to $git_host" -fi - -if [ "$git_user_id" = "" ]; then - git_user_id="GIT_USER_ID" - echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id" -fi - -if [ "$git_repo_id" = "" ]; then - git_repo_id="GIT_REPO_ID" - echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id" -fi - -if [ "$release_note" = "" ]; then - release_note="Minor update" - echo "[INFO] No command line input provided. Set \$release_note to $release_note" -fi - -# Initialize the local directory as a Git repository -git init - -# Adds the files in the local repository and stages them for commit. -git add . - -# Commits the tracked changes and prepares them to be pushed to a remote repository. -git commit -m "$release_note" - -# Sets the new remote -git_remote=`git remote` -if [ "$git_remote" = "" ]; then # git remote not defined - - if [ "$GIT_TOKEN" = "" ]; then - echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment." - git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git - else - git remote add origin https://${git_user_id}:${GIT_TOKEN}@${git_host}/${git_user_id}/${git_repo_id}.git - fi - -fi - -git pull origin master - -# Pushes (Forces) the changes in the local repository up to the remote repository -echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git" -git push origin master 2>&1 | grep -v 'To https' - diff --git a/go.mod b/go.mod index f981155..f030601 100644 --- a/go.mod +++ b/go.mod @@ -1,7 +1,10 @@ -module github.com/GIT_USER_ID/GIT_REPO_ID +module github.com/satraul/bca-go -go 1.13 +go 1.14 require ( + github.com/PuerkitoBio/goquery v1.5.1 + github.com/shopspring/decimal v1.2.0 golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 + ) diff --git a/go.sum b/go.sum index ce55b3c..29f97d6 100644 --- a/go.sum +++ b/go.sum @@ -1,15 +1,24 @@ cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -github.com/antihax/optional v1.0.0 h1:xK2lYat7ZLaVVcIuj82J8kIro4V6kDe0AUDFboUCwcg= -github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= +github.com/PuerkitoBio/goquery v1.5.1 h1:PSPBGne8NIUWw+/7vFBV+kG2J/5MOjbzc7154OaKCSE= +github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc= +github.com/andybalholm/cascadia v1.1.0 h1:BuuO6sSfQNFRu1LppgbD25Hr2vLYW25JvxHs5zzsLTo= +github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y= github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ= +github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e h1:bRhVy7zSSasaqNksaRZiA5EEI+Ei4I1nO5Jh72wfHlg= golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20200202094626-16171245cfb2 h1:CCH4IOTTfewWjGOlSp+zGcjutRKlBEZQ6wTn8ozI/nI= +golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 h1:SVwTIAaPC2U/AvvLNZ2a7OVsmBpC8L5BlwK1whH3hm0= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 h1:YUO/7uOKsKeq9UokNS62b8FYywz3ker1l1vDZRCRefw= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= diff --git a/model_inline_object.go b/model_inline_object.go deleted file mode 100644 index 5baa74d..0000000 --- a/model_inline_object.go +++ /dev/null @@ -1,310 +0,0 @@ -/* - * BCA - * - * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) - * - * API version: 1.0 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package bca - -import ( - "encoding/json" -) - -// InlineObject struct for InlineObject -type InlineObject struct { - R1 string `json:"r1"` - Value28D129 string `json:"value%28D1%29"` - Value28startDt29 string `json:"value%28startDt%29"` - Value28startMt29 string `json:"value%28startMt%29"` - Value28startYr29 string `json:"value%28startYr%29"` - Value28endDt29 string `json:"value%28endDt%29"` - Value28endMt29 string `json:"value%28endMt%29"` - Value28endYr29 string `json:"value%28endYr%29"` -} - -// NewInlineObject instantiates a new InlineObject object -// This constructor will assign default values to properties that have it defined, -// and makes sure properties required by API are set, but the set of arguments -// will change when the set of required properties is changed -func NewInlineObject(r1 string, value28D129 string, value28startDt29 string, value28startMt29 string, value28startYr29 string, value28endDt29 string, value28endMt29 string, value28endYr29 string, ) *InlineObject { - this := InlineObject{} - this.R1 = r1 - this.Value28D129 = value28D129 - this.Value28startDt29 = value28startDt29 - this.Value28startMt29 = value28startMt29 - this.Value28startYr29 = value28startYr29 - this.Value28endDt29 = value28endDt29 - this.Value28endMt29 = value28endMt29 - this.Value28endYr29 = value28endYr29 - return &this -} - -// NewInlineObjectWithDefaults instantiates a new InlineObject object -// This constructor will only assign default values to properties that have it defined, -// but it doesn't guarantee that properties required by API are set -func NewInlineObjectWithDefaults() *InlineObject { - this := InlineObject{} - return &this -} - -// GetR1 returns the R1 field value -func (o *InlineObject) GetR1() string { - if o == nil { - var ret string - return ret - } - - return o.R1 -} - -// GetR1Ok returns a tuple with the R1 field value -// and a boolean to check if the value has been set. -func (o *InlineObject) GetR1Ok() (*string, bool) { - if o == nil { - return nil, false - } - return &o.R1, true -} - -// SetR1 sets field value -func (o *InlineObject) SetR1(v string) { - o.R1 = v -} - -// GetValue28D129 returns the Value28D129 field value -func (o *InlineObject) GetValue28D129() string { - if o == nil { - var ret string - return ret - } - - return o.Value28D129 -} - -// GetValue28D129Ok returns a tuple with the Value28D129 field value -// and a boolean to check if the value has been set. -func (o *InlineObject) GetValue28D129Ok() (*string, bool) { - if o == nil { - return nil, false - } - return &o.Value28D129, true -} - -// SetValue28D129 sets field value -func (o *InlineObject) SetValue28D129(v string) { - o.Value28D129 = v -} - -// GetValue28startDt29 returns the Value28startDt29 field value -func (o *InlineObject) GetValue28startDt29() string { - if o == nil { - var ret string - return ret - } - - return o.Value28startDt29 -} - -// GetValue28startDt29Ok returns a tuple with the Value28startDt29 field value -// and a boolean to check if the value has been set. -func (o *InlineObject) GetValue28startDt29Ok() (*string, bool) { - if o == nil { - return nil, false - } - return &o.Value28startDt29, true -} - -// SetValue28startDt29 sets field value -func (o *InlineObject) SetValue28startDt29(v string) { - o.Value28startDt29 = v -} - -// GetValue28startMt29 returns the Value28startMt29 field value -func (o *InlineObject) GetValue28startMt29() string { - if o == nil { - var ret string - return ret - } - - return o.Value28startMt29 -} - -// GetValue28startMt29Ok returns a tuple with the Value28startMt29 field value -// and a boolean to check if the value has been set. -func (o *InlineObject) GetValue28startMt29Ok() (*string, bool) { - if o == nil { - return nil, false - } - return &o.Value28startMt29, true -} - -// SetValue28startMt29 sets field value -func (o *InlineObject) SetValue28startMt29(v string) { - o.Value28startMt29 = v -} - -// GetValue28startYr29 returns the Value28startYr29 field value -func (o *InlineObject) GetValue28startYr29() string { - if o == nil { - var ret string - return ret - } - - return o.Value28startYr29 -} - -// GetValue28startYr29Ok returns a tuple with the Value28startYr29 field value -// and a boolean to check if the value has been set. -func (o *InlineObject) GetValue28startYr29Ok() (*string, bool) { - if o == nil { - return nil, false - } - return &o.Value28startYr29, true -} - -// SetValue28startYr29 sets field value -func (o *InlineObject) SetValue28startYr29(v string) { - o.Value28startYr29 = v -} - -// GetValue28endDt29 returns the Value28endDt29 field value -func (o *InlineObject) GetValue28endDt29() string { - if o == nil { - var ret string - return ret - } - - return o.Value28endDt29 -} - -// GetValue28endDt29Ok returns a tuple with the Value28endDt29 field value -// and a boolean to check if the value has been set. -func (o *InlineObject) GetValue28endDt29Ok() (*string, bool) { - if o == nil { - return nil, false - } - return &o.Value28endDt29, true -} - -// SetValue28endDt29 sets field value -func (o *InlineObject) SetValue28endDt29(v string) { - o.Value28endDt29 = v -} - -// GetValue28endMt29 returns the Value28endMt29 field value -func (o *InlineObject) GetValue28endMt29() string { - if o == nil { - var ret string - return ret - } - - return o.Value28endMt29 -} - -// GetValue28endMt29Ok returns a tuple with the Value28endMt29 field value -// and a boolean to check if the value has been set. -func (o *InlineObject) GetValue28endMt29Ok() (*string, bool) { - if o == nil { - return nil, false - } - return &o.Value28endMt29, true -} - -// SetValue28endMt29 sets field value -func (o *InlineObject) SetValue28endMt29(v string) { - o.Value28endMt29 = v -} - -// GetValue28endYr29 returns the Value28endYr29 field value -func (o *InlineObject) GetValue28endYr29() string { - if o == nil { - var ret string - return ret - } - - return o.Value28endYr29 -} - -// GetValue28endYr29Ok returns a tuple with the Value28endYr29 field value -// and a boolean to check if the value has been set. -func (o *InlineObject) GetValue28endYr29Ok() (*string, bool) { - if o == nil { - return nil, false - } - return &o.Value28endYr29, true -} - -// SetValue28endYr29 sets field value -func (o *InlineObject) SetValue28endYr29(v string) { - o.Value28endYr29 = v -} - -func (o InlineObject) MarshalJSON() ([]byte, error) { - toSerialize := map[string]interface{}{} - if true { - toSerialize["r1"] = o.R1 - } - if true { - toSerialize["value%28D1%29"] = o.Value28D129 - } - if true { - toSerialize["value%28startDt%29"] = o.Value28startDt29 - } - if true { - toSerialize["value%28startMt%29"] = o.Value28startMt29 - } - if true { - toSerialize["value%28startYr%29"] = o.Value28startYr29 - } - if true { - toSerialize["value%28endDt%29"] = o.Value28endDt29 - } - if true { - toSerialize["value%28endMt%29"] = o.Value28endMt29 - } - if true { - toSerialize["value%28endYr%29"] = o.Value28endYr29 - } - return json.Marshal(toSerialize) -} - -type NullableInlineObject struct { - value *InlineObject - isSet bool -} - -func (v NullableInlineObject) Get() *InlineObject { - return v.value -} - -func (v *NullableInlineObject) Set(val *InlineObject) { - v.value = val - v.isSet = true -} - -func (v NullableInlineObject) IsSet() bool { - return v.isSet -} - -func (v *NullableInlineObject) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableInlineObject(val *InlineObject) *NullableInlineObject { - return &NullableInlineObject{value: val, isSet: true} -} - -func (v NullableInlineObject) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableInlineObject) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - - diff --git a/model_inline_object_1.go b/model_inline_object_1.go deleted file mode 100644 index 24214b8..0000000 --- a/model_inline_object_1.go +++ /dev/null @@ -1,339 +0,0 @@ -/* - * BCA - * - * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) - * - * API version: 1.0 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package bca - -import ( - "encoding/json" -) - -// InlineObject1 struct for InlineObject1 -type InlineObject1 struct { - Value28userId29 string `json:"value%28user_id%29"` - Value28pswd29 string `json:"value%28pswd%29"` - Value28Submit29 string `json:"value%28Submit%29"` - Value28actions29 string `json:"value%28actions%29"` - Value28userIp29 string `json:"value%28user_ip%29"` - UserIp string `json:"user_ip"` - Value28mobile29 string `json:"value%28mobile%29"` - Value28browserInfo29 string `json:"value%28browser_info%29"` - Mobile string `json:"mobile"` -} - -// NewInlineObject1 instantiates a new InlineObject1 object -// This constructor will assign default values to properties that have it defined, -// and makes sure properties required by API are set, but the set of arguments -// will change when the set of required properties is changed -func NewInlineObject1(value28userId29 string, value28pswd29 string, value28Submit29 string, value28actions29 string, value28userIp29 string, userIp string, value28mobile29 string, value28browserInfo29 string, mobile string, ) *InlineObject1 { - this := InlineObject1{} - this.Value28userId29 = value28userId29 - this.Value28pswd29 = value28pswd29 - this.Value28Submit29 = value28Submit29 - this.Value28actions29 = value28actions29 - this.Value28userIp29 = value28userIp29 - this.UserIp = userIp - this.Value28mobile29 = value28mobile29 - this.Value28browserInfo29 = value28browserInfo29 - this.Mobile = mobile - return &this -} - -// NewInlineObject1WithDefaults instantiates a new InlineObject1 object -// This constructor will only assign default values to properties that have it defined, -// but it doesn't guarantee that properties required by API are set -func NewInlineObject1WithDefaults() *InlineObject1 { - this := InlineObject1{} - return &this -} - -// GetValue28userId29 returns the Value28userId29 field value -func (o *InlineObject1) GetValue28userId29() string { - if o == nil { - var ret string - return ret - } - - return o.Value28userId29 -} - -// GetValue28userId29Ok returns a tuple with the Value28userId29 field value -// and a boolean to check if the value has been set. -func (o *InlineObject1) GetValue28userId29Ok() (*string, bool) { - if o == nil { - return nil, false - } - return &o.Value28userId29, true -} - -// SetValue28userId29 sets field value -func (o *InlineObject1) SetValue28userId29(v string) { - o.Value28userId29 = v -} - -// GetValue28pswd29 returns the Value28pswd29 field value -func (o *InlineObject1) GetValue28pswd29() string { - if o == nil { - var ret string - return ret - } - - return o.Value28pswd29 -} - -// GetValue28pswd29Ok returns a tuple with the Value28pswd29 field value -// and a boolean to check if the value has been set. -func (o *InlineObject1) GetValue28pswd29Ok() (*string, bool) { - if o == nil { - return nil, false - } - return &o.Value28pswd29, true -} - -// SetValue28pswd29 sets field value -func (o *InlineObject1) SetValue28pswd29(v string) { - o.Value28pswd29 = v -} - -// GetValue28Submit29 returns the Value28Submit29 field value -func (o *InlineObject1) GetValue28Submit29() string { - if o == nil { - var ret string - return ret - } - - return o.Value28Submit29 -} - -// GetValue28Submit29Ok returns a tuple with the Value28Submit29 field value -// and a boolean to check if the value has been set. -func (o *InlineObject1) GetValue28Submit29Ok() (*string, bool) { - if o == nil { - return nil, false - } - return &o.Value28Submit29, true -} - -// SetValue28Submit29 sets field value -func (o *InlineObject1) SetValue28Submit29(v string) { - o.Value28Submit29 = v -} - -// GetValue28actions29 returns the Value28actions29 field value -func (o *InlineObject1) GetValue28actions29() string { - if o == nil { - var ret string - return ret - } - - return o.Value28actions29 -} - -// GetValue28actions29Ok returns a tuple with the Value28actions29 field value -// and a boolean to check if the value has been set. -func (o *InlineObject1) GetValue28actions29Ok() (*string, bool) { - if o == nil { - return nil, false - } - return &o.Value28actions29, true -} - -// SetValue28actions29 sets field value -func (o *InlineObject1) SetValue28actions29(v string) { - o.Value28actions29 = v -} - -// GetValue28userIp29 returns the Value28userIp29 field value -func (o *InlineObject1) GetValue28userIp29() string { - if o == nil { - var ret string - return ret - } - - return o.Value28userIp29 -} - -// GetValue28userIp29Ok returns a tuple with the Value28userIp29 field value -// and a boolean to check if the value has been set. -func (o *InlineObject1) GetValue28userIp29Ok() (*string, bool) { - if o == nil { - return nil, false - } - return &o.Value28userIp29, true -} - -// SetValue28userIp29 sets field value -func (o *InlineObject1) SetValue28userIp29(v string) { - o.Value28userIp29 = v -} - -// GetUserIp returns the UserIp field value -func (o *InlineObject1) GetUserIp() string { - if o == nil { - var ret string - return ret - } - - return o.UserIp -} - -// GetUserIpOk returns a tuple with the UserIp field value -// and a boolean to check if the value has been set. -func (o *InlineObject1) GetUserIpOk() (*string, bool) { - if o == nil { - return nil, false - } - return &o.UserIp, true -} - -// SetUserIp sets field value -func (o *InlineObject1) SetUserIp(v string) { - o.UserIp = v -} - -// GetValue28mobile29 returns the Value28mobile29 field value -func (o *InlineObject1) GetValue28mobile29() string { - if o == nil { - var ret string - return ret - } - - return o.Value28mobile29 -} - -// GetValue28mobile29Ok returns a tuple with the Value28mobile29 field value -// and a boolean to check if the value has been set. -func (o *InlineObject1) GetValue28mobile29Ok() (*string, bool) { - if o == nil { - return nil, false - } - return &o.Value28mobile29, true -} - -// SetValue28mobile29 sets field value -func (o *InlineObject1) SetValue28mobile29(v string) { - o.Value28mobile29 = v -} - -// GetValue28browserInfo29 returns the Value28browserInfo29 field value -func (o *InlineObject1) GetValue28browserInfo29() string { - if o == nil { - var ret string - return ret - } - - return o.Value28browserInfo29 -} - -// GetValue28browserInfo29Ok returns a tuple with the Value28browserInfo29 field value -// and a boolean to check if the value has been set. -func (o *InlineObject1) GetValue28browserInfo29Ok() (*string, bool) { - if o == nil { - return nil, false - } - return &o.Value28browserInfo29, true -} - -// SetValue28browserInfo29 sets field value -func (o *InlineObject1) SetValue28browserInfo29(v string) { - o.Value28browserInfo29 = v -} - -// GetMobile returns the Mobile field value -func (o *InlineObject1) GetMobile() string { - if o == nil { - var ret string - return ret - } - - return o.Mobile -} - -// GetMobileOk returns a tuple with the Mobile field value -// and a boolean to check if the value has been set. -func (o *InlineObject1) GetMobileOk() (*string, bool) { - if o == nil { - return nil, false - } - return &o.Mobile, true -} - -// SetMobile sets field value -func (o *InlineObject1) SetMobile(v string) { - o.Mobile = v -} - -func (o InlineObject1) MarshalJSON() ([]byte, error) { - toSerialize := map[string]interface{}{} - if true { - toSerialize["value%28user_id%29"] = o.Value28userId29 - } - if true { - toSerialize["value%28pswd%29"] = o.Value28pswd29 - } - if true { - toSerialize["value%28Submit%29"] = o.Value28Submit29 - } - if true { - toSerialize["value%28actions%29"] = o.Value28actions29 - } - if true { - toSerialize["value%28user_ip%29"] = o.Value28userIp29 - } - if true { - toSerialize["user_ip"] = o.UserIp - } - if true { - toSerialize["value%28mobile%29"] = o.Value28mobile29 - } - if true { - toSerialize["value%28browser_info%29"] = o.Value28browserInfo29 - } - if true { - toSerialize["mobile"] = o.Mobile - } - return json.Marshal(toSerialize) -} - -type NullableInlineObject1 struct { - value *InlineObject1 - isSet bool -} - -func (v NullableInlineObject1) Get() *InlineObject1 { - return v.value -} - -func (v *NullableInlineObject1) Set(val *InlineObject1) { - v.value = val - v.isSet = true -} - -func (v NullableInlineObject1) IsSet() bool { - return v.isSet -} - -func (v *NullableInlineObject1) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableInlineObject1(val *InlineObject1) *NullableInlineObject1 { - return &NullableInlineObject1{value: val, isSet: true} -} - -func (v NullableInlineObject1) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableInlineObject1) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - - diff --git a/utils.go b/utils.go deleted file mode 100644 index 3151f0a..0000000 --- a/utils.go +++ /dev/null @@ -1,334 +0,0 @@ -/* - * BCA - * - * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) - * - * API version: 1.0 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package bca - -import ( - "encoding/json" - "time" -) - -// PtrBool is a helper routine that returns a pointer to given integer value. -func PtrBool(v bool) *bool { return &v } - -// PtrInt is a helper routine that returns a pointer to given integer value. -func PtrInt(v int) *int { return &v } - -// PtrInt32 is a helper routine that returns a pointer to given integer value. -func PtrInt32(v int32) *int32 { return &v } - -// PtrInt64 is a helper routine that returns a pointer to given integer value. -func PtrInt64(v int64) *int64 { return &v } - -// PtrFloat32 is a helper routine that returns a pointer to given float value. -func PtrFloat32(v float32) *float32 { return &v } - -// PtrFloat64 is a helper routine that returns a pointer to given float value. -func PtrFloat64(v float64) *float64 { return &v } - -// PtrString is a helper routine that returns a pointer to given string value. -func PtrString(v string) *string { return &v } - -// PtrTime is helper routine that returns a pointer to given Time value. -func PtrTime(v time.Time) *time.Time { return &v } - -type NullableBool struct { - value *bool - isSet bool -} - -func (v NullableBool) Get() *bool { - return v.value -} - -func (v *NullableBool) Set(val *bool) { - v.value = val - v.isSet = true -} - -func (v NullableBool) IsSet() bool { - return v.isSet -} - -func (v *NullableBool) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableBool(val *bool) *NullableBool { - return &NullableBool{value: val, isSet: true} -} - -func (v NullableBool) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableBool) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - - -type NullableInt struct { - value *int - isSet bool -} - -func (v NullableInt) Get() *int { - return v.value -} - -func (v *NullableInt) Set(val *int) { - v.value = val - v.isSet = true -} - -func (v NullableInt) IsSet() bool { - return v.isSet -} - -func (v *NullableInt) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableInt(val *int) *NullableInt { - return &NullableInt{value: val, isSet: true} -} - -func (v NullableInt) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableInt) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - - -type NullableInt32 struct { - value *int32 - isSet bool -} - -func (v NullableInt32) Get() *int32 { - return v.value -} - -func (v *NullableInt32) Set(val *int32) { - v.value = val - v.isSet = true -} - -func (v NullableInt32) IsSet() bool { - return v.isSet -} - -func (v *NullableInt32) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableInt32(val *int32) *NullableInt32 { - return &NullableInt32{value: val, isSet: true} -} - -func (v NullableInt32) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableInt32) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - - -type NullableInt64 struct { - value *int64 - isSet bool -} - -func (v NullableInt64) Get() *int64 { - return v.value -} - -func (v *NullableInt64) Set(val *int64) { - v.value = val - v.isSet = true -} - -func (v NullableInt64) IsSet() bool { - return v.isSet -} - -func (v *NullableInt64) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableInt64(val *int64) *NullableInt64 { - return &NullableInt64{value: val, isSet: true} -} - -func (v NullableInt64) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableInt64) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - - -type NullableFloat32 struct { - value *float32 - isSet bool -} - -func (v NullableFloat32) Get() *float32 { - return v.value -} - -func (v *NullableFloat32) Set(val *float32) { - v.value = val - v.isSet = true -} - -func (v NullableFloat32) IsSet() bool { - return v.isSet -} - -func (v *NullableFloat32) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableFloat32(val *float32) *NullableFloat32 { - return &NullableFloat32{value: val, isSet: true} -} - -func (v NullableFloat32) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableFloat32) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - - -type NullableFloat64 struct { - value *float64 - isSet bool -} - -func (v NullableFloat64) Get() *float64 { - return v.value -} - -func (v *NullableFloat64) Set(val *float64) { - v.value = val - v.isSet = true -} - -func (v NullableFloat64) IsSet() bool { - return v.isSet -} - -func (v *NullableFloat64) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableFloat64(val *float64) *NullableFloat64 { - return &NullableFloat64{value: val, isSet: true} -} - -func (v NullableFloat64) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableFloat64) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - - -type NullableString struct { - value *string - isSet bool -} - -func (v NullableString) Get() *string { - return v.value -} - -func (v *NullableString) Set(val *string) { - v.value = val - v.isSet = true -} - -func (v NullableString) IsSet() bool { - return v.isSet -} - -func (v *NullableString) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableString(val *string) *NullableString { - return &NullableString{value: val, isSet: true} -} - -func (v NullableString) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableString) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - - -type NullableTime struct { - value *time.Time - isSet bool -} - -func (v NullableTime) Get() *time.Time { - return v.value -} - -func (v *NullableTime) Set(val *time.Time) { - v.value = val - v.isSet = true -} - -func (v NullableTime) IsSet() bool { - return v.isSet -} - -func (v *NullableTime) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableTime(val *time.Time) *NullableTime { - return &NullableTime{value: val, isSet: true} -} - -func (v NullableTime) MarshalJSON() ([]byte, error) { - return v.value.MarshalJSON() -} - -func (v *NullableTime) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -}