outliner 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a6b3e32c28045daaedc8385bafa2363feda000954ebd9cd056438aefe7ea868d
4
+ data.tar.gz: ce770363063c8a15c697c0dee6c09594465c07f262becc4f4a422945f1e7dab6
5
+ SHA512:
6
+ metadata.gz: 9c0ced89c0f1365fe33acda03a54cbf04660d2d17721fb84665508b65f5124d4d893e28985fafa8aad9692ba3553c4fcfc86e3a1b7098572807653d732d90998
7
+ data.tar.gz: 9949c41e764a318a99f62ca53ef1152a80215a955246eb0dc9762a1764e533e6e14d1ddce55f35103359378566fed38616838818986e927530bafb1d0a470e6d
data/.editorconfig ADDED
@@ -0,0 +1,12 @@
1
+ ; This file is for unifying the coding style for different editors and IDEs.
2
+ ; More information at http://EditorConfig.org
3
+
4
+ root = true
5
+ ; Use 2 spaces for indentation in all files
6
+ [*]
7
+ end_of_line = lf
8
+ charset = utf-8
9
+ trim_trailing_whitespace = true
10
+ indent_style = space
11
+ indent_size = 2
12
+ insert_final_newline = true
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /vendor/
10
+ Gemfile.lock
data/CHANGELOG.md ADDED
@@ -0,0 +1,18 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ - Dockerfile
11
+
12
+ ## 0.1.0 - 2019-07-24
13
+
14
+ ### Added
15
+
16
+ - Initial release
17
+
18
+ [unreleased]: https://github.com/olivierlacan/keep-a-changelog/compare/v0.1.0...HEAD
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at me@captnemo.in. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in outliner.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2019 Abhay Rana
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # Outliner [![Gem Version](https://badge.fury.io/rb/outliner.svg)](https://badge.fury.io/rb/outliner)
2
+
3
+ A simple HTTParty based wrapper for the [Outline API](https://www.getoutline.com/developers). It also offers a one-line import option to let you migrate an existing set of Markdown files to Outline.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'outliner'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install outliner
20
+
21
+ ## Usage
22
+
23
+ The API Client automatically picks up the Token from the `OUTLINE_TOKEN` environment variable. All the API calls are available with the `.` replaced with a `_` in the method name. So if you need to call the `collections.remove_user` API, use the `collections_remove_user` method.
24
+
25
+ ```ruby
26
+ require 'outliner'
27
+
28
+ client = Outliner.new('https://knowledge.example.com')
29
+ pp client.auth_info
30
+ pp client.collections_list(offset: 0, limit: 10)
31
+ ```
32
+
33
+ ### Import
34
+
35
+ `outliner` can be used to import an existing collection of documents into Outline. To do this run:
36
+
37
+ ```bash
38
+ export OUTLINE_BASE_URI="https://kb.example.com"
39
+ export OUTLINE_TOKEN="PUT YOUR TOKEN HERE"
40
+ export SOURCE_DIRECTORY="/home/user/wiki"
41
+ export DESTINATION_COLLECTION_NAME="Archive"
42
+ bundle install outliner
43
+ bundle exec bin/import "$SOURCE_DIRECTORY" "$DESTINATION_COLLECTION_NAME"
44
+ ```
45
+
46
+ #### Limitations
47
+
48
+ - Images are currently not imported
49
+ - Only `.md` files are currently supported
50
+
51
+ ## Development
52
+
53
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
54
+
55
+ 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).
56
+
57
+ ## Contributing
58
+
59
+ Bug reports and pull requests are welcome on GitHub at https://github.com/captn3m0/outliner. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
60
+
61
+ ## Code of Conduct
62
+
63
+ Everyone interacting in the Outliner project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/captn3m0/outliner/blob/master/CODE_OF_CONDUCT.md).
64
+
65
+ ## License
66
+
67
+ Licensed under the [MIT License](https://nemo.mit-license.org/). See LICENSE file for details.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "rake/testtask"
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.test_files = FileList['test/**/test_*.rb']
5
+ end
6
+
7
+ desc "Run tests"
8
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "outliner"
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(__FILE__)
data/bin/import ADDED
@@ -0,0 +1,78 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "outliner"
5
+
6
+ def validate
7
+ unless (ARGV.size == 2) and Dir.exists?(ARGV[0]) and ARGV[1].match(/\w+/) and ENV.key?('OUTLINE_BASE_URI')
8
+ puts "[E] Please call as import local_directory remote_collection_name"
9
+ puts "[E] Please export OUTLINE_BASE_URI and OUTLINE_TOKEN environment variables"
10
+ puts "[E] OUTLINE_BASE_URI should not include /api"
11
+ end
12
+ end
13
+
14
+ def find_or_create_collection(name)
15
+ collections = CLIENT.collections_list(limit: 100)['data']
16
+ collections.filter!{|c|c['name'] == name}
17
+ if collections.size >= 1
18
+ collections[0]['id']
19
+ else
20
+ CLIENT.collections_create(name: name, description: 'Imported Collection')['data']['id']
21
+ end
22
+ end
23
+
24
+ def create_documents_recursively(directory, collection_id, parent_document_id=nil)
25
+ cwd = Dir.pwd
26
+ Dir.chdir directory
27
+ # Create all documents for this directory
28
+ Dir["*.md"].each do |file|
29
+ params = {
30
+ title: file[0...-3],
31
+ text: file[0...-3] + "\n" + File.read(file) + "\n\n---\nImported at #{Time.now}",
32
+ collectionId: collection_id,
33
+ publish: true
34
+ }
35
+
36
+ params[:parentDocumentId] = parent_document_id if parent_document_id
37
+ CLIENT.documents_create(params)
38
+ puts "[-] #{file}"
39
+ end
40
+
41
+ # Create child documents for each sub-directory
42
+ Dir.glob('*').select {|f| File.directory? f}.each do |dir|
43
+ puts "[-] #{dir}"
44
+ params = {
45
+ title: dir,
46
+ text: dir +"\nImported at #{Time.now}",
47
+ collectionId: collection_id,
48
+ publish: true,
49
+ parentDocumentId: parent_document_id
50
+ }
51
+ response = CLIENT.documents_create(params)
52
+ create_documents_recursively(dir, collection_id, response['data']['id'])
53
+ end
54
+ Dir.chdir cwd
55
+ end
56
+
57
+ # Run validations
58
+ validate
59
+
60
+ # Setup variables
61
+ local_directory = ARGV[0]
62
+ remote_collection_name = ARGV[1]
63
+
64
+ # Create a root collection
65
+ CLIENT = Outliner::Client.new ENV['OUTLINE_BASE_URI']
66
+ root_collection_id = find_or_create_collection(remote_collection_name)
67
+
68
+ begin
69
+ create_documents_recursively(local_directory, root_collection_id)
70
+ puts "[S] Import successful"
71
+ rescue Exception => e
72
+ # If we fail, print an error, and delete the collection
73
+ puts "[E] Import failed with error: #{e.message}"
74
+ CLIENT.collections_delete(id: root_collection_id)
75
+ puts "[E] Deleted collection, please report the issue or retry"
76
+ exit 1
77
+ end
78
+
data/bin/setup ADDED
@@ -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,29 @@
1
+ require 'httparty'
2
+ require 'json'
3
+
4
+ module Outliner
5
+ class Client
6
+ include HTTParty
7
+
8
+ def initialize(base_uri)
9
+ self.class.base_uri (base_uri + "/api")
10
+ @token = ENV['OUTLINE_TOKEN']
11
+ end
12
+
13
+ def method_missing(method_name, params = {})
14
+ method_name = '/' + method_name.to_s.sub('_', '.')
15
+ body = {token: @token}.merge(params).to_json
16
+ options = {
17
+ body: body,
18
+ headers: {
19
+ 'Accept'=>'application/json',
20
+ 'Content-Type': 'application/json',
21
+ 'User-Agent': "Outliner/#{Outliner::VERSION}"
22
+ },
23
+ format: :json
24
+ }
25
+
26
+ self.class.post(method_name, options)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ module Outliner
2
+ VERSION = "0.1.0"
3
+ end
data/lib/outliner.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "outliner/version"
2
+
3
+ module Outliner
4
+ class Error < StandardError; end
5
+ end
data/outliner.gemspec ADDED
@@ -0,0 +1,35 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ require "outliner/version"
5
+ require "outliner/client"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "outliner"
9
+ spec.version = Outliner::VERSION
10
+ spec.authors = ["Nemo"]
11
+ spec.email = ["rubygem.outliner@captnemo.in"]
12
+
13
+ spec.summary = "A simple HTTParty based client for outline knowledge base."
14
+ spec.homepage = "https://github.com/captn3m0/outliner"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/captn3m0/outliner"
18
+ spec.metadata["changelog_uri"] = "https://github.com/captn3m0/outliner/blob/master/CHANGELOG.md"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ # spec.add_dependency "httparty", "~> 0.17"
30
+
31
+ spec.add_development_dependency "bundler", "~> 2.0"
32
+ spec.add_development_dependency "rake", "~> 10.0"
33
+ spec.add_development_dependency "webmock", "~> 3.6.0"
34
+ spec.add_development_dependency "minitest", "~> 5.8.4"
35
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: outliner
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nemo
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-07-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: webmock
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.6.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.6.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 5.8.4
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 5.8.4
69
+ description:
70
+ email:
71
+ - rubygem.outliner@captnemo.in
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".editorconfig"
77
+ - ".gitignore"
78
+ - CHANGELOG.md
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - LICENSE
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/import
86
+ - bin/setup
87
+ - lib/outliner.rb
88
+ - lib/outliner/client.rb
89
+ - lib/outliner/version.rb
90
+ - outliner.gemspec
91
+ homepage: https://github.com/captn3m0/outliner
92
+ licenses: []
93
+ metadata:
94
+ homepage_uri: https://github.com/captn3m0/outliner
95
+ source_code_uri: https://github.com/captn3m0/outliner
96
+ changelog_uri: https://github.com/captn3m0/outliner/blob/master/CHANGELOG.md
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubygems_version: 3.0.4
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: A simple HTTParty based client for outline knowledge base.
116
+ test_files: []