virtualsms-sdk 1.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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/virtualsms.rb +96 -0
  3. metadata +65 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8ca4fddec9f37c3ce2a242a33f80c45737c12351af6e5a6d7d395f5b206e86be
4
+ data.tar.gz: 5697a72089b494b8208988f09f6c5b6878063b906ecab5f36825fbde6e4a215d
5
+ SHA512:
6
+ metadata.gz: 83805c23e7d09896d3122a6157f53a0d656a634bfd0d4aed4e13441904bf7451a58e6012d024b19a5eb1312b54fa876f89d23cad86b25981560aae5f9ecd9a43
7
+ data.tar.gz: d6c331cc558204d238873e2c98f5ed5719845055f23ec7273bf3ea48c5c0de4b1d9c554ea9b3785eabc67ae4f9a8b81e3e7c0a4c256a00f74cc9ff85ebaef9f6
data/lib/virtualsms.rb ADDED
@@ -0,0 +1,96 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'json'
4
+
5
+ # VirtualSMS Ruby SDK — SMS verification with real physical SIM cards.
6
+ #
7
+ # Unlike VoIP services, VirtualSMS uses real SIM cards in hardware modems
8
+ # connected to European and US cellular networks. Near-100% delivery rates
9
+ # on WhatsApp, Telegram, and platforms that block virtual numbers.
10
+ #
11
+ # Get your API key at https://virtualsms.io (Settings → API Keys)
12
+ # API Docs: https://virtualsms.io/api
13
+ # Pricing: https://virtualsms.io/pricing
14
+ #
15
+ # @example Quick start
16
+ # client = VirtualSMS.new('vsms_your_api_key')
17
+ # activation = client.get_number('wa', country: 22) # WhatsApp, UK
18
+ # code = client.wait_for_code(activation[:activation_id])
19
+ # puts "Code: #{code}"
20
+ # client.done(activation[:activation_id])
21
+ class VirtualSMS
22
+ BASE_URL = 'https://virtualsms.io/stubs/handler_api.php'
23
+
24
+ class Error < StandardError; end
25
+ class NoNumbersError < Error; end
26
+
27
+ def initialize(api_key, base_url: BASE_URL)
28
+ @api_key = api_key
29
+ @base_url = base_url
30
+ end
31
+
32
+ # Get current account balance in USD.
33
+ def get_balance
34
+ result = request('getBalance')
35
+ raise Error, result unless result.start_with?('ACCESS_BALANCE:')
36
+ result.split(':')[1].to_f
37
+ end
38
+
39
+ # Request a phone number for SMS verification.
40
+ # @param service [String] Service code ('wa', 'tg', 'go', etc.)
41
+ # @param country [Integer] Country ID (187=US, 22=UK, 12=Germany)
42
+ def get_number(service, country: 187)
43
+ result = request('getNumber', service: service, country: country)
44
+ if result.start_with?('ACCESS_NUMBER:')
45
+ parts = result.split(':')
46
+ { activation_id: parts[1].to_i, phone: parts[2], service: service, country: country }
47
+ elsif result == 'NO_NUMBERS'
48
+ raise NoNumbersError, "No numbers for #{service} in country #{country}"
49
+ else
50
+ raise Error, result
51
+ end
52
+ end
53
+
54
+ # Check status of an activation.
55
+ def get_status(activation_id)
56
+ result = request('getStatus', id: activation_id)
57
+ case result
58
+ when 'STATUS_WAIT_CODE' then { status: 'waiting', code: nil }
59
+ when /^STATUS_OK:/ then { status: 'received', code: result.split(':')[1] }
60
+ when 'STATUS_CANCEL' then { status: 'cancelled', code: nil }
61
+ else { status: result, code: nil }
62
+ end
63
+ end
64
+
65
+ # Mark activation as done.
66
+ def done(activation_id)
67
+ request('setStatus', id: activation_id, status: 6)
68
+ end
69
+
70
+ # Cancel activation and get refund.
71
+ def cancel(activation_id)
72
+ request('setStatus', id: activation_id, status: 8)
73
+ end
74
+
75
+ # Wait for SMS code to arrive.
76
+ # @param timeout [Integer] Max wait in seconds (default: 300)
77
+ # @param poll_interval [Integer] Seconds between checks (default: 5)
78
+ def wait_for_code(activation_id, timeout: 300, poll_interval: 5)
79
+ start = Time.now
80
+ while Time.now - start < timeout
81
+ result = get_status(activation_id)
82
+ return result[:code] if result[:code]
83
+ return nil if result[:status] == 'cancelled'
84
+ sleep(poll_interval)
85
+ end
86
+ nil
87
+ end
88
+
89
+ private
90
+
91
+ def request(action, **params)
92
+ uri = URI(@base_url)
93
+ uri.query = URI.encode_www_form(params.merge(action: action, api_key: @api_key))
94
+ Net::HTTP.get(uri).strip
95
+ end
96
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: virtualsms-sdk
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - VirtualSMS
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-04-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: net-http
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.3'
27
+ description: Ruby SDK for VirtualSMS — SMS verification using real physical SIM cards
28
+ in European and US mobile networks. Supports WhatsApp, Telegram, Google and 700+
29
+ services. Near-100% delivery rates. Crypto payments. API compatible with sms-activate
30
+ protocol.
31
+ email: dev@virtualsms.io
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - lib/virtualsms.rb
37
+ homepage: https://virtualsms.io
38
+ licenses:
39
+ - MIT
40
+ metadata:
41
+ homepage_uri: https://virtualsms.io
42
+ source_code_uri: https://github.com/virtualsms-io/ruby-sdk
43
+ documentation_uri: https://virtualsms.io/api
44
+ changelog_uri: https://github.com/virtualsms-io/ruby-sdk/blob/main/CHANGELOG.md
45
+ bug_tracker_uri: https://github.com/virtualsms-io/ruby-sdk/issues
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 2.7.0
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubygems_version: 3.3.5
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: SMS verification with real physical SIM cards
65
+ test_files: []