crowi-client 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6388fff5bc284cbf0d49c2f31883309847e8fdf0d40c073fe168bffe52662adb
4
- data.tar.gz: 3e6dd95a3611fc8b5e887f53cb209733806186be5fdebf0be1064f393ddb47b2
3
+ metadata.gz: 310285c37c1db2f5953063e99c161c6a1236f66f1ce2f47c31f317d04c04409d
4
+ data.tar.gz: eee12e023f1311472a314ed17dc6488cb1c41978f8fe0e2a6693a56bdfb79626
5
5
  SHA512:
6
- metadata.gz: 721ed10e71c335768ee331c1c49f1fd8393cbae2028bad25abafee11dacbee20a75c869b5b163de287234bba09d9bb6014b84b288f3b4435b9535b5db09691ab
7
- data.tar.gz: 27e91594ff1e3af6c60991b596465600332a3f29120284f5717f77f32e247225b1c23679f2ea5d4172b7b2122e22983a351653d57ed7c9e1fa4c7f657b9c1dfe
6
+ metadata.gz: b5340275410bd45e55f42bdf61da53d1dc54fa81f2cd807a80b94e7112e5ca3141463967db635894e19745a719008c86cbfdf4b07ebf982feffb440bc14b6fea
7
+ data.tar.gz: e9dd54e46956a2ef52d9887666cf98f5ef37e00965c7259f279e4536aaea50f72e3e9e6164850156f3596ba1be08054b898d5a7156578d151fce92799e92ee72
data/.gitignore CHANGED
File without changes
data/.rspec CHANGED
File without changes
File without changes
File without changes
data/Gemfile CHANGED
File without changes
data/LICENSE CHANGED
File without changes
File without changes
data/README.md CHANGED
@@ -20,76 +20,75 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- At first, you need to create setting file ```config/settings.yml``` in your application directory.
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
- Then, you can use crowi client with ```require 'crowi-client'```.
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
- puts CrowiClient.instance.page_exist?( path_exp: '/' )
37
- puts CrowiClient.instance.attachment_exist?( path_exp: '/', attachment_name: 'LICENSE.txt' )
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 CrowiClient.instance.page_id( path_exp: '/' )
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
- CrowiClient.instance.page_exist?( path_exp: '/' )
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
- CrowiClient.instance.attachment_exist?( path_exp: '/', attachment_name: 'LICENSE.txt' )
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 CrowiClient.instance.attachment_id( path_exp: '/', attachment_name: 'LICENSE.txt' )
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 CrowiClient.instance.attachment( path_exp: '/', attachment_name: 'LICENSE.txt' )
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 CrowiClient.instance.request(req)
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 CrowiClient.instance.request(req)
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: CrowiClient.instance.page_id(path: '/')
82
- puts CrowiClient.instance.request(req)
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 = CrowiClient.instance.request(reqtmp)
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 CrowiClient.instance.request(req)
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 CrowiClient.instance.request(req)
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 = CrowiClient.instance.page_id(path: test_page_path)
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 CrowiClient.instance.request(req)
115
+ puts crowi_client.request(req)
117
116
  end
118
117
  ```
119
118
 
120
119
  ```ruby
121
120
  # pages seen
122
- page_id = CrowiClient.instance.page_id(path: '/')
121
+ page_id = crowi_client.page_id(path_exp: '/')
123
122
  req = CPApiRequestPagesSeen.new page_id: page_id
124
- puts CrowiClient.instance.request(req)
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 = CrowiClient.instance.page_id(path: test_page_path)
129
+ page_id = crowi_client.page_id(path_exp: test_page_path)
131
130
  req = CPApiRequestLikesAdd.new page_id: page_id
132
- puts CrowiClient.instance.request(req)
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 = CrowiClient.instance.page_id(path: test_page_path)
137
+ page_id = crowi_client.page_id(path_exp: test_page_path)
139
138
  req = CPApiRequestLikesRemove.new page_id: page_id
140
- puts CrowiClient.instance.request(req)
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 CrowiClient.instance.request(req)
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 = CrowiClient.instance.page_id(path: test_page_path)
153
+ page_id = crowi_client.page_id(path_exp: test_page_path)
155
154
  req = CPApiRequestAttachmentsList.new page_id: page_id
156
- puts CrowiClient.instance.request(req)
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 = CrowiClient.instance.page_id(path: test_page_path)
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 CrowiClient.instance.request(req)
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 = CrowiClient.instance.page_id(path: test_page_path)
170
+ page_id = crowi_client.page_id(path_exp: test_page_path)
172
171
  reqtmp = CPApiRequestAttachmentsList.new page_id: page_id
173
- ret = CrowiClient.instance.request(reqtmp)
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 CrowiClient.instance.request(req)
175
+ puts crowi_client.request(req)
177
176
  ```
178
177
 
179
178
  ## Development
data/Rakefile CHANGED
File without changes
@@ -37,5 +37,4 @@ Gem::Specification.new do |spec|
37
37
 
38
38
  spec.add_dependency "rest-client", "~> 2.0"
39
39
  spec.add_dependency "json", "~> 2.1"
40
- spec.add_dependency "easy_settings", "~> 0.1"
41
40
  end
File without changes
@@ -1,28 +1,29 @@
1
- require 'singleton'
2
1
  require 'rest-client'
3
2
  require 'json'
4
3
  require 'yaml'
5
- require "easy_settings"
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 url is required.' unless EasySettings['url']
17
- raise ArgumentError, 'Config token is required.' unless EasySettings['token']
18
- @cp_entry_point = URI.join(EasySettings['url'], '/_api/').to_s
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] = EasySettings['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&.data&.find { |p| p.path.match(path_exp) != nil }&.id
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
@@ -1,5 +1,5 @@
1
1
  module Crowi
2
2
  module Client
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
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.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-05-01 00:00:00.000000000 Z
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
@@ -1,2 +0,0 @@
1
- url: http://localhost:3000/
2
- token: 9MFP98pB81xFI/4EuBzoYgIGZvno5QT3kcgSB3oEuHE=