R3c 0.0.7 → 0.0.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e5e019a10262dc43a59ee5a07f6bc09f3a07db27
4
- data.tar.gz: 77db92f428df6417afcbc0fef1f808a311bbda7b
3
+ metadata.gz: 891785aca6c9373f5d616109a1dd8671fe54a82b
4
+ data.tar.gz: 3db7c2db12dc86c51e5723451b96a646d79f4161
5
5
  SHA512:
6
- metadata.gz: 701b5de884c5adad1de2e1dcaf64942e3dbcfd6632b51b01fd7524c2fc40a8dc6dc9ac2e8c4088a77b3a6b5e9ff86d612443befcad881014101c819483824b28
7
- data.tar.gz: 93d055d1f42d9b3f60c21ad6ad9e8f44693d9ae229f8d49d961527a52ad709ef3e914098a4415a8bc9e2927dd203e48fafa42998f9542a409f0e95d53d4c5b9d
6
+ metadata.gz: c51fc0d15f1a1f08709a2d60ca3010a28022a8578b2261daee222edb3f65b0d71db4ed126495d84e4a9c5371cac9fb9158becb9be439fabc1a7d2e7f155c5573
7
+ data.tar.gz: fba8dbf911b4050dcf246627cca98972d6a5a79eda331241fbef262584d03800a372a17a8fde0e5a4d09acef35dff4c7f925da4a13239a59ef2b4d56b2105f31
data/lib/r3c.rb CHANGED
@@ -21,7 +21,20 @@ module R3c
21
21
  def self.auth auth
22
22
  R3c::BaseEntity.auth auth
23
23
  end
24
+
25
+ def self.ssl ssl_options
26
+ if R3c::BaseEntity.include?("https")
27
+ return R3c::BaseEntity.set_ssl ssl_options
28
+ end
29
+ end
24
30
 
31
+ def self.verify_ssl?
32
+ if R3c::BaseEntity.self.ssl_options[:verify_mode] == OpenSSL::SSL::VERIFY_NONE
33
+ return false
34
+ else
35
+ return true
36
+ end
37
+ end
25
38
 
26
39
  private
27
40
 
@@ -8,6 +8,10 @@ class BaseEntity < ActiveResource::Base
8
8
  self.format = :xml
9
9
 
10
10
  def self.set_site(url)
11
+ if !self.ssl_options and url.include?("https")
12
+ self.ssl_options ={}
13
+ self.ssl_options[:verify_mode] =OpenSSL::SSL::VERIFY_PEER
14
+ end
11
15
  self.site= url
12
16
  end
13
17
 
@@ -25,6 +29,14 @@ class BaseEntity < ActiveResource::Base
25
29
  end
26
30
  end
27
31
 
32
+ def self.set_ssl(ssl_options)
33
+ self.ssl_options = {:cert => ssl_options[:cert],
34
+ :key => ssl_options[:key],
35
+ :ca_path => ssl_options[:ca_path],
36
+ :verify_mode => ssl_options[:verify_mode]
37
+ }
38
+ end
39
+
28
40
  private
29
41
  def self.api_key(api_key)
30
42
  self.headers['X-Redmine-API-Key'] = api_key
@@ -3,18 +3,23 @@ require "rest-client"
3
3
 
4
4
  module R3c
5
5
 
6
+
7
+
8
+
6
9
  def self.upload(file, format="xml")
7
- response = RestClient.post("#{R3c::BaseEntity.site}/uploads.#{format}?key=#{R3c::BaseEntity.headers['X-Redmine-API-Key']}", file, {:multipart => true, :content_type => 'application/octet-stream'})
10
+ response = execute(method: :post, url: "#{R3c::BaseEntity.site}/uploads.#{format}", file: file, :multipart => true, :content_type => 'application/octet-stream')
8
11
  token = JSON.parse(response)['upload']['token']
9
12
  end
10
13
 
11
14
 
15
+
16
+
12
17
  #Note: see r3c.rb for example about how to retrieve watchers on an issue
13
18
  #Example:
14
19
  # R3c.add_watcher(1, 1)
15
20
  def self.add_watcher(issue_id, user_id, format="xml")
16
21
  #POST /issues/[id]/watchers.[format]
17
- response = RestClient.post("#{R3c::BaseEntity.site}/issues/#{issue_id}/watchers.#{format}?key=#{R3c::BaseEntity.headers['X-Redmine-API-Key']}", {user_id: user_id})
22
+ response = execute(method: :post, url: "#{R3c::BaseEntity.site}/issues/#{issue_id}/watchers.#{format}", headers: {params: {user_id: user_id}})
18
23
  return JSON.parse(response) if format == "json"
19
24
  response
20
25
  end
@@ -23,7 +28,7 @@ module R3c
23
28
  # R3c.remove_watcher(1, 1)
24
29
  def self.remove_watcher(issue_id, user_id, format="xml")
25
30
  #DELETE /issues/[id]/watchers/[user_id].[format]
26
- response = RestClient.delete("#{R3c::BaseEntity.site}/issues/#{issue_id}/watchers/#{user_id}.#{format}?key=#{R3c::BaseEntity.headers['X-Redmine-API-Key']}")
31
+ response = execute(method: :delete, url: "#{R3c::BaseEntity.site}/issues/#{issue_id}/watchers/#{user_id}.#{format}")
27
32
  return JSON.parse(response) if format == "json"
28
33
  response
29
34
  end
@@ -32,18 +37,37 @@ module R3c
32
37
  # R3c.enumerations("issue_priorities")
33
38
  def self.enumerations(enumeration, format="xml")
34
39
  #GET /enumerations/<enumeration>.[format] #enumeration= "issue_priorities" OR "time_entry_activities"
35
- response = RestClient.get("#{R3c::BaseEntity.site}/enumerations/#{enumeration}.#{format}?key=#{R3c::BaseEntity.headers['X-Redmine-API-Key']}")
40
+ response = self.execute(method: :get, url: "#{R3c::BaseEntity.site}/enumerations/#{enumeration}.#{format}")
36
41
  return JSON.parse(response) if format == "json"
37
42
  response
38
43
  end
39
44
 
45
+
46
+
40
47
  #Example:
41
48
  # R3c.search("sometext")
42
49
  def self.search(q, format = "xml")
43
50
  # GET '/search.xml', :q => 'recipe subproject commit', :all_words => ''
44
- response = RestClient.get("#{R3c::BaseEntity.site}/search.#{format}/?key=#{R3c::BaseEntity.headers['X-Redmine-API-Key']}", {all_words: '', q: q})
51
+ response = execute(method: :get, url: "#{R3c::BaseEntity.site}/search.#{format}", headers: {params: {all_words: "", q: q}} )
45
52
  return JSON.parse(response) if format == "json"
46
53
  response
47
54
  end
48
55
 
56
+ private
57
+ def self.execute(params)
58
+ if R3c::BaseEntity.user
59
+ params[:user]= R3c::BaseEntity.user
60
+ params[:password]=R3c::BaseEntity.password
61
+ else
62
+ params[:url]= params[:url]+"?key=#{R3c::BaseEntity.headers['X-Redmine-API-Key']}"
63
+ end
64
+ puts "rest-helper.rb->execute: params="+params.inspect.to_s
65
+ if R3c::BaseEntity.site.to_s.include?("https")
66
+ params[:verify_ssl]=R3c::BaseEntity.ssl_options[:verify_mode]
67
+ params= params.merge(R3c::BaseEntity.ssl_options)
68
+ puts "rest-helper.rb->execute: params="+params.inspect.to_s
69
+ end
70
+ RestClient::Request.execute(params)
71
+ end
72
+
49
73
  end
@@ -1,5 +1,5 @@
1
1
  module R3c
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
4
4
 
5
5
 
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.7
4
+ version: 0.0.8
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-16 00:00:00.000000000 Z
11
+ date: 2016-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeresource
@@ -109,3 +109,4 @@ signing_key:
109
109
  specification_version: 4
110
110
  summary: Rest Redmine Ruby Client
111
111
  test_files: []
112
+ has_rdoc: false