crowi-client -- client of crowi with use API

A client of crowi with use API.

Installation

Add this line to your application's Gemfile:

gem 'crowi-client'

And then execute:

$ bundle

Or install it yourself as:

$ gem install crowi-client

Usage

Export these environments.

export CROWI_ACCESS_TOKEN=0123456789abcdef0123456789abcdef0123456789ab
export CROWI_URL=http://localhost:3000/
require 'crowi-client'

crowi_client = CrowiClient.new(crowi_url: ENV['CROWI_URL'], access_token: ENV['CROWI_ACCESS_TOKEN'])

puts crowi_client.page_exist?( path_exp: '/' )
puts crowi_client.attachment_exist?( path_exp: '/', attachment_name: 'LICENSE.txt' )

Examples

# get page's ID
puts crowi_client.page_id( path_exp: '/' )
# Check existence of page by page path (you can use regular expression)
crowi_client.page_exist?( path_exp: '/' )
# Check existence of attachment by file name of attachment
crowi_client.attachment_exist?( path_exp: '/', attachment_name: 'LICENSE.txt' )
# get attachment's ID
puts crowi_client.attachment_id( path_exp: '/', attachment_name: 'LICENSE.txt' )
# get attachment (return data is object of CrowiAttachment)
puts crowi_client.attachment( path_exp: '/', attachment_name: 'LICENSE.txt' )
# pages list
req = CPApiRequestPagesList.new path_exp: '/'
puts crowi_client.request(req)
# pages get - path_exp
req = CPApiRequestPagesList.new path_exp: '/'
puts crowi_client.request(req)
# pages get - page_id
req = CPApiRequestPagesGet.new page_id: crowi_client.page_id(path_exp: '/')
puts crowi_client.request(req)
# pages get - revision_id
reqtmp = CPApiRequestPagesList.new path_exp: '/'
ret = crowi_client.request(reqtmp)
path = ret.data[0].path
revision_id = ret.data[0].revision._id
req = CPApiRequestPagesGet.new path: path, revision_id: revision_id
puts crowi_client.request(req)
# pages create
test_page_path = '/tmp/crowi-client test page'
body = "# crowi-client\n"
req = CPApiRequestPagesCreate.new path: test_page_path,
        body: body
puts crowi_client.request(req)
# pages update
test_page_path = '/tmp/crowi-client test page'
test_cases = [nil, CrowiPage::GRANT_PUBLIC, CrowiPage::GRANT_RESTRICTED,
              CrowiPage::GRANT_SPECIFIED, CrowiPage::GRANT_OWNER]
page_id = crowi_client.page_id(path_exp: test_page_path)

body = "# crowi-client\n"
test_cases.each do |grant|
  body = body + grant.to_s
  req = CPApiRequestPagesUpdate.new page_id: page_id,
          body: body, grant: grant
  puts crowi_client.request(req)
end
# pages seen
page_id = crowi_client.page_id(path_exp: '/')
req = CPApiRequestPagesSeen.new page_id: page_id
puts crowi_client.request(req)
# likes add
test_page_path = '/tmp/crowi-client test page'
page_id = crowi_client.page_id(path_exp: test_page_path)
req = CPApiRequestLikesAdd.new page_id: page_id
puts crowi_client.request(req)
# likes remove
test_page_path = '/tmp/crowi-client test page'
page_id = crowi_client.page_id(path_exp: test_page_path)
req = CPApiRequestLikesRemove.new page_id: page_id
puts crowi_client.request(req)
# update post
test_page_path = '/tmp/crowi-client test page'
req = CPApiRequestPagesUpdatePost.new path: test_page_path
puts crowi_client.request(req)
# attachments list
test_page_path = '/tmp/crowi-client test page'
page_id = crowi_client.page_id(path_exp: test_page_path)
req = CPApiRequestAttachmentsList.new page_id: page_id
puts crowi_client.request(req)
# attachments add
test_page_path = '/tmp/crowi-client test page'
page_id = crowi_client.page_id(path_exp: test_page_path)
req = CPApiRequestAttachmentsAdd.new page_id: page_id,
                                     file: File.new('LICENSE.txt')
puts crowi_client.request(req)
# attachments remove
test_page_path = '/tmp/crowi-client test page'
page_id = crowi_client.page_id(path_exp: test_page_path)
reqtmp = CPApiRequestAttachmentsList.new page_id: page_id
ret = crowi_client.request(reqtmp)
attachment_id = ret.data[0]._id
req = CPApiRequestAttachmentsRemove.new attachment_id: attachment_id
puts crowi_client.request(req)

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/ryu-sato/crowi-client. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Crowi::Client project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

ToDo

  • [ ] Support crowi with basic Authentication