rodzilla 0.1.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/Gemfile +9 -0
- data/lib/rodzilla.rb +21 -46
- data/lib/rodzilla/error.rb +6 -0
- data/lib/rodzilla/json_rpc/error.rb +35 -0
- data/lib/rodzilla/json_rpc/request.rb +24 -0
- data/lib/rodzilla/json_rpc/response.rb +20 -0
- data/lib/rodzilla/json_rpc/service.rb +94 -0
- data/lib/rodzilla/resource/base.rb +24 -47
- data/lib/rodzilla/resource/bug.rb +128 -24
- data/lib/rodzilla/resource/bugzilla.rb +4 -4
- data/lib/rodzilla/resource/group.rb +7 -0
- data/lib/rodzilla/resource/product.rb +4 -4
- data/lib/rodzilla/resource/user.rb +7 -0
- data/lib/rodzilla/util.rb +22 -0
- data/lib/rodzilla/version.rb +2 -2
- data/lib/rodzilla/web_service.rb +67 -0
- data/rodzilla.gemspec +0 -5
- data/test/fixtures/methods/Bugzilla_extensions.json +1 -0
- data/test/fixtures/methods/Bugzilla_version.json +1 -0
- data/test/rodzilla/json_rpc/error_test.rb +34 -0
- data/test/rodzilla/json_rpc/request_test.rb +65 -0
- data/test/rodzilla/json_rpc/response_test.rb +42 -0
- data/test/rodzilla/json_rpc/service_test.rb +110 -0
- data/test/rodzilla/resource/base_test.rb +45 -58
- data/test/rodzilla/resource/bug_test.rb +0 -38
- data/test/rodzilla/resource/util_test.rb +25 -0
- data/test/rodzilla/web_service_test.rb +35 -12
- data/test/test_helper.rb +50 -1
- metadata +25 -73
- metadata.gz.sig +0 -0
- data/lib/rodzilla/exception.rb +0 -4
@@ -3,19 +3,19 @@ module Rodzilla
|
|
3
3
|
class Bugzilla < Base
|
4
4
|
|
5
5
|
def version
|
6
|
-
rpc_call
|
6
|
+
rpc_call :version
|
7
7
|
end
|
8
8
|
|
9
9
|
def time
|
10
|
-
rpc_call
|
10
|
+
rpc_call :time
|
11
11
|
end
|
12
12
|
|
13
13
|
def timezone
|
14
|
-
rpc_call
|
14
|
+
rpc_call :timezone
|
15
15
|
end
|
16
16
|
|
17
17
|
def extensions
|
18
|
-
rpc_call
|
18
|
+
rpc_call :extensions
|
19
19
|
end
|
20
20
|
|
21
21
|
end
|
@@ -6,19 +6,19 @@ module Rodzilla
|
|
6
6
|
|
7
7
|
# Returns a list of the ids of the products the user can search on.
|
8
8
|
def get_selectable_products
|
9
|
-
rpc_call
|
9
|
+
rpc_call :get_selectable_products
|
10
10
|
end
|
11
11
|
|
12
12
|
def get_enterable_products
|
13
|
-
rpc_call
|
13
|
+
rpc_call :get_selectable_products
|
14
14
|
end
|
15
15
|
|
16
16
|
def get_accessible_products
|
17
|
-
rpc_call
|
17
|
+
rpc_call :get_accessible_products
|
18
18
|
end
|
19
19
|
|
20
20
|
def get_products(params={})
|
21
|
-
rpc_call
|
21
|
+
rpc_call :get, params
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Rodzilla
|
2
|
+
module Util
|
3
|
+
|
4
|
+
# Extracts the class name from a module string
|
5
|
+
#
|
6
|
+
# example:
|
7
|
+
# demodulize( Rodzilla::WebService::Error ) => 'Error'
|
8
|
+
#
|
9
|
+
# returns the String path argument
|
10
|
+
def demodulize(path)
|
11
|
+
path = path.to_s
|
12
|
+
if i = path.rindex('::')
|
13
|
+
path[(i+2)..-1]
|
14
|
+
else
|
15
|
+
path
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module_function :demodulize
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
data/lib/rodzilla/version.rb
CHANGED
@@ -0,0 +1,67 @@
|
|
1
|
+
module Rodzilla
|
2
|
+
class WebService
|
3
|
+
|
4
|
+
attr_accessor :base_url, :format, :resource
|
5
|
+
|
6
|
+
# base_url - The String full uri of the Bugzilla api server
|
7
|
+
# username - The String containing the bugzilla authorized users username
|
8
|
+
# password - The String containing the bugzilla authorized users password
|
9
|
+
# format - The request/response format which defaults to :json
|
10
|
+
def initialize(base_url, username, password, format=:json)
|
11
|
+
@base_url = base_url
|
12
|
+
@username = username
|
13
|
+
@password = password
|
14
|
+
@format = format
|
15
|
+
end
|
16
|
+
|
17
|
+
# Provide a shortcut for instantiation Bug objects
|
18
|
+
#
|
19
|
+
# Returns an instance of the Rodzilla::Resource::Bug class
|
20
|
+
def bugs
|
21
|
+
bugzilla_resource('Bug')
|
22
|
+
end
|
23
|
+
|
24
|
+
# Provide a shortcut for instantiation Bugzilla objects
|
25
|
+
#
|
26
|
+
# Returns an instance of the Rodzilla::Resource::Bugzilla class
|
27
|
+
def bugzilla
|
28
|
+
bugzilla_resource('Bugzilla')
|
29
|
+
end
|
30
|
+
|
31
|
+
# Provide a shortcut for instantiation Classification objects
|
32
|
+
#
|
33
|
+
# Returns an instance of the Rodzilla::Resource::Classification class
|
34
|
+
def classifications
|
35
|
+
bugzilla_resource('Classification')
|
36
|
+
end
|
37
|
+
|
38
|
+
# Provide a shortcut for instantiation Group objects
|
39
|
+
#
|
40
|
+
# Returns an instance of the Rodzilla::Resource::Group class
|
41
|
+
def groups
|
42
|
+
bugzilla_resource('Group')
|
43
|
+
end
|
44
|
+
|
45
|
+
# Provide a shortcut for instantiation Product objects
|
46
|
+
#
|
47
|
+
# Returns an instance of the Rodzilla::Resource::Product class
|
48
|
+
def products
|
49
|
+
bugzilla_resource('Product')
|
50
|
+
end
|
51
|
+
|
52
|
+
# Provide a shortcut for instantiation User objects
|
53
|
+
#
|
54
|
+
# Returns an instance of the Rodzilla::Resource::User class
|
55
|
+
def users
|
56
|
+
bugzilla_resource('User')
|
57
|
+
end
|
58
|
+
|
59
|
+
def bugzilla_resource(resource)
|
60
|
+
raise Rodzilla::Error::ResourceNotFoundError, "Error: Rodzilla::Resource::#{resource} does not exist." unless Rodzilla::Resource.constants.include?(resource.to_sym)
|
61
|
+
@resource = Object.module_eval("Rodzilla::Resource::#{resource}").new(@base_url, @username, @password, @format)
|
62
|
+
end
|
63
|
+
|
64
|
+
protected :bugzilla_resource
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
data/rodzilla.gemspec
CHANGED
@@ -22,11 +22,6 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
24
|
spec.add_dependency "httparty"
|
25
|
-
spec.add_dependency "libxml-ruby"
|
26
|
-
spec.add_dependency "yajl-ruby"
|
27
25
|
|
28
26
|
spec.add_development_dependency "bundler", "~> 1.3"
|
29
|
-
spec.add_development_dependency "minitest"
|
30
|
-
spec.add_development_dependency "rake"
|
31
|
-
spec.add_development_dependency "debugger", "~> 1.6.2"
|
32
27
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
{"error":null,"id":1,"result":{"extensions":{"AutoComplete":{"version":"0.1"}}}}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"error":null,"id":1,"result":{"version":"4.4"}}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe Rodzilla::JsonRpc::Error do
|
4
|
+
|
5
|
+
describe "Exceptions" do
|
6
|
+
it "it should have a InvalidResponseId" do
|
7
|
+
Rodzilla::JsonRpc::Error.constants.must_include(:InvalidResponseId)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "it should have a UnsupportedHttpMethod" do
|
11
|
+
Rodzilla::JsonRpc::Error.constants.must_include(:UnsupportedHttpMethod)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "it should have a ResponseError" do
|
15
|
+
Rodzilla::JsonRpc::Error.constants.must_include(:ResponseError)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "it should have a ClientError which inherits from ResponseError" do
|
19
|
+
Rodzilla::JsonRpc::Error.constants.must_include(:ClientError)
|
20
|
+
Rodzilla::JsonRpc::Error::ClientError.superclass.must_equal(Rodzilla::JsonRpc::Error::ResponseError)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "it should have a ServerError which inherits from ResponseError" do
|
24
|
+
Rodzilla::JsonRpc::Error.constants.must_include(:ServerError)
|
25
|
+
Rodzilla::JsonRpc::Error::ServerError.superclass.must_equal(Rodzilla::JsonRpc::Error::ResponseError)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "it should have a HttpError" do
|
29
|
+
Rodzilla::JsonRpc::Error.constants.must_include(:HttpError)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
describe Rodzilla::JsonRpc::Request do
|
4
|
+
before do
|
5
|
+
@request = Rodzilla::JsonRpc::Request.new
|
6
|
+
def new_breq(&block)
|
7
|
+
Rodzilla::JsonRpc::Request.new(&block)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should yield itself if a block is given on initialize" do
|
12
|
+
r = new_breq { |req| req.id = 15 }
|
13
|
+
r.id.must_equal(15)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should have a method get_request_object" do
|
17
|
+
@request.must_respond_to(:get_request_object)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "get_request_object should return a hash with id, method, and params" do
|
21
|
+
r = new_breq do |req|
|
22
|
+
req.id = 5
|
23
|
+
req.method = 'Test'
|
24
|
+
req.params = { name: 'nada' }
|
25
|
+
end
|
26
|
+
|
27
|
+
obj = r.get_request_object
|
28
|
+
obj.must_be_kind_of(Hash)
|
29
|
+
|
30
|
+
obj.keys.must_include(:id)
|
31
|
+
obj.keys.must_include(:method)
|
32
|
+
obj.keys.must_include(:params)
|
33
|
+
|
34
|
+
obj[:params].must_be_kind_of(Array)
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
it "serialize should a valid JSON String" do
|
39
|
+
r = new_breq { |req| req.id = 5; req.method = "Hello" }
|
40
|
+
r.serialize.must_be_kind_of(String)
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "attributes" do
|
44
|
+
it "should have methods 'method' and 'method='" do
|
45
|
+
@request.must_respond_to(:method)
|
46
|
+
@request.must_respond_to(:method=)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should have methods params and params=" do
|
50
|
+
@request.must_respond_to(:params)
|
51
|
+
@request.must_respond_to(:params=)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should have methods id and id=" do
|
55
|
+
@request.must_respond_to(:id)
|
56
|
+
@request.must_respond_to(:id=)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should have methods headers and headers=" do
|
60
|
+
@request.must_respond_to(:headers)
|
61
|
+
@request.must_respond_to(:headers=)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
describe Rodzilla::JsonRpc::Response do
|
4
|
+
|
5
|
+
before do
|
6
|
+
def new_response; Rodzilla::JsonRpc::Response.new; end
|
7
|
+
@response = Rodzilla::JsonRpc::Response.new
|
8
|
+
end
|
9
|
+
|
10
|
+
it "error should always be nil after initialization" do
|
11
|
+
new_response.error.must_be_nil
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "read_http_response" do
|
15
|
+
it "should respond_to read_http_response" do
|
16
|
+
@response.must_respond_to(:read_http_response)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should raise an ArgumentError when no args" do
|
20
|
+
lambda {
|
21
|
+
@response.read_http_response
|
22
|
+
}.must_raise(ArgumentError)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "accessors" do
|
27
|
+
it "should have method id & id=" do
|
28
|
+
@response.must_respond_to(:id)
|
29
|
+
@response.must_respond_to(:id=)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should have methods error & error=" do
|
33
|
+
@response.must_respond_to(:error)
|
34
|
+
@response.must_respond_to(:error=)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should have methods result & result=" do
|
38
|
+
@response.must_respond_to(:result)
|
39
|
+
@response.must_respond_to(:result=)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe Rodzilla::JsonRpc::Service do
|
4
|
+
before do
|
5
|
+
def new_service; Rodzilla::JsonRpc::Service.new('http://bugzilla.test.com/jsonrpc.cgi', 'user', 'passwd'); end
|
6
|
+
@service = Rodzilla::JsonRpc::Service.new('http://bugzilla.test.com/jsonrpc.cgi', 'user', 'passwd')
|
7
|
+
stub_bugzilla_request('Bugzilla.version')
|
8
|
+
@version_body = method_fixture('Bugzilla_version.json').read
|
9
|
+
end
|
10
|
+
|
11
|
+
it "must include HTTParty" do
|
12
|
+
@service.class.ancestors.must_include(HTTParty)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "must set Bugzilla_login and Bugzilla_password on initialize" do
|
16
|
+
s = new_service
|
17
|
+
s.instance_variable_get(:@credentials).wont_be_nil
|
18
|
+
s.credentials.must_equal({ Bugzilla_login: "user", Bugzilla_password: "passwd" })
|
19
|
+
end
|
20
|
+
|
21
|
+
it "execute_request_and_response should return the Response#result" do
|
22
|
+
s = Rodzilla::JsonRpc::Service.new('http://bugzilla.test.com/jsonrpc.cgi', 'user', 'passwd')
|
23
|
+
res = s.execute_request_and_response(:post)
|
24
|
+
res.must_be_kind_of(Hash)
|
25
|
+
res.must_equal(s.rpc_response.result)
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "cycle_id checks" do
|
29
|
+
|
30
|
+
it "generate_cycle_id should return 1" do
|
31
|
+
@service.send(:generate_cycle_id).must_equal(1)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "check_cycle_id should return false if request.id is not equal to response.id" do
|
35
|
+
s = new_service
|
36
|
+
s.send(:setup_request)
|
37
|
+
s.rpc_request.id = 5
|
38
|
+
s.rpc_response = Rodzilla::JsonRpc::Response.new
|
39
|
+
s.rpc_response.id = 4
|
40
|
+
s.send(:check_cycle_id).must_equal(false)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "check_cycle_id should return true if request.id and response.id are equal" do
|
44
|
+
s = new_service
|
45
|
+
s.send(:setup_request)
|
46
|
+
s.rpc_request.id = 3
|
47
|
+
s.rpc_response = Rodzilla::JsonRpc::Response.new
|
48
|
+
s.rpc_response.id = 3
|
49
|
+
s.send(:check_cycle_id).must_equal(true)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
describe "send_request!" do
|
55
|
+
it "should raise an ArgumentError when no rpc_method is supplied" do
|
56
|
+
lambda { @service.send_request! }.must_raise(ArgumentError)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should raise a UnsupportedHttpMethod error when a http_method besides GET or POST is used" do
|
60
|
+
lambda {
|
61
|
+
@service.send_request!('Bugzilla.version', {}, :put)
|
62
|
+
}.must_raise(Rodzilla::JsonRpc::Error::UnsupportedHttpMethod)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should return a JSON Hash for a successfull API call" do
|
66
|
+
@service.send_request!('Bugzilla.version').must_be_kind_of(Hash)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "setup request" do
|
71
|
+
|
72
|
+
it "should instantiate the request object" do
|
73
|
+
s = new_service
|
74
|
+
s.rpc_request = nil
|
75
|
+
s.send(:setup_request)
|
76
|
+
s.rpc_request.must_be_kind_of(Rodzilla::JsonRpc::Request)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should set the json-rpc header on request.headers object" do
|
80
|
+
s = new_service
|
81
|
+
s.rpc_request = nil
|
82
|
+
s.send(:setup_request)
|
83
|
+
s.rpc_request.headers.must_equal({ 'Content-Type' => 'application/json-rpc' })
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "setup_request_data" do
|
89
|
+
|
90
|
+
it "should raise an ArgumentError when no rcp_method is supplied" do
|
91
|
+
lambda { @service.send(:setup_request_data) }.must_raise(ArgumentError)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should always include the credentials in the params" do
|
95
|
+
new_method = 'Bugzilla.version'
|
96
|
+
new_params = { ids: [1,2,3] }
|
97
|
+
|
98
|
+
orig_creds = @service.credentials.dup
|
99
|
+
|
100
|
+
@service.send(:setup_request_data, new_method, new_params )
|
101
|
+
|
102
|
+
|
103
|
+
@service.rpc_request.method.must_equal(new_method)
|
104
|
+
|
105
|
+
@service.rpc_request.params[:Bugzilla_login].wont_be_nil
|
106
|
+
@service.rpc_request.params[:Bugzilla_password].wont_be_nil
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|