module Dito
Constants
- VERSION
Public Class Methods
alias(options = {})
click to toggle source
# File lib/dito/alias.rb, line 3 def self.alias(options = {}) Dito.symbolize_keys!(options) settings = Dito.generate_alias_settings(options) return { :error => settings[:error] } if settings[:error].present? Dito::Request.post 'login', "/users/#{settings[:id]}/link", settings[:params] end
api_key()
click to toggle source
# File lib/dito.rb, line 27 def api_key configuration.api_key end
configuration()
click to toggle source
# File lib/dito.rb, line 19 def configuration @configuration ||= Configuration.new end
configure() { |configuration| ... }
click to toggle source
# File lib/dito.rb, line 23 def configure yield(configuration) end
domains(module_name)
click to toggle source
# File lib/dito/domains.rb, line 3 def self.domains module_name domains = { :js => 'js', :analytics => 'analytics', :login => 'login', :events => 'events', :share => 'share', :comments => 'comments', :ranking => 'ranking', :badge => 'badge', :notification => 'notification' } if domains[module_name.to_sym].present? name = domains[module_name.to_sym] url = case @configuration.environment when "production" "https://#{name}.plataformasocial.com.br" when "development" "http://#{name}.dev.plataformasocial.com.br" when "test" "http://#{name}.dev.plataformasocial.com.br" when "staging" "http://#{name}.dev.plataformasocial.com.br" end url end end
environment()
click to toggle source
# File lib/dito.rb, line 35 def environment configuration.environment end
generate_alias_settings(options = {})
click to toggle source
# File lib/dito/alias.rb, line 23 def self.generate_alias_settings(options = {}) id, id_type = Dito.generate_credentials(options) return { :error => { :message => 'Missing the user id param. See the available options here: http://developers.dito.com.br/docs/sdks/ruby' } } if id.blank? return { :error => { :message => 'Missing the accounts param. See the available options here: http://developers.dito.com.br/docs/rest-api/users' } } if options[:accounts].blank? params = { :accounts => options[:accounts] } params[:id_type] = id_type if id_type.present? { :id => id, :params => params } end
generate_credentials(options)
click to toggle source
# File lib/helpers/generate_credentials.rb, line 5 def self.generate_credentials(options) if options[:reference].present? id = options[:reference] id_type = nil elsif options[:facebook_id].present? id = options[:facebook_id] id_type = 'facebook_id' elsif options[:google_plus_id].present? id = options[:google_plus_id] id_type = 'google_plus_id' elsif options[:twitter_id].present? id = options[:twitter_id] id_type = 'twitter_id' elsif options[:id].present? id = options[:id] id_type = 'id' else id = nil id_type = nil end return id, id_type end
identify(user = {})
click to toggle source
# File lib/dito/identify.rb, line 3 def self.identify user = {} Dito.symbolize_keys!(user) params = {} if user[:facebook_id].present? network_name = 'facebook' id = user[:facebook_id] params[:network_name] = 'fb' elsif user[:google_plus_id].present? network_name = 'plus' id = user[:google_plus_id] params[:network_name] = 'pl' elsif user[:twitter_id].present? network_name = 'twitter' id = user[:twitter_id] params[:network_name] = 'tw' elsif user[:id].present? network_name = 'portal' id = user[:id] params[:network_name] = 'pt' else return { :error => { :message => 'Missing the user id param. See the available options here: http://developers.dito.com.br/docs/sdks/ruby' } } end params[:user_data] = {} if network_name == 'portal' params[:user_data].merge!(user) params[:user_data].delete(:id) else params[:user_data][:data] = user[:data] end if params[:user_data][:data].present? && params[:user_data][:data].is_a?(Hash) params[:user_data][:data] = params[:user_data][:data].to_json end params[:access_token] = user[:access_token] if user[:access_token].present? params[:signed_request] = user[:signed_request] if user[:signed_request].present? params[:id_token] = user[:id_token] if user[:id_token].present? Dito::Request.post 'login', "/users/#{network_name}/#{id}/signup", params end
root()
click to toggle source
# File lib/dito.rb, line 14 def self.root File.expand_path '../..', __FILE__ end
secret()
click to toggle source
# File lib/dito.rb, line 31 def secret configuration.secret end
symbolize_keys(thing)
click to toggle source
# File lib/helpers/symbolize_keys.rb, line 16 def self.symbolize_keys(thing) case thing when Array thing.map{|v| symbolize_keys(v)} when Hash inj = thing.inject({}) {|h, (k,v)| h[k] = symbolize_keys(v); h} inj.symbolize_keys else thing end end
symbolize_keys!(thing)
click to toggle source
# File lib/helpers/symbolize_keys.rb, line 5 def self.symbolize_keys!(thing) case thing when Array thing.each{|v| symbolize_keys!(v)} when Hash thing.symbolize_keys! thing.values.each{|v| symbolize_keys!(v)} end thing end
track(options = {})
click to toggle source
# File lib/dito/track.rb, line 3 def self.track options = {} Dito.symbolize_keys!(options) id, id_type = Dito.generate_credentials(options) return { :error => { :message => 'Missing the user id param. See the available options here: http://developers.dito.com.br/docs/sdks/ruby' } } if id.blank? params = { :event => options[:event].to_json } params[:id_type] = id_type if id_type.present? Dito::Request.post 'events', "/users/#{id}/", params end
unalias(options = {})
click to toggle source
# File lib/dito/alias.rb, line 13 def self.unalias(options = {}) Dito.symbolize_keys!(options) settings = Dito.generate_alias_settings(options) return { :error => settings[:error] } if settings[:error].present? Dito::Request.post 'login', "/users/#{settings[:id]}/unlink", settings[:params] end