nexboard-api 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3e047c812b6cf48c7a5547a9050bdc065cc6cd24
4
+ data.tar.gz: 6774b3d922aa629043e442a394db4c0f90c316bd
5
+ SHA512:
6
+ metadata.gz: ceb3c2311b48125696bcd32ce2800cfe37ea2d4e423a6c797212bd926c0d8ca1d93e786bf12658e2e7dce3dcad4ebb5df86e962841104084358615e9df8fe81c
7
+ data.tar.gz: da197a3152093c18ebbfddf7a8d8d8dafc29f64c06aa2341346c4291f001222086c9c98101355ee5f852d264682fe9c7a0c4c0c122554e6f7c26356887cfdb15
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # Nexboard API
2
+
3
+ `nexboard-api` is a wrapper for the Nexboard API (see http://nexboard-api.nexenio.com/) packaged as Ruby Gem.
4
+
5
+ The gem uses Restify (https://github.com/jgraichen/restify) for handling HTTP communication.
6
+
7
+ ## Usage
8
+ Initialize the API with `API key` and `user_id` (both provided with your Nexboard API account). You can optionally add a `template_project_id`, which would be a Nexboard `project_id` where you store boards meant as templates for your application. If you run your own Nexboard server, you can add a custom `base_url`.
9
+
10
+ ```ruby
11
+ require 'nexboard_api'
12
+
13
+ params = {
14
+ api_key = 'my_secret_api_key',
15
+ user_id = 1,
16
+ template_project_id = 123,
17
+ base_url = 'https://my-server.example.com/api/public/'
18
+ }
19
+
20
+ nexboard_api = NexboardApi.new **params
21
+
22
+ ```
23
+
24
+ tbc.
25
+
26
+ ## Contributing
27
+
28
+ - Fork it
29
+ - Create your feature branch (git checkout -b my-new-feature)
30
+ - Commit specs for your feature so that I do not break it later
31
+ - Commit your changes (git commit -am 'Add some feature')
32
+ - Push to the branch (git push origin my-new-feature)
33
+ - Create new Pull Request
@@ -0,0 +1,62 @@
1
+ class NexboardApi
2
+ DEFAULT_BASE_URL = 'https://nexboard.nexenio.com/portal/api/public/'.freeze
3
+
4
+ attr_reader :api_key, :user_id, :template_project_id, :base_url
5
+
6
+ def initialize(api_key:, user_id:, template_project_id: nil, base_url: nil)
7
+ @api_key = api_key
8
+ @user_id = user_id
9
+ @template_project_id = template_project_id unless template_project_id.nil?
10
+ @base_url = if base_url.nil?
11
+ DEFAULT_BASE_URL
12
+ else
13
+ base_url
14
+ end
15
+ end
16
+
17
+ def get_project_ids
18
+ projects = Restify.new(@base_url + 'projects')
19
+ .get(userId: @user_id, token: @api_key)
20
+ .value!
21
+
22
+ projects.data.map{|project| project['project_id']}
23
+ end
24
+
25
+ def create_project(title:, description:)
26
+ data = {
27
+ title: title,
28
+ description: description,
29
+ user_id: @user_id
30
+ }
31
+
32
+ Restify.new(@base_url + 'projects')
33
+ .post(data, token: @api_key)
34
+ .value!
35
+ end
36
+
37
+ def get_boards_for_project(project_id:)
38
+ Restify.new(@base_url + 'projects/{project_id}/boards')
39
+ .get(project_id: project_id, token: @api_key, userId: @user_id)
40
+ .value!
41
+ end
42
+
43
+ def get_template_boards
44
+ return [] if @template_project_id.nil?
45
+ template_boards = get_boards_for_project(project_id: @template_project_id)
46
+ template_boards.data.map{ |board| {board_id: board['boardId'], title: board['title'] } }
47
+ end
48
+
49
+ def create_board_for_project(project_id:, title:, description:, template_id: nil)
50
+ data = {
51
+ project_id: project_id,
52
+ title: title,
53
+ description: description,
54
+ user_id: @user_id
55
+ }
56
+ data.merge!(template_id: template_id) unless template_id.nil?
57
+
58
+ Restify.new(@base_url + 'boards')
59
+ .post(data, token: @api_key)
60
+ .value!
61
+ end
62
+ end
@@ -0,0 +1,20 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = 'nexboard-api'
3
+ spec.version = '0.1.0'
4
+ spec.authors = ['Xikolo Development Team']
5
+ spec.email = %w(xikolo-dev@hpi.uni-potsdam.de)
6
+ spec.description = %q{Ruby wrapper for Nexboard API (https://nexboard.nexenio.com)}
7
+ spec.summary = %q{Ruby wrapper for Nexboard API (https://nexboard.nexenio.com)}
8
+ spec.homepage = 'https://github.com/openHPI/nexboard-api'
9
+ spec.license = ''
10
+
11
+ spec.files = Dir['**/*'].grep(/((bin|lib|test|spec|features)\/|
12
+ .*\.gemspec|.*LICENSE.*|.*README.*|.*CHANGELOG.*)/x)
13
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
14
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
+ spec.require_paths = %w(lib)
16
+
17
+ spec.add_dependency 'restify'
18
+
19
+ spec.add_development_dependency 'bundler', '~> 1.3'
20
+ end
@@ -0,0 +1,130 @@
1
+ require 'spec_helper'
2
+
3
+ describe NexboardApi do
4
+ let(:api_key) { 'RandomApiKey' }
5
+ let(:user_id) { 1337 }
6
+ let(:params) { {api_key: api_key, user_id: user_id} }
7
+
8
+ let(:api) { NexboardApi.new **params }
9
+
10
+ let(:default_base_url) { 'https://nexboard.nexenio.com/portal/api/public/' }
11
+ let(:default_headers) { {'Content-Type' => 'application/json'} }
12
+
13
+ describe '#initialize' do
14
+ subject { NexboardApi.new **params }
15
+
16
+ it 'should be initialized with correct params' do
17
+ expect(subject.api_key).to eq(api_key)
18
+ expect(subject.user_id).to eq(user_id)
19
+ expect(subject.base_url).to eq(default_base_url)
20
+ end
21
+
22
+ context 'with custom base_url' do
23
+ let(:params) { super().merge(base_url: 'https://p3k.com') }
24
+
25
+ it 'should be initialized with custom base_url' do
26
+ expect(subject.base_url).to eq('https://p3k.com')
27
+ end
28
+ end
29
+
30
+ context 'with template_project_id' do
31
+ let(:params) { super().merge(template_project_id: 666) }
32
+
33
+ it 'should be initialized with template_project_id' do
34
+ expect(subject.template_project_id).to eq(666)
35
+ end
36
+ end
37
+ end
38
+
39
+ describe '#get_project_ids' do
40
+ subject { api.get_project_ids }
41
+
42
+ let!(:projects_stub) do
43
+ stub_request(:get, "#{default_base_url}projects?token=#{api_key}&userId=#{user_id}").
44
+ with(headers: default_headers).
45
+ to_return(status: 200, body: "[{\"project_id\": 1}, {\"project_id\": 3000}]", headers: default_headers)
46
+ end
47
+
48
+ it 'should request Nexboard API' do
49
+ subject
50
+ expect(projects_stub).to have_been_requested
51
+ end
52
+
53
+ it 'should return a list of project ids' do
54
+ expect(subject).to eq([1, 3000])
55
+ end
56
+ end
57
+
58
+ describe '#create_project' do
59
+ let(:create_params) { {title: 'My project', description: 'My description'} }
60
+
61
+ subject { api.create_project **create_params }
62
+
63
+ let!(:create_project_stub) do
64
+ stub_request(:post, "#{default_base_url}projects?token=#{api_key}").
65
+ with(headers: default_headers, body: create_params.merge(user_id: user_id)).
66
+ to_return(status: 200, body: "{}", headers: default_headers)
67
+ end
68
+
69
+ it 'should request Nexboard API' do
70
+ subject
71
+ expect(create_project_stub).to have_been_requested
72
+ end
73
+ end
74
+
75
+ describe '#get_boards_for_project' do
76
+ let(:project_id) { 123 }
77
+
78
+ subject { api.get_boards_for_project project_id: project_id }
79
+
80
+ let(:board) do
81
+ {
82
+ boardId: 1,
83
+ project_id: project_id,
84
+ title: 'My board',
85
+ description: 'My description'
86
+ }
87
+ end
88
+
89
+ let!(:boards_stub) do
90
+ stub_request(:get, "#{default_base_url}projects/#{project_id}/boards?token=#{api_key}&userId=#{user_id}").
91
+ with(headers: default_headers).
92
+ to_return(status: 200, body: "[#{board.to_json}]", headers: default_headers)
93
+ end
94
+
95
+ it 'should request Nexboard API' do
96
+ subject
97
+ expect(boards_stub).to have_been_requested
98
+ end
99
+
100
+ it 'should return a list of board resources' do
101
+ expect(subject.data.to_json).to eq([board].to_json)
102
+ end
103
+ end
104
+
105
+ describe '#create_board_for_project' do
106
+ let(:create_params) { {project_id: 123, title: 'My title', description: 'My description'} }
107
+
108
+ subject { api.create_board_for_project **create_params }
109
+
110
+ let(:create_board_stub) do
111
+ stub_request(:post, "#{default_base_url}boards?token=#{api_key}").
112
+ with(headers: default_headers, body: create_params.merge(user_id: user_id)).
113
+ to_return(status: 200, body: "{}", headers: default_headers)
114
+ end
115
+
116
+ before { create_board_stub; subject }
117
+
118
+ it 'should request Nexboard API' do
119
+ expect(create_board_stub).to have_been_requested
120
+ end
121
+
122
+ context 'with template_id' do
123
+ let(:create_params) { super().merge(template_id: 1234) }
124
+
125
+ it 'should request Nexboard API' do
126
+ expect(create_board_stub).to have_been_requested
127
+ end
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,53 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ require 'simplecov'
3
+ SimpleCov.start do
4
+ at_exit do
5
+ result = SimpleCov.result
6
+ SimpleCov::Formatter::HTMLFormatter.new.format result
7
+ end
8
+ end
9
+
10
+ require 'rspec'
11
+ require 'webmock/rspec'
12
+ require 'nexboard_api'
13
+ require 'restify'
14
+
15
+ # Requires supporting ruby files with custom matchers and macros, etc,
16
+ # in spec/support/ and its subdirectories.
17
+ Dir['spec/support/**/*.rb'].each {|f| require f}
18
+
19
+ RSpec.configure do |config|
20
+ # ## Mock Framework
21
+ #
22
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
23
+ #
24
+ # config.mock_with :mocha
25
+ # config.mock_with :flexmock
26
+ # config.mock_with :rr
27
+
28
+ # Run specs in random order to surface order dependencies. If you find an
29
+ # order dependency and want to debug it, you can fix the order by providing
30
+ # the seed, which is printed after each run.
31
+ # --seed 1234
32
+ config.order = 'random'
33
+
34
+ config.expect_with :rspec do |expectations|
35
+ # Enable only the newer, non-monkey-patching expect syntax.
36
+ # For more details, see:
37
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
38
+ expectations.syntax = :expect
39
+ end
40
+
41
+ # rspec-mocks config goes here. You can use an alternate test double
42
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
43
+ config.mock_with :rspec do |mocks|
44
+ # Enable only the newer, non-monkey-patching expect syntax.
45
+ # For more details, see:
46
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
47
+ mocks.syntax = :expect
48
+
49
+ # Prevents you from mocking or stubbing a method that does not exist on
50
+ # a real object. This is generally recommended.
51
+ mocks.verify_partial_doubles = true
52
+ end
53
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nexboard-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Xikolo Development Team
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-08-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: restify
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ description: Ruby wrapper for Nexboard API (https://nexboard.nexenio.com)
42
+ email:
43
+ - xikolo-dev@hpi.uni-potsdam.de
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - README.md
49
+ - lib/nexboard_api.rb
50
+ - nexboard-api.gemspec
51
+ - spec/lib/nexboard_api_spec.rb
52
+ - spec/spec_helper.rb
53
+ homepage: https://github.com/openHPI/nexboard-api
54
+ licenses:
55
+ - ''
56
+ metadata: {}
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubyforge_project:
73
+ rubygems_version: 2.5.1
74
+ signing_key:
75
+ specification_version: 4
76
+ summary: Ruby wrapper for Nexboard API (https://nexboard.nexenio.com)
77
+ test_files:
78
+ - spec/lib/nexboard_api_spec.rb
79
+ - spec/spec_helper.rb