openproject_api 0.1.1

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: 68cc46b14855c5f876562d29894f8178743f53d3b4b4b69aadbefac7122e1d3a
4
+ data.tar.gz: f82e5b462670ba24fadc94df44d5b48d5911d4fa9126448ddf6994d9ce3fb807
5
+ SHA512:
6
+ metadata.gz: e574c9fbcd7aa834ef87f1cd1a247bddbeb41d78525644a69fffb7101e2d6b7cc3d8c2c01999483a028c7a743f42dbc92081808d546adcac08eaca5f9aa19a03
7
+ data.tar.gz: 653926c310c30d04a4eeacdf11f58de21903182d6ff42a935c9833e4f2049da65539f2dfd329e0b82f450d0206f61683a62cf21a3e96bacf0e166e97b08f7944
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'rake', '~> 13.0'
6
+ gem 'rspec', '~> 3.0'
7
+ gem 'pry'
data/Gemfile.lock ADDED
@@ -0,0 +1,40 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ openproject_api (0.1.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ coderay (1.1.3)
10
+ diff-lcs (1.4.4)
11
+ method_source (1.0.0)
12
+ pry (0.13.1)
13
+ coderay (~> 1.1)
14
+ method_source (~> 1.0)
15
+ rake (13.0.1)
16
+ rspec (3.9.0)
17
+ rspec-core (~> 3.9.0)
18
+ rspec-expectations (~> 3.9.0)
19
+ rspec-mocks (~> 3.9.0)
20
+ rspec-core (3.9.3)
21
+ rspec-support (~> 3.9.3)
22
+ rspec-expectations (3.9.2)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.9.0)
25
+ rspec-mocks (3.9.1)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.9.0)
28
+ rspec-support (3.9.3)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ openproject_api!
35
+ pry
36
+ rake (~> 13.0)
37
+ rspec (~> 3.0)
38
+
39
+ BUNDLED WITH
40
+ 1.17.3
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
8
+ task :generate_files do
9
+ File.write(File.expand_path('files.txt', __dir__), Dir['lib/**/*', 'Gemfile', 'Gemfile.lock', 'openproject-api.gemspec', 'Rakefile', 'files.txt'].join("\n"))
10
+ end
data/files.txt ADDED
@@ -0,0 +1,17 @@
1
+ lib/openproject_api
2
+ lib/openproject_api/version.rb
3
+ lib/openproject_api/client
4
+ lib/openproject_api/client/time_entries.rb
5
+ lib/openproject_api/client/work_packages.rb
6
+ lib/openproject_api/client/statuses.rb
7
+ lib/openproject_api/client/types.rb
8
+ lib/openproject_api/client/projects.rb
9
+ lib/openproject_api/objectified_hash.rb
10
+ lib/openproject_api/api.rb
11
+ lib/openproject_api/client.rb
12
+ lib/openproject_api.rb
13
+ Gemfile
14
+ Gemfile.lock
15
+ openproject_api.gemspec
16
+ Rakefile
17
+ files.txt
@@ -0,0 +1,67 @@
1
+ require 'uri'
2
+ require 'net/https'
3
+ require 'json'
4
+ require_relative 'objectified_hash'
5
+
6
+ module OpenprojectApi
7
+ class Api
8
+ attr_accessor :endpoint
9
+ attr_accessor :apikey
10
+
11
+ def initialize(endpoint:, apikey:)
12
+ self.endpoint = endpoint
13
+ self.apikey = apikey
14
+ end
15
+
16
+ def request(resource, query: {}, &block)
17
+ uri = URI.join(endpoint, resource)
18
+ uri.query = URI.encode_www_form(query)
19
+
20
+ response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme=='https') do |http|
21
+ request = yield(uri)
22
+
23
+ request.basic_auth('apikey', apikey)
24
+
25
+ http.request(request)
26
+ end
27
+
28
+ if response.is_a?(Net::HTTPSuccess)
29
+ ObjectifiedHash.new(JSON.parse(response.body))
30
+ else
31
+ response.error!
32
+ end
33
+ end
34
+
35
+ def get(resource, *args)
36
+ request(resource, *args) do |uri|
37
+ Net::HTTP::Get.new(uri.request_uri)
38
+ end
39
+ end
40
+
41
+ def post(resource, body, *args)
42
+ request(resource, *args) do |uri|
43
+ Net::HTTP::Post.new(uri.request_uri).tap do |request|
44
+ request['Content-Type'] = 'application/json'
45
+ request['Accept' ] = 'application/json'
46
+ request.body = body.to_json
47
+ end
48
+ end
49
+ end
50
+
51
+ def patch(resource, body, *args)
52
+ request(resource, *args) do |uri|
53
+ Net::HTTP::Patch.new(uri.request_uri).tap do |request|
54
+ request['Content-Type'] = 'application/json'
55
+ request['Accept' ] = 'application/json'
56
+ request.body = body.to_json
57
+ end
58
+ end
59
+ end
60
+
61
+ def delete(resource, *args)
62
+ request(resource, *args) do |uri|
63
+ Net::HTTP::Delete.new(uri.request_uri)
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,33 @@
1
+ module OpenprojectApi
2
+ class Client
3
+ module Projects
4
+ def projects(*args)
5
+ get('/api/v3/projects', *args)
6
+ end
7
+
8
+ def project(project_id, *args)
9
+ get("/api/v3/projects/#{project_id}", *args)
10
+ end
11
+
12
+ def patch_project(project_id, body, *args)
13
+ patch("/api/v3/projects/#{project_id}", body, *args)
14
+ end
15
+
16
+ def create_project(body, *args)
17
+ get('/api/v3/projects', body, *args)
18
+ end
19
+
20
+ def delete_project(project_id, *args)
21
+ delete("/api/v3/projects/#{project_id}", *args)
22
+ end
23
+
24
+ def project_types(project_id, *args)
25
+ get("/api/v3/projects/#{project_id}/types", *args)
26
+ end
27
+
28
+ def project_available_parent_project_candidates(*args)
29
+ get('/api/v3/projects/available_parent_projects', *args)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,13 @@
1
+ module OpenprojectApi
2
+ class Client
3
+ module Statuses
4
+ def statuses(*args)
5
+ get('/api/v3/statuses', *args)
6
+ end
7
+
8
+ def status(status_id, *args)
9
+ get("/api/v3/statuses/#{status_id}", *args)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,29 @@
1
+ module OpenprojectApi
2
+ class Client
3
+ module TimeEntries
4
+ def time_entries(*args)
5
+ get('/api/v3/time_entries', *args)
6
+ end
7
+
8
+ def time_entry(time_entry_id, *args)
9
+ get("/api/v3/time_entries/#{time_entry_id}", *args)
10
+ end
11
+
12
+ def patch_time_entry(time_entry_id, body, *args)
13
+ patch("/api/v3/time_entries/#{time_entry_id}", body, *args)
14
+ end
15
+
16
+ def create_time_entry(body, *args)
17
+ post('/api/v3/time_entries', body, *args)
18
+ end
19
+
20
+ def delete_time_entry(time_entry_id, *args)
21
+ delete("/api/v3/time_entries/#{time_entry_id}", *args)
22
+ end
23
+
24
+ def time_entries_available_projects(*args)
25
+ get('/api/v3/time_entries/available_projects', *args)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,13 @@
1
+ module OpenprojectApi
2
+ class Client
3
+ module Types
4
+ def types(*args)
5
+ get('/api/v3/types', *args)
6
+ end
7
+
8
+ def type(type_id, *args)
9
+ get("/api/v3/types/#{type_id}", *args)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,69 @@
1
+ module OpenprojectApi
2
+ class Client
3
+ module WorkPackages
4
+ def work_packages(*args)
5
+ get('/api/v3/work_packages', *args)
6
+ end
7
+
8
+ def work_package(work_package_id, *args)
9
+ get("/api/v3/work_packages/#{work_package_id}", *args)
10
+ end
11
+
12
+ def patch_work_package(work_package_id, body, *args)
13
+ patch("/api/v3/work_packages/#{work_package_id}", body, *args)
14
+ end
15
+
16
+ def create_work_package(body, *args)
17
+ post('/api/v3/work_packages', body, *args)
18
+ end
19
+
20
+ def delete_work_package(work_package_id, *args)
21
+ delete("/api/v3/work_packages/#{work_package_id}", *args)
22
+ end
23
+
24
+ def work_package_relations(work_package_id, *args)
25
+ get("/api/v3/work_packages/#{work_package_id}/relations", *args)
26
+ end
27
+
28
+ def add_work_package_relation(work_package_id, body, *args)
29
+ post("/api/v3/work_packages/#{work_package_id}/relations", body, *args)
30
+ end
31
+
32
+ def work_package_available_relation_candidates(work_package_id, *args)
33
+ get("/api/v3/work_packages/#{work_package_id}/available_relation_candidates", *args)
34
+ end
35
+
36
+ def work_package_watchers(work_package_id, *args)
37
+ get("/api/v3/work_packages/#{work_package_id}/watchers", *args)
38
+ end
39
+
40
+ def add_work_package_watcher(work_package_id, body, *args)
41
+ post("/api/v3/work_packages/#{work_package_id}/watchers", body, *args)
42
+ end
43
+
44
+ def delete_work_package_watcher(work_package_id, watcher_id, *args)
45
+ get("/api/v3/work_packages/#{work_package_id}/watchers/#{watcher_id}", *args)
46
+ end
47
+
48
+ def work_package_available_watchers(work_package_id, *args)
49
+ get("/api/v3/work_packages/#{work_package_id}/available_watchers", *args)
50
+ end
51
+
52
+ def work_package_activities(work_package_id, *args)
53
+ get("/api/v3/work_packages/#{work_package_id}/activities", *args)
54
+ end
55
+
56
+ def add_work_package_activity(work_package_id, body, *args)
57
+ post("/api/v3/work_packages/#{work_package_id}/activities", body, *args)
58
+ end
59
+
60
+ def work_package_available_assignees(work_package_id, *args)
61
+ get("/api/v3/work_packages/#{work_package_id}/available_assignees", *args)
62
+ end
63
+
64
+ def work_package_available_responsibles(work_package_id, *args)
65
+ get("/api/v3/work_packages/#{work_package_id}/available_responsibles", *args)
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,15 @@
1
+ require_relative 'api'
2
+
3
+ module OpenprojectApi
4
+ class Client < Api
5
+ Dir[File.expand_path('client/*.rb', __dir__)].each do |f|
6
+ require f
7
+ end
8
+
9
+ include Projects
10
+ include Statuses
11
+ include TimeEntries
12
+ include Types
13
+ include WorkPackages
14
+ end
15
+ end
@@ -0,0 +1,44 @@
1
+ # Slightly modified version from https://github.com/NARKOZ/gitlab/blob/3dd41722670570069693cc9b84c73f475d95e6be/lib/gitlab/objectified_hash.rb
2
+
3
+ module OpenprojectApi
4
+ class ObjectifiedHash
5
+ def initialize(hash)
6
+ @hash = hash
7
+ @data = hash.each_with_object({}) do |(key, value), data|
8
+ value = self.class.new(value) if value.is_a? Hash
9
+ value = value.map { |v| v.is_a?(Hash) ? self.class.new(v) : v } if value.is_a? Array
10
+ data[key.to_s] = value
11
+ end
12
+ end
13
+
14
+ def to_hash
15
+ @hash
16
+ end
17
+ alias to_h to_hash
18
+
19
+ def inspect
20
+ "#<#{self.class}:#{object_id} {hash: #{@hash.inspect}}"
21
+ end
22
+
23
+ def [](key)
24
+ @data[key]
25
+ end
26
+
27
+ private
28
+
29
+ def method_missing(method_name, *args, &block)
30
+ if @data.key?(method_name.to_s)
31
+ @data[method_name.to_s]
32
+ elsif @data.respond_to?(method_name)
33
+ @data.send(method_name, *args, &block)
34
+ else
35
+ super
36
+ end
37
+ end
38
+
39
+ def respond_to_missing?(method_name, include_private = false)
40
+ @hash.keys.map(&:to_sym).include?(method_name.to_sym) || super
41
+ end
42
+ end
43
+ end
44
+
@@ -0,0 +1,3 @@
1
+ module OpenprojectApi
2
+ VERSION = '0.1.1'
3
+ end
@@ -0,0 +1,6 @@
1
+ require_relative 'openproject_api/version'
2
+ require_relative 'openproject_api/client'
3
+
4
+ module OpenprojectApi
5
+ class Error < StandardError; end
6
+ end
@@ -0,0 +1,20 @@
1
+ require_relative 'lib/openproject_api/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'openproject_api'
5
+ spec.version = OpenprojectApi::VERSION
6
+ spec.authors = ['expeehaa']
7
+ spec.email = ['expeehaa@outlook.com']
8
+
9
+ spec.summary = %q{Ruby interface for the OpenProject API.}
10
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
11
+
12
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
13
+
14
+ # Specify which files should be added to the gem when it is released.
15
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
16
+ spec.files = File.read(File.expand_path('files.txt', __dir__)).split("\n")
17
+ spec.bindir = 'exe'
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ['lib']
20
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: openproject_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - expeehaa
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-10-22 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - expeehaa@outlook.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - Gemfile
21
+ - Gemfile.lock
22
+ - Rakefile
23
+ - files.txt
24
+ - lib/openproject_api.rb
25
+ - lib/openproject_api/api.rb
26
+ - lib/openproject_api/client.rb
27
+ - lib/openproject_api/client/projects.rb
28
+ - lib/openproject_api/client/statuses.rb
29
+ - lib/openproject_api/client/time_entries.rb
30
+ - lib/openproject_api/client/types.rb
31
+ - lib/openproject_api/client/work_packages.rb
32
+ - lib/openproject_api/objectified_hash.rb
33
+ - lib/openproject_api/version.rb
34
+ - openproject_api.gemspec
35
+ homepage:
36
+ licenses: []
37
+ metadata:
38
+ allowed_push_host: https://rubygems.org
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 2.3.0
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubygems_version: 3.0.6
55
+ signing_key:
56
+ specification_version: 4
57
+ summary: Ruby interface for the OpenProject API.
58
+ test_files: []