verb-rb 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +38 -0
- data/LICENSE +21 -0
- data/README.md +153 -0
- data/Rakefile +10 -0
- data/Vagrantfile +16 -0
- data/lib/verb.rb +159 -0
- data/test/test_verb.rb +7 -0
- data/verb-sh.gemspec +18 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8bb90c53a78be4172cbe7b83653b962c115f689e
|
4
|
+
data.tar.gz: 53afa05216045bec3b20c17b7f49dac7d7f0f517
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8a5eab9b5332016b5324a1d57be2fe9223c11bd78eadd033e612950db273067ec651ac578f0988105014444bc5deb9665a71760cc5a55a94128a9b3e92b5117b
|
7
|
+
data.tar.gz: 0144dd4bee086b97a3d7cbaf2131c73dea07ab443f00315533b4b602816f49703fdbace5d4aab494ce64e0c78fe92cc81d3b00670a5e10c12bac948f119044a9
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
verb-sh (0.0.1)
|
5
|
+
bundler (~> 1.7)
|
6
|
+
minitest (~> 5.7, >= 5.7.0)
|
7
|
+
rake (~> 10.4, >= 10.4.2)
|
8
|
+
rest-client (~> 2.0.2)
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: https://rubygems.org/
|
12
|
+
specs:
|
13
|
+
domain_name (0.5.20170404)
|
14
|
+
unf (>= 0.0.5, < 1.0.0)
|
15
|
+
http-cookie (1.0.3)
|
16
|
+
domain_name (~> 0.5)
|
17
|
+
mime-types (3.1)
|
18
|
+
mime-types-data (~> 3.2015)
|
19
|
+
mime-types-data (3.2016.0521)
|
20
|
+
minitest (5.10.3)
|
21
|
+
netrc (0.11.0)
|
22
|
+
rake (10.5.0)
|
23
|
+
rest-client (2.0.2)
|
24
|
+
http-cookie (>= 1.0.2, < 2.0)
|
25
|
+
mime-types (>= 1.16, < 4.0)
|
26
|
+
netrc (~> 0.8)
|
27
|
+
unf (0.1.4)
|
28
|
+
unf_ext
|
29
|
+
unf_ext (0.0.7.4)
|
30
|
+
|
31
|
+
PLATFORMS
|
32
|
+
ruby
|
33
|
+
|
34
|
+
DEPENDENCIES
|
35
|
+
verb-sh!
|
36
|
+
|
37
|
+
BUNDLED WITH
|
38
|
+
1.15.4
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 craaft.co
|
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,153 @@
|
|
1
|
+
# verb.sh [Ruby Client]
|
2
|
+
|
3
|
+
The official Ruby Client for the [Verb](https://verb.sh) messaging platform.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```sh
|
8
|
+
gem install verb-rb
|
9
|
+
```
|
10
|
+
|
11
|
+
#### Requirements
|
12
|
+
|
13
|
+
- *[Ruby 2.3.0+](https://www.ruby-lang.org/)*
|
14
|
+
|
15
|
+
### Configuration
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
Verb.configure(token: '<Project API Key>')
|
19
|
+
```
|
20
|
+
|
21
|
+
The API is non-blocking so you can simply send and forget. The processing happens in the background on a highly efficient queue system.
|
22
|
+
|
23
|
+
### Sending Email Messages
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
msg = Verb.email({
|
27
|
+
to: 'me@me.com', text: 'Email Text', html: 'Email HTML'
|
28
|
+
})
|
29
|
+
|
30
|
+
msg.send
|
31
|
+
```
|
32
|
+
|
33
|
+
### Attaching Files
|
34
|
+
|
35
|
+
Files can only be attached to email messages (this is also dependent on the service you are using to send the emails). Only pass the path to the file.
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
msg = Verb.email({
|
39
|
+
to: 'me@me.com', text: 'Email Text', html: 'Email HTML'
|
40
|
+
})
|
41
|
+
|
42
|
+
msg.attach('file.pdf')
|
43
|
+
|
44
|
+
# OR
|
45
|
+
|
46
|
+
msg.attach(['file1.pdf', 'file2.pdf'])
|
47
|
+
|
48
|
+
# OR
|
49
|
+
|
50
|
+
msg.attach('file1.pdf')
|
51
|
+
msg.attach('file2.pdf')
|
52
|
+
msg.attach('file3.pdf')
|
53
|
+
|
54
|
+
msg.send
|
55
|
+
|
56
|
+
```
|
57
|
+
|
58
|
+
### Restricted File Types:
|
59
|
+
|
60
|
+
These file types are generally not allowed and will be blocked.
|
61
|
+
|
62
|
+
```
|
63
|
+
vbs, exe, bin, bat, chm, com, cpl,
|
64
|
+
crt, hlp, hta, inf, ins, isp, jse,
|
65
|
+
lnk, mdb, pcd, pif, reg, scr, sct,
|
66
|
+
shs, vbe, vba, wsf, wsh, wsl, msc,
|
67
|
+
msi, msp, mst
|
68
|
+
```
|
69
|
+
|
70
|
+
### Scheduling Messages
|
71
|
+
|
72
|
+
Verb has a built-in scheduler that allows you schedule messages to be delivered in the future. These are quite useful in the sense that you can target future user behavior or events.
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
msg = Verb.email({
|
76
|
+
to: 'me@me.com', text: 'Email Text', html: 'Email HTML'
|
77
|
+
})
|
78
|
+
|
79
|
+
msg.send(in: '1h')
|
80
|
+
```
|
81
|
+
|
82
|
+
There is no limit to how far in the future a message can be scheduled for.
|
83
|
+
|
84
|
+
Schedule Examples:
|
85
|
+
|
86
|
+
- `'1h' # 1 hour`
|
87
|
+
- `'1h20m' # 1 hour 20 minutes`
|
88
|
+
- `'3Y2W' # 3 years 2 weeks`
|
89
|
+
|
90
|
+
Available Date Tokens:
|
91
|
+
|
92
|
+
- 's' seconds
|
93
|
+
- 'h' hours
|
94
|
+
- 'm' minutes
|
95
|
+
- 'D' days
|
96
|
+
- 'M' months
|
97
|
+
- 'W' weeks
|
98
|
+
- 'Y' years
|
99
|
+
|
100
|
+
### Sending SMS Messages
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
msg = Verb.sms({
|
104
|
+
to: '+20830000000', text: 'SMS Text'
|
105
|
+
})
|
106
|
+
|
107
|
+
msg.send(in: '1h')
|
108
|
+
```
|
109
|
+
|
110
|
+
### Re-usable Templates
|
111
|
+
|
112
|
+
Templates are a powerful way to add reusable message (SMS / Email) templates on the server side where you can edit content without requiring direct access to source code or perform re-deployments.
|
113
|
+
|
114
|
+
Templates are available for the following message types:
|
115
|
+
|
116
|
+
- Email Messages
|
117
|
+
- SMS Messages
|
118
|
+
|
119
|
+
Example:
|
120
|
+
|
121
|
+
```ruby
|
122
|
+
msg = Verb.sms({
|
123
|
+
template: 'welcome-sms-template', to: '+20830000000', data: { name: 'My Name', other: 'More data' }
|
124
|
+
})
|
125
|
+
|
126
|
+
msg.send(in: '20m')
|
127
|
+
```
|
128
|
+
|
129
|
+
Templates are created in the [Verb](https://verb.sh) admin dashboard using Text, HTML or [Mustache](https://mustache.github.io/). If your template contains variables, you can specify these by adding a `data: {}` field into the parameters list.
|
130
|
+
|
131
|
+
### Other API/SDK Methods
|
132
|
+
|
133
|
+
The SDK has purposely been kept simple to use in attempt to keep code as minimal as possible. There are however two additional methods that can be used to determine if messages were sent successfully.
|
134
|
+
|
135
|
+
```ruby
|
136
|
+
puts msg.status # Integer, the response code from the API
|
137
|
+
puts msg.sent? # Boolean, based on if the message was sent or not
|
138
|
+
puts msg.error # Hash, contains all the error details from the API if a message was not delivered
|
139
|
+
```
|
140
|
+
|
141
|
+
#### Running the tests
|
142
|
+
|
143
|
+
To test the current stable version of verb-sh, simply run:
|
144
|
+
|
145
|
+
rake test
|
146
|
+
|
147
|
+
#### License
|
148
|
+
|
149
|
+
Please see [LICENSE](https://github.com/apollo-black/verb-ruby/blob/master/LICENSE) for licensing details.
|
150
|
+
|
151
|
+
#### Author
|
152
|
+
|
153
|
+
Sean Nieuwoudt, [@seannieuwoudt](https://twitter.com/seannieuwoudt)
|
data/Rakefile
ADDED
data/Vagrantfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
# vi: set ft=ruby :
|
3
|
+
|
4
|
+
Vagrant.configure("2") do |config|
|
5
|
+
config.vm.box = "apolloblack/ruby"
|
6
|
+
config.vm.box_check_update = false
|
7
|
+
config.vm.synced_folder ".", "/vagrant_data"
|
8
|
+
|
9
|
+
config.vm.provider "virtualbox" do |vb|
|
10
|
+
vb.memory = "1024"
|
11
|
+
end
|
12
|
+
|
13
|
+
config.vm.provision "shell", privileged: false, inline: <<-SHELL
|
14
|
+
ln -s /vagrant_data ~/app
|
15
|
+
SHELL
|
16
|
+
end
|
data/lib/verb.rb
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'net/http'
|
3
|
+
require 'json'
|
4
|
+
require 'uri'
|
5
|
+
require 'rest_client'
|
6
|
+
|
7
|
+
module Verb
|
8
|
+
def self.configure(api_key = nil, debug = false)
|
9
|
+
pieces = api_key.split('-')
|
10
|
+
|
11
|
+
raise ArgumentError, 'The provided API Token is invalid' if pieces.count != 2
|
12
|
+
|
13
|
+
@api_key = api_key
|
14
|
+
@debug = debug
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.email(params = {})
|
18
|
+
Email.new(@api_key, params, @debug)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.sms(params = {})
|
22
|
+
SMS.new(@api_key, params, @debug)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
class Message
|
28
|
+
API_URL = ENV['VERB_API'] || 'https://verb.sh/api/v1/message'
|
29
|
+
|
30
|
+
attr_reader :context
|
31
|
+
attr_reader :files
|
32
|
+
|
33
|
+
def initialize(params = {}, debug = false)
|
34
|
+
@context = {}
|
35
|
+
@files = []
|
36
|
+
@context[:tags] = []
|
37
|
+
@debug = debug
|
38
|
+
@api_key = nil
|
39
|
+
|
40
|
+
params.each do |k, v|
|
41
|
+
if k != :api_key
|
42
|
+
@context[k] = v
|
43
|
+
else
|
44
|
+
@context[:pid] = v.split('-').last # We add the project ID to the ctx
|
45
|
+
|
46
|
+
@api_key = v.split('-').first
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Attach files to the message (if possible)
|
52
|
+
def attach(files)
|
53
|
+
if @context[:type] == :sms
|
54
|
+
raise 'This message type cannot have file attachments'
|
55
|
+
end
|
56
|
+
|
57
|
+
parsed_files(files).each do |f|
|
58
|
+
@files << f
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# Add tags to the internal tag array
|
63
|
+
def tag(tags)
|
64
|
+
if tags.is_a? Array
|
65
|
+
tags.each do |t|
|
66
|
+
@context[:tags] << t
|
67
|
+
end
|
68
|
+
else
|
69
|
+
@context[:tags] << tags
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# Send the message to the Verb API
|
74
|
+
def send(args = {})
|
75
|
+
payload = {
|
76
|
+
files: []
|
77
|
+
}
|
78
|
+
|
79
|
+
payload.merge!(args)
|
80
|
+
payload.merge!(@context)
|
81
|
+
|
82
|
+
# Attach Files
|
83
|
+
|
84
|
+
@files.each_with_index do |f, idx|
|
85
|
+
payload[:files] << File.open(f)
|
86
|
+
end
|
87
|
+
|
88
|
+
log(payload)
|
89
|
+
|
90
|
+
begin
|
91
|
+
RestClient.post API_URL, payload, {
|
92
|
+
'x-api-key': @api_key
|
93
|
+
}
|
94
|
+
rescue RestClient::ExceptionWithResponse => e
|
95
|
+
e.response
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
private
|
100
|
+
|
101
|
+
# Parse the files and return an array of files that exist
|
102
|
+
def parsed_files(files)
|
103
|
+
buffer = []
|
104
|
+
|
105
|
+
if files.kind_of?(Array)
|
106
|
+
files.each do |f|
|
107
|
+
buffer << canonical_path(f)
|
108
|
+
end
|
109
|
+
else
|
110
|
+
buffer << canonical_path(files)
|
111
|
+
end
|
112
|
+
|
113
|
+
buffer.compact
|
114
|
+
end
|
115
|
+
|
116
|
+
# Ensure that we get the path to the file instead of the File objects
|
117
|
+
def canonical_path(f)
|
118
|
+
buffer = nil
|
119
|
+
|
120
|
+
if f.kind_of?(String)
|
121
|
+
if File.exist?(f)
|
122
|
+
buffer = f
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
if f.kind_of?(File)
|
127
|
+
buffer = f.path
|
128
|
+
end
|
129
|
+
|
130
|
+
buffer
|
131
|
+
end
|
132
|
+
|
133
|
+
# Perform the message logging
|
134
|
+
def log(s)
|
135
|
+
if @debug
|
136
|
+
require 'logger'
|
137
|
+
Logger.new(STDOUT).debug(s)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
public
|
143
|
+
|
144
|
+
class Email < Message
|
145
|
+
def initialize(api_key, params = {}, debug = false)
|
146
|
+
params[:api_key] = api_key
|
147
|
+
params[:type] = :email
|
148
|
+
super(params, debug)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
class SMS < Message
|
153
|
+
def initialize(api_key, params = {}, debug = false)
|
154
|
+
params[:api_key] = api_key
|
155
|
+
params[:type] = :sms
|
156
|
+
super(params, debug)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
data/test/test_verb.rb
ADDED
data/verb-sh.gemspec
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'verb-rb'
|
3
|
+
s.version = '1.0.1'
|
4
|
+
s.date = Time.now.strftime('%Y-%m-%e').to_s
|
5
|
+
s.summary = 'A simple messaging API for web and mobile applications'
|
6
|
+
s.description = 'Verb gives you a simple & consistent way to send messages from web and mobile applications using any backing services'
|
7
|
+
s.authors = ['Sean Nieuwoudt']
|
8
|
+
s.email = 'hi@verb.sh'
|
9
|
+
s.files = `git ls-files -z`.split("\x0")
|
10
|
+
s.license = 'MIT'
|
11
|
+
s.homepage = 'https://github.com/apollo-black/verb-ruby'
|
12
|
+
s.require_paths = ['lib']
|
13
|
+
|
14
|
+
s.add_runtime_dependency 'minitest', '~> 5.7'
|
15
|
+
s.add_runtime_dependency 'rake', '~> 10.4'
|
16
|
+
s.add_runtime_dependency 'bundler', '~> 1.7'
|
17
|
+
s.add_runtime_dependency 'rest-client', '~> 2.0'
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: verb-rb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sean Nieuwoudt
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-04-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: minitest
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.7'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.4'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.7'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rest-client
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.0'
|
69
|
+
description: Verb gives you a simple & consistent way to send messages from web and
|
70
|
+
mobile applications using any backing services
|
71
|
+
email: hi@verb.sh
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- Gemfile.lock
|
79
|
+
- LICENSE
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- Vagrantfile
|
83
|
+
- lib/verb.rb
|
84
|
+
- test/test_verb.rb
|
85
|
+
- verb-sh.gemspec
|
86
|
+
homepage: https://github.com/apollo-black/verb-ruby
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
metadata: {}
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 2.6.14
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: A simple messaging API for web and mobile applications
|
110
|
+
test_files: []
|