Class: MobilyApiJsonRequestHandler
- Inherits:
-
Object
- Object
- MobilyApiJsonRequestHandler
- Defined in:
- lib/mobily/mobily_api_json_request_handler.rb
Instance Attribute Summary collapse
-
#auth ⇒ Object
Returns the value of attribute auth.
-
#request ⇒ Object
Returns the value of attribute request.
Instance Method Summary collapse
- #add_auth(auth) ⇒ Object
- #add_parameter(key, value) ⇒ Object
- #get_request_data ⇒ Object
- #handle ⇒ Object
-
#initialize(auth = nil, request = MobilyApiRequest.new) ⇒ MobilyApiJsonRequestHandler
constructor
A new instance of MobilyApiJsonRequestHandler.
- #set_api_method(method_name) ⇒ Object
Constructor Details
#initialize(auth = nil, request = MobilyApiRequest.new) ⇒ MobilyApiJsonRequestHandler
Returns a new instance of MobilyApiJsonRequestHandler.
10 11 12 13 14 15 16 |
# File 'lib/mobily/mobily_api_json_request_handler.rb', line 10 def initialize(auth=nil, request=MobilyApiRequest.new) @request = request @params = {} @content_type = 'json' @json_dict = {'Data' => {}} @auth = auth end |
Instance Attribute Details
#auth ⇒ Object
Returns the value of attribute auth.
8 9 10 |
# File 'lib/mobily/mobily_api_json_request_handler.rb', line 8 def auth @auth end |
#request ⇒ Object
Returns the value of attribute request.
8 9 10 |
# File 'lib/mobily/mobily_api_json_request_handler.rb', line 8 def request @request end |
Instance Method Details
#add_auth(auth) ⇒ Object
18 19 20 21 22 |
# File 'lib/mobily/mobily_api_json_request_handler.rb', line 18 def add_auth(auth) if auth.is_a? MobilyApiAuth @json_dict['Data'].merge!({'Auth' => {'mobile' => auth.mobile_number, 'password' => auth.password}}) end end |
#add_parameter(key, value) ⇒ Object
28 29 30 31 32 |
# File 'lib/mobily/mobily_api_json_request_handler.rb', line 28 def add_parameter(key, value) if !value.nil? @params.merge!({key => value}) end end |
#get_request_data ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/mobily/mobily_api_json_request_handler.rb', line 34 def get_request_data if @params.size > 0 @json_dict['Data'].update({'Params' => @params}) end add_auth(@auth) JSON.generate(@json_dict) end |
#handle ⇒ Object
42 43 44 |
# File 'lib/mobily/mobily_api_json_request_handler.rb', line 42 def handle parse_response(request.send(get_request_data, @content_type)) end |
#set_api_method(method_name) ⇒ Object
24 25 26 |
# File 'lib/mobily/mobily_api_json_request_handler.rb', line 24 def set_api_method(method_name) @json_dict['Data'].merge!({'Method' => method_name}) end |