bicho 0.0.4 → 0.0.5

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.
data/lib/bicho/bug.rb CHANGED
@@ -80,7 +80,7 @@ module Bicho
80
80
  # URL where the bug can be viewed
81
81
  # Example: http://bugs.foo.com/2345
82
82
  def url
83
- "#{@client.url}/#{id}"
83
+ "#{@client.site_url}/#{id}"
84
84
  end
85
85
 
86
86
  end
data/lib/bicho/client.rb CHANGED
@@ -62,15 +62,40 @@ module Bicho
62
62
 
63
63
  include Bicho::Logging
64
64
 
65
- attr_reader :url, :userid
65
+ # @return [URI] XML-RPC API end-point
66
+ #
67
+ # This URL is automatically inferred from the
68
+ # Client#site_url
69
+ #
70
+ # Plugins can modify the inferred value by providing
71
+ # a transform_api_url_hook(url, logger) method returning
72
+ # the modified value.
73
+ #
74
+ attr_reader :api_url
66
75
 
67
- def initialize(url)
68
- # Don't modify the original url
69
- url = url.is_a?(URI) ? url.clone : URI.parse(url)
70
- # save the unmodified (by plugins) url
71
- @original_url = url.clone
76
+ # @return [URI] Bugzilla installation website
77
+ #
78
+ # This value is provided at construction time
79
+ attr_reader :site_url
80
+
81
+ # @return [String] user id, available after login
82
+ attr_reader :userid
83
+
84
+ # @visibility private
85
+ # Implemented only to warn users about the replacement
86
+ # APIs
87
+ def url
88
+ warn "url is deprecated. Use site_url or api_url"
89
+ raise NoMethodError
90
+ end
72
91
 
73
- url.path = '/xmlrpc.cgi'
92
+ # @param [String] site_url Bugzilla installation site url
93
+ def initialize(site_url)
94
+ # Don't modify the original url
95
+ @site_url = site_url.is_a?(URI) ? site_url.clone : URI.parse(site_url)
96
+
97
+ @api_url = @site_url.clone
98
+ @api_url.path = '/xmlrpc.cgi'
74
99
 
75
100
  # Scan plugins
76
101
  plugin_glob = File.join(File.dirname(__FILE__), 'plugins', '*.rb')
@@ -84,10 +109,14 @@ module Bicho
84
109
  pl_class = ::Bicho::Plugins.const_get(cnt)
85
110
  pl_instance = pl_class.new
86
111
  logger.debug("Loaded: #{pl_instance}")
87
- pl_instance.initialize_hook(url, logger)
112
+
113
+ # Modify API url
114
+ if pl_instance.respond_to?(:transform_api_url_hook)
115
+ @api_url = pl_instance.transform_api_url_hook(@api_url, logger)
116
+ end
88
117
  end
89
118
 
90
- @client = XMLRPC::Client.new_from_uri(url.to_s, nil, 900)
119
+ @client = XMLRPC::Client.new_from_uri(@api_url.to_s, nil, 900)
91
120
  @client.set_debug
92
121
 
93
122
  # User.login sets the credentials cookie for subsequent calls
@@ -96,9 +125,6 @@ module Bicho
96
125
  handle_faults(ret)
97
126
  @userid = ret['id']
98
127
  end
99
-
100
- # Save modified url
101
- @url = url
102
128
  end
103
129
 
104
130
  def cookie
@@ -141,7 +167,7 @@ module Bicho
141
167
  end
142
168
 
143
169
  logger.info("Expanding named query: '#{what}' with '#{cookie}'")
144
- http = Net::HTTP.new(@url.host, @url.port)
170
+ http = Net::HTTP.new(@api_url.host, @api_url.port)
145
171
  http.use_ssl = true
146
172
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
147
173
  http.set_debug_output(Bicho::LoggerIODevice.new)
@@ -58,17 +58,20 @@ module Bicho
58
58
  end
59
59
  end
60
60
 
61
- def initialize_hook(url, logger)
62
-
63
- return if not url.host.include?('bugzilla.novell.com')
61
+ def transform_api_url_hook(url, logger)
62
+
63
+ return url if not url.host.include?('bugzilla.novell.com')
64
64
 
65
65
  auth = Novell.oscrc_credentials
66
+
67
+ url = url.clone
66
68
  url.user = auth[:user]
67
69
  url.password = auth[:password]
68
70
  url.host = url.host.gsub(/bugzilla\.novell.com/, 'apibugzilla.novell.com')
69
71
  url.path = url.path.gsub(/xmlrpc\.cgi/, 'tr_xmlrpc.cgi')
70
72
 
71
73
  logger.debug("#{self} : Rewrote url to '#{url.to_s.gsub(/#{url.user}:#{url.password}/, "USER:PASS")}'")
74
+ return url
72
75
  end
73
76
 
74
77
  end
data/lib/bicho/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Bicho
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -0,0 +1,17 @@
1
+ require File.join(File.dirname(__FILE__), 'helper')
2
+
3
+ class NovellPlugin_test < Test::Unit::TestCase
4
+
5
+ def test_urls_are_correct
6
+ client = Bicho::Client.new('https://bugzilla.novell.com')
7
+
8
+ assert_raises NoMethodError do
9
+ client.url
10
+ end
11
+
12
+ assert_equal 'https://apibugzilla.novell.com/tr_xmlrpc.cgi', "#{client.api_url.scheme}://#{client.api_url.host}#{client.api_url.path}"
13
+ assert_equal 'https://bugzilla.novell.com', "#{client.site_url.scheme}://#{client.site_url.host}#{client.site_url.path}"
14
+
15
+ end
16
+
17
+ end
metadata CHANGED
@@ -1,68 +1,94 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: bicho
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.4
3
+ version: !ruby/object:Gem::Version
4
+ hash: 21
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 5
10
+ version: 0.0.5
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Duncan Mac-Vicar P.
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2011-12-09 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
17
+
18
+ date: 2012-01-02 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
15
22
  name: inifile
16
- requirement: &6670800 !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
17
25
  none: false
18
- requirements:
26
+ requirements:
19
27
  - - ~>
20
- - !ruby/object:Gem::Version
28
+ - !ruby/object:Gem::Version
29
+ hash: 13
30
+ segments:
31
+ - 0
32
+ - 4
33
+ - 1
21
34
  version: 0.4.1
22
35
  type: :runtime
23
- prerelease: false
24
- version_requirements: *6670800
25
- - !ruby/object:Gem::Dependency
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
26
38
  name: trollop
27
- requirement: &6670160 !ruby/object:Gem::Requirement
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
28
41
  none: false
29
- requirements:
30
- - - ! '>='
31
- - !ruby/object:Gem::Version
32
- version: '1.16'
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 47
46
+ segments:
47
+ - 1
48
+ - 16
49
+ version: "1.16"
33
50
  type: :runtime
34
- prerelease: false
35
- version_requirements: *6670160
36
- - !ruby/object:Gem::Dependency
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
37
53
  name: highline
38
- requirement: &6669600 !ruby/object:Gem::Requirement
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
39
56
  none: false
40
- requirements:
57
+ requirements:
41
58
  - - ~>
42
- - !ruby/object:Gem::Version
59
+ - !ruby/object:Gem::Version
60
+ hash: 11
61
+ segments:
62
+ - 1
63
+ - 6
64
+ - 2
43
65
  version: 1.6.2
44
66
  type: :runtime
45
- prerelease: false
46
- version_requirements: *6669600
47
- - !ruby/object:Gem::Dependency
67
+ version_requirements: *id003
68
+ - !ruby/object:Gem::Dependency
48
69
  name: nokogiri
49
- requirement: &6669180 !ruby/object:Gem::Requirement
70
+ prerelease: false
71
+ requirement: &id004 !ruby/object:Gem::Requirement
50
72
  none: false
51
- requirements:
52
- - - ! '>='
53
- - !ruby/object:Gem::Version
54
- version: '0'
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ hash: 3
77
+ segments:
78
+ - 0
79
+ version: "0"
55
80
  type: :runtime
56
- prerelease: false
57
- version_requirements: *6669180
81
+ version_requirements: *id004
58
82
  description: Library to access bugzilla
59
- email:
83
+ email:
60
84
  - dmacvicar@suse.de
61
- executables:
85
+ executables:
62
86
  - bicho
63
87
  extensions: []
88
+
64
89
  extra_rdoc_files: []
65
- files:
90
+
91
+ files:
66
92
  - .gitignore
67
93
  - Gemfile
68
94
  - MIT-LICENSE
@@ -83,32 +109,43 @@ files:
83
109
  - lib/bicho/query.rb
84
110
  - lib/bicho/version.rb
85
111
  - test/helper.rb
112
+ - test/test_novell_plugin.rb
86
113
  - test/test_query.rb
114
+ has_rdoc: true
87
115
  homepage: http://github.com/dmacvicar/bicho
88
116
  licenses: []
117
+
89
118
  post_install_message:
90
119
  rdoc_options: []
91
- require_paths:
120
+
121
+ require_paths:
92
122
  - lib
93
- required_ruby_version: !ruby/object:Gem::Requirement
123
+ required_ruby_version: !ruby/object:Gem::Requirement
94
124
  none: false
95
- requirements:
96
- - - ! '>='
97
- - !ruby/object:Gem::Version
98
- version: '0'
99
- required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ hash: 3
129
+ segments:
130
+ - 0
131
+ version: "0"
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
133
  none: false
101
- requirements:
102
- - - ! '>='
103
- - !ruby/object:Gem::Version
104
- version: '0'
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ hash: 3
138
+ segments:
139
+ - 0
140
+ version: "0"
105
141
  requirements: []
142
+
106
143
  rubyforge_project: bicho
107
- rubygems_version: 1.8.11
144
+ rubygems_version: 1.6.2
108
145
  signing_key:
109
146
  specification_version: 3
110
147
  summary: Library to access bugzilla
111
- test_files:
148
+ test_files:
112
149
  - test/helper.rb
150
+ - test/test_novell_plugin.rb
113
151
  - test/test_query.rb
114
- has_rdoc: