Class: Rodzilla::JsonRpc::Service

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/rodzilla/json_rpc/service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, username, password) ⇒ Service

Returns a new instance of Service.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rodzilla/json_rpc/service.rb', line 11

def initialize(url, username, password)
  @url = url
  @options = {}
  @username = username
  @password = password
  @credentials = {
    Bugzilla_login: @username,
    Bugzilla_password: @password
  }
  setup_request
end

Instance Attribute Details

#credentialsObject

Returns the value of attribute credentials.



8
9
10
# File 'lib/rodzilla/json_rpc/service.rb', line 8

def credentials
  @credentials
end

#optionsObject

Returns the value of attribute options.



8
9
10
# File 'lib/rodzilla/json_rpc/service.rb', line 8

def options
  @options
end

#passwordObject

Returns the value of attribute password.



8
9
10
# File 'lib/rodzilla/json_rpc/service.rb', line 8

def password
  @password
end

#rpc_requestObject

Returns the value of attribute rpc_request.



8
9
10
# File 'lib/rodzilla/json_rpc/service.rb', line 8

def rpc_request
  @rpc_request
end

#rpc_responseObject

Returns the value of attribute rpc_response.



8
9
10
# File 'lib/rodzilla/json_rpc/service.rb', line 8

def rpc_response
  @rpc_response
end

#urlObject

Returns the value of attribute url.



8
9
10
# File 'lib/rodzilla/json_rpc/service.rb', line 8

def url
  @url
end

#usernameObject

Returns the value of attribute username.



8
9
10
# File 'lib/rodzilla/json_rpc/service.rb', line 8

def username
  @username
end

Instance Method Details

#execute_request_and_response(http_method) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/rodzilla/json_rpc/service.rb', line 38

def execute_request_and_response(http_method)
  raw_request(http_method)
  parse_http_response
  raise Rodzilla::JsonRpc::Error::InvalidResponseId unless check_cycle_id
  raise Rodzilla::JsonRpc::Error::ResponseError.new(@rpc_response.error["code"]), @rpc_response.error["message"] if @rpc_response.error
  @rpc_response.result
end

#send_raw_request(http_method, url, options = {}) ⇒ Object



23
24
25
# File 'lib/rodzilla/json_rpc/service.rb', line 23

def send_raw_request(http_method, url, options={})
  http_response = self.class.send(http_method, url, options )
end

#send_request!(rpc_method, params = {}, http_method = :post) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/rodzilla/json_rpc/service.rb', line 27

def send_request!(rpc_method, params={}, http_method=:post)
  setup_request
  setup_request_data(rpc_method, params)

  unless ["post","get"].include?(http_method.to_s.downcase)
    raise Rodzilla::JsonRpc::Error::UnsupportedHttpMethod, "Error: Only GET and POST request are supported HTTP methods."
  end

  execute_request_and_response(http_method)
end