ruby_hlr_client 0.0.18 → 2.0.0

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
- SHA1:
3
- metadata.gz: a11c50a8f15b65f50c14464d678f1fe3e8dd4222
4
- data.tar.gz: 242e2248639d42d9e703d79b73e2a68695616145
2
+ SHA256:
3
+ metadata.gz: b0e1cbd5c9c2b7f194d463ffcfe957adc176a531ebcc828b5da2321047cc73eb
4
+ data.tar.gz: ae9a0145396168bfd6e97322e29966e56dd109a6a006a45c2b97d194bca073e2
5
5
  SHA512:
6
- metadata.gz: 8d3f1a533b476a6e35c357a99e42c4d75d7dd11379d0a988987b1a7c2a0b0db68a691b451952f9152693a1dce0837a52d01664fa09563bab80b0da12fe6448c7
7
- data.tar.gz: 5b6cfab7510b80b29b21be12260ba82841d0d7ad5f4fc8051825d11098678058d568b17ccdb0ee6dde463ac65236862be1abfc97de9edf22b54e0cba96cddef7
6
+ metadata.gz: 231f4d7764deb39e424a8b8b44a2141b58a52fccde61488c8e4b3f19813bbaf889f49c785572f4e089be72e13739d2051e091a45019a55bc04a293391c70248c
7
+ data.tar.gz: 8a89336e1803244a7fcb37173dcbafaa0b339450b4d98f02d828f5b5f0134854a524e847935a00014734135d4b128f1ab08a364edf63219fcc5b7dab918bec76
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
3
  # Specify dependencies in ruby_hlr_client.gemspec
4
- gemspec
4
+ gemspec
@@ -0,0 +1,64 @@
1
+ #!/usr/bin/env ruby
2
+ require 'ruby_hlr_client/client'
3
+
4
+ # This file contains examples on how to interact with the HLR Lookup API.
5
+ # All endpoints of the API are documented here: https://www.hlr-lookups.com/en/api-docs
6
+
7
+ # Create an HLR Lookups API client
8
+ # The constructor takes your API Key, API Secret and an optional log file location as parameters
9
+ # Your API Key and Secret can be obtained here: https://www.hlr-lookups.com.com/en/api-settings
10
+
11
+ client = HlrLookupsSDK::Client.new(
12
+ 'YOUR-API-KEY',
13
+ 'YOUR-API-SECRET',
14
+ '/var/log/hlr-lookups-api.log' # an optional log file location
15
+ )
16
+
17
+ # Invoke a request to GET /auth-test (https://www.hlr-lookups.com/en/api-docs#get-auth-test) to see if everything worked
18
+ response = client.get('/auth-test')
19
+
20
+ # The API returns an HTTP status code of 200 if the request was successfully processed, let's have a look.
21
+ print "Status Code: " + response.code.to_s + "\n"
22
+ print "Response Body: " + response.body + "\n"
23
+
24
+ # Submit an HLR Lookup via POST /hlr-lookup (https://www.hlr-lookups.com/en/api-docs#post-hlr-lookup)
25
+ response = client.post('/hlr-lookup', msisdn: '+905536939460')
26
+
27
+ print "HLR Lookup Status Code: " + response.code.to_s + "\n"
28
+ print "HLR Lookup Response Body: " + response.body + "\n"
29
+
30
+ if response.code != 200
31
+ # something went wrong
32
+ print "Received non-OK status code from server." + "\n"
33
+ end
34
+
35
+ # do something with the HLR data
36
+ data = JSON.parse(response.body)
37
+
38
+ # Submit an NT Lookup via POST /nt-lookup (https://www.hlr-lookups.com/en/api-docs#post-nt-lookup)
39
+ response = client.post('/nt-lookup', number: '+905536939460')
40
+
41
+ print "NT Lookup Status Code: " + response.code.to_s + "\n"
42
+ print "NT Lookup Response Body: " + response.body + "\n"
43
+
44
+ if response.code != 200
45
+ # something went wrong
46
+ print "Received non-OK status code from server." + "\n"
47
+ end
48
+
49
+ # do something with the NT data
50
+ data = JSON.parse(response.body)
51
+
52
+ # Submit an MNP Lookup via POST /mnp-lookup (https://www.hlr-lookups.com/en/api-docs#post-mnp-lookup)
53
+ response = client.post('/mnp-lookup', msisdn: '+905536939460')
54
+
55
+ print "MNP Lookup Status Code: " + response.code.to_s + "\n"
56
+ print "MNP Lookup Response Body: " + response.body + "\n"
57
+
58
+ if response.code != 200
59
+ # something went wrong
60
+ print "Received non-OK status code from server." + "\n"
61
+ end
62
+
63
+ # do something with the NT data
64
+ data = JSON.parse(response.body)
@@ -1,3 +1,3 @@
1
- module RubyHlrClient
1
+ module HlrLookupsSDK
2
2
  # Your code goes here...
3
3
  end
@@ -0,0 +1,185 @@
1
+ require 'rest-client'
2
+ require 'json'
3
+ require 'time'
4
+ require 'ruby_hlr_client/config'
5
+ require 'uri'
6
+ require 'openssl'
7
+
8
+ # Ruby implementation of a REST client for the HLR Lookups API
9
+ # see https://www.hlr-lookups.com/en/api-docs
10
+ module HlrLookupsSDK
11
+
12
+ class Client
13
+
14
+ # HLR Lookups API client constructor, initialize this with the API key and secret as given by https://www.hlr-lookups.com/en/api-settings
15
+ # @param key; as given by https://www.hlr-lookups.com/en/api-settings
16
+ # @param secret; as given by https://www.hlr-lookups.com/en/api-settings
17
+ # @param log_file; optional log file path
18
+ # @constructor
19
+ def initialize(key, secret, log_file = NIL)
20
+
21
+ # @string The API Key as given by https://www.hlr-lookups.com/en/api-settings
22
+ @key = key
23
+
24
+ # @string The API Secret as given by https://www.hlr-lookups.com/en/api-settings
25
+ @secret = secret
26
+
27
+ # @string The API version to which we connect (leave it as is)
28
+ @api_version = HlrLookupsSDK::API_VERSION
29
+
30
+ # @string Used in the HTTP user agent (leave it as is)
31
+ @client_name = HlrLookupsSDK::CLIENT_NAME
32
+
33
+ # @string The current version of this SDK, used in the HTTP user agent (leave it as is)
34
+ @client_version = HlrLookupsSDK::CLIENT_VERSION
35
+
36
+ # @string HLR Lookup connect url
37
+ @connect_url = HlrLookupsSDK::CONNECT_URL
38
+
39
+ # @string|NIL Specifies the log file to which to write, if any.
40
+ @log_file = log_file ? log_file : NIL
41
+
42
+ end
43
+
44
+ # Use this method to communicate with GET endpoints
45
+ # @param endpoint (string), e.g. GET /auth-test
46
+ # @param params (hash), a list of GET parameters to be included in the request
47
+ # @return RestClient::Response, https://github.com/rest-client/rest-client/blob/2c72a2e77e2e87d25ff38feba0cf048d51bd5eca/lib/restclient/response.rb
48
+ def get(endpoint, params = {})
49
+
50
+ path = build_connect_url(endpoint) + '?' + URI.encode_www_form(params)
51
+ headers = build_headers(endpoint, 'GET', params)
52
+
53
+ log "GET " + path
54
+ log headers.to_s
55
+
56
+ begin
57
+ response = RestClient::Request.execute(method: :get, url: path, headers: headers, timeout: 15)
58
+ rescue RestClient::ExceptionWithResponse => e
59
+ log e.http_code.to_s + " " + e.response.to_s
60
+ return e.response
61
+ end
62
+
63
+ log response.code.to_s + " " + response.to_s
64
+
65
+ response
66
+
67
+ end
68
+
69
+ # Use this method to communicate with POST endpoints
70
+ # @param endpoint (string), e.g. POST /hlr-lookup
71
+ # @param params (hash), a list of parameters to be included in the request
72
+ # @return RestClient::Response, https://github.com/rest-client/rest-client/blob/2c72a2e77e2e87d25ff38feba0cf048d51bd5eca/lib/restclient/response.rb
73
+ def post(endpoint, params = {})
74
+
75
+ path = build_connect_url(endpoint)
76
+ headers = build_headers(endpoint, 'POST', params)
77
+
78
+ log "POST " + path + " " + params.to_s
79
+ log headers.to_s
80
+
81
+ begin
82
+ response = RestClient::Request.execute(method: :post, url: path, payload: params.to_json, headers: headers, timeout: 15)
83
+ rescue RestClient::ExceptionWithResponse => e
84
+ log e.http_code.to_s + " " + e.response.to_s
85
+ return e.response
86
+ end
87
+
88
+ log response.code.to_s + " " + response.to_s
89
+
90
+ response
91
+
92
+ end
93
+
94
+ # Use this method to communicate with PUT endpoints
95
+ # @param endpoint (string)
96
+ # @param params (hash), a list of parameters to be included in the request
97
+ # @return RestClient::Response, https://github.com/rest-client/rest-client/blob/2c72a2e77e2e87d25ff38feba0cf048d51bd5eca/lib/restclient/response.rb
98
+ def put(endpoint, params = {})
99
+
100
+ path = build_connect_url(endpoint)
101
+ headers = build_headers(endpoint, 'PUT', params)
102
+
103
+ log "PUT " + path + " " + params.to_s
104
+ log headers.to_s
105
+
106
+ begin
107
+ response = RestClient::Request.execute(method: :put, url: path, payload: params.to_json, headers: headers, timeout: 15)
108
+ rescue RestClient::ExceptionWithResponse => e
109
+ log e.http_code.to_s + " " + e.response.to_s
110
+ return e.response
111
+ end
112
+
113
+ log response.code.to_s + " " + response.to_s
114
+
115
+ response
116
+
117
+ end
118
+
119
+ # Use this method to communicate with DELETE endpoints
120
+ # @param endpoint (string)
121
+ # @param params (hash), a list of parameters to be included in the request
122
+ # @return RestClient::Response, https://github.com/rest-client/rest-client/blob/2c72a2e77e2e87d25ff38feba0cf048d51bd5eca/lib/restclient/response.rb
123
+ def delete(endpoint, params = {})
124
+
125
+ path = build_connect_url(endpoint)
126
+ headers = build_headers(endpoint, 'DELETE', params)
127
+
128
+ log "DELETE " + path + " " + params.to_s
129
+ log headers.to_s
130
+
131
+ begin
132
+ response = RestClient::Request.execute(method: :delete, url: path, payload: params.to_json, headers: headers, timeout: 15)
133
+ rescue RestClient::ExceptionWithResponse => e
134
+ log e.http_code.to_s + " " + e.response.to_s
135
+ return e.response
136
+ end
137
+
138
+ log response.code.to_s + " " + response.to_s
139
+
140
+ response
141
+
142
+ end
143
+
144
+ # private class to generate connect url on HLR Lookups servers
145
+ private
146
+ def build_connect_url(endpoint)
147
+ @connect_url + @api_version + endpoint
148
+ end
149
+
150
+ # private class to generate authentication headers
151
+ private
152
+ def build_headers(endpoint, method, params)
153
+
154
+ timestamp = Time.now.to_i
155
+ body = nil
156
+ if method != 'GET'
157
+ body = params.length > 0 ? params.to_json : nil
158
+ end
159
+ data = endpoint + timestamp.to_s + method + body.to_s
160
+
161
+ {
162
+ :"X-Digest-Key" => @key,
163
+ :"X-Digest-Signature" => OpenSSL::HMAC.hexdigest('sha256', @secret, data),
164
+ :"X-Digest-Timestamp" => timestamp,
165
+ :"User-Agent" => @client_name + " " + @client_version + " (" + @key + ")"
166
+ }
167
+
168
+ end
169
+
170
+
171
+ private
172
+ def log(text)
173
+
174
+ if @log_file == nil
175
+ return
176
+ end
177
+
178
+ File.open(@log_file, 'a') { |f| f.write(Time.now.utc.rfc822 + " [HlrLookupsSDK] " + text + "\n") }
179
+ # print Time.now.utc.rfc822 + " [HlrLookupsSDK] " + text + "\n"
180
+
181
+ end
182
+
183
+ end
184
+
185
+ end
@@ -0,0 +1,11 @@
1
+ module HlrLookupsSDK
2
+
3
+ CLIENT_VERSION = '2.0.0'
4
+
5
+ CLIENT_NAME = 'ruby_hlr_client'
6
+
7
+ API_VERSION = 'v2'
8
+
9
+ CONNECT_URL = 'https://www.hlr-lookups.com/api/'
10
+
11
+ end
@@ -1,26 +1,23 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  $:.push File.expand_path('../lib', __FILE__)
3
- require 'ruby_hlr_client/version'
3
+ require 'ruby_hlr_client/config'
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = 'ruby_hlr_client'
7
- s.version = RubyHlrClient::VERSION
7
+ s.version = HlrLookupsSDK::CLIENT_VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ['Velocity Made Good Ltd.']
10
10
  s.email = ['service@hlr-lookups.com']
11
- s.homepage = 'http://www.hlr-lookups.com'
12
- s.summary = %q{Official HLR Lookup API Ruby SDK by www.hlr-lookups.com}
11
+ s.homepage = 'https://www.hlr-lookups.com'
12
+ s.summary = %q{HLR Lookups SDK. Obtain live mobile phone connectivity and portability data from network operators directly.}
13
13
  s.licenses = ['Apache-2.0']
14
14
  s.required_ruby_version = '>= 2.0.0'
15
15
 
16
- s.add_dependency 'sinatra'
17
- s.add_dependency 'rest-client'
18
- s.add_dependency 'json'
19
-
20
- s.rubyforge_project = 'ruby_hlr_client'
16
+ s.add_runtime_dependency 'rest-client', '~> 2.1', '>= 2.1.0'
17
+ s.add_runtime_dependency 'json', '~> 2.3', '>= 2.3.0'
21
18
 
22
19
  s.files = `git ls-files`.split("\n")
23
20
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
24
21
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
25
22
  s.require_paths = ['lib']
26
- end
23
+ end
metadata CHANGED
@@ -1,99 +1,91 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_hlr_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.18
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Velocity Made Good Ltd.
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-19 00:00:00.000000000 Z
11
+ date: 2020-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: sinatra
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - '>='
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - '>='
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: rest-client
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
- - - '>='
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.1'
20
+ - - ">="
32
21
  - !ruby/object:Gem::Version
33
- version: '0'
22
+ version: 2.1.0
34
23
  type: :runtime
35
24
  prerelease: false
36
25
  version_requirements: !ruby/object:Gem::Requirement
37
26
  requirements:
38
- - - '>='
27
+ - - "~>"
39
28
  - !ruby/object:Gem::Version
40
- version: '0'
29
+ version: '2.1'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 2.1.0
41
33
  - !ruby/object:Gem::Dependency
42
34
  name: json
43
35
  requirement: !ruby/object:Gem::Requirement
44
36
  requirements:
45
- - - '>='
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '2.3'
40
+ - - ">="
46
41
  - !ruby/object:Gem::Version
47
- version: '0'
42
+ version: 2.3.0
48
43
  type: :runtime
49
44
  prerelease: false
50
45
  version_requirements: !ruby/object:Gem::Requirement
51
46
  requirements:
52
- - - '>='
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '2.3'
50
+ - - ">="
53
51
  - !ruby/object:Gem::Version
54
- version: '0'
55
- description:
52
+ version: 2.3.0
53
+ description:
56
54
  email:
57
55
  - service@hlr-lookups.com
58
- executables:
59
- - test_callback_handler.rb
60
- - test_client.rb
56
+ executables: []
61
57
  extensions: []
62
58
  extra_rdoc_files: []
63
59
  files:
64
- - .gitignore
60
+ - ".gitignore"
65
61
  - Gemfile
66
- - Rakefile
67
- - bin/test_callback_handler.rb
68
- - bin/test_client.rb
69
- - create_gem.txt
62
+ - examples/example.rb
70
63
  - lib/ruby_hlr_client.rb
71
- - lib/ruby_hlr_client/hlr_callback_handler.rb
72
- - lib/ruby_hlr_client/hlr_client.rb
73
- - lib/ruby_hlr_client/version.rb
64
+ - lib/ruby_hlr_client/client.rb
65
+ - lib/ruby_hlr_client/config.rb
74
66
  - ruby_hlr_client.gemspec
75
- homepage: http://www.hlr-lookups.com
67
+ homepage: https://www.hlr-lookups.com
76
68
  licenses:
77
69
  - Apache-2.0
78
70
  metadata: {}
79
- post_install_message:
71
+ post_install_message:
80
72
  rdoc_options: []
81
73
  require_paths:
82
74
  - lib
83
75
  required_ruby_version: !ruby/object:Gem::Requirement
84
76
  requirements:
85
- - - '>='
77
+ - - ">="
86
78
  - !ruby/object:Gem::Version
87
79
  version: 2.0.0
88
80
  required_rubygems_version: !ruby/object:Gem::Requirement
89
81
  requirements:
90
- - - '>='
82
+ - - ">="
91
83
  - !ruby/object:Gem::Version
92
84
  version: '0'
93
85
  requirements: []
94
- rubyforge_project: ruby_hlr_client
95
- rubygems_version: 2.0.14
96
- signing_key:
86
+ rubygems_version: 3.1.2
87
+ signing_key:
97
88
  specification_version: 4
98
- summary: Official HLR Lookup API Ruby SDK by www.hlr-lookups.com
89
+ summary: HLR Lookups SDK. Obtain live mobile phone connectivity and portability data
90
+ from network operators directly.
99
91
  test_files: []
data/Rakefile DELETED
@@ -1 +0,0 @@
1
- require 'bundler/gem_tasks'
@@ -1,23 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'sinatra'
4
- require 'ruby_hlr_client/hlr_callback_handler'
5
-
6
- set :run, true
7
-
8
- get '/' do
9
-
10
- client = RubyHlrClient::HlrCallbackHandler.new
11
-
12
- # Parses an asynchronous HLR Lookup callback and returns a JSON string with the results.
13
- # @param params
14
- # @returns string (JSON)
15
- #
16
- # Params example: {"success":true,"results":[{"id":"40ebb8d9e7cc","msisdncountrycode":"DE","msisdn":"+491788735001","statuscode":"HLRSTATUS_DELIVERED","hlrerrorcodeid":null,"subscriberstatus":"SUBSCRIBERSTATUS_CONNECTED","imsi":"262032000000000","mccmnc":"26203","mcc":"262","mnc":"03","msin":"2000000000","servingmsc":"491770","servinghlr":null,"originalnetworkname":"178","originalcountryname":"Germany","originalcountrycode":"DE","originalcountryprefix":"+49","originalnetworkprefix":"178","roamingnetworkname":null,"roamingcountryname":null,"roamingcountrycode":null,"roamingcountryprefix":null,"roamingnetworkprefix":null,"portednetworkname":null,"portedcountryname":null,"portedcountrycode":null,"portedcountryprefix":null,"portednetworkprefix":null,"isvalid":"Yes","isroaming":"No","isported":"No","usercharge":"0.0100","inserttime":"2014-12-28 05:53:03.765798+08","storage":"ASYNC-API","route":"IP4"}]}
17
- print client.parse_callback(params)
18
-
19
- # send HTTP response body (OK)
20
- content_type :text
21
- return client.send_response
22
-
23
- end
@@ -1,84 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'ruby_hlr_client/hlr_client'
4
-
5
- # Initializes the HLR Lookup Client
6
- # @param username - www.hlr-lookups.com username
7
- # @param password - www.hlr-lookups.com password
8
- # @param ssl - set to false to disable SSL
9
- # @constructor
10
- client = RubyHlrClient::HlrClient.new(
11
- 'username',
12
- 'password'
13
- )
14
- print "\n"
15
-
16
- # Submits a synchronous HLR Lookup request. The HLR is queried in real time and results presented in the response body.
17
- # @param msisdn - An MSISDN in international format, e.g. +491788735000
18
- # @param route - An optional route assignment, see: http://www.hlr-lookups.com/en/routing-options
19
- # @param storage - An optional storage assignment, see: http://www.hlr-lookups.com/en/storages
20
- # @returns string (JSON)
21
- #
22
- # Return example: {"success":true,"results":[{"id":"e1fdf26531e4","msisdncountrycode":"DE","msisdn":"+491788735000","statuscode":"HLRSTATUS_DELIVERED","hlrerrorcodeid":null,"subscriberstatus":"SUBSCRIBERSTATUS_CONNECTED","imsi":"262031300000000","mccmnc":"26203","mcc":"262","mnc":"03","msin":"1300000000","servingmsc":"140445","servinghlr":null,"originalnetworkname":"E-Plus","originalcountryname":"Germany","originalcountrycode":"DE","originalcountryprefix":"+49","originalnetworkprefix":"178","roamingnetworkname":"Fixed Line Operators and Other Networks","roamingcountryname":"United States","roamingcountrycode":"US","roamingcountryprefix":"+1","roamingnetworkprefix":"404455","portednetworkname":null,"portedcountryname":null,"portedcountrycode":null,"portedcountryprefix":null,"portednetworkprefix":null,"isvalid":"Yes","isroaming":"Yes","isported":"No","usercharge":"0.0100","inserttime":"2014-12-28 06:22:00.328844+08","storage":"SDK-TEST-SYNC-API","route":"IP1","interface":"Sync API"}]}
23
- print client.submit_sync_lookup_request('+491788735000', 'IP4', 'SDK-TEST')
24
- print "\n\n"
25
-
26
- # Submits a synchronous number type lookup request. Results are presented in the response body.
27
- # @param number - An number in international format, e.g. +4989702626
28
- # @param route - An optional route assignment, see: http://www.hlr-lookups.com/en/routing-options
29
- # @param storage - An optional storage assignment, see: http://www.hlr-lookups.com/en/storages
30
- # @returns string (JSON)
31
- #
32
- # Return example: { "success":true, "results":[ { "id":"2ed0788379c6", "number":"+4989702626", "numbertype":"LANDLINE", "state":"COMPLETED", "isvalid":"Yes", "ispossiblyported":"No", "isvalidshortnumber":"No", "isvanitynumber":"No", "qualifiesforhlrlookup":"No", "originalcarrier":null, "mccmnc":null, "mcc":null, "mnc":null, "countrycode":"DE", "region":"Munich", "timezones":[ "Europe\/Berlin" ], "infotext":"This is a landline number.", "usercharge":"0.0050", "inserttime":"2015-12-04 10:36:41.866283+00", "storage":"SYNC-API-NT-2015-12", "route":"LC1" } ] }
33
- print client.submit_sync_number_type_lookup_request('+4989702626', 'LC1', 'SDK-TEST')
34
- print "\n\n"
35
-
36
- # Sets the callback URL for asynchronous lookups. Read more about the concept of asynchronous HLR lookups @ http://www.hlr-lookups.com/en/asynchronous-hlr-lookup-api
37
- # @param url - callback url on your server
38
- # @returns string (JSON)
39
- #
40
- # Return example: {"success":true,"messages":[],"results":{"url":"http:\/\/user:pass@www.your-server.com\/path\/file"}}
41
- print client.set_async_callback_url('http://user:pass@www.your-server.com/path/file')
42
- print "\n\n"
43
-
44
- # Sets the callback URL for asynchronous number type lookups.
45
- # @param url - callback url on your server
46
- # @returns string (JSON)
47
- #
48
- # Return example: {"success":true,"messages":[],"results":{"url":"http:\/\/user:pass@www.your-server.com\/path\/file"}}
49
- print client.set_nt_async_callback_url('http://user:pass@www.your-server.com/path/file')
50
- print "\n\n"
51
-
52
- # Submits asynchronous HLR Lookups containing up to 1,000 MSISDNs per request. Results are sent back asynchronously to a callback URL on your server. Use \VmgLtd\HlrCallbackHandler to capture them.
53
- # @param msisdns - A list of MSISDNs in international format, e.g. +491788735000
54
- # @param route - An optional route assignment, see: http://www.hlr-lookups.com/en/routing-options
55
- # @param storage - An optional storage assignment, see: http://www.hlr-lookups.com/en/storages
56
- # @returns string (JSON)
57
- #
58
- # Return example: {"success":true,"messages":[],"results":{"acceptedMsisdns":[{"id":"e489a092eba7","msisdn":"+491788735000"},{"id":"23ad48bf0c26","msisdn":"+491788735001"}],"rejectedMsisdns":[],"acceptedMsisdnCount":2,"rejectedMsisdnCount":0,"totalCount":2,"charge":0.02,"storage":"SDK-TEST-ASYNC-API","route":"IP4"}}
59
- print client.submit_async_lookup_request(['+491788735000', '+491788735001'])
60
- print "\n\n"
61
-
62
- # Submits asynchronous number type lookups containing up to 1,000 numbers per request. Results are sent back asynchronously to a callback URL on your server.
63
- # @param numbers - A list of numbers in international format, e.g. +4989702626,+491788735000
64
- # @param route - An optional route assignment, see: http://www.hlr-lookups.com/en/routing-options
65
- # @param storage - An optional storage assignment, see: http://www.hlr-lookups.com/en/storages
66
- # @returns string (JSON)
67
- #
68
- # Return example: { "success":true, "messages":[], "results":{ "acceptedNumbers":[ { "id":"f09b30014d5e", "number":"+4989702626" }, { "id":"364c0ad33c02", "number":"+491788735000" } ], "rejectedNumbers":[ { "id":null, "number":"asdf" } ], "acceptedNumberCount":2, "rejectedNumberCount":1, "totalCount":3, "charge":0.01, "storage":"ASYNC-API-NT-2015-12", "route":"LC1" } }
69
- print client.submit_async_number_type_lookup_request(['+4989702626','+491788735000'])
70
- print "\n\n"
71
-
72
- # Returns the remaining balance (EUR) in your account.
73
- # @returns string (JSON)
74
- #
75
- # Return example: {"success":true,"messages":[],"results":{"balance":"5878.24600"}}
76
- print client.get_balance
77
- print "\n\n"
78
-
79
- # Performs a health check on the system status, the user account and availability of each route.
80
- # @returns string (JSON)
81
- #
82
- # Return example: { "success":true, "results":{ "system":{ "state":"up" }, "routes":{ "states":{ "IP1":"up", "ST2":"up", "SV3":"up", "IP4":"up", "XT5":"up", "XT6":"up", "NT7":"up", "LC1":"up" } }, "account":{ "lookupsPermitted":true, "balance":"295.23000" } } }
83
- print client.do_health_check
84
- print "\n"
@@ -1,2 +0,0 @@
1
- 1. rake install
2
- 2. cd pkg/; gem push ruby_hlr_client-VERSION.gem
@@ -1,36 +0,0 @@
1
- require 'json'
2
-
3
- module RubyHlrClient
4
- class HlrCallbackHandler
5
-
6
- # Parses an asynchronous HLR Lookup callback and returns a JSON string with the results.
7
- # @param params
8
- # @returns {*}
9
- #
10
- # Params example: {"success":true,"results":[{"id":"40ebb8d9e7cc","msisdncountrycode":"DE","msisdn":"+491788735001","statuscode":"HLRSTATUS_DELIVERED","hlrerrorcodeid":null,"subscriberstatus":"SUBSCRIBERSTATUS_CONNECTED","imsi":"262032000000000","mccmnc":"26203","mcc":"262","mnc":"03","msin":"2000000000","servingmsc":"491770","servinghlr":null,"originalnetworkname":"178","originalcountryname":"Germany","originalcountrycode":"DE","originalcountryprefix":"+49","originalnetworkprefix":"178","roamingnetworkname":null,"roamingcountryname":null,"roamingcountrycode":null,"roamingcountryprefix":null,"roamingnetworkprefix":null,"portednetworkname":null,"portedcountryname":null,"portedcountrycode":null,"portedcountryprefix":null,"portednetworkprefix":null,"isvalid":"Yes","isroaming":"No","isported":"No","usercharge":"0.0100","inserttime":"2014-12-28 05:53:03.765798+08","storage":"ASYNC-API","route":"IP4","interface":"Async API"}]}
11
- def parse_callback(params)
12
-
13
- unless params.has_key?('json')
14
- return generate_error_result('Invalid callback parameters. Missing json payload.')
15
- end
16
-
17
- params['json']
18
-
19
- end
20
-
21
- def send_response
22
-
23
- 'OK'
24
-
25
- end
26
-
27
- def generate_error_result(message)
28
-
29
- result = {:success => false, :fieldErrors => [], :globalErrors => ["#{message}"]}
30
- result.to_json
31
-
32
- end
33
-
34
- end
35
-
36
- end
@@ -1,237 +0,0 @@
1
- require 'rest-client'
2
- require 'json'
3
-
4
- module RubyHlrClient
5
-
6
- class HlrClient
7
-
8
- # Initializes the HLR Lookup Client
9
- # @param username - www.hlr-lookups.com username
10
- # @param password - www.hlr-lookups.com password
11
- # @param ssl - set to false to disable SSL
12
- # @constructor
13
- def initialize(username, password, ssl = true)
14
- @username = username
15
- @password = password
16
- @url = "#{ssl ? 'https' : 'http'}://www.hlr-lookups.com/api"
17
- end
18
-
19
- # Submits a synchronous HLR Lookup request. The HLR is queried in real time and results presented in the response body.
20
- # @param msisdn - An MSISDN in international format, e.g. +491788735000
21
- # @param route - An optional route assignment, see: http://www.hlr-lookups.com/en/routing-options
22
- # @param storage - An optional storage assignment, see: http://www.hlr-lookups.com/en/storages
23
- # @returns string (JSON)
24
- #
25
- # Return example: {"success":true,"results":[{"id":"e1fdf26531e4","msisdncountrycode":"DE","msisdn":"+491788735000","statuscode":"HLRSTATUS_DELIVERED","hlrerrorcodeid":null,"subscriberstatus":"SUBSCRIBERSTATUS_CONNECTED","imsi":"262031300000000","mccmnc":"26203","mcc":"262","mnc":"03","msin":"1300000000","servingmsc":"140445","servinghlr":null,"originalnetworkname":"E-Plus","originalcountryname":"Germany","originalcountrycode":"DE","originalcountryprefix":"+49","originalnetworkprefix":"178","roamingnetworkname":"Fixed Line Operators and Other Networks","roamingcountryname":"United States","roamingcountrycode":"US","roamingcountryprefix":"+1","roamingnetworkprefix":"404455","portednetworkname":null,"portedcountryname":null,"portedcountrycode":null,"portedcountryprefix":null,"portednetworkprefix":null,"isvalid":"Yes","isroaming":"Yes","isported":"No","usercharge":"0.0100","inserttime":"2014-12-28 06:22:00.328844+08","storage":"SDK-TEST-SYNC-API","route":"IP1","interface":"Sync API"}]}
26
- def submit_sync_lookup_request(msisdn, route = nil, storage = nil)
27
-
28
- params = {
29
- :action => 'submitSyncLookupRequest',
30
- :msisdn => msisdn,
31
- :username => @username,
32
- :password => @password
33
- }
34
-
35
- unless route.nil?
36
- params.merge!(route: route)
37
- end
38
-
39
- unless storage.nil?
40
- params.merge!(storage: storage)
41
- end
42
-
43
- send_request(params)
44
-
45
- end
46
-
47
- # Submits a synchronous number type lookup request. Results are presented in the response body.
48
- # @param number - An number in international format, e.g. +4989702626
49
- # @param route - An optional route assignment, see: http://www.hlr-lookups.com/en/routing-options
50
- # @param storage - An optional storage assignment, see: http://www.hlr-lookups.com/en/storages
51
- # @returns string (JSON)
52
- #
53
- # Return example: {"success":true,"results":[{"id":"2ed0788379c6","number":"+4989702626","numbertype":"LANDLINE","state":"COMPLETED","isvalid":"Yes","invalidreason":null,"ispossiblyported":"No","isvanitynumber":"No","qualifiesforhlrlookup":"No","originalcarrier":null,"mccmnc":null,"mcc":null,"mnc":null,"countrycode":"DE","regions":["Munich"],"timezones":["Europe\/Berlin"],"infotext":"This is a landline number.","usercharge":"0.0050","inserttime":"2015-12-04 10:36:41.866283+00","storage":"SYNC-API-NT-2015-12","route":"LC1","interface":"Sync API"}]}
54
- def submit_sync_number_type_lookup_request(number, route = nil, storage = nil)
55
-
56
- params = {
57
- :action => 'submitSyncLookupRequest',
58
- :number => number,
59
- :username => @username,
60
- :password => @password
61
- }
62
-
63
- unless route.nil?
64
- params.merge!(route: route)
65
- end
66
-
67
- unless storage.nil?
68
- params.merge!(storage: storage)
69
- end
70
-
71
- send_request(params)
72
-
73
- end
74
-
75
- # Submits asynchronous HLR Lookups containing up to 1,000 MSISDNs per request. Results are sent back asynchronously to a callback URL on your server.
76
- # @param msisdns - A list of MSISDNs in international format, e.g. +491788735000,+491788735001
77
- # @param route - An optional route assignment, see: http://www.hlr-lookups.com/en/routing-options
78
- # @param storage - An optional storage assignment, see: http://www.hlr-lookups.com/en/storages
79
- # @returns string (JSON)
80
- #
81
- # Return example: {"success":true,"messages":[],"results":{"acceptedMsisdns":[{"id":"e489a092eba7","msisdn":"+491788735000"},{"id":"23ad48bf0c26","msisdn":"+491788735001"}],"rejectedMsisdns":[],"acceptedMsisdnCount":2,"rejectedMsisdnCount":0,"totalCount":2,"charge":0.02,"storage":"SDK-TEST-ASYNC-API","route":"IP4"}}
82
- def submit_async_lookup_request(msisdns, route = nil, storage = nil)
83
-
84
- params = {
85
- :action => 'submitAsyncLookupRequest',
86
- :msisdns => msisdns_to_string(msisdns),
87
- :username => @username,
88
- :password => @password
89
- }
90
-
91
- unless route.nil?
92
- params.merge!(route: route)
93
- end
94
-
95
- unless storage.nil?
96
- params.merge!(storage: storage)
97
- end
98
-
99
- send_request(params)
100
-
101
- end
102
-
103
- # Submits asynchronous number type lookups containing up to 1,000 numbers per request. Results are sent back asynchronously to a callback URL on your server.
104
- # @param numbers - A list of numbers in international format, e.g. +4989702626,+491788735000
105
- # @param route - An optional route assignment, see: http://www.hlr-lookups.com/en/routing-options
106
- # @param storage - An optional storage assignment, see: http://www.hlr-lookups.com/en/storages
107
- # @returns string (JSON)
108
- #
109
- # Return example: { "success":true, "messages":[], "results":{ "acceptedNumbers":[ { "id":"f09b30014d5e", "number":"+4989702626" }, { "id":"364c0ad33c02", "number":"+491788735000" } ], "rejectedNumbers":[ { "id":null, "number":"asdf" } ], "acceptedNumberCount":2, "rejectedNumberCount":1, "totalCount":3, "charge":0.01, "storage":"ASYNC-API-NT-2015-12", "route":"LC1" } }
110
- def submit_async_number_type_lookup_request(numbers, route = nil, storage = nil)
111
-
112
- params = {
113
- :action => 'submitAsyncNumberTypeLookupRequest',
114
- :msisdns => msisdns_to_string(numbers),
115
- :username => @username,
116
- :password => @password
117
- }
118
-
119
- unless route.nil?
120
- params.merge!(route: route)
121
- end
122
-
123
- unless storage.nil?
124
- params.merge!(storage: storage)
125
- end
126
-
127
- send_request(params)
128
-
129
- end
130
-
131
- # Sets the callback URL for asynchronous HLR lookups. Read more about the concept of asynchronous HLR lookups @ http://www.hlr-lookups.com/en/asynchronous-hlr-lookup-api
132
- # @param url - callback url on your server
133
- # @returns string (JSON)
134
- #
135
- # Return example: {"success":true,"messages":[],"results":{"url":"http:\/\/user:pass@www.your-server.com\/path\/file"}}
136
- def set_async_callback_url(url)
137
-
138
- send_request({
139
- :action => 'setAsyncCallbackUrl',
140
- :url => url,
141
- :username => @username,
142
- :password => @password
143
- })
144
-
145
- end
146
-
147
- # Sets the callback URL for asynchronous number type lookups.
148
- # @param url - callback url on your server
149
- # @returns string (JSON)
150
- #
151
- # Return example: {"success":true,"messages":[],"results":{"url":"http:\/\/user:pass@www.your-server.com\/path\/file"}}
152
- def set_nt_async_callback_url(url)
153
-
154
- send_request({
155
- :action => 'setNtAsyncCallbackUrl',
156
- :url => url,
157
- :username => @username,
158
- :password => @password
159
- })
160
-
161
- end
162
-
163
- # Returns the remaining balance (EUR) in your account.
164
- # @returns string (JSON)
165
- #
166
- # Return example: {"success":true,"messages":[],"results":{"balance":"5878.24600"}}
167
- def get_balance
168
-
169
- send_request({
170
- :action => 'getBalance',
171
- :username => @username,
172
- :password => @password
173
- })
174
-
175
- end
176
-
177
- # Performs a health check on the system status, the user account and availability of each route.
178
- # @returns string (JSON)
179
- #
180
- # Return example: { "success":true, "results":{ "system":{ "state":"up" }, "routes":{ "states":{ "IP1":"up", "ST2":"up", "SV3":"up", "IP4":"up", "XT5":"up", "XT6":"up", "NT7":"up", "LC1":"up" } }, "account":{ "lookupsPermitted":true, "balance":"295.23000" } } }
181
- def do_health_check
182
-
183
- send_request({
184
- :action => 'doHealthCheck',
185
- :username => @username,
186
- :password => @password
187
- })
188
-
189
- end
190
-
191
- private
192
- def send_request(query)
193
-
194
- begin
195
- response = RestClient.get @url, :params => query
196
- rescue => e
197
- return generate_error_result("HTTP Status Code #{e.message}")
198
- end
199
-
200
- unless response.code == 200
201
- return generate_error_result("HTTP Status Code #{response.code}")
202
- end
203
-
204
- response.to_str
205
-
206
- end
207
-
208
- private
209
- def generate_error_result(message)
210
-
211
- {:success => false, :fieldErrors => [], :globalErrors => ["#{message}"]}.to_json
212
-
213
- end
214
-
215
- def msisdns_to_string(msisdns)
216
-
217
- string = ''
218
- c = 0
219
- msisdns.each { |msisdn|
220
-
221
- if c > 0
222
- string += ','
223
- end
224
-
225
- string += msisdn
226
-
227
- c = c+1
228
-
229
- }
230
-
231
- string
232
-
233
- end
234
-
235
- end
236
-
237
- end
@@ -1,3 +0,0 @@
1
- module RubyHlrClient
2
- VERSION = '0.0.18'
3
- end