SmsAPI 0.0.1

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,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in SmsAPI.gemspec
4
+ gemspec
@@ -0,0 +1,49 @@
1
+ 1. ���������� ������:
2
+
3
+ - API ��� ������������� ������� �������� ��������� sms16.ru
4
+ - ������ ���������� �� Ruby
5
+
6
+
7
+ 2. ������ ��������:
8
+
9
+ ��� ������� �������� ���������� ������� MySQL ���� ������, ��������� ������� ��������� � db.sql
10
+ �� ��������� ���� ����������� ������� �������������� ������������� � �������, ������� ���������� �������� �� ��������.
11
+
12
+
13
+ 3. �������� API:
14
+
15
+ ����� SmsApi �������� ��������� �������:
16
+
17
+ # ������� ��������� ������� ������������
18
+ getBalance(login, password)
19
+ login - ����� ������������ � �������
20
+ password - ������ ������������ � �������
21
+
22
+ # ������� �������� ���������
23
+ sendMessage(login, password, type, sender, text, recs, vcard)
24
+ login - ����� ������������ � �������
25
+ password - ������ ������������ � �������
26
+ type - ��� ������������� ��������� (sms, flashsms, wappush, vcard)
27
+ sender - ��� �����������
28
+ text - ����� ���������
29
+ recs - ������ �����������
30
+ vcard - ������ ������������ ��� �������� ��������
31
+
32
+ # ������� �������� ��������� ������������
33
+ getSenders(login, password)
34
+ login - ����� ������������ � �������
35
+ password - ������ ������������ � �������
36
+
37
+ # ������� ��������� ��������� ���������
38
+ getStates(login, password, smsIds)
39
+ login - ����� ������������ � �������
40
+ password - ������ ������������ � �������
41
+ smsIds - ������ id ������������ ���
42
+
43
+ # ������� ��������� �������� ���������
44
+ getIncomingMessages(login, password, start, end)
45
+ login - ����� ������������ � �������
46
+ password - ������ ������������ � �������
47
+ start - ��������� ���� �������� �������� ��� � ������� YYYY-MM-DD HH:MM:SS
48
+ ���, YYYY-���, MM-�����, DD-����, HH-����, MM-������, SS-�������.
49
+ end - �������� ���� �������� �������� ���
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "SmsAPI/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "SmsAPI"
7
+ s.version = SmsAPI::VERSION
8
+ s.authors = ["Alex Lysenko"]
9
+ s.email = ["tywonka@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = "SMS API to sms16.ru"
12
+ s.description = "SMS API to sms16.ru"
13
+
14
+ s.rubyforge_project = "SmsAPI"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ # s.add_runtime_dependency "rest-client"
24
+ end
@@ -0,0 +1,153 @@
1
+ # encoding: utf-8
2
+ require "SmsAPI/version"
3
+ require "builder"
4
+ require "rest_client"
5
+ require "simple_xml"
6
+
7
+ module SmsAPI
8
+ class SmsAPI
9
+
10
+ # Функция проверки баланса
11
+ def self.getBalance(login, password)
12
+ xml = Builder::XmlMarkup.new( :indent => 2 )
13
+ xml.instruct! :xml, :encoding => "utf-8"
14
+ xml.request { |b| b.security { |x| x.login("value" => login);
15
+ x.password("value" => password) } }
16
+ response = RestClient.post 'http://xml.sms16.ru/xml/balance.php',
17
+ xml.target!, {:content_type => "text/xml; charset=utf-8"}
18
+ doc = REXML::Document.new(response)
19
+ h = Hash.new()
20
+ if doc.elements.each('response/error').length > 0
21
+ raise "Ошибка проверки баланса: " +
22
+ doc.elements.each('response/error').first.text
23
+ end
24
+ doc.elements.each('response/money') do |ele|
25
+ h["money"] = ele.text + " " + ele.attributes["currency"]
26
+ end
27
+ doc.elements.each('response/sms') do |ele|
28
+ h[ele.attributes["area"]] = ele.text
29
+ end
30
+ return h
31
+ end
32
+
33
+ # Функция получения списка отправителей
34
+ def self.getSenders(login, password)
35
+ xml = Builder::XmlMarkup.new( :indent => 2 )
36
+ xml.instruct! :xml, :encoding => "utf-8"
37
+ xml.request { |b| b.security { |x| x.login("value" => login);
38
+ x.password("value" => password) } }
39
+ response = RestClient.post 'http://xml.sms16.ru/xml/originator.php',
40
+ xml.target!, {:content_type => "text/xml; charset=utf-8"}
41
+ doc = REXML::Document.new(response)
42
+ h = Hash.new()
43
+ if doc.elements.each('response/error').length > 0
44
+ raise "Ошибка получения списка отправителей: " +
45
+ doc.elements.each('response/error').first.text
46
+ end
47
+ doc.elements.each('response/any_originator') do |ele|
48
+ h["Любой отправитель"] = ele.text
49
+ end
50
+ doc.elements.each('response/list_originator/originator') do |ele|
51
+ h[ele.text] = ele.attributes["state"]
52
+ end
53
+ return h
54
+ end
55
+
56
+ # Функция получения входящих сообщений
57
+ def self.getIncomingMsgs(login, password, startDate, endDate)
58
+ xml = Builder::XmlMarkup.new( :indent => 2 )
59
+ xml.instruct! :xml, :encoding => "utf-8"
60
+ xml.request { |b| b.security { |x| x.login("value" => login);
61
+ x.password("value" => password) };
62
+ b.time("start" => startDate, "end" => endDate) }
63
+ response = RestClient.post 'http://xml.sms16.ru/xml/incoming.php',
64
+ xml.target!, {:content_type => "text/xml; charset=utf-8"}
65
+ doc = REXML::Document.new(response)
66
+ msgs = Array.new()
67
+ if doc.elements.each('response/error').length > 0
68
+ raise "Ошибка получения входящих сообщений: " +
69
+ doc.elements.each('response/error').first.text
70
+ end
71
+ if doc.elements.each('response/sms').length == 0
72
+ raise "Входящих сообщений нет"
73
+ end
74
+ doc.elements.each('response/sms') do |ele|
75
+ incMsg = Hash.new()
76
+ incMsg["date_receive"] = ele.attributes["date_receive"]
77
+ incMsg["phone"] = ele.attributes["phone"]
78
+ incMsg["originator"] = ele.attributes["originator"]
79
+ incMsg["text"] = ele.text
80
+ msgs.put(incMsg)
81
+ end
82
+ return msgs
83
+ end
84
+
85
+ # Функция проверки состояния отправленных сообщений
86
+ def self.getStates(login, password, smsIds)
87
+ if (smsIds.length == 0)
88
+ raise "Нет сообщений для проверки состояния. Необходимо отправить смс."
89
+ end
90
+ xml = Builder::XmlMarkup.new( :indent => 2 )
91
+ xml.instruct! :xml, :encoding => "utf-8"
92
+ xml.request { |b| b.security { |x| x.login("value" => login);
93
+ x.password("value" => password) };
94
+ b.get_state { |s| smsIds.each { |m| s.id_sms(m) } } }
95
+ response = RestClient.post 'http://xml.sms16.ru/xml/state.php',
96
+ xml.target!, {:content_type => "text/xml; charset=utf-8"}
97
+ doc = REXML::Document.new(response)
98
+ h = Hash.new()
99
+ if doc.elements.each('response/error').length > 0
100
+ raise "Ошибка проверки состояния отправленных сообщений: " +
101
+ doc.elements.each('response/error').first.text
102
+ end
103
+ doc.elements.each('response/state') do |ele|
104
+ h[ele.attributes["id_sms"]] = ele.text
105
+ end
106
+ return h
107
+ end
108
+
109
+ # Функция отправки сообщения
110
+ def self.sendMessage(login, password, type, sender, text, recs, vcard)
111
+ xml = Builder::XmlMarkup.new( :indent => 2 )
112
+ xml.instruct! :xml, :encoding => "utf-8"
113
+ xml.request { |b|
114
+ b.message("type" => type) { |mes| mes.sender(sender);
115
+ mes.text(text);
116
+ if (type == "wappush" || type == "vcard")
117
+ mes.url(vcard["url"]);
118
+ mes.name(vcard["name"]);
119
+ mes.phone("cell" => vcard["cell"], "work" => vcard["work"], "fax" => vcard["fax"]);
120
+ mes.email(vcard["email"]);
121
+ mes.position(vcard["position"]);
122
+ mes.organization(vcard["organization"]);
123
+ mes.address("post_office_box" => vcard["post_office_box"],
124
+ "street" => vcard["street"], "city" => vcard["city"],
125
+ "region" => vcard["region"], "postal_code" => vcard["postal_code"],
126
+ "country" => vcard["country"]);
127
+ mes.additional(vcard["additional"]);
128
+ end
129
+ recs.each do |rec|
130
+ mes.abonent("phone" => rec["phone"], "number_sms" => 1 + recs.index(rec),
131
+ "client_id_sms" => Time.now.to_i + recs.index(rec),
132
+ "time_send" => "", "validity_period" => "" );
133
+ end
134
+ };
135
+ b.security { |x| x.login("value" => login);
136
+ x.password("value" => password) } }
137
+ response = RestClient.post 'http://xml.sms16.ru/xml/',
138
+ xml.target!, {:content_type => "text/xml; charset=utf-8"}
139
+ doc = REXML::Document.new(response)
140
+ states = Array.new()
141
+ if doc.elements.each('response/error').length > 0
142
+ raise "Ошибка отправки сообщения: " +
143
+ doc.elements.each('response/error').first.text
144
+ end
145
+ doc.elements.each('response/information') do |ele|
146
+ state = Hash.new()
147
+ state[ele.attributes["id_sms"]] = ele.text
148
+ states.push(state)
149
+ end
150
+ return states
151
+ end
152
+ end
153
+ end
@@ -0,0 +1,3 @@
1
+ module SmsAPI
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: SmsAPI
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alex Lysenko
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-28 00:00:00.000000000Z
13
+ dependencies: []
14
+ description: SMS API to sms16.ru
15
+ email:
16
+ - tywonka@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - README.txt
24
+ - Rakefile
25
+ - SmsAPI.gemspec
26
+ - lib/SmsAPI.rb
27
+ - lib/SmsAPI/version.rb
28
+ homepage: ''
29
+ licenses: []
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubyforge_project: SmsAPI
48
+ rubygems_version: 1.8.13
49
+ signing_key:
50
+ specification_version: 3
51
+ summary: SMS API to sms16.ru
52
+ test_files: []