Module: Loginza::Utils
- Defined in:
- lib/loginza/utils.rb
Class Method Summary collapse
- .generate_url(callback_url, options = {}, params = {}) ⇒ Object
- .new_safe_buffer ⇒ Object
- .parse_json(data) ⇒ Object
- .parse_query(value, spliter = '&') ⇒ Object
- .turn_into_json(data) ⇒ Object
Class Method Details
.generate_url(callback_url, options = {}, params = {}) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/loginza/utils.rb', line 29 def self.generate_url(callback_url, = {}, params = {}) params[:token_url] = callback_url params[:lang] ||= ::I18n.locale.to_s providers = [:providers] ? .delete(:providers).map(&:to_s).join(',') : .delete(:provider) query = ::Rack::Utils.build_query(params) query += "&providers_set=#{providers}" "https://loginza.ru/api/widget?#{query}" end |
.new_safe_buffer ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/loginza/utils.rb', line 21 def self.new_safe_buffer if Object.const_defined?('ActiveSupport') ActiveSupport::SafeBuffer.new else String.new end end |
.parse_json(data) ⇒ Object
10 11 12 |
# File 'lib/loginza/utils.rb', line 10 def self.parse_json(data) JSON.parse(data) end |
.parse_query(value, spliter = '&') ⇒ Object
14 15 16 17 18 19 |
# File 'lib/loginza/utils.rb', line 14 def self.parse_query(value, spliter = '&') Rack::Utils.parse_query(value, spliter).inject({}) {|h,(k,v)| h[k] = Array === v ? v.first : v h } end |
.turn_into_json(data) ⇒ Object
6 7 8 |
# File 'lib/loginza/utils.rb', line 6 def self.turn_into_json(data) JSON.generate(data) end |