mobilepronto 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # What is it?
2
+
3
+ A Ruby interface to the [MobilePronto](http://www.mobilepronto.org/) SMS gateway API.
4
+ Please note: this gem is a proxy to MobiePronto SMS gateway, to use it you should get your credentials with the service of [MobilePronto](http://www.mobilepronto.org/), not responsible at any time by the service offered by [MobilePronto](http://www.mobilepronto.org/).
5
+
6
+ # Installation
7
+
8
+ Download [the latest version of gem](http://rubygems.org/gems/mobilepronto) or install using RubyGems.
9
+
10
+ ```shell
11
+ $ sudo gem install mobilepronto
12
+ ```
13
+
14
+ ## MobilePronto on GitHub
15
+
16
+ ```shell
17
+ $ git clone git://github.com/nuxlli/mobilepronto.git
18
+ ```
19
+
20
+ # Basic Usage
21
+
22
+ To use this gem, you will need sign up for an account at the [MobilePronto](http://www.mobilepronto.org/) website.
23
+ Once you are registered and logged into your account centre, you should add
24
+ an HTTP API connection to your account. This will give you your CREDENCIAL.
25
+
26
+ ## Demonstration
27
+ ### EnviaSMS
28
+
29
+ ```ruby
30
+ require 'mobilepronto'
31
+
32
+ # Configure default values
33
+ MobilePronto.configure do |config|
34
+ # Default api url
35
+ # config.url_api = "http://www.mpgateway.com/v_2_00/smspush/enviasms.aspx"
36
+
37
+ config.credential = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
38
+ config.project_name = "MYPROJECT"
39
+ config.send_project = true
40
+ end
41
+
42
+ sms = {
43
+ :mobile => 552199999999,
44
+ :user_name => "MYUSER",
45
+ :message => "Mensagem de test"
46
+ }
47
+
48
+ # Using blocks to analyze the result
49
+ MobilePronto.send_sms(sms) do |result|
50
+ result.on(:ok) { puts "Mensagem sendend..." }
51
+ result.on(1..999) { puts "Ops: #{result.error.message}"}
52
+ end
53
+
54
+ # Or begin/rescue
55
+ begin
56
+ MobilePronto.send_sms(sms)
57
+ rescue MobilePronto::SendError => e
58
+ puts "Ops: #{e.message}"
59
+ end
60
+
61
+ ```
62
+
63
+ # References
64
+
65
+ http://www.mobilepronto.info/samples/en-US/1205-httpget-php-v_2_00.pdf
66
+
67
+ # License
68
+
69
+ MobilePronto is licensed under the [BSD License](http://opensource.org/licenses/BSD-2-Clause).
70
+
71
+ See LICENSE file for details.
72
+
@@ -0,0 +1,53 @@
1
+ # encoding: UTF-8
2
+ require 'active_support/configurable'
3
+
4
+ class MobilePronto
5
+ module Basic
6
+ def self.extended(base)
7
+ base.send(:include, ActiveSupport::Configurable)
8
+ end
9
+
10
+ def send_msg(options = {}, &block)
11
+ request(options.merge(config), &block)
12
+ end
13
+
14
+ private
15
+
16
+ def request(params)
17
+ query = build_query(params)
18
+ uri = URI.parse(config.url_api)
19
+ uri.query = query != "" ? query : nil
20
+ http = Net::HTTP.new(uri.host, uri.port)
21
+ request = Net::HTTP::Get.new(uri.request_uri)
22
+ response = http.request(request)
23
+ if (response.body != "000")
24
+ error = SendError.new(response.body)
25
+ block_given? ? yield(Result.new(response.body, error)) : raise(error)
26
+ else
27
+ block_given? ? yield(Result.new(:ok)) : :ok
28
+ end
29
+ end
30
+
31
+ def build_query(params)
32
+ keys = {
33
+ :credencial => 'CREDENCIAL',
34
+ :project_name => 'PRINCIPAL_USER',
35
+ :user_name => 'AUX_USER',
36
+ :mobile => 'MOBILE',
37
+ :send_project => 'SEND_PROJECT',
38
+ :message => 'MESSAGE'
39
+ }
40
+
41
+ params = params.inject({}) do |options, (key, value)|
42
+ options[(key.to_sym rescue key) || key] = value
43
+ options
44
+ end
45
+
46
+ unless params[:send_project].nil?
47
+ params[:send_project] = params[:send_project] ? 'S' : 'N'
48
+ end
49
+
50
+ params.map { |k, v| keys.key?(k) ? "#{keys[k]}=#{URI.escape(v.to_s)}" : nil }.compact.join("&")
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,49 @@
1
+ # encoding: UTF-8
2
+
3
+ class MobilePronto
4
+ class SendError < Exception
5
+ attr_accessor :code
6
+
7
+ # X01 ou X02 – Parâmetros com Erro.
8
+ # 000 - Mensagem enviada com Sucesso.
9
+ # 001 - Credencial Inválida.
10
+ # 005 - Mobile fora do formato-Formato +999(9999)99999999
11
+ # 007 - SEND_PROJECT tem que ser S,
12
+ # 008 - Mensagem ou FROM+MESSAGE maior que 142 posições
13
+ # 009 - Sem crédito para envio de SMS. Favor repor
14
+ # 010 - Gateway Bloqueado.
15
+ # 012 - Mobile no formato padrão, mas incorreto
16
+ # 013 - Mensagem Vazia ou Corpo Inválido
17
+ # 015 - Pais sem operação.
18
+ # 016 - Mobile com tamanho do código de área inválido
19
+ # 017 - Operadora não autorizada para esta Credencial
20
+ # De 800 a 899 - Falha no gateway Mobile Pronto
21
+ # 900 - Erro de autenticação ou Limite de segurança
22
+ # De 901 a 999 - Erro no acesso as operadoras.
23
+ def initialize(code)
24
+ self.code = code.strip
25
+ if (code == "X01" || code == "X02")
26
+ msg = "Parâmetros com Erro."
27
+ else
28
+ msg = case(code.to_i)
29
+ when 1 then "Credencial Inválida."
30
+ when 5 then "Mobile fora do formato-Formato +999(9999)99999999."
31
+ when 7 then "SEND_PROJECT tem que ser S ou N"
32
+ when 8 then "Mensagem ou FROM+MESSAGE maior que 142 posições."
33
+ when 9 then "Sem crédito para envio de SMS."
34
+ when 10 then "Gateway Bloqueado."
35
+ when 12 then "Mobile no formato padrão, mas incorreto."
36
+ when 13 then "Mensagem Vazia ou Corpo Inválido."
37
+ when 15 then "Pais sem operação."
38
+ when 16 then "Mobile com tamanho do código de área inválido."
39
+ when 17 then "Operadora não autorizada para esta Credencial."
40
+ when 900 then "Erro de autenticação ou Limite de segurança"
41
+ when 800..899 then "Falha no gateway Mobile Pronto"
42
+ when 901..999 then "Erro no acesso as operadoras."
43
+ end
44
+ end
45
+
46
+ super("#{self.code} - #{msg}")
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,28 @@
1
+ # encoding: UTF-8
2
+
3
+ class MobilePronto
4
+ class Result
5
+ attr_reader :code
6
+ attr_reader :error
7
+
8
+ def initialize(code, error = nil)
9
+ @code = ["X01", "X02", :ok].include?(code) ? code : code.to_i
10
+ @error = error
11
+ end
12
+
13
+ def on(*args)
14
+ if block_given? and
15
+ args.any? { |i| i.kind_of?(Range) ? i.include?(code) : i == code }
16
+ yield
17
+ end
18
+ end
19
+
20
+ def method_missing(method, *args, &block)
21
+ if block_given? && !(code = /on_([0-9]*)/.match(method)).nil?
22
+ self.on(code[1].to_i, &block)
23
+ else
24
+ super(method, *args, &block)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,26 @@
1
+ # encoding: UTF-8
2
+
3
+ begin
4
+ require "step-up"
5
+ rescue Exception => e; end
6
+
7
+ class MobilePronto
8
+ module VERSION #:nodoc:
9
+ pwd = ::File.expand_path(::File.dirname(__FILE__))
10
+ version = nil
11
+ version = $1 if ::File.join(pwd, '../..') =~ /\/mobilepronto-(\d[\w\.]+)/
12
+ version_file = ::File.join(pwd, '../../GEM_VERSION')
13
+ version = File.read(version_file) if version.nil? && ::File.exists?(version_file)
14
+ if version.nil? && ::File.exists?(::File.join(pwd, '/../../.git'))
15
+ version = ::StepUp::Driver::Git.new.last_version_tag("HEAD", true) rescue "v0.0.0+0"
16
+ ::File.open(version_file, "w"){ |f| f.write version }
17
+ end
18
+
19
+ STRING = version.gsub(/^v?([^\+]+)\+?\d*$/, '\1')
20
+ MAJOR, MINOR, PATCH, TINY = STRING.scan(/\d+/)
21
+
22
+ def self.to_s
23
+ STRING
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,23 @@
1
+ # encoding: UTF-8
2
+ $:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__))
3
+
4
+ # Dependencies
5
+ require "rubygems"
6
+ require "net/http"
7
+ require "uri"
8
+
9
+ require File.dirname(__FILE__) + '/mobilepronto/version'
10
+ require File.dirname(__FILE__) + '/mobilepronto/errors'
11
+ require File.dirname(__FILE__) + '/mobilepronto/result'
12
+ require File.dirname(__FILE__) + '/mobilepronto/basic'
13
+
14
+ class MobilePronto
15
+ extend Basic
16
+ # autoload :AClass , "migrator/a_class"
17
+ end
18
+
19
+ # Default configuration
20
+ MobilePronto.configure do |config|
21
+ config.url_api = "http://www.mpgateway.com/v_2_00/smspush/enviasms.aspx"
22
+ config.send_project = false
23
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mobilepronto
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Éverton A. Ribeiro
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-16 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: &70139252945720 !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: *70139252945720
25
+ - !ruby/object:Gem::Dependency
26
+ name: webmock
27
+ requirement: &70139252944880 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70139252944880
36
+ - !ruby/object:Gem::Dependency
37
+ name: minitest
38
+ requirement: &70139252936920 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70139252936920
47
+ - !ruby/object:Gem::Dependency
48
+ name: step-up
49
+ requirement: &70139252936220 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.7.0
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70139252936220
58
+ description:
59
+ email: nuxlli@gmail.com.br
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - lib/mobilepronto/basic.rb
65
+ - lib/mobilepronto/errors.rb
66
+ - lib/mobilepronto/result.rb
67
+ - lib/mobilepronto/version.rb
68
+ - lib/mobilepronto.rb
69
+ - README.md
70
+ homepage: http://github.com/nuxlli/mobilepronto
71
+ licenses: []
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 1.8.15
91
+ signing_key:
92
+ specification_version: 3
93
+ summary: A Ruby interface to the MobilePronto SMS gateway API.
94
+ test_files: []