module EricTools
Constants
- VERSION
Public Class Methods
generate_random_string(length, type=1)
click to toggle source
type=1表示只包含数字,type=2表示只包含字母,type=3表示都包含
# File lib/eric_tools.rb, line 41 def self.generate_random_string length, type=1 case type when 1 rand(10 ** length).to_s(10) when 2 rand(26 ** length).to_s(26) when 3 rand(36 ** length).to_s(36) end end
get_city_name_from_ip(options)
click to toggle source
功能描述¶ ↑
根据ip获取城市名称。
参数说明¶ ↑
ak:需要从百度申请每个应用的ak,用于根据ip查找城市名称,每个ak每天限制调用100万次。 ip: 需要获取城市名称的ip
返回值¶ ↑
返回一个hash , 其中,通地 :city 获取城市名称 :province 获以省份名称 :address 地址详细信息:如 CN|上海|上海|None|CHINANET|0|0
示例¶ ↑
EricTools.get_city_name_from_ip
{:ak=> 'HS8ViRxQT0xMu8d3uARISMif', :ip => '101.231.116.38', :default_province => '上海', :default_city => '上海'}
# File lib/eric_tools.rb, line 66 def self.get_city_name_from_ip options response = RestClient.get("http://api.map.baidu.com/location/ip?ak=#{options[:ak]}&ip=#{options[:ip]}") response = JSON.parse(response.body) {:address => response["address"], :province => response["content"]["address_detail"]["province"], :city => response["content"]["address_detail"]["city"]} rescue {} end
uuid()
click to toggle source