Class: Rodzilla::JsonRpc::Service
- Inherits:
-
Object
- Object
- Rodzilla::JsonRpc::Service
- Includes:
- HTTParty
- Defined in:
- lib/rodzilla/json_rpc/service.rb
Instance Attribute Summary collapse
-
#credentials ⇒ Object
Returns the value of attribute credentials.
-
#options ⇒ Object
Returns the value of attribute options.
-
#password ⇒ Object
Returns the value of attribute password.
-
#rpc_request ⇒ Object
Returns the value of attribute rpc_request.
-
#rpc_response ⇒ Object
Returns the value of attribute rpc_response.
-
#url ⇒ Object
Returns the value of attribute url.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #execute_request_and_response(http_method) ⇒ Object
-
#initialize(url, username, password) ⇒ Service
constructor
A new instance of Service.
- #send_raw_request(http_method, url, options = {}) ⇒ Object
- #send_request!(rpc_method, params = {}, http_method = :post) ⇒ Object
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
#credentials ⇒ Object
Returns the value of attribute credentials.
8 9 10 |
# File 'lib/rodzilla/json_rpc/service.rb', line 8 def credentials @credentials end |
#options ⇒ Object
Returns the value of attribute options.
8 9 10 |
# File 'lib/rodzilla/json_rpc/service.rb', line 8 def @options end |
#password ⇒ Object
Returns the value of attribute password.
8 9 10 |
# File 'lib/rodzilla/json_rpc/service.rb', line 8 def password @password end |
#rpc_request ⇒ Object
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_response ⇒ Object
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 |
#url ⇒ Object
Returns the value of attribute url.
8 9 10 |
# File 'lib/rodzilla/json_rpc/service.rb', line 8 def url @url end |
#username ⇒ Object
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, ={}) http_response = self.class.send(http_method, url, ) 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 |