Module: Social
- Defined in:
- lib/social.rb,
lib/social/env.rb,
lib/social/config.rb,
lib/social/balance.rb,
lib/social/network.rb,
lib/social/version.rb,
lib/social/networks.rb,
lib/social/determinant.rb
Defined Under Namespace
Modules: Balance
Classes: Config, Determinant, Env, Network, Networks
Constant Summary
collapse
- SOCIAL_TYPES =
{
1 => :ok,
2 => :vk,
3 => :fb
}
- SOCIAL_PREFIX =
{
:ok => 'odkl',
:vk => 'vk',
:fb => 'fb'
}
- VK_PARAMS =
%w(
api_url api_id api_settings viewer_id
viewer_type sid secret access_token
user_id group_id is_app_user auth_key
language parent_language ad_info
is_secure ads_app_id referrer lc_name hash
)
- OK_PARAMS =
%w(
authorized ip_geo_location api_server
new_sig apiconnection first_start
clientLog session_secret_key
application_key auth_sig web_server
session_key logged_user_id sig
)
- VERSION =
"0.3.3"
Class Method Summary
collapse
Class Method Details
.by_name(network, params = nil) ⇒ Object
Also known as:
Network
112
113
114
115
116
117
118
119
120
|
# File 'lib/social.rb', line 112
def by_name(network, params = nil)
raise 'Not set network' unless network
unless SOCIAL_TYPES.values.include?(network.to_sym)
raise "Can`t find network type: #{network}"
end
Social::Networks.instance.site(network.to_sym, params)
end
|
.current(params = nil) ⇒ Object
124
125
126
|
# File 'lib/social.rb', line 124
def current(params = nil)
by_name(Social::Env.type)
end
|
.id_by_prefix(prefix) ⇒ Object
142
143
144
|
# File 'lib/social.rb', line 142
def id_by_prefix(prefix)
id_by_type(type_by_prefix(prefix))
end
|
.id_by_type(type = nil) ⇒ Object
133
134
135
136
|
# File 'lib/social.rb', line 133
def id_by_type(type = nil)
type ||= 'ok'
SOCIAL_TYPES.detect { |id, t| t == type.to_sym }.first
end
|
.params_social_type(params) ⇒ Object
Определяем тип социальной сети по параметрам первоначального запроса. Например если передан параметр viewer_id и sid, то это Вконтакте
85
86
87
88
89
90
91
92
|
# File 'lib/social.rb', line 85
def params_social_type(params)
case
when params[:viewer_id].present? && params[:sid].present? then :vk
when params[:logged_user_id].present? && params[:session_key].present? then :ok
else
nil
end
end
|
.prefix_by_type(type) ⇒ Object
146
147
148
|
# File 'lib/social.rb', line 146
def prefix_by_type(type)
SOCIAL_PREFIX[type]
end
|
.request_session_token(params, type = nil) ⇒ Object
94
95
96
97
98
99
100
101
|
# File 'lib/social.rb', line 94
def request_session_token(params, type = nil)
case (type || request_social_type(params))
when :vk then "vk::#{params[:sid]}"
when :ok then "ok::#{params[:session_key]}"
else
raise 'Not defined social type'
end
end
|
.request_social_type(params) ⇒ Object
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/social.rb', line 71
def request_social_type(params)
if social_env = (params[:social_env])
params[:social_env][:type]
else
params_social_type(params)
end
end
|
.request_uid(params, type = nil) ⇒ Object
103
104
105
106
107
108
109
110
|
# File 'lib/social.rb', line 103
def request_uid(params, type = nil)
case (type || request_social_type(params))
when :vk then "vk::#{params[:user_id]}"
when :ok then "ok::#{params[:logged_user_id]}"
else
raise 'Not defined social type'
end
end
|
.social_params(params) ⇒ Object
63
64
65
|
# File 'lib/social.rb', line 63
def social_params(params)
params.slice(VK_PARAMS + OK_PARAMS)
end
|
.social_request?(params) ⇒ Boolean
67
68
69
|
# File 'lib/social.rb', line 67
def social_request?(params)
request_social_type(params).present?
end
|
.type_by_id(id = nil) ⇒ Object
128
129
130
131
|
# File 'lib/social.rb', line 128
def type_by_id(id = nil)
id ||= 1
SOCIAL_TYPES[id.to_i]
end
|
.type_by_prefix(prefix) ⇒ Object
138
139
140
|
# File 'lib/social.rb', line 138
def type_by_prefix(prefix)
SOCIAL_PREFIX.detect { |type, pref| pref == prefix.to_s }.first
end
|
.type_codes ⇒ Object
150
151
152
|
# File 'lib/social.rb', line 150
def type_codes
SOCIAL_TYPES.values
end
|
.type_ids ⇒ Object
154
155
156
|
# File 'lib/social.rb', line 154
def type_ids
SOCIAL_TYPES.keys
end
|
.type_prefixes ⇒ Object
158
159
160
|
# File 'lib/social.rb', line 158
def type_prefixes
SOCIAL_PREFIX.values
end
|