crowi-client 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- 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 +38 -19
- data/Rakefile +0 -0
- data/crowi-client.gemspec +0 -0
- data/lib/crowi-client.rb +0 -0
- data/lib/crowi/client/apireq/api_request_attachments.rb +19 -13
- data/lib/crowi/client/apireq/api_request_base.rb +6 -4
- data/lib/crowi/client/apireq/api_request_pages.rb +64 -32
- data/lib/crowi/client/client.rb +10 -9
- 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
- data/wercker.yml +89 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27b61000e5d32781330c8b28a95bd5fae5cec26cb9ad1e525575d2a285a7a971
|
4
|
+
data.tar.gz: de26c5480ae0c69df1142215cc7dec282655b79458787191f29bd768f5334cfb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 468e265e36c000263960f29e72171f93a5f580dc3f23a680fe27a9481055cc27ba6b1c1e16e8fd86e8bbcb2ed973f02f6499c9c4ecbf4ec1ec7db36760148b63
|
7
|
+
data.tar.gz: 8721f9e22543c7f362c27334ff51d748d56f48dc1d828687092f59a3147c3f0157444bd40cd0579ab63638f9fbc5436de975787e6878ee779bda14ef3afa84ba
|
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
@@ -1,3 +1,5 @@
|
|
1
|
+
[![wercker status](https://app.wercker.com/status/8d49d851e9cdf0c7e1b7c840cc2fe6ad/s/master "wercker status")](https://app.wercker.com/project/byKey/8d49d851e9cdf0c7e1b7c840cc2fe6ad)
|
2
|
+
|
1
3
|
# crowi-client -- client of crowi with use API
|
2
4
|
|
3
5
|
A client of crowi with use API.
|
@@ -32,15 +34,15 @@ require 'crowi-client'
|
|
32
34
|
|
33
35
|
crowi_client = CrowiClient.new(crowi_url: ENV['CROWI_URL'], access_token: ENV['CROWI_ACCESS_TOKEN'])
|
34
36
|
|
35
|
-
|
36
|
-
|
37
|
+
p crowi_client.page_exist?( path_exp: '/' )
|
38
|
+
p crowi_client.attachment_exist?( path_exp: '/', attachment_name: 'LICENSE.txt' )
|
37
39
|
```
|
38
40
|
|
39
41
|
## Examples
|
40
42
|
|
41
43
|
```ruby
|
42
44
|
# get page's ID
|
43
|
-
|
45
|
+
p crowi_client.page_id( path_exp: '/' )
|
44
46
|
```
|
45
47
|
|
46
48
|
```ruby
|
@@ -55,30 +57,30 @@ crowi_client.attachment_exist?( path_exp: '/', attachment_name: 'LICENSE.txt' )
|
|
55
57
|
|
56
58
|
```ruby
|
57
59
|
# get attachment's ID
|
58
|
-
|
60
|
+
p crowi_client.attachment_id( path_exp: '/', attachment_name: 'LICENSE.txt' )
|
59
61
|
```
|
60
62
|
|
61
63
|
```ruby
|
62
64
|
# get attachment (return data is object of CrowiAttachment)
|
63
|
-
|
65
|
+
p crowi_client.attachment( path_exp: '/', attachment_name: 'LICENSE.txt' )
|
64
66
|
```
|
65
67
|
|
66
68
|
```ruby
|
67
69
|
# pages list
|
68
70
|
req = CPApiRequestPagesList.new path_exp: '/'
|
69
|
-
|
71
|
+
p crowi_client.request(req)
|
70
72
|
```
|
71
73
|
|
72
74
|
```ruby
|
73
75
|
# pages get - path_exp
|
74
76
|
req = CPApiRequestPagesList.new path_exp: '/'
|
75
|
-
|
77
|
+
p crowi_client.request(req)
|
76
78
|
```
|
77
79
|
|
78
80
|
```ruby
|
79
81
|
# pages get - page_id
|
80
82
|
req = CPApiRequestPagesGet.new page_id: crowi_client.page_id(path_exp: '/')
|
81
|
-
|
83
|
+
p crowi_client.request(req)
|
82
84
|
```
|
83
85
|
|
84
86
|
```ruby
|
@@ -88,7 +90,7 @@ ret = crowi_client.request(reqtmp)
|
|
88
90
|
path = ret.data[0].path
|
89
91
|
revision_id = ret.data[0].revision._id
|
90
92
|
req = CPApiRequestPagesGet.new path: path, revision_id: revision_id
|
91
|
-
|
93
|
+
p crowi_client.request(req)
|
92
94
|
```
|
93
95
|
|
94
96
|
```ruby
|
@@ -97,7 +99,7 @@ test_page_path = '/tmp/crowi-client test page'
|
|
97
99
|
body = "# crowi-client\n"
|
98
100
|
req = CPApiRequestPagesCreate.new path: test_page_path,
|
99
101
|
body: body
|
100
|
-
|
102
|
+
p crowi_client.request(req)
|
101
103
|
```
|
102
104
|
|
103
105
|
```ruby
|
@@ -112,7 +114,7 @@ test_cases.each do |grant|
|
|
112
114
|
body = body + grant.to_s
|
113
115
|
req = CPApiRequestPagesUpdate.new page_id: page_id,
|
114
116
|
body: body, grant: grant
|
115
|
-
|
117
|
+
p crowi_client.request(req)
|
116
118
|
end
|
117
119
|
```
|
118
120
|
|
@@ -120,7 +122,7 @@ end
|
|
120
122
|
# pages seen
|
121
123
|
page_id = crowi_client.page_id(path_exp: '/')
|
122
124
|
req = CPApiRequestPagesSeen.new page_id: page_id
|
123
|
-
|
125
|
+
p crowi_client.request(req)
|
124
126
|
```
|
125
127
|
|
126
128
|
```ruby
|
@@ -128,7 +130,7 @@ puts crowi_client.request(req)
|
|
128
130
|
test_page_path = '/tmp/crowi-client test page'
|
129
131
|
page_id = crowi_client.page_id(path_exp: test_page_path)
|
130
132
|
req = CPApiRequestLikesAdd.new page_id: page_id
|
131
|
-
|
133
|
+
p crowi_client.request(req)
|
132
134
|
```
|
133
135
|
|
134
136
|
```ruby
|
@@ -136,14 +138,14 @@ puts crowi_client.request(req)
|
|
136
138
|
test_page_path = '/tmp/crowi-client test page'
|
137
139
|
page_id = crowi_client.page_id(path_exp: test_page_path)
|
138
140
|
req = CPApiRequestLikesRemove.new page_id: page_id
|
139
|
-
|
141
|
+
p crowi_client.request(req)
|
140
142
|
```
|
141
143
|
|
142
144
|
```ruby
|
143
145
|
# update post
|
144
146
|
test_page_path = '/tmp/crowi-client test page'
|
145
147
|
req = CPApiRequestPagesUpdatePost.new path: test_page_path
|
146
|
-
|
148
|
+
p crowi_client.request(req)
|
147
149
|
```
|
148
150
|
|
149
151
|
|
@@ -152,7 +154,7 @@ puts crowi_client.request(req)
|
|
152
154
|
test_page_path = '/tmp/crowi-client test page'
|
153
155
|
page_id = crowi_client.page_id(path_exp: test_page_path)
|
154
156
|
req = CPApiRequestAttachmentsList.new page_id: page_id
|
155
|
-
|
157
|
+
p crowi_client.request(req)
|
156
158
|
```
|
157
159
|
|
158
160
|
```ruby
|
@@ -161,7 +163,7 @@ test_page_path = '/tmp/crowi-client test page'
|
|
161
163
|
page_id = crowi_client.page_id(path_exp: test_page_path)
|
162
164
|
req = CPApiRequestAttachmentsAdd.new page_id: page_id,
|
163
165
|
file: File.new('LICENSE.txt')
|
164
|
-
|
166
|
+
p crowi_client.request(req)
|
165
167
|
```
|
166
168
|
|
167
169
|
```ruby
|
@@ -172,7 +174,24 @@ reqtmp = CPApiRequestAttachmentsList.new page_id: page_id
|
|
172
174
|
ret = crowi_client.request(reqtmp)
|
173
175
|
attachment_id = ret.data[0]._id
|
174
176
|
req = CPApiRequestAttachmentsRemove.new attachment_id: attachment_id
|
175
|
-
|
177
|
+
p crowi_client.request(req)
|
178
|
+
```
|
179
|
+
|
180
|
+
### Basic Authentication
|
181
|
+
|
182
|
+
```ruby
|
183
|
+
require 'crowi-client'
|
184
|
+
|
185
|
+
# Create crowiclient instance with username and password that is used by basic authentication
|
186
|
+
crowi_client = CrowiClient.new(crowi_url: ENV['CROWI_URL'], access_token: ENV['CROWI_ACCESS_TOKEN'],
|
187
|
+
rest_client_param: { user: 'who', password: 'bar'})
|
188
|
+
|
189
|
+
# Check existence of page
|
190
|
+
p crowi_client.page_exist?( path_exp: '/' ) ? '/ exist' : '/ not exist'
|
191
|
+
|
192
|
+
# Create page whose path is '/tmp'
|
193
|
+
req = CPApiRequestPagesCreate.new path: '/tmp', body: 'tmp'
|
194
|
+
p crowi_client.request(req)
|
176
195
|
```
|
177
196
|
|
178
197
|
## Development
|
@@ -195,4 +214,4 @@ Everyone interacting in the Crowi::Client project’s codebases, issue trackers,
|
|
195
214
|
|
196
215
|
## ToDo
|
197
216
|
|
198
|
-
- [
|
217
|
+
- [x] Support crowi with basic Authentication
|
data/Rakefile
CHANGED
File without changes
|
data/crowi-client.gemspec
CHANGED
File without changes
|
data/lib/crowi-client.rb
CHANGED
File without changes
|
@@ -14,12 +14,14 @@ class CPApiRequestAttachmentsList < CPApiRequestBase
|
|
14
14
|
# リクエストを実行する
|
15
15
|
# @override
|
16
16
|
# @param [String] entry_point APIのエントリーポイントとなるURL(ex. http://localhost:3000/_api/pages.list)
|
17
|
-
# @
|
18
|
-
|
17
|
+
# @param [Hash] rest_client_param RestClientのパラメータ
|
18
|
+
# @return [Array] リクエスト実行結果
|
19
|
+
def execute(entry_point, rest_client_param: {})
|
19
20
|
if invalid?
|
20
21
|
return validation_msg
|
21
22
|
end
|
22
|
-
|
23
|
+
params = { method: :get, url: entry_point, headers: { params: @param } }.merge(rest_client_param)
|
24
|
+
ret = JSON.parse RestClient::Request.execute params
|
23
25
|
if (ret['ok'] == false)
|
24
26
|
return CPInvalidRequest.new "API return false with msg: #{ret['msg']}"
|
25
27
|
end
|
@@ -57,12 +59,13 @@ class CPApiRequestAttachmentsAdd < CPApiRequestBase
|
|
57
59
|
# リクエストを実行する
|
58
60
|
# @override
|
59
61
|
# @param [String] entry_point APIのエントリーポイントとなるURL(ex. http://localhost:3000/_api/pages.list)
|
60
|
-
# @
|
61
|
-
|
62
|
+
# @param [Hash] rest_client_param RestClientのパラメータ
|
63
|
+
# @return [Array] リクエスト実行結果
|
64
|
+
def execute(entry_point, rest_client_param: {})
|
62
65
|
if invalid?
|
63
66
|
return validation_msg
|
64
67
|
end
|
65
|
-
|
68
|
+
params = {
|
66
69
|
method: :post,
|
67
70
|
url: entry_point,
|
68
71
|
payload: {
|
@@ -70,8 +73,8 @@ class CPApiRequestAttachmentsAdd < CPApiRequestBase
|
|
70
73
|
page_id: @param[:page_id],
|
71
74
|
file: @param[:file]
|
72
75
|
}
|
73
|
-
)
|
74
|
-
ret = JSON.parse
|
76
|
+
}.merge(rest_client_param)
|
77
|
+
ret = JSON.parse RestClient::Request.execute params
|
75
78
|
if (ret['ok'] == false)
|
76
79
|
return CPInvalidRequest.new "API return false with msg: #{ret['msg']}"
|
77
80
|
end
|
@@ -103,17 +106,20 @@ class CPApiRequestAttachmentsRemove < CPApiRequestBase
|
|
103
106
|
{ attachment_id: param[:attachment_id] })
|
104
107
|
end
|
105
108
|
|
106
|
-
|
107
109
|
# リクエストを実行する
|
108
110
|
# @override
|
109
111
|
# @param [String] entry_point APIのエントリーポイントとなるURL(ex. http://localhost:3000/_api/pages.list)
|
110
|
-
# @
|
111
|
-
|
112
|
+
# @param [Hash] rest_client_param RestClientのパラメータ
|
113
|
+
# @return [Array] リクエスト実行結果
|
114
|
+
def execute(entry_point, rest_client_param: {})
|
112
115
|
if invalid?
|
113
116
|
return validation_msg
|
114
117
|
end
|
115
|
-
|
116
|
-
|
118
|
+
params = { method: :post, url: entry_point,
|
119
|
+
payload: @param.to_json,
|
120
|
+
headers: { content_type: :json, accept: :json }
|
121
|
+
}.merge(rest_client_param)
|
122
|
+
ret = JSON.parse RestClient::Request.execute params
|
117
123
|
if (ret['ok'] == false)
|
118
124
|
return CPInvalidRequest.new "API return false with msg: #{ret['msg']}"
|
119
125
|
end
|
@@ -74,8 +74,9 @@ class CPApiRequestBase
|
|
74
74
|
|
75
75
|
# リクエストを実行する
|
76
76
|
# @param [String] entry_point APIのエントリーポイントとなるURL(ex. http://localhost:3000/_api/pages.list)
|
77
|
+
# @param [Hash] rest_client_param RestClientのパラメータ
|
77
78
|
# @return [String] リクエスト実行結果(CPApiReturnオブジェクト)
|
78
|
-
def execute(entry_point)
|
79
|
+
def execute(entry_point, rest_client_param: {})
|
79
80
|
|
80
81
|
if invalid?
|
81
82
|
return validation_msg
|
@@ -83,11 +84,12 @@ class CPApiRequestBase
|
|
83
84
|
|
84
85
|
case @method
|
85
86
|
when 'GET'
|
86
|
-
|
87
|
+
params = { method: :get, url: entry_point, headers: { params: @param } }.merge(rest_client_param)
|
87
88
|
when 'POST'
|
88
|
-
|
89
|
-
|
89
|
+
params = { method: :post, url: entry_point, content_type: :json, accept: :json,
|
90
|
+
headers: { params: @param.to_json } }.merge()
|
90
91
|
end
|
92
|
+
ret_json = RestClient::Request.execute params
|
91
93
|
ret = JSON.parse(ret_json)
|
92
94
|
return CPApiReturn.new(ok: ret['ok'], data: ret.reject { |k,v| k == 'ok' })
|
93
95
|
end
|
@@ -16,14 +16,16 @@ class CPApiRequestPagesList < CPApiRequestBase
|
|
16
16
|
# リクエストを実行する
|
17
17
|
# @override
|
18
18
|
# @param [String] entry_point APIのエントリーポイントとなるURL(ex. http://localhost:3000/_api/pages.list)
|
19
|
+
# @param [Hash] rest_client_param RestClientのパラメータ
|
19
20
|
# @return [Array] リクエスト実行結果
|
20
|
-
def execute(entry_point)
|
21
|
+
def execute(entry_point, rest_client_param: {})
|
21
22
|
|
22
23
|
if invalid?
|
23
24
|
return validation_msg
|
24
25
|
end
|
25
26
|
|
26
|
-
|
27
|
+
params = { method: :get, url: entry_point, headers: { params: @param } }.merge(rest_client_param)
|
28
|
+
ret = JSON.parse RestClient::Request.execute params
|
27
29
|
if (ret['ok'] == false)
|
28
30
|
return CPInvalidRequest.new "API return false with msg: #{ret['msg']}"
|
29
31
|
end
|
@@ -41,7 +43,10 @@ protected
|
|
41
43
|
# @return [nil/CPInvalidRequest] バリデーションエラー結果
|
42
44
|
def _invalid
|
43
45
|
if ! (@param[:path] || @param[:user])
|
44
|
-
return CPInvalidRequest.new 'Parameter path or
|
46
|
+
return CPInvalidRequest.new 'Parameter path or user is required.'
|
47
|
+
end
|
48
|
+
if (@param[:path] && @param[:user])
|
49
|
+
return CPInvalidRequest.new 'Parameter path and user can not be specified both.'
|
45
50
|
end
|
46
51
|
end
|
47
52
|
|
@@ -64,13 +69,15 @@ class CPApiRequestPagesGet < CPApiRequestBase
|
|
64
69
|
# リクエストを実行する
|
65
70
|
# @override
|
66
71
|
# @param [String] entry_point APIのエントリーポイントとなるURL(ex. http://localhost:3000/_api/pages.list)
|
67
|
-
# @
|
68
|
-
|
72
|
+
# @param [Hash] rest_client_param RestClientのパラメータ
|
73
|
+
# @return [Array] リクエスト実行結果
|
74
|
+
def execute(entry_point, rest_client_param: {})
|
69
75
|
|
70
76
|
if invalid?
|
71
77
|
return validation_msg
|
72
78
|
end
|
73
|
-
|
79
|
+
params = { method: :get, url: entry_point, headers: { params: @param } }.merge(rest_client_param)
|
80
|
+
ret = JSON.parse RestClient::Request.execute params
|
74
81
|
if (ret['ok'] == false)
|
75
82
|
return CPInvalidRequest.new "API return false with msg: #{ret['msg']}"
|
76
83
|
end
|
@@ -106,14 +113,19 @@ class CPApiRequestPagesCreate < CPApiRequestBase
|
|
106
113
|
# リクエストを実行する
|
107
114
|
# @override
|
108
115
|
# @param [String] entry_point APIのエントリーポイントとなるURL(ex. http://localhost:3000/_api/pages.list)
|
109
|
-
# @
|
110
|
-
|
116
|
+
# @param [Hash] rest_client_param RestClientのパラメータ
|
117
|
+
# @return [Array] リクエスト実行結果
|
118
|
+
def execute(entry_point, rest_client_param: {})
|
111
119
|
|
112
120
|
if invalid?
|
113
121
|
return validation_msg
|
114
122
|
end
|
115
|
-
|
116
|
-
|
123
|
+
|
124
|
+
params = { method: :post, url: entry_point,
|
125
|
+
payload: @param.to_json,
|
126
|
+
headers: { content_type: :json, accept: :json }
|
127
|
+
}.merge(rest_client_param)
|
128
|
+
ret = JSON.parse RestClient::Request.execute params
|
117
129
|
if (ret['ok'] == false)
|
118
130
|
return CPInvalidRequest.new "API return false with msg: #{ret['msg']}"
|
119
131
|
end
|
@@ -149,14 +161,18 @@ class CPApiRequestPagesUpdate < CPApiRequestBase
|
|
149
161
|
# リクエストを実行する
|
150
162
|
# @override
|
151
163
|
# @param [String] entry_point APIのエントリーポイントとなるURL(ex. http://localhost:3000/_api/pages.list)
|
152
|
-
# @
|
153
|
-
|
164
|
+
# @param [Hash] rest_client_param RestClientのパラメータ
|
165
|
+
# @return [Array] リクエスト実行結果
|
166
|
+
def execute(entry_point, rest_client_param: {})
|
154
167
|
|
155
168
|
if invalid?
|
156
169
|
return validation_msg
|
157
170
|
end
|
158
|
-
|
159
|
-
|
171
|
+
params = { method: :post, url: entry_point,
|
172
|
+
payload: @param.to_json,
|
173
|
+
headers: { content_type: :json, accept: :json }
|
174
|
+
}.merge(rest_client_param)
|
175
|
+
ret = JSON.parse RestClient::Request.execute params
|
160
176
|
if (ret['ok'] == false)
|
161
177
|
return CPInvalidRequest.new "API return false with msg: #{ret['msg']}"
|
162
178
|
end
|
@@ -191,14 +207,18 @@ class CPApiRequestPagesSeen < CPApiRequestBase
|
|
191
207
|
# リクエストを実行する
|
192
208
|
# @override
|
193
209
|
# @param [String] entry_point APIのエントリーポイントとなるURL(ex. http://localhost:3000/_api/pages.list)
|
194
|
-
# @
|
195
|
-
|
210
|
+
# @param [Hash] rest_client_param RestClientのパラメータ
|
211
|
+
# @return [Array] リクエスト実行結果
|
212
|
+
def execute(entry_point, rest_client_param: {})
|
196
213
|
|
197
214
|
if invalid?
|
198
215
|
return validation_msg
|
199
216
|
end
|
200
|
-
|
201
|
-
|
217
|
+
params = { method: :post, url: entry_point,
|
218
|
+
payload: @param.to_json,
|
219
|
+
headers: { content_type: :json, accept: :json }
|
220
|
+
}.merge(rest_client_param)
|
221
|
+
ret = JSON.parse RestClient::Request.execute params
|
202
222
|
if (ret['ok'] == false)
|
203
223
|
return CPInvalidRequest.new "API return false with msg: #{ret['msg']}"
|
204
224
|
end
|
@@ -232,14 +252,18 @@ class CPApiRequestLikesAdd < CPApiRequestBase
|
|
232
252
|
# リクエストを実行する
|
233
253
|
# @override
|
234
254
|
# @param [String] entry_point APIのエントリーポイントとなるURL(ex. http://localhost:3000/_api/pages.list)
|
235
|
-
# @
|
236
|
-
|
255
|
+
# @param [Hash] rest_client_param RestClientのパラメータ
|
256
|
+
# @return [Array] リクエスト実行結果
|
257
|
+
def execute(entry_point, rest_client_param: {})
|
237
258
|
|
238
259
|
if invalid?
|
239
260
|
return validation_msg
|
240
261
|
end
|
241
|
-
|
242
|
-
|
262
|
+
params = { method: :post, url: entry_point,
|
263
|
+
payload: @param.to_json,
|
264
|
+
headers: { content_type: :json, accept: :json }
|
265
|
+
}.merge(rest_client_param)
|
266
|
+
ret = JSON.parse RestClient::Request.execute params
|
243
267
|
if (ret['ok'] == false)
|
244
268
|
return CPInvalidRequest.new "API return false with msg: #{ret['msg']}"
|
245
269
|
end
|
@@ -273,14 +297,18 @@ class CPApiRequestLikesRemove < CPApiRequestBase
|
|
273
297
|
# リクエストを実行する
|
274
298
|
# @override
|
275
299
|
# @param [String] entry_point APIのエントリーポイントとなるURL(ex. http://localhost:3000/_api/pages.list)
|
276
|
-
# @
|
277
|
-
|
300
|
+
# @param [Hash] rest_client_param RestClientのパラメータ
|
301
|
+
# @return [Array] リクエスト実行結果
|
302
|
+
def execute(entry_point, rest_client_param: {})
|
278
303
|
|
279
304
|
if invalid?
|
280
305
|
return validation_msg
|
281
306
|
end
|
282
|
-
|
283
|
-
|
307
|
+
params = { method: :post, url: entry_point,
|
308
|
+
payload: @param.to_json,
|
309
|
+
headers: { content_type: :json, accept: :json }
|
310
|
+
}.merge(rest_client_param)
|
311
|
+
ret = JSON.parse RestClient::Request.execute params
|
284
312
|
if (ret['ok'] == false)
|
285
313
|
return CPInvalidRequest.new "API return false with msg: #{ret['msg']}"
|
286
314
|
end
|
@@ -315,13 +343,15 @@ class CPApiRequestPagesUpdatePost < CPApiRequestBase
|
|
315
343
|
# リクエストを実行する
|
316
344
|
# @override
|
317
345
|
# @param [String] entry_point APIのエントリーポイントとなるURL(ex. http://localhost:3000/_api/pages.list)
|
318
|
-
# @
|
319
|
-
|
346
|
+
# @param [Hash] rest_client_param RestClientのパラメータ
|
347
|
+
# @return [Array] リクエスト実行結果
|
348
|
+
def execute(entry_point, rest_client_param: {})
|
320
349
|
|
321
350
|
if invalid?
|
322
351
|
return validation_msg
|
323
352
|
end
|
324
|
-
|
353
|
+
params = { method: :get, url: entry_point, headers: { params: @param } }.merge(rest_client_param)
|
354
|
+
ret = JSON.parse RestClient::Request.execute params
|
325
355
|
if (ret['ok'] == false)
|
326
356
|
return CPInvalidRequest.new "API return false with msg: #{ret['msg']}"
|
327
357
|
end
|
@@ -361,13 +391,15 @@ class CPApiRequestPagesRemove < CPApiRequestBase
|
|
361
391
|
# リクエストを実行する
|
362
392
|
# @override
|
363
393
|
# @param [String] entry_point APIのエントリーポイントとなるURL(ex. http://localhost:3000/_api/pages.list)
|
364
|
-
# @
|
365
|
-
|
394
|
+
# @param [Hash] rest_client_param RestClientのパラメータ
|
395
|
+
# @return [Array] リクエスト実行結果
|
396
|
+
def execute(entry_point, rest_client_param: {})
|
366
397
|
|
367
398
|
if invalid?
|
368
399
|
return validation_msg
|
369
400
|
end
|
370
|
-
|
401
|
+
param = { method: :get, url: entry_point, headers: { params: @param } }.merge(rest_client_param)
|
402
|
+
ret = JSON.parse RestClient::Request.execute param
|
371
403
|
if (ret['ok'] == false)
|
372
404
|
return CPInvalidRequest.new "API return false with msg: #{ret['msg']}"
|
373
405
|
end
|
data/lib/crowi/client/client.rb
CHANGED
@@ -10,12 +10,13 @@ require 'crowi/client/apireq/api_request_attachments'
|
|
10
10
|
class CrowiClient
|
11
11
|
|
12
12
|
# コンストラクタ
|
13
|
-
def initialize(crowi_url: '', access_token: '')
|
13
|
+
def initialize(crowi_url: '', access_token: '', rest_client_param: {})
|
14
14
|
raise ArgumentError, 'Config `crowi_url` is required.' if crowi_url.empty?
|
15
15
|
raise ArgumentError, 'Config `access_token` is required.' if access_token.empty?
|
16
16
|
|
17
17
|
@crowi_url = crowi_url
|
18
|
-
@
|
18
|
+
@access_token = access_token
|
19
|
+
@rest_client_param = rest_client_param
|
19
20
|
@cp_entry_point = URI.join(crowi_url, '/_api/').to_s
|
20
21
|
end
|
21
22
|
|
@@ -23,8 +24,9 @@ class CrowiClient
|
|
23
24
|
# @param [ApiRequestBase] req APIリクエスト
|
24
25
|
# @return [String] APIリクエストの応答(JSON形式)
|
25
26
|
def request(req)
|
26
|
-
req.param[:access_token] = @
|
27
|
-
return req.execute URI.join(@cp_entry_point, req.entry_point).to_s
|
27
|
+
req.param[:access_token] = @access_token
|
28
|
+
return req.execute URI.join(@cp_entry_point, req.entry_point).to_s,
|
29
|
+
rest_client_param: @rest_client_param
|
28
30
|
end
|
29
31
|
|
30
32
|
# ページIDを取得する
|
@@ -56,17 +58,16 @@ class CrowiClient
|
|
56
58
|
# @param [String] path_exp ページパス(正規表現)
|
57
59
|
# @return [String] attachment's file name
|
58
60
|
def attachment_id(path_exp: nil, attachment_name: nil)
|
59
|
-
|
60
|
-
|
61
|
+
ret = request(CPApiRequestAttachmentsList.new page_id: page_id(path_exp: path_exp))
|
62
|
+
return ret&.data&.find { |a| a.originalName == attachment_name }&._id
|
61
63
|
end
|
62
64
|
|
63
65
|
# 指定した添付ファイル情報を取得する
|
64
66
|
# @param [String] path_exp ページパス(正規表現)
|
65
67
|
# @return [String] attachment's file name
|
66
68
|
def attachment(path_exp: nil, attachment_name: nil)
|
67
|
-
|
68
|
-
|
69
|
+
ret = request(CPApiRequestAttachmentsList.new page_id: page_id(path_exp: path_exp))
|
70
|
+
return ret&.data&.find { |a| a.originalName == attachment_name }
|
69
71
|
end
|
70
72
|
|
71
73
|
end
|
72
|
-
|
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
data/wercker.yml
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
box: ruby:2.5.1
|
2
|
+
|
3
|
+
# Run weseek/growi, mongo, elasticsearch
|
4
|
+
services:
|
5
|
+
- name: mongo
|
6
|
+
id: mongo:3.4
|
7
|
+
|
8
|
+
build:
|
9
|
+
# Steps make up the actions in your pipeline
|
10
|
+
# Read more about steps on our dev center:
|
11
|
+
# http://devcenter.wercker.com/docs/steps/index.html
|
12
|
+
steps:
|
13
|
+
- bundle-install
|
14
|
+
|
15
|
+
- script:
|
16
|
+
name: "Install utility tools"
|
17
|
+
code: |
|
18
|
+
apt-get update
|
19
|
+
apt-get install -y netcat
|
20
|
+
|
21
|
+
- script:
|
22
|
+
name: "Wait for MongoDB connection"
|
23
|
+
code: |
|
24
|
+
echo Wait for connect to $MONGO_PORT_27017_TCP_ADDR:$MONGO_PORT_27017_TCP_PORT
|
25
|
+
while ! nc -q 1 $MONGO_PORT_27017_TCP_ADDR $MONGO_PORT_27017_TCP_PORT </dev/null; do
|
26
|
+
echo "...waiting 3s"; sleep 3;
|
27
|
+
done
|
28
|
+
|
29
|
+
- internal/docker-run:
|
30
|
+
image: weseek/growi:3.1.12
|
31
|
+
name: growi
|
32
|
+
env: >
|
33
|
+
MONGO_URI=mongodb://$MONGO_PORT_27017_TCP_ADDR:$MONGO_PORT_27017_TCP_PORT/growi
|
34
|
+
PASSWORD_SEED=empty
|
35
|
+
FILE_UPLOAD=local
|
36
|
+
|
37
|
+
- script:
|
38
|
+
name: "Wait for GROWI connection"
|
39
|
+
code: |
|
40
|
+
echo Wait for connect to growi:3000
|
41
|
+
while ! nc -q 1 growi 3000 < /dev/null; do
|
42
|
+
echo "...waiting 3s"; sleep 3;
|
43
|
+
done
|
44
|
+
export GROWI_URL=http://growi:3000
|
45
|
+
|
46
|
+
- script:
|
47
|
+
name: "Create admin user"
|
48
|
+
code: |
|
49
|
+
export ADMIN_USER_NAME=admin1
|
50
|
+
export ADMIN_USER_PASS=admin1pass
|
51
|
+
LOGIN_COOKIE=login.cookie
|
52
|
+
OUTPUT_PAGE_NAME=installer.html
|
53
|
+
curl $GROWI_URL/installer -c ${LOGIN_COOKIE} -o ${OUTPUT_PAGE_NAME}
|
54
|
+
CSRF=`grep data-csrftoken ${OUTPUT_PAGE_NAME} | awk -F'=' '{ print $2 }' | sed -e s/\"//g`
|
55
|
+
curl $GROWI_URL/installer/createAdmin -b ${LOGIN_COOKIE} -X POST \
|
56
|
+
-d "registerForm[name]=${ADMIN_USER_NAME}®isterForm[username]=${ADMIN_USER_NAME}®isterForm[email]=${ADMIN_USER_NAME}@localhost®isterForm[password]=${ADMIN_USER_PASS}&_csrf=${CSRF}"
|
57
|
+
|
58
|
+
- script:
|
59
|
+
name: "Login as admin1"
|
60
|
+
code: |
|
61
|
+
OUTPUT_PAGE_NAME=login.html
|
62
|
+
curl $GROWI_URL/login -c ${LOGIN_COOKIE} -o ${OUTPUT_PAGE_NAME}
|
63
|
+
CSRF=`grep data-csrftoken ${OUTPUT_PAGE_NAME} | awk -F'=' '{ print $2 }' | sed -e s/\"//g`
|
64
|
+
curl $GROWI_URL/login -b ${LOGIN_COOKIE} -X POST -d "loginForm[username]=${ADMIN_USER_NAME}&loginForm[password]=${ADMIN_USER_PASS}&_csrf=${CSRF}"
|
65
|
+
|
66
|
+
- script:
|
67
|
+
name: "Generate API token"
|
68
|
+
code: |
|
69
|
+
OUTPUT_PAGE_NAME=apiToken.html
|
70
|
+
curl $GROWI_URL/me/apiToken -b ${LOGIN_COOKIE} -o ${OUTPUT_PAGE_NAME}
|
71
|
+
CSRF=`grep data-csrftoken ${OUTPUT_PAGE_NAME} | awk -F'=' '{ print $2 }' | sed -e s/\"//g`
|
72
|
+
curl $GROWI_URL/me/apiToken -b ${LOGIN_COOKIE} -X POST -d "apiTokenForm[confirm]=1&_csrf=${CSRF}"
|
73
|
+
curl $GROWI_URL/me/apiToken -b ${LOGIN_COOKIE} -o ${OUTPUT_PAGE_NAME}
|
74
|
+
export APITOKEN=`grep -A 10 'Current API Token' ${OUTPUT_PAGE_NAME} | grep '<input' | awk -F'value=' '{ print $2 }' | awk -F'"' '{ print $2 }'`
|
75
|
+
|
76
|
+
- script:
|
77
|
+
name: "Export environment variables"
|
78
|
+
code: |
|
79
|
+
export CROWI_URL=$GROWI_URL
|
80
|
+
export CROWI_ACCESS_TOKEN=$APITOKEN
|
81
|
+
|
82
|
+
- script:
|
83
|
+
name: "View environment variables"
|
84
|
+
code: |
|
85
|
+
env
|
86
|
+
|
87
|
+
- script:
|
88
|
+
name: rspec
|
89
|
+
code: bundle exec rspec
|
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.4
|
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-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -125,6 +125,7 @@ files:
|
|
125
125
|
- lib/crowi/client/model/crowi_page_revision.rb
|
126
126
|
- lib/crowi/client/model/crowi_user.rb
|
127
127
|
- lib/crowi/client/version.rb
|
128
|
+
- wercker.yml
|
128
129
|
homepage: https://github.com/ryu-sato/crowi-client
|
129
130
|
licenses:
|
130
131
|
- MIT
|