messente-rails 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.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +2 -0
- data/LICENSE +21 -0
- data/README.md +41 -0
- data/Rakefile +1 -0
- data/lib/generators/messente_rails/install_generator.rb +12 -0
- data/lib/generators/messente_rails/templates/messente.rb.erb +8 -0
- data/lib/messente-rails/configuration.rb +17 -0
- data/lib/messente-rails/messente.rb +138 -0
- data/lib/messente-rails/version.rb +3 -0
- data/lib/messente-rails.rb +7 -0
- data/messente-rails.gemspec +26 -0
- metadata +112 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 54946d4694f6df2962df67f0e7fd47ff32dc6324
|
4
|
+
data.tar.gz: 3d5608bc4a6b381c96127e3295ff2bda6a3c928e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6899f0992094856cc9d74b9d98b6d17c6aaf4bb5462cf35c53475b5e13389fc75d1c0b69d313f5736d2703b313ef6487ae51e45f8c783eade1149c7a36118da9
|
7
|
+
data.tar.gz: e772cf556ddd73f7541fb1e970b981fac314d40564d3d61378f868cd45a1ff12b459618e8926c11ce8e720f9cd81c94676e52ae9bbe000d2ecc2c3e0e0689ff0
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Vjatseslav Gedrovits
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, 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,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Messente::Rails
|
2
|
+
|
3
|
+
Messente.com API wrapper for Rails (non official)
|
4
|
+
|
5
|
+
Original API documentation: [https://messente.com/docs/api/rest/](https://messente.com/docs/api/rest/)
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'messente-rails'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install messente-rails
|
20
|
+
|
21
|
+
Then you should run install generator:
|
22
|
+
|
23
|
+
$ rails g messente_rails:install
|
24
|
+
|
25
|
+
You should review the generated file and at least insert your credentials.
|
26
|
+
|
27
|
+
NB! Don't forget to restart server after configuration.
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
Methods from original documentation as is, but only synchronous sending is supported for now.
|
32
|
+
|
33
|
+
Original API documentation: [https://messente.com/docs/api/rest/](https://messente.com/docs/api/rest/)
|
34
|
+
|
35
|
+
## Contributing
|
36
|
+
|
37
|
+
1. Fork it ( https://github.com/Gedrovits/messente-rails/fork )
|
38
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
39
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
40
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
41
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module MessenteRails
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
desc 'Copies messente.rb into config/initializers directory'
|
6
|
+
|
7
|
+
def copy_initializer
|
8
|
+
template 'messente.rb.erb', File.join(Rails.root, 'config', 'initializers', 'messente.rb')
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# You can configure messente-rails within this file
|
2
|
+
MessenteRails.configure do |config|
|
3
|
+
## Messente.com API credentials
|
4
|
+
#
|
5
|
+
config.username = <% if ::Rails::VERSION::MAJOR == 4 %>Rails.application.secrets.messente_username<% else %>Rails.env.development? ? 'dev' : 'prod'<% end %>
|
6
|
+
#
|
7
|
+
config.password = <% if ::Rails::VERSION::MAJOR == 4 %>Rails.application.secrets.messente_password<% else %>Rails.env.development? ? 'dev' : 'prod'<% end %>
|
8
|
+
end
|
@@ -0,0 +1,138 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
class Messente
|
4
|
+
include HTTParty
|
5
|
+
base_uri 'api2.messente.com'
|
6
|
+
|
7
|
+
ERROR_101 = 'Access is restricted, wrong credentials. Check username and password values.'
|
8
|
+
ERROR_102 = 'Parameters are wrong or missing. Check that all required parameters are present.'
|
9
|
+
ERROR_103 = 'Invalid IP address. The IP address you made the request from, is not in the API settings whitelist.'
|
10
|
+
ERROR_111 = 'Sender parameter "from" is invalid. You have not activated this sender name from Messente.com'
|
11
|
+
FAILED_209 = 'Server failure, try again after a few seconds or try api3.messente.com backup server.'
|
12
|
+
|
13
|
+
class << self
|
14
|
+
# https://messente.com/docs/api/rest/sms/
|
15
|
+
def send_sms(mobile, message, backup_uri = false)
|
16
|
+
action = '/send_sms/'
|
17
|
+
query = credentials.merge({ to: mobile, text: message })
|
18
|
+
url = backup_uri ? self.backup_uri + action : action
|
19
|
+
|
20
|
+
response = get(url, { query: query })
|
21
|
+
return false unless ok? response
|
22
|
+
|
23
|
+
case response.parsed_response
|
24
|
+
when 'ERROR 101' then ERROR_101
|
25
|
+
when 'ERROR 102' then ERROR_102
|
26
|
+
when 'ERROR 103' then ERROR_103
|
27
|
+
when 'ERROR 111' then ERROR_111
|
28
|
+
when 'FAILED 209' then backup_uri ? false : send_sms(mobile, message, true)
|
29
|
+
else
|
30
|
+
# TODO: Should we save somewhere unique SMS ID?
|
31
|
+
# unique_sms_id = response.parsed_response.split(' ').second
|
32
|
+
true
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# https://messente.com/docs/api/rest/delivery-request/sync/
|
37
|
+
def get_dlr_response(sms_unique_id, backup_uri = false)
|
38
|
+
action = '/get_dlr_response/'
|
39
|
+
query = credentials.merge({ sms_unique_id: sms_unique_id })
|
40
|
+
url = backup_uri ? self.backup_uri + action : action
|
41
|
+
|
42
|
+
response = get(url, { query: query })
|
43
|
+
return false unless ok? response
|
44
|
+
|
45
|
+
case response.parsed_response
|
46
|
+
when 'ERROR 101' then ERROR_101
|
47
|
+
when 'ERROR 102' then ERROR_102
|
48
|
+
when 'FAILED 209' then backup_uri ? false : get_dlr_response(sms_unique_id, true)
|
49
|
+
else response.parsed_response.split(' ').second.downcase
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# https://messente.com/docs/api/rest/cancel-sms/
|
54
|
+
def cancel_sms(sms_unique_id, backup_uri = false)
|
55
|
+
action = '/cancel_sms/'
|
56
|
+
query = credentials.merge({ sms_unique_id: sms_unique_id })
|
57
|
+
url = backup_uri ? self.backup_uri + action : action
|
58
|
+
|
59
|
+
response = get(url, { query: query })
|
60
|
+
return false unless ok? response
|
61
|
+
|
62
|
+
case response.parsed_response
|
63
|
+
when 'ERROR 107' then 'Could not find message with sms_unique_id.'
|
64
|
+
when 'FAILED 209' then backup_uri ? false : cancel_sms(sms_unique_id, true)
|
65
|
+
else true
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# https://messente.com/docs/api/rest/balance/
|
70
|
+
def get_balance(backup_uri = false)
|
71
|
+
action = '/get_balance/'
|
72
|
+
url = backup_uri ? self.backup_uri + action : action
|
73
|
+
|
74
|
+
response = get(url, { query: credentials })
|
75
|
+
return false unless ok? response
|
76
|
+
|
77
|
+
case response.parsed_response
|
78
|
+
when 'ERROR 101' then ERROR_101
|
79
|
+
when 'ERROR 102' then ERROR_102
|
80
|
+
when 'FAILED 209' then backup_uri ? false : get_balance(true)
|
81
|
+
else response.parsed_response.split(' ').second
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# https://messente.com/docs/api/rest/prices/
|
86
|
+
def prices(country, format = 'json', backup_uri = false)
|
87
|
+
action = '/prices/'
|
88
|
+
query = credentials.merge({ country: country, format: format })
|
89
|
+
url = backup_uri ? self.backup_uri + action : action
|
90
|
+
|
91
|
+
response = get(url, { query: query })
|
92
|
+
return false unless ok? response
|
93
|
+
|
94
|
+
case response.parsed_response
|
95
|
+
when 'ERROR 101' then ERROR_101
|
96
|
+
when 'ERROR 102' then ERROR_102
|
97
|
+
when 'ERROR 103' then 'IP address not allowed.'
|
98
|
+
when 'ERROR 104' then 'Country was not found.'
|
99
|
+
when 'ERROR 105' then 'This country is not supported.'
|
100
|
+
when 'ERROR 106' then 'Invalid format provided. Only json or xml is allowed.'
|
101
|
+
when 'FAILED 209' then backup_uri ? false : prices(country, 'json', true)
|
102
|
+
else response.parsed_response
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# https://messente.com/docs/api/rest/full-pricelist/
|
107
|
+
def pricelist(backup_uri = false)
|
108
|
+
action = '/pricelist/'
|
109
|
+
url = backup_uri ? self.backup_uri + action : action
|
110
|
+
|
111
|
+
response = get(url, { query: credentials })
|
112
|
+
return false unless ok? response
|
113
|
+
|
114
|
+
case response.parsed_response
|
115
|
+
when 'ERROR 101' then ERROR_101
|
116
|
+
when 'ERROR 102' then ERROR_102
|
117
|
+
when 'ERROR 103' then 'IP address not allowed.'
|
118
|
+
when 'FAILED 209' then backup_uri ? false : pricelist(true)
|
119
|
+
else response.parsed_response
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
private
|
124
|
+
|
125
|
+
def credentials
|
126
|
+
{ username: MessenteRails::Configuration.username,
|
127
|
+
password: MessenteRails::Configuration.password }
|
128
|
+
end
|
129
|
+
|
130
|
+
def backup_uri
|
131
|
+
base_uri.gsub('api2', 'api3')
|
132
|
+
end
|
133
|
+
|
134
|
+
def ok?(response)
|
135
|
+
response.code == 200
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'messente-rails/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'messente-rails'
|
8
|
+
spec.version = MessenteRails::VERSION
|
9
|
+
spec.authors = ['Vjatseslav Gedrovits']
|
10
|
+
spec.email = ['vjatseslav.gedrovits@gmail.com']
|
11
|
+
spec.summary = %q{Messente.com API wrapper for Rails}
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.homepage = 'https://github.com/Gedrovits/messente-rails'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
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_runtime_dependency 'httparty', '~> 0.13'
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
24
|
+
spec.add_development_dependency 'rake'
|
25
|
+
spec.add_development_dependency 'rails', '~> 4.1'
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: messente-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vjatseslav Gedrovits
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.13'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rails
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '4.1'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '4.1'
|
69
|
+
description: Messente.com API wrapper for Rails
|
70
|
+
email:
|
71
|
+
- vjatseslav.gedrovits@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- lib/generators/messente_rails/install_generator.rb
|
82
|
+
- lib/generators/messente_rails/templates/messente.rb.erb
|
83
|
+
- lib/messente-rails.rb
|
84
|
+
- lib/messente-rails/configuration.rb
|
85
|
+
- lib/messente-rails/messente.rb
|
86
|
+
- lib/messente-rails/version.rb
|
87
|
+
- messente-rails.gemspec
|
88
|
+
homepage: https://github.com/Gedrovits/messente-rails
|
89
|
+
licenses:
|
90
|
+
- MIT
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 2.3.0
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: Messente.com API wrapper for Rails
|
112
|
+
test_files: []
|