crowi-client 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +0 -0
- data/.rspec +0 -0
- data/.travis.yml +0 -0
- data/CODE_OF_CONDUCT.md +0 -0
- data/Gemfile +0 -0
- data/LICENSE +0 -0
- data/LICENSE.txt +0 -0
- data/README.md +37 -38
- data/Rakefile +0 -0
- data/crowi-client.gemspec +0 -1
- data/lib/crowi-client.rb +0 -0
- data/lib/crowi/client/apireq/api_request_attachments.rb +0 -0
- data/lib/crowi/client/apireq/api_request_base.rb +0 -0
- data/lib/crowi/client/apireq/api_request_pages.rb +0 -0
- data/lib/crowi/client/client.rb +12 -10
- data/lib/crowi/client/model/crowi_attachment.rb +0 -0
- data/lib/crowi/client/model/crowi_model.rb +0 -0
- data/lib/crowi/client/model/crowi_model_base.rb +0 -0
- data/lib/crowi/client/model/crowi_page.rb +0 -0
- data/lib/crowi/client/model/crowi_page_revision.rb +0 -0
- data/lib/crowi/client/model/crowi_user.rb +0 -0
- data/lib/crowi/client/version.rb +1 -1
- metadata +2 -17
- data/config/settings.yml +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 310285c37c1db2f5953063e99c161c6a1236f66f1ce2f47c31f317d04c04409d
|
4
|
+
data.tar.gz: eee12e023f1311472a314ed17dc6488cb1c41978f8fe0e2a6693a56bdfb79626
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5340275410bd45e55f42bdf61da53d1dc54fa81f2cd807a80b94e7112e5ca3141463967db635894e19745a719008c86cbfdf4b07ebf982feffb440bc14b6fea
|
7
|
+
data.tar.gz: e9dd54e46956a2ef52d9887666cf98f5ef37e00965c7259f279e4536aaea50f72e3e9e6164850156f3596ba1be08054b898d5a7156578d151fce92799e92ee72
|
data/.gitignore
CHANGED
File without changes
|
data/.rspec
CHANGED
File without changes
|
data/.travis.yml
CHANGED
File without changes
|
data/CODE_OF_CONDUCT.md
CHANGED
File without changes
|
data/Gemfile
CHANGED
File without changes
|
data/LICENSE
CHANGED
File without changes
|
data/LICENSE.txt
CHANGED
File without changes
|
data/README.md
CHANGED
@@ -20,76 +20,75 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
|
24
|
-
And set token key of crowi API, and URL of crowi (ex. http://localhost:3000) in ```settings.yml```.
|
23
|
+
Export these environments.
|
25
24
|
|
26
|
-
```YAML
|
27
|
-
# Example of config/settings.yml. YOU NEED TO REPLACE token!!!
|
28
|
-
token: xEKAueUZDrQlr30iFZr96ti3GUd8sqP/pTkS3DGrwcc=
|
29
|
-
url: http://localhost:3000/
|
30
25
|
```
|
31
|
-
|
32
|
-
|
26
|
+
export CROWI_ACCESS_TOKEN=0123456789abcdef0123456789abcdef0123456789ab
|
27
|
+
export CROWI_URL=http://localhost:3000/
|
28
|
+
```
|
33
29
|
|
34
30
|
```ruby
|
35
31
|
require 'crowi-client'
|
36
|
-
|
37
|
-
|
32
|
+
|
33
|
+
crowi_client = CrowiClient.new(crowi_url: ENV['CROWI_URL'], access_token: ENV['CROWI_ACCESS_TOKEN'])
|
34
|
+
|
35
|
+
puts crowi_client.page_exist?( path_exp: '/' )
|
36
|
+
puts crowi_client.attachment_exist?( path_exp: '/', attachment_name: 'LICENSE.txt' )
|
38
37
|
```
|
39
38
|
|
40
39
|
## Examples
|
41
40
|
|
42
41
|
```ruby
|
43
42
|
# get page's ID
|
44
|
-
puts
|
43
|
+
puts crowi_client.page_id( path_exp: '/' )
|
45
44
|
```
|
46
45
|
|
47
46
|
```ruby
|
48
47
|
# Check existence of page by page path (you can use regular expression)
|
49
|
-
|
48
|
+
crowi_client.page_exist?( path_exp: '/' )
|
50
49
|
```
|
51
50
|
|
52
51
|
```ruby
|
53
52
|
# Check existence of attachment by file name of attachment
|
54
|
-
|
53
|
+
crowi_client.attachment_exist?( path_exp: '/', attachment_name: 'LICENSE.txt' )
|
55
54
|
```
|
56
55
|
|
57
56
|
```ruby
|
58
57
|
# get attachment's ID
|
59
|
-
puts
|
58
|
+
puts crowi_client.attachment_id( path_exp: '/', attachment_name: 'LICENSE.txt' )
|
60
59
|
```
|
61
60
|
|
62
61
|
```ruby
|
63
62
|
# get attachment (return data is object of CrowiAttachment)
|
64
|
-
puts
|
63
|
+
puts crowi_client.attachment( path_exp: '/', attachment_name: 'LICENSE.txt' )
|
65
64
|
```
|
66
65
|
|
67
66
|
```ruby
|
68
67
|
# pages list
|
69
68
|
req = CPApiRequestPagesList.new path_exp: '/'
|
70
|
-
puts
|
69
|
+
puts crowi_client.request(req)
|
71
70
|
```
|
72
71
|
|
73
72
|
```ruby
|
74
73
|
# pages get - path_exp
|
75
74
|
req = CPApiRequestPagesList.new path_exp: '/'
|
76
|
-
puts
|
75
|
+
puts crowi_client.request(req)
|
77
76
|
```
|
78
77
|
|
79
78
|
```ruby
|
80
79
|
# pages get - page_id
|
81
|
-
req = CPApiRequestPagesGet.new page_id:
|
82
|
-
puts
|
80
|
+
req = CPApiRequestPagesGet.new page_id: crowi_client.page_id(path_exp: '/')
|
81
|
+
puts crowi_client.request(req)
|
83
82
|
```
|
84
83
|
|
85
84
|
```ruby
|
86
85
|
# pages get - revision_id
|
87
86
|
reqtmp = CPApiRequestPagesList.new path_exp: '/'
|
88
|
-
ret =
|
87
|
+
ret = crowi_client.request(reqtmp)
|
89
88
|
path = ret.data[0].path
|
90
89
|
revision_id = ret.data[0].revision._id
|
91
90
|
req = CPApiRequestPagesGet.new path: path, revision_id: revision_id
|
92
|
-
puts
|
91
|
+
puts crowi_client.request(req)
|
93
92
|
```
|
94
93
|
|
95
94
|
```ruby
|
@@ -98,7 +97,7 @@ test_page_path = '/tmp/crowi-client test page'
|
|
98
97
|
body = "# crowi-client\n"
|
99
98
|
req = CPApiRequestPagesCreate.new path: test_page_path,
|
100
99
|
body: body
|
101
|
-
puts
|
100
|
+
puts crowi_client.request(req)
|
102
101
|
```
|
103
102
|
|
104
103
|
```ruby
|
@@ -106,74 +105,74 @@ puts CrowiClient.instance.request(req)
|
|
106
105
|
test_page_path = '/tmp/crowi-client test page'
|
107
106
|
test_cases = [nil, CrowiPage::GRANT_PUBLIC, CrowiPage::GRANT_RESTRICTED,
|
108
107
|
CrowiPage::GRANT_SPECIFIED, CrowiPage::GRANT_OWNER]
|
109
|
-
page_id =
|
108
|
+
page_id = crowi_client.page_id(path_exp: test_page_path)
|
110
109
|
|
111
110
|
body = "# crowi-client\n"
|
112
111
|
test_cases.each do |grant|
|
113
112
|
body = body + grant.to_s
|
114
113
|
req = CPApiRequestPagesUpdate.new page_id: page_id,
|
115
114
|
body: body, grant: grant
|
116
|
-
puts
|
115
|
+
puts crowi_client.request(req)
|
117
116
|
end
|
118
117
|
```
|
119
118
|
|
120
119
|
```ruby
|
121
120
|
# pages seen
|
122
|
-
page_id =
|
121
|
+
page_id = crowi_client.page_id(path_exp: '/')
|
123
122
|
req = CPApiRequestPagesSeen.new page_id: page_id
|
124
|
-
puts
|
123
|
+
puts crowi_client.request(req)
|
125
124
|
```
|
126
125
|
|
127
126
|
```ruby
|
128
127
|
# likes add
|
129
128
|
test_page_path = '/tmp/crowi-client test page'
|
130
|
-
page_id =
|
129
|
+
page_id = crowi_client.page_id(path_exp: test_page_path)
|
131
130
|
req = CPApiRequestLikesAdd.new page_id: page_id
|
132
|
-
puts
|
131
|
+
puts crowi_client.request(req)
|
133
132
|
```
|
134
133
|
|
135
134
|
```ruby
|
136
135
|
# likes remove
|
137
136
|
test_page_path = '/tmp/crowi-client test page'
|
138
|
-
page_id =
|
137
|
+
page_id = crowi_client.page_id(path_exp: test_page_path)
|
139
138
|
req = CPApiRequestLikesRemove.new page_id: page_id
|
140
|
-
puts
|
139
|
+
puts crowi_client.request(req)
|
141
140
|
```
|
142
141
|
|
143
142
|
```ruby
|
144
143
|
# update post
|
145
144
|
test_page_path = '/tmp/crowi-client test page'
|
146
145
|
req = CPApiRequestPagesUpdatePost.new path: test_page_path
|
147
|
-
puts
|
146
|
+
puts crowi_client.request(req)
|
148
147
|
```
|
149
148
|
|
150
149
|
|
151
150
|
```ruby
|
152
151
|
# attachments list
|
153
152
|
test_page_path = '/tmp/crowi-client test page'
|
154
|
-
page_id =
|
153
|
+
page_id = crowi_client.page_id(path_exp: test_page_path)
|
155
154
|
req = CPApiRequestAttachmentsList.new page_id: page_id
|
156
|
-
puts
|
155
|
+
puts crowi_client.request(req)
|
157
156
|
```
|
158
157
|
|
159
158
|
```ruby
|
160
159
|
# attachments add
|
161
160
|
test_page_path = '/tmp/crowi-client test page'
|
162
|
-
page_id =
|
161
|
+
page_id = crowi_client.page_id(path_exp: test_page_path)
|
163
162
|
req = CPApiRequestAttachmentsAdd.new page_id: page_id,
|
164
163
|
file: File.new('LICENSE.txt')
|
165
|
-
puts
|
164
|
+
puts crowi_client.request(req)
|
166
165
|
```
|
167
166
|
|
168
167
|
```ruby
|
169
168
|
# attachments remove
|
170
169
|
test_page_path = '/tmp/crowi-client test page'
|
171
|
-
page_id =
|
170
|
+
page_id = crowi_client.page_id(path_exp: test_page_path)
|
172
171
|
reqtmp = CPApiRequestAttachmentsList.new page_id: page_id
|
173
|
-
ret =
|
172
|
+
ret = crowi_client.request(reqtmp)
|
174
173
|
attachment_id = ret.data[0]._id
|
175
174
|
req = CPApiRequestAttachmentsRemove.new attachment_id: attachment_id
|
176
|
-
puts
|
175
|
+
puts crowi_client.request(req)
|
177
176
|
```
|
178
177
|
|
179
178
|
## Development
|
data/Rakefile
CHANGED
File without changes
|
data/crowi-client.gemspec
CHANGED
data/lib/crowi-client.rb
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/crowi/client/client.rb
CHANGED
@@ -1,28 +1,29 @@
|
|
1
|
-
require 'singleton'
|
2
1
|
require 'rest-client'
|
3
2
|
require 'json'
|
4
3
|
require 'yaml'
|
5
|
-
require
|
4
|
+
require 'uri'
|
6
5
|
|
7
6
|
require 'crowi/client/apireq/api_request_pages'
|
8
7
|
require 'crowi/client/apireq/api_request_attachments'
|
9
8
|
|
10
9
|
# Crowi のクライアントクラス
|
11
10
|
class CrowiClient
|
12
|
-
include Singleton
|
13
11
|
|
14
|
-
#
|
15
|
-
def initialize
|
16
|
-
raise ArgumentError, 'Config
|
17
|
-
raise ArgumentError, 'Config
|
18
|
-
|
12
|
+
# コンストラクタ
|
13
|
+
def initialize(crowi_url: '', access_token: '')
|
14
|
+
raise ArgumentError, 'Config `crowi_url` is required.' if crowi_url.empty?
|
15
|
+
raise ArgumentError, 'Config `access_token` is required.' if access_token.empty?
|
16
|
+
|
17
|
+
@crowi_url = crowi_url
|
18
|
+
@access_toke = access_token
|
19
|
+
@cp_entry_point = URI.join(crowi_url, '/_api/').to_s
|
19
20
|
end
|
20
21
|
|
21
22
|
# APIリクエストを送信する
|
22
23
|
# @param [ApiRequestBase] req APIリクエスト
|
23
24
|
# @return [String] APIリクエストの応答(JSON形式)
|
24
25
|
def request(req)
|
25
|
-
req.param[:access_token] =
|
26
|
+
req.param[:access_token] = @access_toke
|
26
27
|
return req.execute URI.join(@cp_entry_point, req.entry_point).to_s
|
27
28
|
end
|
28
29
|
|
@@ -31,7 +32,8 @@ class CrowiClient
|
|
31
32
|
# @return [String] ページID
|
32
33
|
def page_id(path_exp: nil)
|
33
34
|
ret = request(CPApiRequestPagesList.new path_exp: path_exp)
|
34
|
-
return ret
|
35
|
+
return nil if (ret.kind_of? CPInvalidRequest || ret.data.nil?)
|
36
|
+
return ret.data.find { |page| URI.unescape(page.path) == path_exp }&.id
|
35
37
|
end
|
36
38
|
|
37
39
|
# ページが存在するか調べる
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/crowi/client/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crowi-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryu Sato
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,20 +94,6 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '2.1'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: easy_settings
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - "~>"
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0.1'
|
104
|
-
type: :runtime
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - "~>"
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0.1'
|
111
97
|
description: crowi-client is client of crowi with use API.
|
112
98
|
email:
|
113
99
|
- ryu@weseek.co.jp
|
@@ -126,7 +112,6 @@ files:
|
|
126
112
|
- Rakefile
|
127
113
|
- bin/console
|
128
114
|
- bin/setup
|
129
|
-
- config/settings.yml
|
130
115
|
- crowi-client.gemspec
|
131
116
|
- lib/crowi-client.rb
|
132
117
|
- lib/crowi/client/apireq/api_request_attachments.rb
|
data/config/settings.yml
DELETED