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.0"
Class Method Summary
collapse
Class Method Details
.id_by_prefix(prefix) ⇒ Object
135
136
137
|
# File 'lib/social.rb', line 135
def id_by_prefix(prefix)
id_by_type(type_by_prefix(prefix))
end
|
.id_by_type(type = nil) ⇒ Object
126
127
128
129
|
# File 'lib/social.rb', line 126
def id_by_type(type = nil)
type ||= 'ok'
SOCIAL_TYPES.detect { |id, t| t == type.to_sym }.first
end
|
.Network(network, params = nil) ⇒ Object
111
112
113
114
115
116
117
118
119
|
# File 'lib/social.rb', line 111
def Network(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
|
.params_social_type(params) ⇒ Object
Определяем тип социальной сети по параметрам первоначального запроса. Например если передан параметр viewer_id и sid, то это Вконтакте
84
85
86
87
88
89
90
91
|
# File 'lib/social.rb', line 84
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
139
140
141
|
# File 'lib/social.rb', line 139
def prefix_by_type(type)
SOCIAL_PREFIX[type]
end
|
.request_session_token(params) ⇒ Object
93
94
95
96
97
98
99
100
|
# File 'lib/social.rb', line 93
def request_session_token(params)
case 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
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/social.rb', line 70
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) ⇒ Object
102
103
104
105
106
107
108
109
|
# File 'lib/social.rb', line 102
def request_uid(params)
case 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
62
63
64
|
# File 'lib/social.rb', line 62
def social_params(params)
params.slice(VK_PARAMS + OK_PARAMS)
end
|
.social_request?(params) ⇒ Boolean
66
67
68
|
# File 'lib/social.rb', line 66
def social_request?(params)
request_social_type(params).present?
end
|
.type_by_id(id = nil) ⇒ Object
121
122
123
124
|
# File 'lib/social.rb', line 121
def type_by_id(id = nil)
id ||= 1
SOCIAL_TYPES[id.to_i]
end
|
.type_by_prefix(prefix) ⇒ Object
131
132
133
|
# File 'lib/social.rb', line 131
def type_by_prefix(prefix)
SOCIAL_PREFIX.detect { |type, pref| pref == prefix.to_s }.first
end
|
.type_codes ⇒ Object
143
144
145
|
# File 'lib/social.rb', line 143
def type_codes
SOCIAL_TYPES.values
end
|
.type_ids ⇒ Object
147
148
149
|
# File 'lib/social.rb', line 147
def type_ids
SOCIAL_TYPES.keys
end
|
.type_prefixes ⇒ Object
151
152
153
|
# File 'lib/social.rb', line 151
def type_prefixes
SOCIAL_PREFIX.values
end
|