Module: Desmos::RequestSupport
Instance Method Summary collapse
- #build_http(uri) ⇒ Object
- #build_uri(object, method, options = {}) ⇒ Object
- #make_request(object, method, options = {}) ⇒ Object
- #parse_response(response) ⇒ Object
- #request!(object, method, options = {}) ⇒ Object
Methods included from DebugMode
Instance Method Details
#build_http(uri) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/desmos/request_support.rb', line 29 def build_http(uri) debug "\n[RequestSupport.build_http] (#{uri.inspect})" http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE http end |
#build_uri(object, method, options = {}) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/desmos/request_support.rb', line 21 def build_uri(object, method, = {}) debug "\n[RequestSupport.build_uri]: (#{object.inspect}, #{method.inspect}, #{.inspect})" query_string = Desmos::Utils.traversal_to_param_string(Desmos::Utils.traverse_params_hash()) uri = URI.parse("#{Configuration.domain}/#{Configuration.version}/#{object}/#{method}?#{query_string}") debug "uri = #{uri.to_s}" uri end |
#make_request(object, method, options = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/desmos/request_support.rb', line 11 def make_request(object, method, = {}) debug "\n[RequestSupport.make_request] (#{object.inspect}, #{method.inspect}, #{.inspect})" uri = build_uri(object, method, ) consumer = OAuth::Consumer.new(Configuration.key, Configuration.secret, :site => Configuration.domain) http = build_http(uri) request = consumer.create_signed_request(:get, "#{uri.path}?#{uri.query}", nil, .merge(:scheme => 'query_string')) debug "request:\n#{request.path}" http.request(request) end |
#parse_response(response) ⇒ Object
37 38 39 40 41 |
# File 'lib/desmos/request_support.rb', line 37 def parse_response(response) debug "\n[RequestSupport.parse_response] (#{response.inspect})" debug "response.body:\n#{response.body}" parsed_response = Yajl::Parser.parse(response.body).recursive_symbolize_keys end |
#request!(object, method, options = {}) ⇒ Object
5 6 7 8 9 |
# File 'lib/desmos/request_support.rb', line 5 def request!(object, method, = {}) debug "\n[RequestSupport.request!] (#{object.inspect}, #{method.inspect}, #{.inspect})" response = make_request(object, method, ) parse_response(response) end |