smsapipl 0.2.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8da986da8c572fcd77cfb8127cca2a99b7d194c22952aa44ce6926f7d5338799
4
+ data.tar.gz: e7a773a4adc5834d7765c0d55c087850673b9f48e36973a0fd388cc77a6cc5db
5
+ SHA512:
6
+ metadata.gz: 6dd091708fc2d73db19a7e845dcb0011c1c62aadc82eed6331deab6a228791ddc279cb45c9dd59d863cda14b0e9da4e0e72ee3b43b5cf872836e57619e28b031
7
+ data.tar.gz: 0a2d920c556422a12ee77531c75c5bc93f3c973fffedb1cfd8da178fbb1913a2c0e628e6ba5b9611c3c6e5bb8eb247edf338602676bb5f63ff6c2443ca47e6d4
data/CHANGELOG.md ADDED
@@ -0,0 +1,4 @@
1
+ # 0.1.0
2
+ - Server connection
3
+ - Simple SMS
4
+ - Profile check
data/README.md ADDED
@@ -0,0 +1,6 @@
1
+ BUILD
2
+ gem build *.gemspec -o pkg/smsapipl.gem
3
+
4
+
5
+ INSTALL
6
+ gem install pkg/*.gem
@@ -0,0 +1,51 @@
1
+ module Smsapipl
2
+ class Client
3
+ class << self
4
+ def profile
5
+ api_get(path: api[:profile_path])
6
+ end
7
+
8
+ def sms(params:)
9
+ api_post(path: api[:sms_path], params:)
10
+ end
11
+
12
+ private
13
+
14
+ def api_get(path:, params: {})
15
+ get(path:, params:).body
16
+ end
17
+
18
+ def api_post(path:, params: {})
19
+ post(path:, params:).body
20
+ end
21
+
22
+ def api
23
+ Smsapipl.configuration.api
24
+ end
25
+
26
+ def token
27
+ Smsapipl.configuration.token
28
+ end
29
+
30
+ def connection
31
+ @connection ||= Smsapipl::Connection.new(api[:uri], api[:port]).connection
32
+ end
33
+
34
+ def get(path:, params:)
35
+ request = Net::HTTP::Get.new(path)
36
+ request['Authorization'] = "Bearer #{token}"
37
+
38
+ connection.request(request)
39
+ end
40
+
41
+
42
+ def post(path:, params:)
43
+ request = Net::HTTP::Post.new(path)
44
+ request.set_form_data(params) if params.keys.any?
45
+ request['Authorization'] = "Bearer #{token}"
46
+
47
+ connection.request(request)
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Smsapipl
4
+ class Configuration
5
+ attr_accessor :api, :token, :from, :params
6
+
7
+ def initialize(api: nil, token: '', from: '', params: {})
8
+ @api = api || default_api
9
+ @token = token
10
+ @from = from
11
+ @params = default_params.merge(params)
12
+ end
13
+
14
+ private
15
+
16
+ def default_api
17
+ {
18
+ uri: 'api.smsapi.pl',
19
+ port: 443,
20
+ profile_path: '/profile',
21
+ sms_path: '/sms.do'
22
+ }
23
+ end
24
+
25
+ def default_params
26
+ {
27
+ test: '0',
28
+ encoding: 'utf-8'
29
+ }
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'net/http'
4
+ require 'openssl'
5
+
6
+ module Smsapipl
7
+ class Connection
8
+ attr_reader :uri, :port
9
+
10
+ def initialize(uri, port)
11
+ @uri = uri
12
+ @port = port
13
+ end
14
+
15
+ def connection
16
+ connection = Net::HTTP.new(uri, port)
17
+ connection.use_ssl = true
18
+ connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
19
+
20
+ connection
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Smsapipl
4
+ class Profile
5
+ class << self
6
+ def check
7
+ Client.profile
8
+ end
9
+
10
+ def points
11
+ require 'json'
12
+ JSON.parse(Client.profile)['points']
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ module Smsapipl
2
+ class Sms
3
+ class << self
4
+ def send(from: Smsapipl.configuration.from, to:, message:, optional_params: {})
5
+ params = Smsapipl.configuration.params.merge({from:, to:, message:})
6
+ .merge(optional_params)
7
+ Client.sms(params:)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,21 @@
1
+ module Smsapipl
2
+ class SmsTemplate
3
+ class << self
4
+ def send(from: Smsapipl.configuration.from, to:, template:, template_params: {}, optional_params:{})
5
+ raise 'Template params keys not in paramX format (X -> 1,2,3,4)' if invalid_template_params?(template_params)
6
+ params = Smsapipl.configuration.params.merge({from:, to:, template:})
7
+ .merge(optional_params).merge(template_params)
8
+
9
+ Client.sms(params:)
10
+ end
11
+
12
+ private
13
+
14
+
15
+ def invalid_template_params?(params)
16
+ params.values.any?(&:nil?) ||
17
+ params.keys.any?{|k| !%i(param1 param2 param3 param4).include?(k)}
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Smsapipl
4
+ VERSION = '0.2.0'
5
+ end
data/lib/smsapipl.rb ADDED
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'smsapipl/version'
4
+ require 'smsapipl/connection'
5
+ require 'smsapipl/client'
6
+ require 'smsapipl/configuration'
7
+ require 'smsapipl/profile'
8
+ require 'smsapipl/sms'
9
+ require 'smsapipl/sms_template'
10
+
11
+ module Smsapipl
12
+ ERROR_MESSAGES = {
13
+ '101' => 'Bad Credentials',
14
+ '1001' => 'Bad Request Format'
15
+ }.freeze
16
+
17
+ class << self
18
+ def configuration
19
+ @configuration ||= Configuration.new
20
+ end
21
+
22
+ def configure
23
+ yield(configuration)
24
+ end
25
+ end
26
+ end
data/smsapipl.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'smsapipl'
6
+ require 'smsapipl/version'
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = 'smsapipl'
10
+ spec.version = Smsapipl::VERSION
11
+ spec.authors = ['Staszek Zawadzki']
12
+ spec.email = ['staszek@poltrax.live']
13
+
14
+ spec.summary = 'SMSAPI.pl Ruby client - version 2025'
15
+ spec.description = 'Wrapper for SMSAPI.pl.'
16
+ spec.homepage = 'https://github.com/Poltrax.live/smsapipl'
17
+ spec.license = 'MIT'
18
+
19
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.required_ruby_version = '>= 3.0'
25
+
26
+ spec.add_development_dependency 'bundler', '~> 2.0'
27
+ spec.add_development_dependency 'pry', '~> 0.13'
28
+ spec.add_development_dependency 'rake', '~> 10.0'
29
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: smsapipl
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Staszek Zawadzki
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2025-01-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.13'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.13'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: Wrapper for SMSAPI.pl.
56
+ email:
57
+ - staszek@poltrax.live
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - CHANGELOG.md
63
+ - README.md
64
+ - lib/smsapipl.rb
65
+ - lib/smsapipl/client.rb
66
+ - lib/smsapipl/configuration.rb
67
+ - lib/smsapipl/connection.rb
68
+ - lib/smsapipl/profile.rb
69
+ - lib/smsapipl/sms.rb
70
+ - lib/smsapipl/sms_template.rb
71
+ - lib/smsapipl/version.rb
72
+ - smsapipl.gemspec
73
+ homepage: https://github.com/Poltrax.live/smsapipl
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '3.0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubygems_version: 3.5.18
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: SMSAPI.pl Ruby client - version 2025
96
+ test_files: []