ruby-cellsynt 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/cellsynt.rb +78 -0
  3. metadata +58 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4e90f04d77b8ed53f0bce21fd86024ded03bdda2ce302eb40725a10eb5adee4c
4
+ data.tar.gz: 9130496cd64c28388a837584ed414345ec4b30de6f755b60ef1bfc40cc88a1ff
5
+ SHA512:
6
+ metadata.gz: 484dc88dbd4db5988e0be055f28236755be2013f058f5ca9730d4f4ee88e839212bd1b9ad618ea5d3cb43106700805bd4a4cae410cf4597e89f57ac91acee805
7
+ data.tar.gz: 57daa2c57f5038dff0ee7de3988592b78c94ff869b920d8c511b8b73bd9b04bd87328245e925f02a744aefcb6b65d679fe9f488fa9332963775608d9bbdd9039
data/lib/cellsynt.rb ADDED
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+ require 'net/http'
3
+
4
+ # Object for interacting with the api
5
+ class Cellsynt
6
+ SMS_CHAR_LIMIT = 160
7
+ SMS_CONCAT_CHAR_LIMIT = 153
8
+ SMS_CONCAT_HARD_LIMIT = 918
9
+
10
+ attr_accessor :endpoint, :config
11
+
12
+ def initialize(username = nil, password = nil)
13
+ @endpoint = 'https://se-1.cellsynt.net/sms.php'
14
+
15
+ @auth = {
16
+ username: username || ENV['cellsyntUser'],
17
+ password: password || ENV['cellsyntPass']
18
+ }
19
+
20
+ @config = {
21
+ destination: nil,
22
+ allowconcat: nil, # Values: 1 - 6
23
+ originator: nil, # Values: numeric, shortcode & alpha
24
+ expiry: nil, # Value: Unix timestamp
25
+ text: nil, # Type: String
26
+ udh: nil, # Type: Hex
27
+
28
+ originatortype: 'numeric', # Values: numeric, shortcode & alpha
29
+ charset: 'UTF-8', # Values: ISO-8859-1 & UTF-8, Standard: ISO-8859-1
30
+ type: 'text', # Values: text, binary & unicode, Standard: text
31
+ flash: false, # Values: true, false
32
+ class: 1, # Values: 0 - 3, Standard: 1
33
+ pid: 00 # Type: Hex, Standard: 00
34
+ }.compact
35
+ end
36
+
37
+ def adjust_concat(message)
38
+ return nil if message.chars.length == SMS_CONCAT_HARD_LIMIT
39
+
40
+ if message.chars.length > SMS_CHAR_LIMIT
41
+ message_size = message.chars.length
42
+
43
+ (1..6).each do |index|
44
+ if (index * SMS_CONCAT_CHAR_LIMIT) >= message_size
45
+ return index
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ def format_destination(number)
52
+ number.delete_prefix('0')
53
+ number.dup.prepend('0046')
54
+ end
55
+
56
+ def format_originator(number)
57
+ number.delete_prefix('0')
58
+ number.dup.prepend('46')
59
+ end
60
+
61
+ def send
62
+ uri = URI(@endpoint)
63
+ req = Net::HTTP::Post.new(uri)
64
+
65
+ config[:allowconcat] = adjust_concat(@config[:text])
66
+ config[:destination] = format_destination(@config[:destination])
67
+ config[:originator] = format_originator(@config[:originator])
68
+
69
+ form_data = @auth.merge(@config)
70
+ req.set_form_data(form_data)
71
+
72
+ res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true, timeout: 300) do |packet|
73
+ packet.request(req)
74
+ end
75
+
76
+ res.body
77
+ end
78
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-cellsynt
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - beyarz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-06-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubocop
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ description: Ruby gem for interacting with the Cellsynt api
28
+ email: beyar-123@live.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/cellsynt.rb
34
+ homepage: https://rubygems.org/gems/ruby-cellsynt
35
+ licenses:
36
+ - MIT
37
+ metadata:
38
+ source_code_uri: https://github.com/beyarz/ruby-cellsynt
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 3.0.0
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubygems_version: 3.2.3
55
+ signing_key:
56
+ specification_version: 4
57
+ summary: Cellsynt api
58
+ test_files: []