magti 0.1.0.beta1

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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.project ADDED
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <projectDescription>
3
+ <name>magti</name>
4
+ <comment></comment>
5
+ <projects>
6
+ </projects>
7
+ <buildSpec>
8
+ </buildSpec>
9
+ <natures>
10
+ </natures>
11
+ </projectDescription>
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in magti.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Dimitri Kurashvili
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # Magti
2
+
3
+ Magti is a gem for sending SMS messages through [Magticom](http://www.magticom.ge/) gateway.
4
+
5
+ You need access to Magticom's gateway server, also they provide you with user/password parameters.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'magti'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install magti
20
+
21
+ ## Usage
22
+
23
+ TODO: Comming soon
24
+
25
+ ## Additional resources
26
+
27
+ Protocol description which is used by this gem, can be found in `refs` subdirectory.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/lib/magti.rb ADDED
@@ -0,0 +1,7 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'magti/version'
3
+ require 'magti/config'
4
+ require 'magti/sms'
5
+
6
+ module Magti
7
+ end
@@ -0,0 +1,45 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'singleton'
3
+
4
+ module Magti
5
+ # URL for sending SMS.
6
+ SMS_SEND_URL = 'http://81.95.160.47/mt/sendsms'
7
+
8
+ # URL for tracking SMS status.
9
+ SMS_TRACK_URL = 'http://81.95.160.47/bi/track.php'
10
+
11
+ # Maximum size of individual SMS message.
12
+ MAX_SIZE = 160
13
+
14
+ # Service configuration class.
15
+ #
16
+ # Access it, using <code>Magti.config</code>.
17
+ class Config
18
+ include Singleton
19
+
20
+ # user name
21
+ attr_accessor :username
22
+ # password
23
+ attr_accessor :password
24
+ # client
25
+ attr_accessor :client
26
+ # service
27
+ attr_accessor :service
28
+
29
+ def initialize
30
+ self.service = 1
31
+ end
32
+
33
+ # Returns security options hash.
34
+ def security_options
35
+ { :username => self.username, :password => self.password, :client_id => self.client, :service_id => self.service }
36
+ end
37
+ end
38
+
39
+ def self.config(params = {})
40
+ params.each do |k, v|
41
+ Magti::Config.instance.send "#{k}=".to_sym, v
42
+ end
43
+ Magti::Config.instance
44
+ end
45
+ end
data/lib/magti/sms.rb ADDED
@@ -0,0 +1,33 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'set'
3
+ require 'cgi'
4
+ require 'httparty'
5
+
6
+ module Magti
7
+ # Response object.
8
+ # It contains information on response code and message id.
9
+ class Response
10
+ attr_accessor :id
11
+ attr_accessor :code
12
+ end
13
+
14
+ # Sending SMS.
15
+ #
16
+ # @param mobile mobile number
17
+ # @param text text to be sent
18
+ # @return Response object with response code and message ID
19
+ def self.send_sms(mobile, text)
20
+ raise ArgumentError, 'illegal mobile number' unless C12.correct_mobile?(mobile)
21
+ raise ArgumentError, 'max size exceeded' if text.length > Magti::MAX_SIZE
22
+ options = Magti.config.security_options
23
+ if options.nil? or options.empty? or !Set.new(options.keys).proper_subset?(Set[:username, :password, :client, :service])
24
+ raise ArgumentError, 'specify Magti.config(options) with :username, :password, :client and :service keys'
25
+ end
26
+ options = options.merge(:to => "995#{mobile}", :text => text)
27
+ resp = HTTParty.get(Magti::SMS_SEND_URL, options)
28
+ resp = Response.new
29
+ resp.code, resp.id = resp.split(' - ')
30
+ resp
31
+ end
32
+
33
+ end
@@ -0,0 +1,4 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module Magti
3
+ VERSION = "0.1.0.beta1"
4
+ end
data/magti.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/magti/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Dimitri Kurashvili"]
6
+ gem.email = ["dimitri@c12.ge"]
7
+ gem.description = %q{Magti SMS gateway}
8
+ gem.summary = %q{Gem for sending SMS using MagtiGSM.ge gateway}
9
+ gem.homepage = "http://github.com/dimakura/magti"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "magti"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Magti::VERSION
17
+
18
+ gem.add_development_dependency 'rspec', '~> 2'
19
+
20
+ gem.add_runtime_dependency 'c12-commons'
21
+ gem.add_runtime_dependency 'httparty', '~> 0.8'
22
+ end
Binary file
@@ -0,0 +1,33 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe 'Test config' do
5
+ before(:all) do
6
+ Magti.config.username = 'dimitri'
7
+ Magti.config.password = 'secret'
8
+ Magti.config.client = 10
9
+ Magti.config.service = 100
10
+ end
11
+ context 'options for sending SMS' do
12
+ subject { Magti.config.security_options }
13
+ it { should be_instance_of Hash }
14
+ specify { subject[:username].should == 'dimitri' }
15
+ specify { subject[:password].should == 'secret' }
16
+ specify { subject[:client_id].should == 10 }
17
+ specify { subject[:service_id].should == 100 }
18
+ end
19
+ end
20
+
21
+ describe 'Test config assignment using hash' do
22
+ before(:all) do
23
+ Magti.config({:username => 'dk', :password => 'password', :client => 99, :service => 66})
24
+ end
25
+ context 'options for sending SMS' do
26
+ subject { Magti.config.security_options }
27
+ it { should be_instance_of Hash }
28
+ specify { subject[:username].should == 'dk' }
29
+ specify { subject[:password].should == 'password' }
30
+ specify { subject[:client_id].should == 99 }
31
+ specify { subject[:service_id].should == 66 }
32
+ end
33
+ end
@@ -0,0 +1,7 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'rspec'
3
+ require 'magti'
4
+
5
+ RSpec.configure do |config|
6
+ config.include(RSpec::Matchers)
7
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: magti
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.beta1
5
+ prerelease: 6
6
+ platform: ruby
7
+ authors:
8
+ - Dimitri Kurashvili
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '2'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '2'
30
+ - !ruby/object:Gem::Dependency
31
+ name: c12-commons
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: httparty
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '0.8'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0.8'
62
+ description: Magti SMS gateway
63
+ email:
64
+ - dimitri@c12.ge
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - .project
71
+ - .rspec
72
+ - Gemfile
73
+ - LICENSE
74
+ - README.md
75
+ - Rakefile
76
+ - lib/magti.rb
77
+ - lib/magti/config.rb
78
+ - lib/magti/sms.rb
79
+ - lib/magti/version.rb
80
+ - magti.gemspec
81
+ - refs/magti_protocol.pdf
82
+ - spec/config_spec.rb
83
+ - spec/spec_helper.rb
84
+ homepage: http://github.com/dimakura/magti
85
+ licenses: []
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>'
100
+ - !ruby/object:Gem::Version
101
+ version: 1.3.1
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 1.8.22
105
+ signing_key:
106
+ specification_version: 3
107
+ summary: Gem for sending SMS using MagtiGSM.ge gateway
108
+ test_files:
109
+ - spec/config_spec.rb
110
+ - spec/spec_helper.rb
111
+ has_rdoc: