sms16client 0.0.2 → 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.
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source :rubygems
2
+
3
+ platforms :jruby do
4
+ gem 'jruby-openssl'
5
+ end
6
+
7
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,43 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sms16client (0.0.3)
5
+ builder
6
+ sax-machine
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ builder (3.1.4)
12
+ coderay (1.0.8)
13
+ diff-lcs (1.1.3)
14
+ fakeweb (1.3.0)
15
+ method_source (0.8.1)
16
+ nokogiri (1.5.5)
17
+ pry (0.9.10)
18
+ coderay (~> 1.0.5)
19
+ method_source (~> 0.8)
20
+ slop (~> 3.3.1)
21
+ rake (10.0.2)
22
+ rspec (2.12.0)
23
+ rspec-core (~> 2.12.0)
24
+ rspec-expectations (~> 2.12.0)
25
+ rspec-mocks (~> 2.12.0)
26
+ rspec-core (2.12.1)
27
+ rspec-expectations (2.12.0)
28
+ diff-lcs (~> 1.1.3)
29
+ rspec-mocks (2.12.0)
30
+ sax-machine (0.1.0)
31
+ nokogiri (> 0.0.0)
32
+ slop (3.3.3)
33
+
34
+ PLATFORMS
35
+ ruby
36
+
37
+ DEPENDENCIES
38
+ fakeweb
39
+ jruby-openssl
40
+ pry
41
+ rake
42
+ rspec
43
+ sms16client!
data/LICENSE.md ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2010-2013 Nikolay Burlov
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # Sms16Client
2
+
3
+ Sms16Client is a gem that provides an interface for sms16.ru API.
4
+
5
+ ## Usage
6
+
7
+ ```ruby
8
+ sms16 = Sms16Client.new 'username', 'password'
9
+
10
+ sms16.get_balance
11
+ # => {:money=>{:currency=>"RUR", :amount=>"3924.45"}, :sms=>[{:area=>"Россия", :amount=>"26163"}, {:area=>"Украина", :amount=>"0"}]}
12
+ sms16.send_message "hello world", "12345678900", "author"
13
+ # => {:information=>{:number_sms=>"1", :id_sms=>"111", :parts=>"1", :response=>"send"}}
14
+ sms16.get_message_state "111"
15
+ # => {:state=>{:id_sms=>"111", :time=>"2012-12-04 05:39:36", :err=>"000", :response=>"deliver"}}
16
+ ```
17
+
18
+ ## Installation
19
+
20
+ gem install sms16client
21
+
22
+ ## Changelog
23
+
24
+ 0.1.0 - Minor release that includes:
25
+ - Remove obsolete class Client
26
+ - Change method responses from original sms16.ru api xml's to our own hashes
27
+ - Update README, add LICENSE and specs
data/Rakefile CHANGED
@@ -1,12 +1,8 @@
1
- require 'rubygems'
2
- require 'rake'
3
- require 'echoe'
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
4
3
 
5
- Echoe.new('sms16client', '0.0.2') do |p|
6
- p.description = "Sms16 client"
7
- p.url = "http://github.com/kohgpat/sms16client/"
8
- p.author = "Nikolay Burlov"
9
- p.email = "kohgpat@gmail.com"
10
- p.ignore_pattern = ["tmp/*", "script/*"]
11
- p.development_dependencies = []
12
- end
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
8
+ task :test => :spec
@@ -0,0 +1,55 @@
1
+ class Sms16Client
2
+ class Money
3
+ include SAXMachine
4
+ attribute :currency
5
+ value :text
6
+ end
7
+
8
+ class Sms
9
+ include SAXMachine
10
+ attribute :area
11
+ value :text
12
+ end
13
+
14
+ class Information
15
+ include SAXMachine
16
+ attribute :number_sms
17
+ attribute :id_sms
18
+ attribute :parts
19
+ value :text
20
+ end
21
+
22
+ class State
23
+ include SAXMachine
24
+ attribute :id_sms
25
+ attribute :time
26
+ attribute :err
27
+ value :text
28
+ end
29
+
30
+ class Response
31
+ include SAXMachine
32
+ element :error
33
+ element :money, :class => Money
34
+ elements :sms, :class => Sms
35
+ element :information, :class => Information
36
+ element :state, :class => State
37
+
38
+ # helpers to determine response case
39
+ def error?
40
+ @error ? true : false
41
+ end
42
+
43
+ def money?
44
+ @money ? true : false
45
+ end
46
+
47
+ def information?
48
+ @information ? true : false
49
+ end
50
+
51
+ def state?
52
+ @state ? true : false
53
+ end
54
+ end
55
+ end
data/lib/sms16client.rb CHANGED
@@ -1,83 +1,141 @@
1
- # encoding: UTF-8
1
+ # encoding: utf-8
2
2
 
3
- require 'rubygems'
4
- require 'builder'
3
+ $:.push File.expand_path(File.dirname(__FILE__) + "/../lib")
4
+
5
+ # stdlib
5
6
  require 'net/http'
6
7
  require 'net/https'
7
- require 'uri'
8
-
9
- module Sms16Client
10
- VERSION = '0.0.2'
11
-
12
- class Client
13
- attr_accessor :login, :password, :query
14
-
15
- def initialize(login, password)
16
- @login = login
17
- @password = password
18
- @query = String.new
19
- end
20
-
21
- def get_balance
22
- @query = String.new
23
- xml = Builder::XmlMarkup.new(:target => @query)
24
-
25
- xml.request {
26
- xml.security {
27
- xml.login(:value => @login)
28
- xml.password(:value => @password)
29
- }
30
- }
31
-
32
- return execute_query(@query, 'https://my.sms16.ru/xml/balance.php')
33
- end
34
-
35
- def send_message(message, destination, source)
36
- @query = String.new
37
- xml = Builder::XmlMarkup.new(:target => @query)
38
-
39
- xml.request {
40
- xml.message(:type => "sms") {
41
- xml.sender source.to_s
42
- xml.text message.to_s
43
- xml.abonent(:phone => destination.to_s, :number_sms => "1")
44
- }
45
- xml.security {
46
- xml.login(:value => @login)
47
- xml.password(:value => @password)
48
- }
49
- }
50
-
51
- return execute_query(@query, 'https://my.sms16.ru/xml/')
52
- end
53
-
54
- def get_message_state(message_id)
55
- @query = String.new
56
- xml = Builder::XmlMarkup.new(:target => @query)
57
-
58
- xml.request {
59
- xml.security {
60
- xml.login(:value => @login)
61
- xml.password(:value => @password)
62
- }
63
- xml.get_state {
64
- xml.id_sms message_id.to_s
65
- }
66
- }
67
-
68
- return execute_query(@query, 'https://my.sms16.ru/xml/state.php')
69
- end
70
-
71
- private
72
-
73
- def execute_query(query, uri)
74
- url = URI.parse(uri)
75
- headers = {"Content-Type" => "text/xml"}
76
-
77
- request = Net::HTTP.new(url.host, url.port)
78
- request.use_ssl = true
79
-
80
- return request.post(url.path, query, headers).body
81
- end
82
- end
8
+
9
+ # external dependency
10
+ require 'builder'
11
+ require 'sax-machine'
12
+
13
+ # internal dependency
14
+ require 'sms16client/parser'
15
+
16
+ class Sms16Client
17
+ Version = '0.1.0'
18
+
19
+ attr_accessor :login, :password
20
+
21
+ def initialize(login, password)
22
+ @login = login
23
+ @password = password
24
+ end
25
+
26
+ def get_balance
27
+ query = ""
28
+
29
+ xml = Builder::XmlMarkup.new(:target => query)
30
+ xml.request {
31
+ xml.security {
32
+ xml.login(:value => login)
33
+ xml.password(:value => password)
34
+ }
35
+ }
36
+
37
+ return parse_response(execute_query(query, 'https://my.sms16.ru/xml/balance.php'))
38
+ end
39
+
40
+ def send_message(message, destination, source)
41
+ query = ""
42
+
43
+ xml = Builder::XmlMarkup.new(:target => query)
44
+ xml.request {
45
+ xml.security {
46
+ xml.login(:value => login)
47
+ xml.password(:value => password)
48
+ }
49
+ xml.message(:type => "sms") {
50
+ xml.sender source
51
+ xml.text message
52
+ xml.abonent(:phone => destination, :number_sms => "1")
53
+ }
54
+ }
55
+
56
+ return parse_response(execute_query(query, 'https://my.sms16.ru/xml/'))
57
+ end
58
+
59
+ def get_message_state(message_id)
60
+ query = ""
61
+
62
+ xml = Builder::XmlMarkup.new(:target => query)
63
+ xml.request {
64
+ xml.security {
65
+ xml.login(:value => login)
66
+ xml.password(:value => password)
67
+ }
68
+ xml.get_state {
69
+ xml.id_sms message_id
70
+ }
71
+ }
72
+
73
+ return parse_response(execute_query(query, 'https://my.sms16.ru/xml/state.php'))
74
+ end
75
+
76
+ private
77
+
78
+ def execute_query(query, uri)
79
+ url = URI.parse(uri)
80
+ headers = {"Content-Type" => "text/xml"}
81
+ request = Net::HTTP.new(url.host, url.port)
82
+ request.use_ssl = true
83
+ request.post(url.path, query, headers).body
84
+ end
85
+
86
+ def parse_response(response)
87
+ response = Response.parse(response)
88
+
89
+ return error_response(response) if response.error?
90
+ return balance_response(response) if response.money?
91
+ return information_response(response) if response.information?
92
+ return state_response(response) if response.state?
93
+ end
94
+
95
+ def error_response(response)
96
+ {
97
+ :error => response.error
98
+ }
99
+ end
100
+
101
+ def balance_response(response)
102
+ {
103
+ :money => {
104
+ :currency => response.money.currency,
105
+ :amount => response.money.text
106
+ },
107
+ :sms => [
108
+ {
109
+ :area => response.sms[0].area,
110
+ :amount => response.sms[0].text
111
+ },
112
+ {
113
+ :area => response.sms[1].area,
114
+ :amount => response.sms[1].text
115
+ }
116
+ ]
117
+ }
118
+ end
119
+
120
+ def information_response(response)
121
+ {
122
+ :information => {
123
+ :number_sms => response.information.number_sms,
124
+ :id_sms => response.information.id_sms,
125
+ :parts => response.information.parts,
126
+ :response => response.information.text
127
+ }
128
+ }
129
+ end
130
+
131
+ def state_response(response)
132
+ {
133
+ :state => {
134
+ :id_sms => response.state.id_sms,
135
+ :time => response.state.time,
136
+ :err => response.state.err,
137
+ :response => response.state.text
138
+ }
139
+ }
140
+ end
83
141
  end
data/sms16client.gemspec CHANGED
@@ -1,29 +1,25 @@
1
- # -*- encoding: utf-8 -*-
1
+ # encoding: utf-8
2
2
 
3
- Gem::Specification.new do |s|
4
- s.name = %q{sms16client}
5
- s.version = "0.0.2"
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'sms16client'
5
+ spec.description = %q{A gem that provides an interface to sms16.ru API.}
6
+ spec.authors = ['Nikolay Burlov']
7
+ spec.email = ['kohgpat@gmail.com']
6
8
 
7
- s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["Nikolay Burlov"]
9
- s.date = %q{2011-04-04}
10
- s.description = %q{Sms16 client}
11
- s.email = %q{kohgpat@gmail.com}
12
- s.extra_rdoc_files = ["README", "lib/sms16client.rb"]
13
- s.files = ["README", "Rakefile", "lib/sms16client.rb", "sms16client.gemspec", "Manifest"]
14
- s.homepage = %q{http://github.com/kohgpat/sms16client/}
15
- s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Sms16client", "--main", "README"]
16
- s.require_paths = ["lib"]
17
- s.rubyforge_project = %q{sms16client}
18
- s.rubygems_version = %q{1.6.2}
19
- s.summary = %q{Sms16 client}
9
+ spec.add_dependency 'builder'
10
+ spec.add_dependency 'sax-machine'
20
11
 
21
- if s.respond_to? :specification_version then
22
- s.specification_version = 3
12
+ spec.add_development_dependency 'pry'
13
+ spec.add_development_dependency 'rake'
14
+ spec.add_development_dependency 'rspec'
15
+ spec.add_development_dependency 'fakeweb'
23
16
 
24
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
25
- else
26
- end
27
- else
28
- end
17
+ spec.version = '0.1.0'
18
+ spec.files = `git ls-files`.split("\n")
19
+ spec.homepage = 'http://github.com/kohgpat/sms16client'
20
+ spec.licenses = ['MIT']
21
+ spec.require_paths = ['lib']
22
+ spec.required_rubygems_version = Gem::Requirement.new('>= 1.3.6')
23
+ spec.summary = %q{A gem that provides an interface to sms16.ru API.}
24
+ spec.test_files = `git ls-files -- {test,spec,feature}/*`.split("\n")
29
25
  end
@@ -0,0 +1,60 @@
1
+ # encoding: utf-8
2
+
3
+ require 'fakeweb'
4
+
5
+ $:.push File.expand_path(File.dirname(__FILE__) + '/../lib')
6
+
7
+ require 'sms16client'
8
+
9
+ describe Sms16Client do
10
+ before do
11
+ @sms16 = Sms16Client.new 'test', 'test'
12
+ end
13
+
14
+ it "incorrect credentials" do
15
+ FakeWeb.register_uri(
16
+ :post, 'https://my.sms16.ru/xml/balance.php',
17
+ :body => "<?xml version=\"1.0\" encoding=\"utf-8\"?><response><error>Неправильный логин или пароль</error></response>")
18
+
19
+ @sms16.get_balance[:error].should == "Неправильный логин или пароль"
20
+ end
21
+
22
+ it "balance" do
23
+ FakeWeb.register_uri(
24
+ :post, 'https://my.sms16.ru/xml/balance.php',
25
+ :body => "<?xml version=\"1.0\" encoding=\"utf-8\"?><response><money currency=\"RUR\">3924.9</money><sms area=\"Россия\">26166</sms><sms area=\"Украина\">0</sms></response>")
26
+
27
+ response = @sms16.get_balance
28
+
29
+ response[:money][:currency].should == "RUR"
30
+ response[:money][:amount].should == "3924.9"
31
+ response[:sms][0][:area].should == "Россия"
32
+ response[:sms][0][:amount].should == "26166"
33
+ end
34
+
35
+ it "send message" do
36
+ FakeWeb.register_uri(
37
+ :post, 'https://my.sms16.ru/xml/',
38
+ :body => "<?xml version=\"1.0\" encoding=\"utf-8\"?><response><information number_sms=\"1\" id_sms=\"111\" parts=\"1\">send</information></response>")
39
+
40
+ response = @sms16.send_message('test message', 'phone number', 'author')
41
+
42
+ response[:information][:number_sms].should == "1"
43
+ response[:information][:id_sms].should == "111"
44
+ response[:information][:parts].should == "1"
45
+ response[:information][:response].should == "send"
46
+ end
47
+
48
+ it "get message state" do
49
+ FakeWeb.register_uri(
50
+ :post, 'https://my.sms16.ru/xml/state.php',
51
+ :body => "<?xml version=\"1.0\" encoding=\"utf-8\"?><response><state id_sms=\"111\" time=\"2012-12-04 05:20:19\" err=\"000\">deliver</state></response>")
52
+
53
+ response = @sms16.get_message_state('111')
54
+
55
+ response[:state][:id_sms].should == "111"
56
+ response[:state][:time].should == "2012-12-04 05:20:19"
57
+ response[:state][:err].should == "000"
58
+ response[:state][:response].should == "deliver"
59
+ end
60
+ end
metadata CHANGED
@@ -1,66 +1,152 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: sms16client
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
4
5
  prerelease:
5
- version: 0.0.2
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Nikolay Burlov
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-04-04 00:00:00 +09:00
14
- default_executable:
15
- dependencies: []
16
-
17
- description: Sms16 client
18
- email: kohgpat@gmail.com
12
+ date: 2012-12-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: builder
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: sax-machine
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: pry
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rspec
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: fakeweb
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: A gem that provides an interface to sms16.ru API.
111
+ email:
112
+ - kohgpat@gmail.com
19
113
  executables: []
20
-
21
114
  extensions: []
22
-
23
- extra_rdoc_files:
24
- - README
25
- - lib/sms16client.rb
26
- files:
27
- - README
115
+ extra_rdoc_files: []
116
+ files:
117
+ - .rspec
118
+ - Gemfile
119
+ - Gemfile.lock
120
+ - LICENSE.md
121
+ - README.md
28
122
  - Rakefile
29
123
  - lib/sms16client.rb
124
+ - lib/sms16client/parser.rb
30
125
  - sms16client.gemspec
31
- - Manifest
32
- has_rdoc: true
33
- homepage: http://github.com/kohgpat/sms16client/
34
- licenses: []
35
-
126
+ - spec/sms16client_spec.rb
127
+ homepage: http://github.com/kohgpat/sms16client
128
+ licenses:
129
+ - MIT
36
130
  post_install_message:
37
- rdoc_options:
38
- - --line-numbers
39
- - --inline-source
40
- - --title
41
- - Sms16client
42
- - --main
43
- - README
44
- require_paths:
131
+ rdoc_options: []
132
+ require_paths:
45
133
  - lib
46
- required_ruby_version: !ruby/object:Gem::Requirement
134
+ required_ruby_version: !ruby/object:Gem::Requirement
47
135
  none: false
48
- requirements:
49
- - - ">="
50
- - !ruby/object:Gem::Version
51
- version: "0"
52
- required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ! '>='
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
141
  none: false
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- version: "1.2"
142
+ requirements:
143
+ - - ! '>='
144
+ - !ruby/object:Gem::Version
145
+ version: 1.3.6
58
146
  requirements: []
59
-
60
- rubyforge_project: sms16client
61
- rubygems_version: 1.6.2
147
+ rubyforge_project:
148
+ rubygems_version: 1.8.24
62
149
  signing_key:
63
150
  specification_version: 3
64
- summary: Sms16 client
151
+ summary: A gem that provides an interface to sms16.ru API.
65
152
  test_files: []
66
-
data/Manifest DELETED
@@ -1,5 +0,0 @@
1
- README
2
- Rakefile
3
- lib/sms16client.rb
4
- sms16client.gemspec
5
- Manifest
data/README DELETED
File without changes