Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Commit

Permalink
Merge pull request #37 from kintone/v0.9.1
Browse files Browse the repository at this point in the history
V0.9.1
  • Loading branch information
cy-kaneko authored Apr 12, 2018
2 parents 0119bfc + aed6a71 commit abe839c
Show file tree
Hide file tree
Showing 11 changed files with 442 additions and 649 deletions.
8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ before_install:
- go get github.com/kintone/go-kintone
- go get github.com/howeyc/gopass
- go get golang.org/x/text/encoding
- go get github.com/mitchellh/gox
- go get github.com/jessevdk/go-flags
- go get github.com/mitchellh/gox # get gox lib for building cross platform

script:
- go vet -x ./...
- gox -osarch="linux/amd64" -output build/linux-x64/cli-kintone
- zip linux-x64.zip build/linux-x64/cli-kintone
- gox -osarch="darwin/amd64" -output build/macos-x64/cli-kintone
- zip macos-x64.zip build/macos-x64/cli-kintone
- gox -osarch="windows/amd64" -output build/windows-x64/cli-kintone
- gox -osarch="windows/amd64" -tags "forceposix" -output build/windows-x64/cli-kintone
- zip windows-x64.zip build/windows-x64/cli-kintone.exe
- gox -osarch="windows/386" -output build/windows/cli-kintone
- gox -osarch="windows/386" -tags "forceposix" -output build/windows/cli-kintone
- zip windows.zip build/windows/cli-kintone.exe
deploy:
provider: releases
Expand Down
53 changes: 31 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ cli-kintone is a command line utility for exporting and importing kintone App da

## Version

0.9.0
0.9.1

## How to Build

### Requirement

- Go 1.2 or later
- Go 1.9.3 or later
- Git and Mercurial to be able to clone the packages

Getting the source code
Expand All @@ -24,6 +24,7 @@ Install dependencies
$ go get github.com/kintone/go-kintone
$ go get github.com/howeyc/gopass
$ go get golang.org/x/text/encoding
$ go get github.com/jessevdk/go-flags

build

Expand All @@ -41,26 +42,34 @@ These binaries are available for download.
https://github.com/kintone/cli-kintone/releases

## Usage

-d = "" : Domain name. Specify the FQDN.
-a = 0 : App ID.
-u = "" : User's log in name.
-p = "" : User's password.
-t = "" : API token.
-g = 0 : Guest Space ID.
-o = "csv" : Output format. Specify either 'json' or 'csv'(default).
-e = "utf-8" : Character encoding. Specify one of the following -> 'utf-8'(default), 'utf-16', 'utf-16be-with-signature', 'utf-16le-with-signature', 'sjis' or 'euc-jp'.
-U = "" : Basic authentication user name.
-P = "" : Basic authentication password.
-q = "" : Query string.
-c = "" : Fields to export (comma separated). Specify the field code name.
-f = "" : Input file path.
-b = "" : Attachment file directory.
-D = false : Delete records before insert. You can specify the deleting record condition by option "-q".
-l = 1 : Position index of data in the input file. Default is 1.
--import : Import data from stdin. If "-f" is also specified, data is imported from the file instead.
--export : Export kintone data to stdout.

```
Usage:
cli-kintone [OPTIONS]
Application Options:
-d= Domain name (specify the FQDN)
-a= App ID (default: 0)
-u= User's log in name
-p= User's password
-t= API token
-g= Guest Space ID (default: 0)
-o= Output format. Specify either 'json' or 'csv' (default: csv)
-e= Character encoding. Specify one of the following -> 'utf-8'(default), 'utf-16', 'utf-16be-with-signature', 'utf-16le-with-signature', 'sjis' or
'euc-jp' (default: utf-8)
-U= Basic authentication user name
-P= Basic authentication password
-q= Query string
-c= Fields to export (comma separated). Specify the field code name
-f= Input file path
-b= Attachment file directory
-D Delete records before insert. You can specify the deleting record condition by option "-q"
-l= Position index of data in the input file (default: 1)
--import Import data from stdin. If "-f" is also specified, data is imported from the file instead
--export Export kintone data to stdout
Help Options:
-h, --help Show this help message
```
## Examples

### Export all columns from an app
Expand Down
17 changes: 11 additions & 6 deletions bulkRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (bulk *BulkRequests) ImportDataUpdate(app *kintone.App, recordData *kintone
}
recordsUpdate = append(recordsUpdate, recordPUT)
dataPUT = &DataRequestRecordsPUT{App: app.AppId, Records: recordsUpdate}
requestPUTRecords := &BulkRequestItem{"PUT", "/k/v1/records.json", dataPUT}
requestPUTRecords := &BulkRequestItem{"PUT", kintoneURLPath("records", app.GuestSpaceId), dataPUT}
bulk.Requests = append(bulk.Requests, requestPUTRecords)

return nil
Expand Down Expand Up @@ -211,21 +211,26 @@ func (bulk *BulkRequests) ImportDataInsert(app *kintone.App, recordData *kintone
recordsInsert := make([]*kintone.Record, 0)
recordsInsert = append(recordsInsert, recordData)
dataPOST = &DataRequestRecordsPOST{app.AppId, recordsInsert}
requestPostRecords := &BulkRequestItem{"POST", "/k/v1/records.json", dataPOST}
requestPostRecords := &BulkRequestItem{"POST", kintoneURLPath("records", app.GuestSpaceId), dataPOST}
bulk.Requests = append(bulk.Requests, requestPostRecords)

return nil

}

func newRequest(app *kintone.App, method, api string, body io.Reader) (*http.Request, error) {
// kintoneURLPath get path URL of kintone api
func kintoneURLPath(apiName string, GuestSpaceID uint64) string {
var path string
if app.GuestSpaceId == 0 {
path = fmt.Sprintf("/k/v1/%s.json", api)
if GuestSpaceID == 0 {
path = fmt.Sprintf("/k/v1/%s.json", apiName)
} else {
path = fmt.Sprintf("/k/guest/%d/v1/%s.json", app.GuestSpaceId, api)
path = fmt.Sprintf("/k/guest/%d/v1/%s.json", GuestSpaceID, apiName)
}
return path
}

func newRequest(app *kintone.App, method, api string, body io.Reader) (*http.Request, error) {
path := kintoneURLPath(api, app.GuestSpaceId)
u := url.URL{
Scheme: "https",
Host: app.Domain,
Expand Down
Loading

0 comments on commit abe839c

Please sign in to comment.