Module: Utility::Callerloc
- Included in:
- Utility
- Defined in:
- lib/utility/callerloc.rb
Constant Summary collapse
- API_URL =
'http://sj.apidata.cn'
- MUNICIPALITIES =
%w(北京 上海 天津 重庆)
Instance Method Summary collapse
Instance Method Details
#mobile_caller_location(number) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/utility/callerloc.rb', line 9 def mobile_caller_location(number) uri = URI API_URL params = {:mobile => number} uri.query = URI.encode_www_form(params) res = Net::HTTP.get_response(uri) result = JSON.load res.body data = result['data'] if result['status'].to_i == 1 #successed output = data['province'] unless MUNICIPALITIES.include?(data['province']) output.to_s + data['city'] + " " + data['types'] else data['message'] end end |