├── .gitignore ├── .rspec ├── .travis.yml ├── CODE_OF_CONDUCT.md ├── Gemfile ├── LICENSE.txt ├── README.md ├── Rakefile ├── bin ├── console └── setup ├── confluence-api-client.gemspec ├── lib └── confluence │ └── api │ ├── client.rb │ └── client │ └── version.rb └── spec ├── confluence └── api │ └── client_spec.rb └── spec_helper.rb /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /.yardoc 3 | /Gemfile.lock 4 | /_yardoc/ 5 | /coverage/ 6 | /doc/ 7 | /pkg/ 8 | /spec/reports/ 9 | /tmp/ 10 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --format documentation 2 | --color 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | rvm: 3 | - 2.0.0 4 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities. 4 | 5 | We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion. 6 | 7 | Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct. 8 | 9 | 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. Project maintainers who do not follow the Code of Conduct may be removed from the project team. 10 | 11 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers. 12 | 13 | This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/) 14 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in confluence-api-client.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Alex Mishyn 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. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Confluence::Api::Client 2 | 3 | Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/confluence/api/client`. To experiment with that code, run `bin/console` for an interactive prompt. 4 | 5 | TODO: Delete this and the text above, and describe your gem 6 | 7 | ## Installation 8 | 9 | Add this line to your application's Gemfile: 10 | 11 | ```ruby 12 | gem 'confluence-api-client' 13 | ``` 14 | 15 | And then execute: 16 | 17 | $ bundle 18 | 19 | Or install it yourself as: 20 | 21 | $ gem install confluence-api-client 22 | 23 | ## Usage 24 | 25 | require 'rubygems' 26 | require 'confluence/api/client' 27 | 28 | username = 'username' 29 | password = 'password' 30 | space = 'Home' 31 | url = 'https://company.atlassian.net/wiki' 32 | 33 | # Note: url is automatically appended with /rest/api/content so if your 34 | # Confluence base URL is different from "/wiki" specify it above 35 | 36 | client = Confluence::Api::Client.new(username, password, url) 37 | page = client.get({spaceKey: space, title: 'September'})[0] 38 | client.create({type:"page",title: "title", space: {key: space}, ancestors:[{type:"page",id: page['id']}]}) 39 | 40 | ## API Links 41 | 42 | https://developer.atlassian.com/confdev/confluence-rest-api 43 | https://developer.atlassian.com/confdev/confluence-rest-api/confluence-rest-api-examples 44 | 45 | 46 | ## Development 47 | 48 | After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment. 49 | 50 | 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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). 51 | 52 | ## Contributing 53 | 54 | 1. Fork it ( https://github.com/[my-github-username]/confluence-api-client/fork ) 55 | 2. Create your feature branch (`git checkout -b my-new-feature`) 56 | 3. Commit your changes (`git commit -am 'Add some feature'`) 57 | 4. Push to the branch (`git push origin my-new-feature`) 58 | 5. Create a new Pull Request 59 | 60 | 61 | ## TODO 62 | 63 | 1. Cover with tests 64 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | 3 | -------------------------------------------------------------------------------- /bin/console: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require "bundler/setup" 4 | require "confluence/api/client" 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 15 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -euo pipefail 3 | IFS=$'\n\t' 4 | 5 | bundle install 6 | 7 | # Do any other automated setup that you need to do here 8 | -------------------------------------------------------------------------------- /confluence-api-client.gemspec: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | require 'confluence/api/client/version' 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = "confluence-api-client" 8 | spec.version = Confluence::Api::Client::VERSION 9 | spec.authors = ["Alex Mishyn"] 10 | spec.email = ["mishyn@gmail.com"] 11 | 12 | if spec.respond_to?(:metadata) 13 | spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com' to prevent pushes to rubygems.org, or delete to allow pushes to any server." 14 | end 15 | 16 | spec.summary = %q{GET/POST rest client to confluence api} 17 | spec.description = %q{GET/POST rest client to confluence api} 18 | spec.homepage = "" 19 | spec.license = "MIT" 20 | 21 | spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } 22 | spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } 23 | spec.require_paths = ["lib"] 24 | 25 | spec.add_development_dependency "bundler", "~> 1.8" 26 | spec.add_development_dependency "rake", "~> 10.0" 27 | 28 | spec.add_runtime_dependency "json" 29 | spec.add_runtime_dependency "faraday" 30 | end 31 | -------------------------------------------------------------------------------- /lib/confluence/api/client.rb: -------------------------------------------------------------------------------- 1 | require "confluence/api/client/version" 2 | require 'json' 3 | require 'faraday' 4 | 5 | module Confluence 6 | module Api 7 | class Client 8 | attr_accessor :user, :pass, :url, :conn 9 | 10 | def initialize(user, pass, url) 11 | self.user = user 12 | self.pass = pass 13 | self.url = url 14 | self.conn = Faraday.new(url: url) do |faraday| 15 | faraday.request :url_encoded # form-encode POST params 16 | # faraday.response :logger # log requests to STDOUT 17 | faraday.adapter Faraday.default_adapter # make requests with Net::HTTP 18 | faraday.basic_auth(self.user, self.pass) 19 | end 20 | end 21 | 22 | def get(params) 23 | response = conn.get('rest/api/content', params) 24 | JSON.parse(response.body)['results'] 25 | end 26 | 27 | def get_by_id(id) 28 | response = conn.get('/rest/api/content/' + id) 29 | JSON.parse(response.body) 30 | end 31 | 32 | def create(params) 33 | response = conn.post do |req| 34 | req.url 'rest/api/content' 35 | req.headers['Content-Type'] = 'application/json' 36 | req.body = params.to_json 37 | end 38 | JSON.parse(response.body) 39 | end 40 | 41 | def update(id, params) 42 | response = conn.put do |req| 43 | req.url "rest/api/content/#{id}" 44 | req.headers['Content-Type'] = 'application/json' 45 | req.body = params.to_json 46 | end 47 | JSON.parse(response.body) 48 | end 49 | 50 | end 51 | end 52 | end 53 | -------------------------------------------------------------------------------- /lib/confluence/api/client/version.rb: -------------------------------------------------------------------------------- 1 | module Confluence 2 | module Api 3 | class Client 4 | VERSION = "0.1.0" 5 | end 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /spec/confluence/api/client_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe Confluence::Api::Client do 4 | it 'has a version number' do 5 | expect(Confluence::Api::Client::VERSION).not_to be nil 6 | end 7 | 8 | it 'does something useful' do 9 | expect(false).to eq(true) 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) 2 | require 'confluence/api/client' 3 | --------------------------------------------------------------------------------