smsapipl-client 1.0.2

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: 8eee56722cf4a5c59c853560d2c97286021e78fb8a947e8f1fb450c5b355b7ee
4
+ data.tar.gz: 5fa5d4cdc6e9e1b78cfb1c8626a8cfe7cbf5cffb1f1692e2045014bc049aee52
5
+ SHA512:
6
+ metadata.gz: 12f89322b1edb33ba382815c921fae57deb68dabd1fa8fd5a2b13ced6854087afa6ebc0aa1c4597d6145b163f65faf53d26bdd1112ff27602d48c13e62a63910
7
+ data.tar.gz: 877629489b8e91d1088d7bea2d0d4ece7fd76669a7af2151b5a09c7fd06deca98ca48159d9c55c54b3abf7fa0b7b28a764105276f55261889826a01d2abc6d57
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
data/CHANGELOG.md ADDED
@@ -0,0 +1,22 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [1.0.1] - 2019-08-22
10
+ ### Changed
11
+ - Added info about old authentication method to README
12
+ - UTF-8 encoding added to default options
13
+
14
+ ## [1.0.0] - 2019-08-13
15
+ ### Added
16
+ - Changelog.
17
+ - Version tag.
18
+
19
+ ### Changed
20
+ - Removed username/password auth in favor of OAuth2 token.
21
+ - Moved version number to a separate file.
22
+ - Moved main module outside of `smsapi` namespace.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in smsapipl-client.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Michal Musialik
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,91 @@
1
+ # Smsapi::Client
2
+
3
+ Smsapi::Client is a Ruby implementation for SMSAPI.pl gateway created by [Ruby Logic](http://rubylogic.pl)
4
+ Fork by Poltrax
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'smsapipl-client', '~> 1.0'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install smsapipl-client -v '~> 1.0'
21
+
22
+
23
+ ## Usage
24
+
25
+ Be sure you have a token. You can obtain it on [SMSAPI.pl](http://smsapi.pl)
26
+
27
+ ```ruby
28
+ # Include the library
29
+ require 'smsapi'
30
+
31
+ # Create the client
32
+
33
+ client = Smsapi::Client.new('your_secret_token')
34
+
35
+ # Get credits (account details)
36
+ credits = client.credits
37
+ credits.balance # => 2.6600
38
+ credits.pro_sms_limit # => 16
39
+ credits.eco_sms_limit # => 38
40
+ credits.mms_limit # => 8
41
+ credits.vms_gsm_limit # => 26
42
+ credits.vms_stac_limit # => 26
43
+
44
+ # Send a single text message
45
+ sms = client.send_single 500500500, 'Text Message'
46
+ sms.status # 'OK'
47
+ sms.success? # => true
48
+ sms.points # => 0.12
49
+
50
+ # When something goes wrong
51
+ sms.status # 'ERROR'
52
+ sms.success? # => false
53
+ sms.error? # => true
54
+ sms.error_code # => 101
55
+ sms.error_message # => 'Bad Credentials'
56
+
57
+ # Any additional options can be passed as last argument
58
+ sms = client.send_single 500500500, 'Text Message', test: '1'
59
+
60
+ # Sending a single PRO message. Remember to get authorisation for the name here: https://ssl.smsapi.pl/sms_settings/sendernames
61
+ sms = client.send_single 500500500, 'Text Message', from: 'Ruby Logic'
62
+
63
+ # Schedule a single message to be sent in the future
64
+ when = DateTime.new(2015, 10, 10)
65
+ sms = client.schedule_single 500500500, 'Text Message', when
66
+
67
+ # Sending messages in bulk
68
+ bulk = client.send_bulk [500500500, 600600600, 7007007], 'Text Message', test: '1'
69
+
70
+ # Gives access to an array of sent messages
71
+ bulk.sent
72
+ bulk.sent.first.success? # => true
73
+
74
+ # The api returns only statuses for successful messages. Since one of our
75
+ # numbers was too short the array contains only 2 items.
76
+ bulk.sent.count # => 2
77
+ ```
78
+
79
+ ## Development
80
+
81
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
82
+
83
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `smsapi.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
84
+
85
+ ## Contributing
86
+
87
+ 1. Fork it ( https://github.com/ruby-logic/smsapi-client/fork )
88
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
89
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
90
+ 4. Push to the branch (`git push origin my-new-feature`)
91
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "smsapi/client"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/build.sh ADDED
@@ -0,0 +1 @@
1
+ gem build *.gemspec -o pkg/smsapipl-client.gem
@@ -0,0 +1,36 @@
1
+ module Smsapi
2
+ class BulkSMS
3
+ include Smsapi::Defaults
4
+
5
+ attr_reader :sent, :to, :message
6
+ def initialize(to, message, server, options = {})
7
+ @options = default_options.merge options
8
+ @to = to
9
+ @message = message
10
+ @server = server
11
+ @sent = []
12
+ end
13
+
14
+ def deliver
15
+ read_response @server.sms(server_params)
16
+ self
17
+ end
18
+
19
+ private
20
+
21
+ def server_params
22
+ @options.merge(
23
+ to: to.join(','),
24
+ message: message
25
+ )
26
+ end
27
+
28
+ def read_response(response)
29
+ response.each do |single_response|
30
+ sms = SMS.new(single_response.split(':').last, message, @server, @options)
31
+ sms.read_response(single_response)
32
+ @sent << sms
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ module Smsapi
2
+ VERSION = '1.0.2'
3
+ end
@@ -0,0 +1,23 @@
1
+ module Smsapi
2
+ class Client
3
+ def initialize(token)
4
+ @server = Smsapi::Server.new(token)
5
+ end
6
+
7
+ def credits(options = {})
8
+ Smsapi::Credits.new(@server, options).check
9
+ end
10
+
11
+ def send_single(to, message, options = {})
12
+ Smsapi::SMS.new(to, message, @server, options).deliver
13
+ end
14
+
15
+ def schedule_single(to, message, date, options = {})
16
+ Smsapi::SMS.new(to, message, @server, options).deliver_at(date)
17
+ end
18
+
19
+ def send_bulk(to, message, options = {})
20
+ Smsapi::BulkSMS.new(to, message, @server, options).deliver
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,61 @@
1
+ module Smsapi
2
+ class Credits
3
+
4
+ attr_accessor :status, :error_code, :balance, :pro_sms_limit, :eco_sms_limit, :mms_limit, :vms_gsm_limit, :vms_stac_limit
5
+ def initialize(server, options = {})
6
+ @options = default_options.merge options
7
+ @server = server
8
+ end
9
+
10
+ def check
11
+ read_response @server.user(server_params).join(';')
12
+ self
13
+ end
14
+
15
+ def sent?
16
+ not self.status.nil?
17
+ end
18
+
19
+ def error?
20
+ self.status == 'ERROR'
21
+ end
22
+
23
+ def success?
24
+ self.status == 'Points'
25
+ end
26
+
27
+ def error_message
28
+ Smsapi::ERROR_MESSAGES[error_code]
29
+ end
30
+
31
+ def read_response(response)
32
+ response = response.split(':').map(&:strip)
33
+
34
+ self.status = response[0]
35
+ if status == 'ERROR'
36
+ self.error_code = response[1]
37
+ else
38
+ data = response[1].split(';')
39
+ self.balance = data[0].to_f
40
+ self.pro_sms_limit = data[1].to_i
41
+ self.eco_sms_limit = data[2].to_i
42
+ self.mms_limit = data[3].to_i
43
+ self.vms_gsm_limit = data[4].to_i
44
+ self.vms_stac_limit = data[5].to_i
45
+ end
46
+ end
47
+
48
+ private
49
+
50
+ def default_options
51
+ {
52
+ credits: 1,
53
+ details: 1
54
+ }
55
+ end
56
+
57
+ def server_params
58
+ @options
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,9 @@
1
+ module Smsapi::Defaults
2
+ def default_options
3
+ {
4
+ from: 'Test',
5
+ test: '0',
6
+ encoding: 'utf-8'
7
+ }
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ module Smsapi
2
+ class GroupSMS < BulkSMS
3
+ def send
4
+ # read_response = server.send_group(server_params)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,28 @@
1
+ require 'net/http'
2
+ require 'openssl'
3
+
4
+ module Smsapi
5
+ class Server
6
+ class Connection
7
+ def initialize(uri, port, token)
8
+ @http = Net::HTTP.new(uri, port)
9
+ @http.use_ssl = true
10
+ @http.verify_mode = OpenSSL::SSL::VERIFY_NONE
11
+ @token = token
12
+ end
13
+
14
+ def post(path, params)
15
+ @http.request post_request(path, params)
16
+ end
17
+
18
+ private
19
+
20
+ def post_request(path, params)
21
+ request = Net::HTTP::Post.new(path)
22
+ request.set_form_data(params)
23
+ request['Authorization'] = "Bearer #{@token}"
24
+ request
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,32 @@
1
+ module Smsapi
2
+ class Server
3
+ def initialize(token)
4
+ @token = token
5
+ @connection = setup_connection
6
+ end
7
+
8
+ def user(params = {})
9
+ api_response = make_request(Smsapi::API[:user_path], params)
10
+ api_response.split(';')
11
+ end
12
+
13
+ def sms(params = {})
14
+ api_response = make_request(Smsapi::API[:sms_path], params)
15
+ api_response.split(';')
16
+ end
17
+
18
+ private
19
+
20
+ def setup_connection
21
+ Smsapi::Server::Connection.new(
22
+ Smsapi::API[:uri],
23
+ Smsapi::API[:port],
24
+ @token
25
+ )
26
+ end
27
+
28
+ def make_request(path, params)
29
+ @connection.post(path, params).body
30
+ end
31
+ end
32
+ end
data/lib/smsapi/sms.rb ADDED
@@ -0,0 +1,63 @@
1
+ module Smsapi
2
+ class SMS
3
+ include Smsapi::Defaults
4
+
5
+ attr_accessor :to, :message, :id, :points, :status, :error_code, :date
6
+ def initialize(to, message, server, options = {})
7
+ @options = default_options.merge options
8
+ @to = to
9
+ @message = message
10
+ @server = server
11
+ end
12
+
13
+ def deliver
14
+ read_response @server.sms(server_params).first
15
+ self
16
+ end
17
+
18
+ def deliver_at(date)
19
+ @date = date
20
+ params = server_params.merge(date: date.to_time.to_i)
21
+
22
+ read_response @server.sms(params).first
23
+ self
24
+ end
25
+
26
+ def sent?
27
+ not self.status.nil?
28
+ end
29
+
30
+ def error?
31
+ self.status == 'ERROR'
32
+ end
33
+
34
+ def success?
35
+ self.status == 'SUCCESS'
36
+ end
37
+
38
+ def error_message
39
+ Smsapi::ERROR_MESSAGES[error_code]
40
+ end
41
+
42
+ def read_response(response)
43
+ response = response.split(':')
44
+
45
+ self.status = response[0]
46
+ if status == 'ERROR'
47
+ self.error_code = response[1]
48
+ else
49
+ self.id = response[1]
50
+ self.points = response[2]
51
+ end
52
+ end
53
+
54
+ private
55
+
56
+ def server_params
57
+ @options.merge(
58
+ to: to,
59
+ message: message
60
+ )
61
+ end
62
+ end
63
+ end
data/lib/smsapi.rb ADDED
@@ -0,0 +1,26 @@
1
+ require_relative 'smsapi/client/version'
2
+ require 'smsapi/server'
3
+ require 'smsapi/server/connection'
4
+ require 'smsapi/client'
5
+ require 'smsapi/defaults'
6
+ require 'smsapi/credits'
7
+ require 'smsapi/sms'
8
+ require 'smsapi/bulk_sms'
9
+ require 'smsapi/group_sms'
10
+
11
+ module Smsapi
12
+ class Error < StandardError; end
13
+ class ServerError < Error; end
14
+
15
+ API = {
16
+ uri: 'ssl.smsapi.pl',
17
+ port: 443,
18
+ user_path: '/user.do',
19
+ sms_path: '/sms.do'
20
+ }
21
+
22
+ ERROR_MESSAGES = {
23
+ '101' => 'Bad Credentials',
24
+ '1001' => 'Bad Request Format'
25
+ }
26
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'smsapi'
5
+ require 'smsapi/client/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'smsapipl-client'
9
+ spec.version = Smsapi::VERSION
10
+ spec.authors = ['Staszek Zawadzki']
11
+ spec.email = ['staszek@poltrax.live']
12
+
13
+ spec.summary = 'SMSAPI.pl Ruby client - version 2024'
14
+ spec.description = 'Fork of SMSAPI.pl Ruby client created by Ruby Logic S.C.'
15
+ spec.homepage = 'https://github.com/Poltrax.live/smsapipl-client'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.bindir = 'exe'
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.required_ruby_version = '>= 2.2'
24
+
25
+ spec.add_development_dependency 'bundler', '~> 2.0'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: smsapipl-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Staszek Zawadzki
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-07-25 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: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Fork of SMSAPI.pl Ruby client created by Ruby Logic S.C.
42
+ email:
43
+ - staszek@poltrax.live
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".rspec"
50
+ - ".travis.yml"
51
+ - CHANGELOG.md
52
+ - Gemfile
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - bin/console
57
+ - bin/setup
58
+ - build.sh
59
+ - lib/smsapi.rb
60
+ - lib/smsapi/bulk_sms.rb
61
+ - lib/smsapi/client.rb
62
+ - lib/smsapi/client/version.rb
63
+ - lib/smsapi/credits.rb
64
+ - lib/smsapi/defaults.rb
65
+ - lib/smsapi/group_sms.rb
66
+ - lib/smsapi/server.rb
67
+ - lib/smsapi/server/connection.rb
68
+ - lib/smsapi/sms.rb
69
+ - smsapipl-client.gemspec
70
+ homepage: https://github.com/Poltrax.live/smsapipl-client
71
+ licenses:
72
+ - MIT
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '2.2'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubygems_version: 3.4.10
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: SMSAPI.pl Ruby client - version 2024
93
+ test_files: []