imobis_api 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.
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+ pkg
15
+
16
+ test.rb
17
+
18
+ # YARD artifacts
19
+ .yardoc
20
+ _yardoc
21
+ .yardoc/
22
+ Gemfile.lock
23
+ doc/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in imobis_api.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Ivan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 t0pep0
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/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2013 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # ImobisApi
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'imobis_api'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install imobis_api
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ require 'yard'
3
+ YARD::Rake::YardocTask.new
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'imobis_api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "imobis_api"
8
+ spec.version = ImobisApi::VERSION
9
+ spec.authors = ["t0pep0"]
10
+ spec.email = ["t0pep0.gentoo@gmail.com"]
11
+ spec.description = %q{GEM for imobis api}
12
+ spec.summary = %q{GEM for imobis api}
13
+ spec.homepage = "https://github.com/t0pep0/imobis-api-rubyonrails"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "redcarpet", "~> 1.17"
24
+ spec.add_development_dependency "yard", "~> 0.7.5"
25
+ spec.add_development_dependency "rspec-core", "~> 2.0"
26
+ spec.add_development_dependency "rspec-expectations", "~> 2.0"
27
+ spec.add_development_dependency "rr", "~> 1.0"
28
+ end
Binary file
@@ -0,0 +1,141 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'net/http'
3
+ require 'uri'
4
+ require 'rexml/document'
5
+ include REXML
6
+
7
+ class ImobisCore
8
+
9
+ def ReadXml(xmlStr, type)
10
+ result = Hash.new
11
+ doc = Document.new xmlStr
12
+ case type
13
+ when "send"
14
+ result["status"] = doc.root.elements["status"].text
15
+ result["credits"] = doc.root.elements["credits"].text
16
+ when "report"
17
+ if doc.elements["DevileryReport"].text != "noValidIds" then
18
+ doc.elements.each("DeliveryReport/message") do |element|
19
+ res = hash.new
20
+ res["id"] = element.elements["id"].text
21
+ res["uid"] = element.elements["uid"].text
22
+ res["sentdate"] = element.elements["sentdate"].text
23
+ res["donedate"] = element.elements["donedate"].text
24
+ res["status"] = element.elements["status"].text
25
+ result["id"] = res
26
+ end
27
+ else
28
+ result["error"] = "noVaildIds"
29
+ end
30
+ when "check"
31
+ doc.elements.each("RESPONSE/gsm") do |num|
32
+ if num.text != "noBindingDetected" and
33
+ num.text != "invalidPhoneNumber" then
34
+ res = Hash.new
35
+ res["region"] = num.elements["region"].text
36
+ res["operator"] = num.elements["operator"].text
37
+ res["issuedate"] = num.elements["issuedate"].text
38
+ result[num.attributes["phone"]] = res
39
+ else
40
+ result[num.attributes["phone"]] = num.text
41
+ end
42
+ end
43
+ when "stats"
44
+ doc.elements.each("RESPONSE/gsm") do |num|
45
+ res = Hash.new
46
+ res["status"] = num.elements["status"].text
47
+ res["sent"] = num.elements["sent"].text
48
+ res["updated"] = num.elements["updated"].text
49
+ res["sender"] = num.elements["sender"].text
50
+ res["text"] = num.elements["text"].text
51
+ res["count"] = num.elements["count"].text
52
+ res["country"] = num.elements["country"].text
53
+ res["price"] = num.elements["price"].text
54
+ result[num.attributes["phone"]] = res
55
+ end
56
+ when "sender"
57
+ i = 0
58
+ doc.elements.each("RESPONSE/sender") do |sender|
59
+ i = i+1;
60
+ result[i] = sender.text
61
+ end
62
+ end
63
+ return result
64
+ end
65
+
66
+ def WriteXML(user,pass,type,data)
67
+ #type = send)
68
+ #data = [ text = ["message_text","message_sender"], num_list = [num = [numbers,,,], *id=[,,] ]]
69
+ #type = report
70
+ #data = [ id1 = [ id, "externalId"], id2 = [ id, "internalId" ],,,]
71
+ #type = check
72
+ #data = [num1, num2, ,,, numN]
73
+ #Create XML Add root node (SMS) and and Auth node
74
+ doc = Document.new
75
+ root_node = doc.add_element("SMS")
76
+ auth_node = root_node.add_element("authentification")
77
+ user_node = auth_node.add_element("username")
78
+ pass_node = auth_node.add_element("password")
79
+ user_node.add_text(REXML::CData.new(user))
80
+ pass_node.add_text(REXML::CData.new(pass))
81
+ #Select request type and gen XML
82
+ case type
83
+ when "send"
84
+ #Add message node
85
+ message_node = root_node.add_element("message")
86
+ sender_node = message_node.add_element("sender")
87
+ sender_node.add_text(REXML::CData.new(URI.encode(data[0][0])))
88
+ text_node = message_node.add_element("text")
89
+ text_node.add_text(REXML::CData.new(URI.encode(data[0][1])))
90
+ #Add recipients node
91
+ recip_node = root_node.add_element("recipients")
92
+ data[1].each do |num|
93
+ gsm_node = recip_node.add_element("gsm")
94
+ gsm_node.add_text(num[0])
95
+ #Add atributes messageId if needed
96
+ gsm_node.add_attribute("messageId", num.fetch(1,""))
97
+ end
98
+ when "report"
99
+ #Add messageid list
100
+ messageid_node = root_node.add_element("messadeIds")
101
+ data.each do |id|
102
+ id_node = messageid_node.add_element(id[0])
103
+ id_node.add_text(id[1])
104
+ end
105
+ when "check"
106
+ #Add list of phone numbers
107
+ check_node = root_node.add_element("checkgsm")
108
+ data.each do |num|
109
+ num_node = check_node.add_element("gsm")
110
+ num_node.add_text(num)
111
+ end
112
+ when "stats"
113
+ stats_node = root_node.add_element("checkphone")
114
+ stats_node.add_attribute("mode","xml")
115
+ stats_node.add_attribute("limit", "1000")
116
+ data.each do |num|
117
+ num_node = stats_node.add_element("gsm")
118
+ num_node.add_text(num)
119
+ end
120
+ end
121
+ doc.write(xml_string = "", 2)
122
+ puts "XML:\n" + xml_string if $DEBUG
123
+ return xml_string
124
+ end
125
+
126
+ def Post(url,param)
127
+ uri = URI.parse(url)
128
+ response = Net::HTTP.post_form(uri, param)
129
+ content = response.body
130
+ puts "RAW response:\n" + content if $DEBUG
131
+ return content
132
+ end
133
+
134
+ def Get(url)
135
+ uri = URI(url)
136
+ response = Net::HTTP.get_response(uri)
137
+ content = response.body if response.is_a?(Net::HTTPSuccess)
138
+ return content
139
+ end
140
+
141
+ end
@@ -0,0 +1,3 @@
1
+ module ImobisApi
2
+ VERSION = "0.0.1"
3
+ end
data/lib/imobis_api.rb ADDED
@@ -0,0 +1,60 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require "imobis_api/version"
3
+ require "imobis_api/imobis_core"
4
+
5
+ module ImobisApi
6
+
7
+ class Api
8
+
9
+ def initialize(user,pass)
10
+ @core = ImobisCore.new
11
+ @user = user
12
+ @pass = pass
13
+ end
14
+
15
+ def sendsms(sender, text, num)
16
+ message = [sender,text]
17
+ data = [message, num]
18
+ xml = @core.WriteXML(@user, @pass, "send", data)
19
+ xml = @core.Post("http://gate.sms-manager.ru/_xmlsmsd.php", {"XML" => xml})
20
+ data = @core.ReadXml(xml, "send")
21
+ return data
22
+ end
23
+
24
+ def delivery_report(ids)
25
+ xml = @core.WriteXML(@user, @pass, "report", ids)
26
+ xml = @core.Post("http://gate.sms-manager.ru/_callback.php", {"XML" => xml})
27
+ data = @core.ReadXml(xml, "report")
28
+ return data
29
+ end
30
+
31
+ def get_balance
32
+ uri = "http://gate.sms-manager.ru/_balance.php?user="+@user+"&password="+@pass
33
+ data = @core.Get(uri)
34
+ return data
35
+ end
36
+
37
+ def check_number(num)
38
+ xml = @core.WriteXML(@user, @pass, "check", num)
39
+ xml = @core.Post("http://gate.sms-manager.ru/_checkgsm.php", {"XML" => xml})
40
+ data = @core.ReadXml(xml, "check")
41
+ return data
42
+ end
43
+
44
+ def get_state(num)
45
+ xml = @core.WriteXML(@user, @pass, "stats", num)
46
+ xml = @core.Post("http://gate.sms-manager.ru/_checkphone.php", {"XML" => xml})
47
+ data = @core.ReadXml(xml, "stats")
48
+ return data
49
+ end
50
+
51
+ def get_sender
52
+ uri = "http://gate.sms-manager.ru/_checksender.php?user="+@user+"&password="+@pass+"&mode=xml"
53
+ xml = @core.Get(uri)
54
+ data = @core.ReadXml(xml, "sender")
55
+ return data
56
+ end
57
+
58
+ end
59
+
60
+ end
@@ -0,0 +1,17 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+ config.mock_with :rr
12
+ # Run specs in random order to surface order dependencies. If you find an
13
+ # order dependency and want to debug it, you can fix the order by providing
14
+ # the seed, which is printed after each run.
15
+ # --seed 1234
16
+ config.order = 'random'
17
+ end
metadata ADDED
@@ -0,0 +1,173 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: imobis_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - t0pep0
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-12-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
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: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
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: redcarpet
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '1.17'
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: '1.17'
62
+ - !ruby/object:Gem::Dependency
63
+ name: yard
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 0.7.5
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.7.5
78
+ - !ruby/object:Gem::Dependency
79
+ name: rspec-core
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: '2.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: '2.0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rspec-expectations
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: '2.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: '2.0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: rr
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: '1.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: '1.0'
126
+ description: GEM for imobis api
127
+ email:
128
+ - t0pep0.gentoo@gmail.com
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - .gitignore
134
+ - Gemfile
135
+ - LICENSE
136
+ - LICENSE.txt
137
+ - MIT-LICENSE
138
+ - README.md
139
+ - Rakefile
140
+ - imobis_api.gemspec
141
+ - lib/imobis_api.rb
142
+ - lib/imobis_api/.imobis_core.rb.swp
143
+ - lib/imobis_api/imobis_core.rb
144
+ - lib/imobis_api/version.rb
145
+ - spec/spec_helper.rb
146
+ homepage: https://github.com/t0pep0/imobis-api-rubyonrails
147
+ licenses:
148
+ - MIT
149
+ post_install_message:
150
+ rdoc_options: []
151
+ require_paths:
152
+ - lib
153
+ required_ruby_version: !ruby/object:Gem::Requirement
154
+ none: false
155
+ requirements:
156
+ - - ! '>='
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ none: false
161
+ requirements:
162
+ - - ! '>='
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ requirements: []
166
+ rubyforge_project:
167
+ rubygems_version: 1.8.23
168
+ signing_key:
169
+ specification_version: 3
170
+ summary: GEM for imobis api
171
+ test_files:
172
+ - spec/spec_helper.rb
173
+ has_rdoc: