smsapi-client 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: aa2a44ea645440e177899b0a1de97bffe64d5e35
4
+ data.tar.gz: 1752a0ee074d508585c26b132fdd143d37ed2772
5
+ SHA512:
6
+ metadata.gz: 64c1c2dfc5e8a4b071b5a9c1abb1463d9a472c09da0ce74d98e28a39178ce6d0bac740923b11e2b00c8dcd0ce41fb5972844bc400dc1351d211929cc4f495eba
7
+ data.tar.gz: 629bbc32ed73c0b32164b8b6859f9ac6816a481ef9eedd8119c3cef9392035b212d47288794dd9cc904ecd34d1749f91dc94ab1e9891af7525cc34d518ffb9ea
@@ -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
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in smsapi-client.gemspec
4
+ gemspec
@@ -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.
@@ -0,0 +1,69 @@
1
+ # SMSApi::Client
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'smsapi-client'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install smsapi-client
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ # Create the client
23
+ client = SMSApi::Client.new('username', 'password')
24
+
25
+ # Send a single text message
26
+ sms = client.send_single 500500500, 'Text Message'
27
+ sms.status # 'OK'
28
+ sms.success? # => true
29
+ sms.points # => 0.12
30
+
31
+ # When something goes wrong
32
+ sms.status # 'ERROR'
33
+ sms.success? # => false
34
+ sms.error? # => true
35
+ sms.error_code # => 101
36
+ sms.error_message # => 'Bad Credentials'
37
+
38
+ # Any additional options can be passed as last argument
39
+ sms = client.send_single 500500500, 'Text Message', test: '1'
40
+
41
+ # Schedule a single message to be sent in the future
42
+ when = DateTime.new(2015, 10, 10)
43
+ sms = client.schedule_single 500500500, 'Text Message', when
44
+
45
+ # Sending messages in bulk
46
+ bulk = client.send_bulk [500500500, 600600600, 7007007], 'Text Message', test: '1'
47
+
48
+ # Gives access to an array of sent messages
49
+ bulk.sent
50
+ bulk.sent.first.success? # => true
51
+
52
+ # The api returns only statuses for successful messages. Since one of our
53
+ # numbers was too short the array contains only 2 items.
54
+ bulk.sent.count # => 2
55
+ ```
56
+
57
+ ## Development
58
+
59
+ 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.
60
+
61
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.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).
62
+
63
+ ## Contributing
64
+
65
+ 1. Fork it ( https://github.com/[my-github-username]/smsapi-client/fork )
66
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
67
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
68
+ 4. Push to the branch (`git push origin my-new-feature`)
69
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -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
@@ -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
@@ -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,23 @@
1
+ module SMSApi
2
+ class Client
3
+ def initialize(username, password)
4
+ @server = Server.new(username, password)
5
+ end
6
+
7
+ def send_single(to, message, options = {})
8
+ SMS.new(to, message, @server, options).deliver
9
+ end
10
+
11
+ def schedule_single(to, message, date, options = {})
12
+ SMS.new(to, message, @server, options).deliver_at(date)
13
+ end
14
+
15
+ def send_bulk(to, message, options = {})
16
+ BulkSMS.new(to, message, @server, options).deliver
17
+ end
18
+
19
+ def details
20
+ # not implemented
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,8 @@
1
+ module SMSApi::Defaults
2
+ def default_options
3
+ {
4
+ from: 'eco',
5
+ test: '1'
6
+ }
7
+ end
8
+ 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,33 @@
1
+ module SMSApi
2
+ class Server
3
+ def initialize(username, password)
4
+ @username = username
5
+ @password = password
6
+ @connection = setup_connection
7
+ end
8
+
9
+ def sms(params = {})
10
+ api_response = make_request(SMSApi::API[:sms_path], params)
11
+ api_response.split(';')
12
+ end
13
+
14
+ private
15
+
16
+ def setup_connection
17
+ SMSApi::Server::Connection.new(
18
+ SMSApi::API[:uri],
19
+ SMSApi::API[:port]
20
+ )
21
+ end
22
+
23
+ def make_request(path, params)
24
+ params = authorize_params(params)
25
+ response = @connection.post(path, params)
26
+ response.body
27
+ end
28
+
29
+ def authorize_params(params)
30
+ params.merge(username: @username, password: @password)
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,25 @@
1
+ require 'net/http'
2
+
3
+ module SMSApi
4
+ class Server
5
+ class Connection
6
+ def initialize(uri, port)
7
+ @http = Net::HTTP.new(uri, port)
8
+ @http.use_ssl = true
9
+ @http.verify_mode = OpenSSL::SSL::VERIFY_NONE
10
+ end
11
+
12
+ def post(path, params)
13
+ @http.request post_request(path, params)
14
+ end
15
+
16
+ private
17
+
18
+ def post_request(path, params)
19
+ request = Net::HTTP::Post.new(path)
20
+ request.set_form_data(params)
21
+ request
22
+ end
23
+ end
24
+ end
25
+ end
@@ -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
@@ -0,0 +1,23 @@
1
+ require 'smsapi/server'
2
+ require 'smsapi/server/connection'
3
+ require 'smsapi/client'
4
+ require 'smsapi/defaults'
5
+ require 'smsapi/sms'
6
+ require 'smsapi/bulk_sms'
7
+ require 'smsapi/group_sms'
8
+
9
+ module SMSApi
10
+ class Error < StandardError; end
11
+ class ServerError < Error; end
12
+
13
+ VERSION = "0.1.0"
14
+ API = {
15
+ uri: 'ssl.smsapi.pl',
16
+ port: 443,
17
+ sms_path: '/sms.do'
18
+ }
19
+
20
+ ERROR_MESSAGES = {
21
+ '101' => 'Bad Credentials',
22
+ }
23
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'smsapi/smsapi'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "smsapi-client"
8
+ spec.version = SMSApi::VERSION
9
+ spec.authors = ["Alek Niemczyk", "Marek Machula", "Marcin Drozd", "Michal Musialik"]
10
+ spec.email = ["info@rubylogic.pl"]
11
+
12
+ spec.summary = 'SMSAPI.pl Ruby client'
13
+ spec.description = 'SMSAPI.pl Ruby client'
14
+ spec.homepage = 'https://github.com/rubylogicgems/smsapi-client'
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.8"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: smsapi-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Alek Niemczyk
8
+ - Marek Machula
9
+ - Marcin Drozd
10
+ - Michal Musialik
11
+ autorequire:
12
+ bindir: exe
13
+ cert_chain: []
14
+ date: 2015-08-21 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: bundler
18
+ requirement: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - "~>"
21
+ - !ruby/object:Gem::Version
22
+ version: '1.8'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.8'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - "~>"
35
+ - !ruby/object:Gem::Version
36
+ version: '10.0'
37
+ type: :development
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '10.0'
44
+ description: SMSAPI.pl Ruby client
45
+ email:
46
+ - info@rubylogic.pl
47
+ executables: []
48
+ extensions: []
49
+ extra_rdoc_files: []
50
+ files:
51
+ - ".gitignore"
52
+ - ".rspec"
53
+ - ".travis.yml"
54
+ - Gemfile
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - bin/console
59
+ - bin/setup
60
+ - lib/smsapi/bulk_sms.rb
61
+ - lib/smsapi/client.rb
62
+ - lib/smsapi/defaults.rb
63
+ - lib/smsapi/group_sms.rb
64
+ - lib/smsapi/server.rb
65
+ - lib/smsapi/server/connection.rb
66
+ - lib/smsapi/sms.rb
67
+ - lib/smsapi/smsapi.rb
68
+ - smsapi-client.gemspec
69
+ homepage: https://github.com/rubylogicgems/smsapi-client
70
+ licenses:
71
+ - MIT
72
+ metadata: {}
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubyforge_project:
89
+ rubygems_version: 2.4.8
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: SMSAPI.pl Ruby client
93
+ test_files: []