ruby_hlr_client 0.0.9

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.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify dependencies in ruby_hlr_client.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,23 @@
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
+ # Return 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
@@ -0,0 +1,47 @@
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"}]}
23
+ print client.submit_sync_lookup_request('+491788735000', 'IP4', 'SDK-TEST')
24
+ print "\n\n"
25
+
26
+ # 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
27
+ # @param url - callback url on your server
28
+ # @returns string (JSON)
29
+ # Return example: {"success":true,"messages":[],"results":{"url":"http:\/\/user:pass@www.your-server.com\/path\/file"}}
30
+ print client.set_async_callback_url('http://user:pass@www.your-server.com/path/file')
31
+ print "\n\n"
32
+
33
+ # 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.
34
+ # @param msisdns - A list of MSISDNs in international format, e.g. +491788735000
35
+ # @param route - An optional route assignment, see: http://www.hlr-lookups.com/en/routing-options
36
+ # @param storage - An optional storage assignment, see: http://www.hlr-lookups.com/en/storages
37
+ # @returns string (JSON)
38
+ #
39
+ # 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"}}
40
+ print client.submit_async_lookup_request(['+491788735000', '+491788735001'])
41
+ print "\n\n"
42
+
43
+ # Returns the remaining balance (EUR) in your account.
44
+ # @returns string (JSON)
45
+ # Return example: {"success":true,"messages":[],"results":{"balance":"5878.24600"}}
46
+ print client.get_balance
47
+ print "\n"
@@ -0,0 +1,36 @@
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
+ # Return 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"}]}
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
@@ -0,0 +1,142 @@
1
+ require 'rest_client'
2
+
3
+ module RubyHlrClient
4
+
5
+ class HlrClient
6
+
7
+ # Initializes the HLR Lookup Client
8
+ # @param username - www.hlr-lookups.com username
9
+ # @param password - www.hlr-lookups.com password
10
+ # @param ssl - set to false to disable SSL
11
+ # @constructor
12
+ def initialize(username, password, ssl = true)
13
+ @username = username
14
+ @password = password
15
+ @url = "#{ssl ? 'https' : 'http'}://www.hlr-lookups.com/api"
16
+ end
17
+
18
+ # Submits a synchronous HLR Lookup request. The HLR is queried in real time and results presented in the response body.
19
+ # @param msisdn - An MSISDN in international format, e.g. +491788735000
20
+ # @param route - An optional route assignment, see: http://www.hlr-lookups.com/en/routing-options
21
+ # @param storage - An optional storage assignment, see: http://www.hlr-lookups.com/en/storages
22
+ # @returns string (JSON)
23
+ #
24
+ # 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"}]}
25
+ def submit_sync_lookup_request(msisdn, route = nil, storage = nil)
26
+
27
+ params = {
28
+ :action => 'submitSyncLookupRequest',
29
+ :msisdn => msisdn,
30
+ :username => @username,
31
+ :password => @password
32
+ }
33
+
34
+ unless route.nil?
35
+ params.merge!(route: route)
36
+ end
37
+
38
+ unless storage.nil?
39
+ params.merge!(storage: storage)
40
+ end
41
+
42
+ send_request(params)
43
+
44
+ end
45
+
46
+ # 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.
47
+ # @param msisdns - A list of MSISDNs in international format, e.g. +491788735000
48
+ # @param route - An optional route assignment, see: http://www.hlr-lookups.com/en/routing-options
49
+ # @param storage - An optional storage assignment, see: http://www.hlr-lookups.com/en/storages
50
+ # @returns string (JSON)
51
+ #
52
+ # 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"}}
53
+ def submit_async_lookup_request(msisdns, route = nil, storage = nil)
54
+
55
+ params = {
56
+ :action => 'submitAsyncLookupRequest',
57
+ :msisdns => msisdns_to_string(msisdns),
58
+ :username => @username,
59
+ :password => @password
60
+ }
61
+
62
+ unless route.nil?
63
+ params.merge!(route: route)
64
+ end
65
+
66
+ unless storage.nil?
67
+ params.merge!(storage: storage)
68
+ end
69
+
70
+ send_request(params)
71
+
72
+ end
73
+
74
+ # 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
75
+ # @param url - callback url on your server
76
+ # @returns string (JSON)
77
+ # Return example: {"success":true,"messages":[],"results":{"url":"http:\/\/user:pass@www.your-server.com\/path\/file"}}
78
+ def set_async_callback_url(url)
79
+
80
+ send_request({
81
+ :action => 'setAsyncCallbackUrl',
82
+ :url => url,
83
+ :username => @username,
84
+ :password => @password
85
+ })
86
+
87
+ end
88
+
89
+ # Returns the remaining balance (EUR) in your account.
90
+ # @returns string (JSON)
91
+ # Return example: {"success":true,"messages":[],"results":{"balance":"5878.24600"}}
92
+ def get_balance
93
+
94
+ send_request({
95
+ :action => 'getBalance',
96
+ :username => @username,
97
+ :password => @password
98
+ })
99
+
100
+ end
101
+
102
+ def send_request(params)
103
+
104
+ response = RestClient.get @url, :params => params
105
+
106
+ unless response.code == 200
107
+ return generate_error_result("HTTP Status Code #{response.code}")
108
+ end
109
+
110
+ response.to_str
111
+
112
+ end
113
+
114
+ def generate_error_result(message)
115
+
116
+ {:success => false, :fieldErrors => [], :globalErrors => ["#{message}"]}.to_json
117
+
118
+ end
119
+
120
+ def msisdns_to_string(msisdns)
121
+
122
+ string = ''
123
+ c = 0
124
+ msisdns.each { |msisdn|
125
+
126
+ if c > 0
127
+ string += ','
128
+ end
129
+
130
+ string += msisdn
131
+
132
+ c = c+1
133
+
134
+ }
135
+
136
+ string
137
+
138
+ end
139
+
140
+ end
141
+
142
+ end
@@ -0,0 +1,3 @@
1
+ module RubyHlrClient
2
+ VERSION = '0.0.9'
3
+ end
@@ -0,0 +1,3 @@
1
+ module RubyHlrClient
2
+ # Your code goes here...
3
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'ruby_hlr_client/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'ruby_hlr_client'
7
+ s.version = RubyHlrClient::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ['Velocity Made Good Ltd.']
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}
13
+
14
+ s.add_dependency 'sinatra'
15
+ s.add_dependency 'rest_client'
16
+ s.add_dependency 'json'
17
+
18
+ s.rubyforge_project = 'ruby_hlr_client'
19
+
20
+ s.files = `git ls-files`.split("\n")
21
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
23
+ s.require_paths = ['lib']
24
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby_hlr_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.9
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Velocity Made Good Ltd.
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-12-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sinatra
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rest_client
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: json
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description:
63
+ email:
64
+ - service@hlr-lookups.com
65
+ executables:
66
+ - test_callback_handler.rb
67
+ - test_client.rb
68
+ extensions: []
69
+ extra_rdoc_files: []
70
+ files:
71
+ - .gitignore
72
+ - Gemfile
73
+ - Rakefile
74
+ - bin/test_callback_handler.rb
75
+ - bin/test_client.rb
76
+ - lib/ruby_hlr_client.rb
77
+ - lib/ruby_hlr_client/hlr_callback_handler.rb
78
+ - lib/ruby_hlr_client/hlr_client.rb
79
+ - lib/ruby_hlr_client/version.rb
80
+ - ruby_hlr_client.gemspec
81
+ homepage: http://www.hlr-lookups.com
82
+ licenses: []
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project: ruby_hlr_client
101
+ rubygems_version: 1.8.29
102
+ signing_key:
103
+ specification_version: 3
104
+ summary: Official HLR Lookup API Ruby SDK by www.hlr-lookups.com
105
+ test_files: []