commit d12681e05c61a9bbe1ab6592699170293917415e Author: Nemo Date: Wed Jul 24 19:36:18 2019 +0530 Initial Commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..35a0568 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +/.bundle/ +/.yardoc +/_yardoc/ +/coverage/ +/doc/ +/pkg/ +/spec/reports/ +/tmp/ +/vendor/ \ No newline at end of file diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..a8c1274 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,74 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, gender identity and expression, level of experience, +nationality, personal appearance, race, religion, or sexual identity and +orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or +advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at me@captnemo.in. All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at [http://contributor-covenant.org/version/1/4][version] + +[homepage]: http://contributor-covenant.org +[version]: http://contributor-covenant.org/version/1/4/ diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..8e55790 --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source "https://rubygems.org" + +# Specify your gem's dependencies in outliner.gemspec +gemspec diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..b57a22a --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,42 @@ +PATH + remote: . + specs: + outliner (0.1.0) + httparty (~> 0.17) + +GEM + remote: https://rubygems.org/ + specs: + addressable (2.6.0) + public_suffix (>= 2.0.2, < 4.0) + crack (0.4.3) + safe_yaml (~> 1.0.0) + hashdiff (1.0.0) + httparty (0.17.0) + mime-types (~> 3.0) + multi_xml (>= 0.5.2) + mime-types (3.2.2) + mime-types-data (~> 3.2015) + mime-types-data (3.2019.0331) + minitest (5.8.5) + multi_xml (0.6.0) + public_suffix (3.1.1) + rake (10.5.0) + safe_yaml (1.0.5) + webmock (3.6.0) + addressable (>= 2.3.6) + crack (>= 0.3.2) + hashdiff (>= 0.4.0, < 2.0.0) + +PLATFORMS + ruby + +DEPENDENCIES + bundler (~> 2.0) + minitest (~> 5.8.4) + outliner! + rake (~> 10.0) + webmock (~> 3.6.0) + +BUNDLED WITH + 2.0.2 diff --git a/README.md b/README.md new file mode 100644 index 0000000..19312fd --- /dev/null +++ b/README.md @@ -0,0 +1,49 @@ +# Outliner + +A simple HTTParty based wrapper for the [Outline API](https://www.getoutline.com/developers). + +## Installation + +Add this line to your application's Gemfile: + +```ruby +gem 'outliner' +``` + +And then execute: + + $ bundle + +Or install it yourself as: + + $ gem install outliner + +## Usage + +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. + +```ruby +require 'outliner' + +client = Outliner.new('https://knowledge.example.com') +pp client.auth_info +pp client.collections_list(offset: 0, limit: 10) +``` + +## Development + +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. + +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). + +## Contributing + +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. + +## Code of Conduct + +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). + +## License + +Licensed under the [MIT License](https://nemo.mit-license.org/). See LICENSE file for details. diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..43022f7 --- /dev/null +++ b/Rakefile @@ -0,0 +1,2 @@ +require "bundler/gem_tasks" +task :default => :spec diff --git a/bin/console b/bin/console new file mode 100755 index 0000000..3f07c11 --- /dev/null +++ b/bin/console @@ -0,0 +1,14 @@ +#!/usr/bin/env ruby + +require "bundler/setup" +require "outliner" + +# You can add fixtures and/or initialization code here to make experimenting +# with your gem easier. You can also use a different console, if you like. + +# (If you use this, don't forget to add pry to your Gemfile!) +# require "pry" +# Pry.start + +require "irb" +IRB.start(__FILE__) diff --git a/bin/setup b/bin/setup new file mode 100755 index 0000000..dce67d8 --- /dev/null +++ b/bin/setup @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -euo pipefail +IFS=$'\n\t' +set -vx + +bundle install + +# Do any other automated setup that you need to do here diff --git a/lib/outliner.rb b/lib/outliner.rb new file mode 100644 index 0000000..12ba229 --- /dev/null +++ b/lib/outliner.rb @@ -0,0 +1,5 @@ +require "outliner/version" + +module Outliner + class Error < StandardError; end +end diff --git a/lib/outliner/client.rb b/lib/outliner/client.rb new file mode 100644 index 0000000..b6c2d2a --- /dev/null +++ b/lib/outliner/client.rb @@ -0,0 +1,29 @@ +require 'httparty' +require 'json' + +module Outliner + class Client + include HTTParty + + def initialize(base_uri) + self.class.base_uri (base_uri + "/api") + @token = ENV['OUTLINE_TOKEN'] + end + + def method_missing(method_name, params = {}) + method_name = '/' + method_name.to_s.sub('_', '.') + body = {token: @token}.merge(params).to_json + options = { + body: body, + headers: { + 'Accept'=>'application/json', + 'Content-Type': 'application/json', + 'User-Agent': "Outliner/#{Outliner::VERSION}" + }, + format: :json + } + + self.class.post(method_name, options) + end + end +end diff --git a/lib/outliner/version.rb b/lib/outliner/version.rb new file mode 100644 index 0000000..1326879 --- /dev/null +++ b/lib/outliner/version.rb @@ -0,0 +1,3 @@ +module Outliner + VERSION = "0.1.0" +end diff --git a/outliner.gemspec b/outliner.gemspec new file mode 100644 index 0000000..787fbc7 --- /dev/null +++ b/outliner.gemspec @@ -0,0 +1,34 @@ +lib = File.expand_path("lib", __dir__) +$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) +require "outliner/version" +require "outliner/client" + +Gem::Specification.new do |spec| + spec.name = "outliner" + spec.version = Outliner::VERSION + spec.authors = ["Nemo"] + spec.email = ["rubygem.outliner@captnemo.in"] + + spec.summary = "A simple HTTParty based client for outline knowledge base." + spec.homepage = "https://github.com/captn3m0/outliner" + + spec.metadata["homepage_uri"] = spec.homepage + spec.metadata["source_code_uri"] = "https://github.com/captn3m0/outliner" + spec.metadata["changelog_uri"] = "https://github.com/captn3m0/outliner/blob/master/CHANGELOG.md" + + # Specify which files should be added to the gem when it is released. + # The `git ls-files -z` loads the files in the RubyGem that have been added into git. + spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do + `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } + end + spec.bindir = "exe" + spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } + spec.require_paths = ["lib"] + + spec.add_dependency "httparty", "~> 0.17" + + spec.add_development_dependency "bundler", "~> 2.0" + spec.add_development_dependency "rake", "~> 10.0" + spec.add_development_dependency "webmock", "~> 3.6.0" + spec.add_development_dependency "minitest", "~> 5.8.4" +end diff --git a/test/fixtures/auth.info.200.json b/test/fixtures/auth.info.200.json new file mode 100644 index 0000000..83f9cea --- /dev/null +++ b/test/fixtures/auth.info.200.json @@ -0,0 +1,26 @@ +{ + "data": { + "user": { + "id": "d7a6a7c0-9dda-4e01-8dc2-9b1905c08c40", + "createdAt": "2014-01-01T12:37:07.826Z", + "name": "Test User", + "isAdmin": true, + "isSuspended": false, + "avatarUrl": "https://example.com/avatar-url.jpg", + "email": "testuser@example.com" + }, + "team": { + "id": "e0809f93-c199-4472-8a70-77eee3d67986", + "name": "Test Team", + "avatarUrl": "https://example.com/favicon-url.jpg", + "slackConnected": false, + "googleConnected": true, + "sharing": false, + "documentEmbeds": true, + "subdomain": "kb", + "url": "https://kb.example.com" + } + }, + "status": 200, + "ok": true +} diff --git a/test/test_client.rb b/test/test_client.rb new file mode 100644 index 0000000..f266dfb --- /dev/null +++ b/test/test_client.rb @@ -0,0 +1,41 @@ +require 'outliner' +require 'minitest/autorun' +require 'webmock/minitest' +require 'json' + +class ClientTest < Minitest::Test + TOKEN = "c4302eFAKE_TOKEN9b6e27bccb7" + BASE_URI='https://kb.example.com' + def setup + ENV['OUTLINE_TOKEN'] = TOKEN + @client = Outliner::Client.new BASE_URI + end + + def test_client_initialized + assert_kind_of Outliner::Client, @client + end + + def test_auth_info_api + mock('auth.info', 'auth.info.200') + auth_info = @client.auth_info + assert_equal "https://kb.example.com", auth_info['data']['team']['url'] + end + + private + + def read_fixture(file) + File.read "test/fixtures/#{file}.json" + end + + def mock(method_name, fixture_file, params = {}) + stub_request(:post, BASE_URI + "/api/" + method_name) + .with( + body: params.merge({token: TOKEN}).to_json, + headers: { + 'Accept'=>'application/json', + 'User-Agent'=>"Outliner/#{Outliner::VERSION}", + 'Content-Type'=> 'application/json' + } + ).to_return(body: read_fixture(fixture_file)) + end +end \ No newline at end of file