R3c 0.0.9 → 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 +4 -4
- data/README.md +15 -4
- data/lib/r3c/rest_helper.rb +27 -3
- data/lib/r3c/version.rb +1 -1
- data/test/test_r3c.rb +86 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3683d6a35551f5d143d851387767f1b152ed4cca
|
4
|
+
data.tar.gz: 282f607810fa285b89cd49bd665d81507b67917b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a05fab992150850c05fd02acb0bd4be732521b3565ef46d4442f0bce3ecd253417c45cbcf9bb60b7994f20db54b8fc776333dff0a7eaa946c4ffed113df1aeed
|
7
|
+
data.tar.gz: 5ae147f51e7955210f67b4d4908ce6408c5a215690c0759609c83b34f2a173c600a6d0536008ec72fef18d86d07f666ca96c83e8678c91175031a3507d2a1d79
|
data/README.md
CHANGED
@@ -4,6 +4,11 @@
|
|
4
4
|
|
5
5
|
Rest Redmine Ruby Client
|
6
6
|
|
7
|
+
Main Features:
|
8
|
+
* Most of the API is covered
|
9
|
+
* Basic Auth and Key-based authentication are supported
|
10
|
+
* Check code for more usage examples
|
11
|
+
|
7
12
|
## Setup
|
8
13
|
|
9
14
|
```
|
@@ -12,7 +17,7 @@ gem install R3c
|
|
12
17
|
|
13
18
|
## Usage
|
14
19
|
|
15
|
-
###
|
20
|
+
### Configure Redmine URL
|
16
21
|
|
17
22
|
```
|
18
23
|
R3c.site('http://localhost:3000/')
|
@@ -24,11 +29,17 @@ R3c.site('http://localhost:3000/')
|
|
24
29
|
R3c.format(:xml)
|
25
30
|
```
|
26
31
|
|
27
|
-
###
|
32
|
+
### Configure Authentication
|
28
33
|
|
34
|
+
Key-based:
|
29
35
|
```
|
30
36
|
R3c.auth({api: {key: '8091d55257c4c90b6d56e83322622cb5f4ecee64'}})
|
31
37
|
```
|
38
|
+
Or Basic Auth (user/password):
|
39
|
+
|
40
|
+
```
|
41
|
+
R3c.auth({basic_auth: {user: 'admin', password: 'password'}})
|
42
|
+
```
|
32
43
|
|
33
44
|
###Prepare to create an issue with an attachment
|
34
45
|
|
@@ -39,7 +50,7 @@ issue_params= {"project_id"=> 1, "subject"=> "This is the subject"}
|
|
39
50
|
issue_params["uploads"]= [{"upload"=>{"token"=> token, "filename"=> "R3c.gemspec", "description"=> "a gemspec", "content_type"=> "text/plain"}}]
|
40
51
|
```
|
41
52
|
|
42
|
-
###Create issue
|
53
|
+
###Create the new issue
|
43
54
|
|
44
55
|
```
|
45
56
|
issue= R3c.issue.create(issue_params )
|
@@ -51,7 +62,7 @@ issue= R3c.issue.create(issue_params )
|
|
51
62
|
projects= R3c.project.all
|
52
63
|
```
|
53
64
|
|
54
|
-
### Find user
|
65
|
+
### Find user by id
|
55
66
|
|
56
67
|
```
|
57
68
|
user= R3c.user.find 1
|
data/lib/r3c/rest_helper.rb
CHANGED
@@ -51,20 +51,44 @@ module R3c
|
|
51
51
|
response
|
52
52
|
end
|
53
53
|
|
54
|
+
#Example:
|
55
|
+
# R3c.relations(issue_id)
|
56
|
+
def self.relations(issue_id)
|
57
|
+
response = self.execute(method: :get, url: "#{R3c::BaseEntity.site}/issues/#{issue.id}/relations.#{format}")
|
58
|
+
return JSON.parse(response) if format == "json"
|
59
|
+
response
|
60
|
+
end
|
54
61
|
|
62
|
+
def self.add_relation(issue_id, issue_to_id, relation_type, delay=nil)
|
63
|
+
response = self.execute(method: :post, url: "#{R3c::BaseEntity.site}/issues/#{issue.id}/relations.#{format}", headers: {params: {issue_to_id: issue_to_id, relation_type: relation_type, delay: delay}})
|
64
|
+
return JSON.parse(response) if format == "json"
|
65
|
+
response
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.get_relation(relation_id)
|
69
|
+
response = self.execute(method: :get, url: "#{R3c::BaseEntity.site}/relations/#{relation_id}.#{format}")
|
70
|
+
return JSON.parse(response) if format == "json"
|
71
|
+
response
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.delete(relation_id)
|
75
|
+
response = self.execute(method: :delete, url: "#{R3c::BaseEntity.site}/relations/#{relation_id}.#{format}")
|
76
|
+
return JSON.parse(response) if format == "json"
|
77
|
+
response
|
78
|
+
end
|
55
79
|
|
56
80
|
#Example:
|
57
81
|
# R3c.search("sometext")
|
58
|
-
def self.search(q, format = "
|
82
|
+
def self.search(q, format = "json")
|
59
83
|
# GET '/search.xml', :q => 'recipe subproject commit', :all_words => ''
|
60
84
|
response = execute(method: :get, url: "#{R3c::BaseEntity.site}/search.#{format}", headers: {params: {all_words: "", q: q}} )
|
61
|
-
return JSON.parse(response) if format == "json"
|
85
|
+
return JSON.parse(response)# if format == "json"
|
62
86
|
response
|
63
87
|
end
|
64
88
|
|
65
89
|
private
|
66
90
|
def self.execute(params)
|
67
|
-
params =
|
91
|
+
params = add_auth(params)
|
68
92
|
params= set_ssl_params(params)
|
69
93
|
puts "rest-helper.rb->execute: params="+params.inspect.to_s
|
70
94
|
RestClient::Request.execute(params)
|
data/lib/r3c/version.rb
CHANGED
data/test/test_r3c.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'r3c'
|
3
|
+
|
4
|
+
#Assume an new empty redmine installation running on localhost on port 3000
|
5
|
+
class R3cTest < Minitest::Test
|
6
|
+
|
7
|
+
|
8
|
+
#Connection
|
9
|
+
R3c.site "http://localhost:3000"
|
10
|
+
R3c.format :xml
|
11
|
+
R3c.auth basic_auth:{user: "admin", password: "password"}
|
12
|
+
|
13
|
+
|
14
|
+
#Create, Update and Delete a Project
|
15
|
+
def test_crud_project
|
16
|
+
#create
|
17
|
+
@project= create_project
|
18
|
+
assert_equal @project.name, R3c.project.find(@project.id).name
|
19
|
+
size= R3c.project.all.size
|
20
|
+
#update
|
21
|
+
@project.name="replaced"
|
22
|
+
@project.save!
|
23
|
+
assert_equal "replaced", R3c.project.find(@project.id).name
|
24
|
+
#delete
|
25
|
+
delete_project(@project.id)
|
26
|
+
assert_equal (size-1), R3c.project.all.size
|
27
|
+
end
|
28
|
+
|
29
|
+
#Operations on issues
|
30
|
+
def test_issues
|
31
|
+
#create a project container
|
32
|
+
@project= create_project
|
33
|
+
#create first issue
|
34
|
+
@issue = R3c.issue.new
|
35
|
+
@issue.subject="Issue for test"
|
36
|
+
@issue.project_id = @project.id
|
37
|
+
@issue.save!
|
38
|
+
assert 1, R3c.issue.all.size
|
39
|
+
#update issue
|
40
|
+
@issue.subject="Subject Changed"
|
41
|
+
@issue.save!
|
42
|
+
assert_equal "Subject Changed", R3c.issue.find(@issue.id).subject
|
43
|
+
#attach file
|
44
|
+
file = File.read('c:\windows-version.txt')
|
45
|
+
token = R3c.upload file
|
46
|
+
random_string=('a'..'z').to_a.shuffle.first(8).join
|
47
|
+
issue_params= {"project_id"=> 1, "subject"=> "This is the subject #{random_string}"}
|
48
|
+
issue_params["uploads"]= [{"upload"=>{"token"=> token, "filename"=> "R3c.gemspec", "description"=> "a gemspec", "content_type"=> "text/plain"}}]
|
49
|
+
@issue= R3c.issue.create(issue_params)
|
50
|
+
@issue= R3c.issue.find(@issue.id, params: {include: "attachments"})
|
51
|
+
assert_equal "R3c.gemspec", @issue.attachments.first.filename
|
52
|
+
#add a note
|
53
|
+
#TBD
|
54
|
+
#add wathcher
|
55
|
+
R3c.add_watcher(@issue.id, 1)
|
56
|
+
@issue= R3c.issue.find(@issue.id, params: {include: "watchers"})
|
57
|
+
assert_equal 1, @issue.watchers.size
|
58
|
+
#remove watcher
|
59
|
+
R3c.remove_watcher(@issue.id, 1)
|
60
|
+
@issue= R3c.issue.find(@issue.id, params: {include: "watchers"})
|
61
|
+
assert_equal 0, @issue.watchers.size
|
62
|
+
#search
|
63
|
+
results= R3c.search(random_string)
|
64
|
+
assert_equal 1, results["results"].size
|
65
|
+
#delete issue
|
66
|
+
R3c.issue.delete @issue.id
|
67
|
+
assert 0, R3c.issue.all.size
|
68
|
+
#clean up project
|
69
|
+
delete_project(@project.id)
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
private
|
75
|
+
def create_project
|
76
|
+
@project = R3c.project.new
|
77
|
+
@project.name = ('a'..'z').to_a.shuffle.first(8).join #random project name
|
78
|
+
@project.identifier=@project.name
|
79
|
+
@project.save!
|
80
|
+
@project
|
81
|
+
end
|
82
|
+
|
83
|
+
def delete_project(id)
|
84
|
+
R3c.project.delete id
|
85
|
+
end
|
86
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: R3c
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paolo Freuli
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activeresource
|
@@ -84,6 +84,7 @@ files:
|
|
84
84
|
- lib/r3c/r3c.rb
|
85
85
|
- lib/r3c/rest_helper.rb
|
86
86
|
- lib/r3c/version.rb
|
87
|
+
- test/test_r3c.rb
|
87
88
|
homepage: https://github.com/wuatanabe/R3c
|
88
89
|
licenses:
|
89
90
|
- MIT
|