|
| 1 | +#!/usr/bin/env ruby |
| 2 | + |
| 3 | +$:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib/') |
| 4 | +require 'messagebird' |
| 5 | + |
| 6 | +# ACCESS_KEY = 'YOUR KEY HERE' |
| 7 | +# PHONE_NUMBER = '+31612345678' |
| 8 | + |
| 9 | +unless defined?(ACCESS_KEY) |
| 10 | + puts 'You need to set an ACCESS_KEY constant in this file' |
| 11 | + exit 1 |
| 12 | +end |
| 13 | + |
| 14 | +unless defined?(PHONE_NUMBER) |
| 15 | + puts 'You need to set an PHONE_NUMBER constant in this file' |
| 16 | +end |
| 17 | + |
| 18 | +begin |
| 19 | + # Create a MessageBird client with the specified ACCESS_KEY. |
| 20 | + client = MessageBird::Client.new(ACCESS_KEY) |
| 21 | + |
| 22 | + # Fetch the HLR object for the specified HLR_ID. |
| 23 | + lookup = client.lookup(PHONE_NUMBER) |
| 24 | + |
| 25 | + # Print the object information. |
| 26 | + puts |
| 27 | + puts "The following information was returned as an HLR object:" |
| 28 | + puts |
| 29 | + puts " href : #{lookup.href}" |
| 30 | + puts " countryCode : #{lookup.countryCode}" |
| 31 | + puts " countryPrefix : #{lookup.countryPrefix}" |
| 32 | + puts " phoneNumber : #{lookup.phoneNumber}" |
| 33 | + puts " type : #{lookup.type}" |
| 34 | + |
| 35 | + puts " formats :" |
| 36 | + puts " e164 : #{lookup.formats.e164}" |
| 37 | + puts " international : #{lookup.formats.international}" |
| 38 | + puts " national : #{lookup.formats.national}" |
| 39 | + puts " rfc3966 : #{lookup.formats.rfc3966}" |
| 40 | + |
| 41 | + unless lookup.hlr.nil? |
| 42 | + puts " hlr :" |
| 43 | + puts " id : #{lookup.hlr.id}" |
| 44 | + puts " href : #{lookup.hlr.href}" |
| 45 | + puts " msisdn : #{lookup.hlr.msisdn}" |
| 46 | + puts " reference : #{lookup.hlr.reference}" |
| 47 | + puts " status : #{lookup.hlr.status}" |
| 48 | + puts " createdDatetime : #{lookup.hlr.createdDatetime}" |
| 49 | + puts " statusDatetime : #{lookup.hlr.statusDatetime}" |
| 50 | + end |
| 51 | + |
| 52 | +rescue MessageBird::ErrorException => ex |
| 53 | + puts |
| 54 | + puts 'An error occured while requesting the lookup:' |
| 55 | + puts |
| 56 | + |
| 57 | + ex.errors.each do |error| |
| 58 | + puts " code : #{error.code}" |
| 59 | + puts " description : #{error.description}" |
| 60 | + puts " parameter : #{error.parameter}" |
| 61 | + puts |
| 62 | + end |
| 63 | +end |
0 commit comments