Class: InternetHakai::SocialClientHandler

Inherits:
ClientHandler show all
Defined in:
lib/internethakai/client_handler.rb

Overview

ソーシャルアプリ用

Constant Summary

Constants inherited from ClientHandler

ClientHandler::UNIQUE_BY_THREAD

Instance Attribute Summary

Attributes inherited from ClientHandler

#performance_id, #vars

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ClientHandler

#extend_vars, #extend_vars2, #initialize, #send, #set_opt, #set_var, #set_var_id

Constructor Details

This class inherits a constructor from InternetHakai::ClientHandler

Class Method Details

.on_config_load(config) ⇒ Object



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/internethakai/client_handler.rb', line 164

def self::on_config_load config
    super
    if(config.has_key? "opensocial_id_path")
        s = File::open(config["opensocial_id_path"]){|io|io.read}
        lines = s.split("\n")
        config["opensocial_ids"] = lines.map{|i|i.split("\t")}.sort_by{rand}
        config['opensocial_id_len'] = config['opensocial_ids'][0].size
    elsif config['opensocial_ids']
        r = []
        config['opensocial_ids'].each do |i|
            r << [i] unless i.is_a? Array
        end
        config['opensocial_ids'] = r
        config['opensocial_id_len'] = config['opensocial_ids'][0].size
    else
        config['opensocial_ids'] = [1]
    end
    if !config['opensocial_app_id']
        config['opensocial_app_id'] = 'app'
    end
    config['opensocial_app_id'] = config['opensocial_app_id'].to_s
    config
end

Instance Method Details

#get_opensocial_idObject



214
215
216
217
218
219
220
221
222
# File 'lib/internethakai/client_handler.rb', line 214

def get_opensocial_id
    ids = @opt["opensocial_ids"]
    id = ids[@performance_id % ids.size]
    1.upto(@opt['opensocial_id_len']-1) do |idx|
        set_var(idx, id[idx])
    end
    r, = id
    r.to_s
end

#handle_body(client, body, opt) ⇒ Object



191
192
193
194
195
196
197
198
199
# File 'lib/internethakai/client_handler.rb', line 191

def handle_body  client, body, opt
    body = super
    if body[body.size-1] != 38
        body += "&"
    end
    id = get_opensocial_id
    app_id = @opt['opensocial_app_id']
    body += "opensocial_app_id=#{app_id}&opensocial_owner_id=#{id}&opensocial_viewer_id=#{id}"
end

#handle_client(client) ⇒ Object



187
188
189
190
# File 'lib/internethakai/client_handler.rb', line 187

def handle_client client
    super
    @client
end

#handle_url(client, url, opt) ⇒ Object



200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/internethakai/client_handler.rb', line 200

def handle_url client, url, opt
    url = super
    if ! url.include? "?"
        url += "?"
    elsif url[url.size-1] == 63
        url
    elsif url[url.size-1] != 38
        url += "&"
    end
    id = get_opensocial_id
    #app_id = @opt['opensocial_app_id']
    #url += "opensocial_app_id=#{app_id}&opensocial_owner_id=#{id}&opensocial_viewer_id=#{id}"
    url += 'opensocial_app_id=' + @opt['opensocial_app_id'] + '&opensocial_owner_id=' + id + '&opensocial_viewer_id=' + id
end