sms_ru 0.5.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,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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sms_ru.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Alexey Chernikov
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.
@@ -0,0 +1,48 @@
1
+ # SmsRu
2
+
3
+ Send SMS via sms.ru service, including support for "stronger auth" API
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'sms_ru'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install sms_ru
18
+
19
+ ## Usage
20
+
21
+ ### Usage from console
22
+
23
+ Write file .sms_ru_settings in you home dir with contents:
24
+
25
+ api_id = aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee
26
+ from = 123456789
27
+
28
+ where *aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee* is you api_id key; *123456789* - sender of sms. It will show in sms.
29
+ Your number or any allowed alias on service.
30
+
31
+ After that usage as simple as
32
+
33
+ sms 123456789 'my text message'
34
+
35
+ where *12345689* - receipient of sms
36
+
37
+ ### Usage in source code
38
+
39
+ sms = SmsRu::SMS.new(:api_id => "aaaaaaaaaa-bbbb-ccccc-ddddddd")
40
+ sms.send(:to => "123123123", :from => "321321321", :text => "Hello world")
41
+
42
+ ## Contributing
43
+
44
+ 1. Fork it
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/sms ADDED
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'sms_ru'
5
+ require 'parseconfig'
6
+
7
+ SETTINGS_FILE = "#{ENV["HOME"]}/.sms_ru_settings"
8
+
9
+ config = ParseConfig.new("#{ENV["HOME"]}/.sms_ru_settings")
10
+ case ARGV.size
11
+ when 1
12
+ to = config["default_to"]
13
+ text = ARGV[0]
14
+ when 2
15
+ to = ARGV[0]
16
+ text = ARGV[1]
17
+ else
18
+ print "Usage: \tsms TO TEXT\n\tsms TEXT\t(if default_to specified in settings)\n\n"
19
+ print "Possible settings in $HOME/.sms_ru_settings:\n\tapi_id = <api_id>\n\tfrom = <sender number or alias>\n"
20
+ print "\tdefault_to = <default destination number>\n"
21
+ exit
22
+ end
23
+
24
+ if File.exist? SETTINGS_FILE
25
+ sms = SmsRu::SMS.new :api_id => config["api_id"]
26
+ sms.send :from => config["from"], :to => to, :text => text
27
+ else
28
+ print "No settings file found. Please create file .sms_ru_settings in your home directory.\n"
29
+ exit
30
+ end
31
+
@@ -0,0 +1,43 @@
1
+ require "sms_ru/version"
2
+ require "net/http"
3
+
4
+ module SmsRu
5
+ class SMS
6
+ def initialize(params)
7
+ @api_id = params[:api_id]
8
+ @login = params[:login]
9
+ @password = params[:password]
10
+ @auth_token_expire = nil
11
+ end
12
+
13
+ def send(params)
14
+ query_params = ""
15
+ params.each do |key, value|
16
+ query_params += "&#{key.to_s}=#{URI::encode(value.to_s)}"
17
+ end
18
+ if @api_id.nil?
19
+ require 'digest/sha2'
20
+ hash = Digest::SHA512.hexdigest(@password+auth_token+@api_id)
21
+ uri = URI.parse("http://sms.ru/sms/send?api_id=#@api_id#{query_params}")
22
+ else
23
+ uri = URI.parse("http://sms.ru/sms/send?api_id=#@api_id#{query_params}")
24
+ response = Net::HTTP.get_response(uri)
25
+ response.body.split("\n").first
26
+ end
27
+ end
28
+
29
+ def auth_token
30
+ if @auth_token_expire < Time.now
31
+ renew_auth_token
32
+ else
33
+ @auth_token
34
+ end
35
+ end
36
+
37
+ private
38
+ def renew_auth_token
39
+ @auth_token_expire = Time.now + 10.minutes
40
+ @auth_token = Net::HTTP.get_response(URI.parse("http://sms.ru/auth/get_token")).body.strip
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ module SmsRu
2
+ VERSION = "0.5.0"
3
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sms_ru/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "sms_ru"
8
+ gem.version = SmsRu::VERSION
9
+ gem.author = "Alexey Chernikov"
10
+ gem.email = "alexey.chernikov@gmail.com"
11
+ gem.description = %q{Gem to send SMS via sms.ru service}
12
+ gem.summary = %q{Send SMS via sms.ru service, including support for "stronger auth" API}
13
+ gem.homepage = "http://github.com/alexey-chernikov/sms_ru"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_runtime_dependency "parseconfig", "~> 1.0.2"
21
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sms_ru
3
+ version: !ruby/object:Gem::Version
4
+ hash: 11
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 5
9
+ - 0
10
+ version: 0.5.0
11
+ platform: ruby
12
+ authors:
13
+ - Alexey Chernikov
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-09-24 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: parseconfig
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 19
29
+ segments:
30
+ - 1
31
+ - 0
32
+ - 2
33
+ version: 1.0.2
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ description: Gem to send SMS via sms.ru service
37
+ email: alexey.chernikov@gmail.com
38
+ executables:
39
+ - sms
40
+ extensions: []
41
+
42
+ extra_rdoc_files: []
43
+
44
+ files:
45
+ - .gitignore
46
+ - Gemfile
47
+ - LICENSE.txt
48
+ - README.md
49
+ - Rakefile
50
+ - bin/sms
51
+ - lib/sms_ru.rb
52
+ - lib/sms_ru/version.rb
53
+ - sms_ru.gemspec
54
+ homepage: http://github.com/alexey-chernikov/sms_ru
55
+ licenses: []
56
+
57
+ post_install_message:
58
+ rdoc_options: []
59
+
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ hash: 3
68
+ segments:
69
+ - 0
70
+ version: "0"
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ hash: 3
77
+ segments:
78
+ - 0
79
+ version: "0"
80
+ requirements: []
81
+
82
+ rubyforge_project:
83
+ rubygems_version: 1.8.24
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: Send SMS via sms.ru service, including support for "stronger auth" API
87
+ test_files: []
88
+