crowi 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 14e413c7b6aa907b809be9b937745095e0c8800e
4
+ data.tar.gz: 6870d99a37c309fee81df97be25932db0a1f084c
5
+ SHA512:
6
+ metadata.gz: 35b28fb2b0eaaab3b9a7478f6c56bd44de01f11286eb99edb7ead5a52230213f5acafc1f39af60efc2fba9532ee09365b766cff49ecfe6936d947b88feaaddab
7
+ data.tar.gz: 43fd831015ff777d6e1cdf95c5ddf0671215a6d8664fc72ecf6e39cff6596964bd6a9bbab5f984a7cc076eca69377b973c9b8e3f6bc9278ab1b3bb39293c48db
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.13.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in crowi.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Hiromichi Kishi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,59 @@
1
+ # ruby-crowi
2
+
3
+ A ruby client for [Crowi](http://site.crowi.wiki/) API.
4
+
5
+ ruby-crowi supports up to [v1.6.2](https://github.com/crowi/crowi/releases/tag/v1.6.2).
6
+
7
+ **Crowi API is experimental.**
8
+
9
+ ## Installation
10
+
11
+ ```ruby
12
+ gem 'crowi'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install crowi
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ require "crowi"
27
+
28
+ client = Crowi::Client.new(base_url: "<your_crowi_url>", access_token: "<access_token>")
29
+
30
+ # Pages API
31
+ client.page(page_id)
32
+ client.pages(path, user, offset)
33
+ client.create_page(path, body)
34
+ client.update_page(page_id, body)
35
+
36
+ # Comments API
37
+ client.comments(page_id)
38
+ client.add_comment(page_id, comment, revision_id)
39
+
40
+ # Attachments API
41
+ client.attachments(page_id)
42
+ client.add_attachment(page_id, filepath, content_type)
43
+ ```
44
+
45
+ ## Development
46
+
47
+ 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.
48
+
49
+ 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](https://rubygems.org).
50
+
51
+ ## Contributing
52
+
53
+ Bug reports and pull requests are welcome on GitHub at https://github.com/h-kishi/ruby-crowi.
54
+
55
+
56
+ ## License
57
+
58
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
59
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "crowi"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'crowi/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "crowi"
8
+ spec.version = Crowi::VERSION
9
+ spec.authors = ["Hiromichi Kishi"]
10
+ spec.email = ["h.kishi47@gmail.com"]
11
+
12
+ spec.summary = %q{A ruby client for Crowi API}
13
+ spec.description = %q{A ruby client for Crowi API}
14
+ spec.homepage = "https://github.com/h-kishi/ruby-crowi"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_runtime_dependency "faraday", "~> 0.9"
25
+ spec.add_runtime_dependency "faraday_middleware"
26
+ spec.add_development_dependency "bundler", "~> 1.13"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.0"
29
+ spec.add_development_dependency "pry"
30
+ spec.add_development_dependency "webmock"
31
+ end
@@ -0,0 +1,31 @@
1
+ require 'crowi'
2
+
3
+ crowi = Crowi::Client.new(base_url: "<your crowi url>", access_token: "<your access token>")
4
+
5
+ # Create page
6
+ page = crowi.create_page('/sandbox/test', 'new page').body['page']
7
+ puts page
8
+
9
+ page_id = page['_id']
10
+ revision_id = page['revision']['_id']
11
+
12
+ # Get page
13
+ puts crowi.page('/sandbox/test').body['page']
14
+
15
+ # Get pages
16
+ puts crowi.pages('/sandbox/').body['pages']
17
+
18
+ # Update page
19
+ crowi.update_page(page_id, 'updated page')
20
+
21
+ # Add comment
22
+ crowi.add_comment(page_id, 'new comment', revision_id)
23
+
24
+ # Get comments
25
+ puts crowi.comments(page_id).body['comments']
26
+
27
+ # Add attachment
28
+ crowi.add_attachment(page_id, '/Users/kishi/Downloads/unity.png', 'image/png')
29
+
30
+ # Get attachments
31
+ puts crowi.attachments(page_id).body['attachments']
@@ -0,0 +1,7 @@
1
+ require 'faraday'
2
+ require 'faraday_middleware'
3
+
4
+ require 'crowi/version'
5
+ require 'crowi/client'
6
+ require 'crowi/response'
7
+ require 'crowi/api_methods'
@@ -0,0 +1,44 @@
1
+ module Crowi
2
+ module ApiMethods
3
+ def page(path)
4
+ get('/_api/pages.get', { path: path })
5
+ end
6
+
7
+ def pages(path = nil, user = nil, offset = 0)
8
+ raise 'path or user is required' unless path || user
9
+ get('/_api/pages.list', { path: path, user: user, offset: offset })
10
+ end
11
+
12
+ def create_page(path, body)
13
+ post('/_api/pages.create', { path: path, body: body })
14
+ end
15
+
16
+ def update_page(page_id, body)
17
+ post('/_api/pages.update', { page_id: page_id, body: body })
18
+ end
19
+
20
+ def comments(page_id)
21
+ get('/_api/comments.get', { page_id: page_id })
22
+ end
23
+
24
+ def add_comment(page_id, comment, revision_id)
25
+ post('/_api/comments.add', { commentForm: { page_id: page_id, comment: comment, revision_id: revision_id } })
26
+ end
27
+
28
+ def attachments(page_id)
29
+ get('/_api/attachments.list', { page_id: page_id })
30
+ end
31
+
32
+ def add_attachment(page_id, filename, content_type)
33
+ # To use multipart/form-data use faraday directly
34
+ connection = Faraday.new(faraday_options) do |connection|
35
+ connection.request :multipart
36
+ connection.request :url_encoded
37
+ connection.adapter :net_http
38
+ end
39
+
40
+ params = { page_id: page_id, file: Faraday::UploadIO.new(filename, content_type), access_token: @access_token }
41
+ Crowi::Response.new(connection.send(:post, '/_api/attachments.add', params))
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,62 @@
1
+ require 'crowi/api_methods'
2
+ require 'crowi/version'
3
+
4
+ module Crowi
5
+ class Client
6
+ include Crowi::ApiMethods
7
+
8
+ def initialize(base_url: nil, access_token: nil)
9
+ @base_url = base_url
10
+ @access_token = access_token
11
+ end
12
+
13
+ def get(path, params = nil, headers = nil)
14
+ send_request(:get, path, params, headers)
15
+ end
16
+
17
+ def post(path, params = nil, headers = nil)
18
+ send_request(:post, path, params, headers)
19
+ end
20
+
21
+ def put(path, params = nil, headers = nil)
22
+ send_request(:put, path, params, headers)
23
+ end
24
+
25
+ def patch(path, params = nil, headers = nil)
26
+ send_request(:patch, path, params, headers)
27
+ end
28
+
29
+ def delete(path, params = nil, headers = nil)
30
+ send_request(:delete, path, params, headers)
31
+ end
32
+
33
+ def send_request(method, path, params = {}, headers = nil)
34
+ # TODO Crowi does not support Authorization: Bearer
35
+ params[:access_token] = @access_token
36
+ Crowi::Response.new(connection.send(method, path, params, headers))
37
+ end
38
+
39
+ private
40
+ def connection
41
+ @connection ||= Faraday.new(faraday_options) do |connection|
42
+ connection.request :json
43
+ connection.response :json
44
+ connection.adapter Faraday.default_adapter
45
+ end
46
+ end
47
+
48
+ def faraday_options
49
+ {
50
+ url: @base_url,
51
+ headers: headers
52
+ }
53
+ end
54
+
55
+ def headers
56
+ {
57
+ 'Accept' => 'application/json',
58
+ 'User-Agent' => "Crowi Ruby Gem #{Crowi::VERSION}"
59
+ }
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,23 @@
1
+ module Crowi
2
+ class Response
3
+ def initialize(faraday_response)
4
+ @raw_body = faraday_response.body
5
+ @raw_headers = faraday_response.headers
6
+ @raw_status = faraday_response.status
7
+ end
8
+
9
+ def body
10
+ @raw_body
11
+ end
12
+
13
+ def headers
14
+ @headers ||= @raw_headers.inject({}) do |result, (key, value)|
15
+ result.merge(key.split("-").map(&:capitalize).join("-") => value)
16
+ end
17
+ end
18
+
19
+ def status
20
+ @raw_status
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module Crowi
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: crowi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Hiromichi Kishi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-06-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.9'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.13'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.13'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: A ruby client for Crowi API
112
+ email:
113
+ - h.kishi47@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".travis.yml"
121
+ - Gemfile
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - bin/console
126
+ - bin/setup
127
+ - crowi.gemspec
128
+ - examples/crowi_example.rb
129
+ - lib/crowi.rb
130
+ - lib/crowi/api_methods.rb
131
+ - lib/crowi/client.rb
132
+ - lib/crowi/response.rb
133
+ - lib/crowi/version.rb
134
+ homepage: https://github.com/h-kishi/ruby-crowi
135
+ licenses:
136
+ - MIT
137
+ metadata: {}
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubyforge_project:
154
+ rubygems_version: 2.5.1
155
+ signing_key:
156
+ specification_version: 4
157
+ summary: A ruby client for Crowi API
158
+ test_files: []