utility 0.1.9 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: efae9fe3c8901e514220f238a0afe301774f2fd5
4
- data.tar.gz: c165887c69908712d15d18b31d4bb5cc8813e868
3
+ metadata.gz: 8d74cffd346611abbd5a1c881f50d170c8754b10
4
+ data.tar.gz: 854d6c7d89f5be379ee50327696a9d8ed20ddbaa
5
5
  SHA512:
6
- metadata.gz: f006ac97803b86d97b066e31e604e20808cf77a7a4bd5939ef4e5a1dbc0050f9e2a4b12cc5cb4cdb171db9a26d3f9d2d2ff2b9b5acdb8da7d5aa30738cf24600
7
- data.tar.gz: b7d97c94abc25c22c9dd852b6c3cbb156ecace921b6e85a06b858517dc14d16df344ada9da75ece171ce4e71ffb9746020dc49df49c97f8c5f326439d8a873fd
6
+ metadata.gz: 88dc6041c8f4c85ad468f24029f11a6077beb3ab6f986d7c145710caf1dffbba9ec2485d5e6d9b17a155f3378b389c5485eb6793204369d72cf47be4f8f27253
7
+ data.tar.gz: 96221b8bc8694ba3d9eed5d11d56a77e49ce6b3436aa32025610cb0541e107a7394cf8849c7e160b2ca67240f4f06558a915895f7096b7709adb084c98cf982a
data/README.md CHANGED
@@ -99,5 +99,11 @@ Utility.try{ Date.current.year.size } #=> nil
99
99
  #=> nil
100
100
  ```
101
101
 
102
+ #### others ####
103
+ ```ruby
104
+ # mobile caller location query (China)
105
+ Utility.mobile_caller_location 13812345678 #=> "江苏连云港 中国移动 GSM"
106
+ ```
107
+
102
108
  ### License ###
103
109
  Released under the [MIT](http://opensource.org/licenses/MIT) license. See LICENSE file for details.
data/lib/utility.rb CHANGED
@@ -9,4 +9,5 @@ module Utility
9
9
  extend URL
10
10
  extend Computer
11
11
  extend Try
12
+ extend Callerloc
12
13
  end
@@ -0,0 +1,25 @@
1
+ require 'uri'
2
+ require 'json'
3
+ require 'net/http'
4
+
5
+ module Utility::Callerloc
6
+ API_URL = 'http://sj.apidata.cn'
7
+ MUNICIPALITIES = %w(北京 上海 天津 重庆)
8
+
9
+ def mobile_caller_location(number)
10
+ uri = URI API_URL
11
+ params = {:mobile => number}
12
+ uri.query = URI.encode_www_form(params)
13
+
14
+ res = Net::HTTP.get_response(uri)
15
+ result = JSON.load res.body
16
+ data = result['data']
17
+ if result['status'].to_i == 1 #successed
18
+ output = data['province'] unless MUNICIPALITIES.include?(data['province'])
19
+ output.to_s + data['city'] + " " + data['types']
20
+ else
21
+ data['message']
22
+ end
23
+ end
24
+
25
+ end
@@ -7,8 +7,7 @@ module Utility::Computer
7
7
  ip = Socket.ip_address_list.detect do |intf|
8
8
  intf.ipv4? &&
9
9
  !intf.ipv4_loopback? &&
10
- !intf.ipv4_multicast? &&
11
- !intf.ipv4_private?
10
+ !intf.ipv4_multicast?
12
11
  end
13
12
  ip.nil?? "IP address not found" : ip.ip_address
14
13
  end
data/lib/utility/try.rb CHANGED
@@ -35,4 +35,3 @@ module Utility::Try
35
35
  end
36
36
 
37
37
  end
38
-
@@ -1,3 +1,3 @@
1
1
  module Utility
2
- VERSION = "0.1.9"
2
+ VERSION = "0.1.11"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: utility
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cenxky
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-04 00:00:00.000000000 Z
11
+ date: 2017-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: macaddr
@@ -98,6 +98,7 @@ files:
98
98
  - bin/setup
99
99
  - lib/utility.rb
100
100
  - lib/utility/base64.rb
101
+ - lib/utility/callerloc.rb
101
102
  - lib/utility/computer.rb
102
103
  - lib/utility/digest.rb
103
104
  - lib/utility/hmac.rb