startmobile_sms 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc ADDED
@@ -0,0 +1,26 @@
1
+ = StartmobileSms
2
+
3
+ The easy way to send and check a single sms with startmobile.com.ua provider.
4
+
5
+ == Install
6
+
7
+ gem 'startmobile_sms'
8
+
9
+ == Configure
10
+
11
+ StartmobileSms.setup do |config|
12
+ config.login = 'login'
13
+ config.password = 'password'
14
+ end
15
+
16
+ == Usage
17
+
18
+ # Send single sms
19
+ sms_id = StartmobileSms.send(:phone => '30971234567', :text => 'Hello!', :out_number => 'service_name')
20
+
21
+ # Check sms delivery status
22
+ StartmobileSms.check(sms_id)
23
+
24
+ == Wiki
25
+
26
+ {Startmobile service API}[https://github.com/superp/startmobile_sms/wiki/Startmobile-service-API]
@@ -0,0 +1,38 @@
1
+ # encoding: utf-8
2
+ module StartmobileSms
3
+ class Config < Hash
4
+ # Creates an accessor that simply sets and reads a key in the hash:
5
+ #
6
+ # class Config < Hash
7
+ # hash_accessor :routes, :secret_key, :service_number, :project_name
8
+ # end
9
+ #
10
+ # config = Config.new
11
+ # config.routes = '/posts/message'
12
+ # config[:routes] #=> '/posts/message'
13
+ #
14
+ def self.hash_accessor(*names) #:nodoc:
15
+ names.each do |name|
16
+ class_eval <<-METHOD, __FILE__, __LINE__ + 1
17
+ def #{name}
18
+ self[:#{name}]
19
+ end
20
+
21
+ def #{name}=(value)
22
+ self[:#{name}] = value
23
+ end
24
+ METHOD
25
+ end
26
+ end
27
+
28
+ hash_accessor :login, :password, :post_url
29
+
30
+ def initialize(other = {})
31
+ merge!(other)
32
+
33
+ self[:login] ||= 'login'
34
+ self[:password] ||= 'password'
35
+ self[:post_url] ||= 'http://bulk.startmobile.com.ua/clients.php'
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,69 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+
4
+ module StartmobileSms
5
+ class Message
6
+
7
+ attr_accessor :phone, :text, :out_number
8
+
9
+ def initialize(options={})
10
+ @phone = options[:phone]
11
+ @text = options[:text]
12
+ @out_number = options[:out_number] || 'INFO'
13
+ end
14
+
15
+ def xml_content
16
+ "<?xml version='1.0' encoding='UTF-8'?><message>
17
+ <service id='single' source='#{@out_number}'/>
18
+ <to>#{@phone}</to>
19
+ <body content-type='text/plain'><![CDATA[#{@text}]]></body>
20
+ </message>"
21
+ end
22
+
23
+ def check_content(id)
24
+ "<?xml version='1.0' encoding='UTF-8'?><request id='#{id}'>status</request>"
25
+ end
26
+
27
+ def make_post(body)
28
+ url = URI.parse(StartmobileSms.config.post_url)
29
+ request = Net::HTTP::Post.new(url.path)
30
+ request.basic_auth StartmobileSms.config.login, StartmobileSms.config.password
31
+ request.body = body
32
+
33
+ result = Net::HTTP.new(url.host, url.port).start {|http| http.request(request) }
34
+
35
+ case result
36
+ when Net::HTTPSuccess, Net::HTTPRedirection then result.body
37
+ else false
38
+ end
39
+ end
40
+
41
+ def send
42
+ response = make_post(xml_content)
43
+ return nil unless response
44
+
45
+ doc = Nokogiri::XML(response)
46
+ doc.at('.//id').content
47
+ end
48
+
49
+
50
+ def check(id)
51
+ response = make_post(check_content(id))
52
+ return nil unless response
53
+
54
+ doc = Nokogiri::XML(response)
55
+ doc.at('.//state').content
56
+ end
57
+
58
+ # Class methods
59
+
60
+ def self.send(options)
61
+ cms = new(options)
62
+ cms.send
63
+ end
64
+
65
+ def self.check(id)
66
+ new.check(id)
67
+ end
68
+ end
69
+ end
@@ -1,3 +1,3 @@
1
1
  module StartmobileSms
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: startmobile_sms
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Pavel Galeta
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-01-16 00:00:00 +02:00
18
+ date: 2012-01-17 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -46,12 +46,12 @@ extensions: []
46
46
  extra_rdoc_files: []
47
47
 
48
48
  files:
49
- - .gitignore
50
- - Gemfile
51
- - Rakefile
52
49
  - lib/startmobile_sms.rb
50
+ - lib/startmobile_sms/config.rb
53
51
  - lib/startmobile_sms/version.rb
54
- - startmobile_sms.gemspec
52
+ - lib/startmobile_sms/message.rb
53
+ - Rakefile
54
+ - README.rdoc
55
55
  has_rdoc: true
56
56
  homepage: https://github.com/superp/startmobile_sms
57
57
  licenses: []
@@ -75,15 +75,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  requirements:
76
76
  - - ">="
77
77
  - !ruby/object:Gem::Version
78
- hash: 23
78
+ hash: 3
79
79
  segments:
80
- - 1
81
- - 3
82
- - 6
83
- version: 1.3.6
80
+ - 0
81
+ version: "0"
84
82
  requirements: []
85
83
 
86
- rubyforge_project: startmobile_sms
84
+ rubyforge_project:
87
85
  rubygems_version: 1.3.7
88
86
  signing_key:
89
87
  specification_version: 3
data/.gitignore DELETED
@@ -1,3 +0,0 @@
1
- pkg/*
2
- *.gem
3
- .bundle
data/Gemfile DELETED
@@ -1,3 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- gemspec
@@ -1,22 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- require File.expand_path("../lib/startmobile_sms/version", __FILE__)
3
-
4
- Gem::Specification.new do |s|
5
- s.name = "startmobile_sms"
6
- s.version = StartmobileSms::VERSION
7
- s.platform = Gem::Platform::RUBY
8
- s.authors = ["Pavel Galeta"]
9
- s.email = ["superp1987@gmail.com"]
10
- s.homepage = "https://github.com/superp/startmobile_sms"
11
- s.summary = "A Ruby wrapper for startmobile sms service"
12
- s.description = "http://bulk.startmobile.com.ua/"
13
-
14
- s.required_rubygems_version = ">= 1.3.6"
15
- s.rubyforge_project = "startmobile_sms"
16
-
17
- s.add_development_dependency "bundler", ">= 1.0.0.rc.6"
18
-
19
- s.files = `git ls-files`.split("\n")
20
- s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
21
- s.require_path = 'lib'
22
- end