textris 0.1.8 → 0.1.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 809b477aaf1b029a62e607a176a28fd472d39278
4
- data.tar.gz: f016ff50375a87cb76639ada746e94a1fe5b147e
3
+ metadata.gz: cb703c3bd61fb19f5b040f6225d6c390fc1c2473
4
+ data.tar.gz: a42312ca7c46a2f18dc15b739c58ae87157b85c4
5
5
  SHA512:
6
- metadata.gz: 35fdb014b8dd1c9fd44900d6faf8c0e02919975df0d597e1cfe5268f3cfad74d23c54e1c4a90f46c9261155dece5b9c80a7b49eb76378df264f786615f423428
7
- data.tar.gz: a7e10be07676138514db7c118e68f12c55bab309ab7ce40f989f7a8640b8055d464de2d29507ff44606763c116b887392de06094b16921a669b8fcfe15848cf9
6
+ metadata.gz: e30b26878f3cc4894b9b3189a29579c1b4fdc06a7f84a5a3bbf598c9be940725fd14304d34fb1a3d2e8a6598aa044810b0311335ca4807b889abb32fa1f98650
7
+ data.tar.gz: 43f57914ef22307eb2095b787f68763c1a5ce0ac0069b1225d2f349d5f89687c977052cb4617df16daaa3773be3cb71753cc6dbac5d077b2058db8a47b05e58b
data/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  [![Build Status](https://travis-ci.org/visualitypl/textris.svg)](https://travis-ci.org/visualitypl/textris)
4
4
  [![Code Climate](https://codeclimate.com/github/visualitypl/textris/badges/gpa.svg)](https://codeclimate.com/github/visualitypl/textris)
5
+ [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/visualitypl/textris/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/visualitypl/textris/?branch=master)
5
6
 
6
7
  Simple gem for implementing texter classes which allow sending SMS messages in similar way to how e-mails are implemented and sent with ActionMailer-based mailers.
7
8
 
@@ -13,7 +14,7 @@ Unlike similar gems, **textris** has some unique features:
13
14
  - multiple, per-environment configurable and chainable delivery methods
14
15
  - extensible with any number of custom delivery methods (also chainable)
15
16
  - support for testing using self-explanatory `Textris::Base.deliveries`
16
- - simple, extensible and fully tested code written from the ground up instead of copying guts of *ActionMailer*
17
+ - simple, extensible, fully tested code written from the ground up instead of copying *ActionMailer*
17
18
 
18
19
  ## Installation
19
20
 
@@ -23,7 +24,7 @@ Add to `Gemfile`:
23
24
  gem 'textris'
24
25
  ```
25
26
 
26
- And run:
27
+ Then run:
27
28
 
28
29
  bundle install
29
30
 
@@ -174,14 +175,14 @@ config.textris_mail_body_template = '%{content}'
174
175
 
175
176
  You can use the following interpolations in your mail templates:
176
177
 
177
- - `%{app}`: application name (like `AppName`)
178
- - `%{env}`: enviroment name (like `test` or `production`)
179
- - `%{texter}`: texter name (like `User`)
180
- - `%{action}`: action name (like `welcome`)
181
- - `%{from_name}`: name of the sender (like `Our Team`)
182
- - `%{from_phone}`: phone number of the sender (like `48666777888`)
183
- - `%{to_phone}`: phone number of the recipient (like `48111222333`)
184
- - `%{content}`: message content (like `Welcome to our system, Mr Jones!`)
178
+ - `%{app}`: application name (e.g. `AppName`)
179
+ - `%{env}`: enviroment name (e.g. `test` or `production`)
180
+ - `%{texter}`: texter name (e.g. `User`)
181
+ - `%{action}`: action name (e.g. `welcome`)
182
+ - `%{from_name}`: name of the sender (e.g. `Our Team`)
183
+ - `%{from_phone}`: phone number of the sender (e.g. `48666777888`)
184
+ - `%{to_phone}`: phone number of the recipient (e.g. `48111222333`)
185
+ - `%{content}`: message content (e.g. `Welcome to our system, Mr Jones!`)
185
186
 
186
187
  You can add optional interpolation modifiers using the `%{variable:modifiers}` syntax. These are most useful for making names e-mail friendly. The following modifiers are available:
187
188
 
@@ -42,39 +42,37 @@ module Textris
42
42
  "%{content}"
43
43
  end
44
44
 
45
- def apply_template(template, message, vars)
45
+ def apply_template(template, message, variables)
46
46
  template.gsub(/\%\{[a-z_:]+\}/) do |match|
47
47
  directive = match.gsub(/[%{}]/, '')
48
- var = directive.split(':').first
48
+ key = directive.split(':').first
49
49
  modifiers = directive.split(':')[1] || ''
50
50
 
51
- content = get_template_interpolation(var, message, vars)
51
+ content = get_template_interpolation(key, message, variables)
52
52
  content = apply_template_modifiers(content, modifiers.chars)
53
+ content = 'unknown' unless content.present?
53
54
 
54
55
  content
55
56
  end
56
57
  end
57
58
 
58
- def get_template_interpolation(var, message, vars)
59
- content = case var
59
+ def get_template_interpolation(key, message, variables)
60
+ content = case key
61
+ when 'app', 'env'
62
+ get_rails_variable(key)
63
+ when 'texter', 'action', 'from_name', 'from_phone', 'content'
64
+ message.send(key)
65
+ else
66
+ variables[key.to_sym]
67
+ end.to_s.strip
68
+ end
69
+
70
+ def get_rails_variable(var)
71
+ case var
60
72
  when 'app'
61
73
  Rails.application.class.parent_name
62
74
  when 'env'
63
75
  Rails.env
64
- when 'texter'
65
- message.texter.to_s.split('::').last.to_s.sub(/Texter$/, '')
66
- when 'action', 'from_name'
67
- message.send(var)
68
- when 'content', 'from_phone'
69
- message.send(var)
70
- else
71
- value = vars[var.to_sym]
72
- end.to_s.strip
73
-
74
- if content.present?
75
- content
76
- else
77
- 'unknown'
78
76
  end
79
77
  end
80
78
 
@@ -34,17 +34,29 @@ module Textris
34
34
  self
35
35
  end
36
36
 
37
+ def texter
38
+ if @texter.present?
39
+ @texter.to_s.split('::').last.to_s.sub(/Texter$/, '')
40
+ end
41
+ end
42
+
37
43
  private
38
44
 
39
45
  def parse_from(from)
40
- if from.blank?
41
- nil
42
- elsif (matches = from.match(/(.*)\<(.*)\>\s*$/).to_a).size == 3 &&
46
+ parse_from_dual(from) || parse_from_singular(from)
47
+ end
48
+
49
+ def parse_from_dual(from)
50
+ if (matches = from.to_s.match(/(.*)\<(.*)\>\s*$/).to_a).size == 3 &&
43
51
  Phony.plausible?(matches[2])
44
52
  [matches[1].strip, Phony.normalize(matches[2])]
45
- elsif Phony.plausible?(from)
53
+ end
54
+ end
55
+
56
+ def parse_from_singular(from)
57
+ if Phony.plausible?(from)
46
58
  [nil, Phony.normalize(from)]
47
- else
59
+ elsif from.present?
48
60
  [from.strip, nil]
49
61
  end
50
62
  end
@@ -1,3 +1,3 @@
1
1
  module Textris
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: textris
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karol Słuszniak
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.7'
19
+ version: '1.6'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.7'
26
+ version: '1.6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0.9'
69
+ - !ruby/object:Gem::Dependency
70
+ name: scrutinizer-ocular
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: actionmailer
71
85
  requirement: !ruby/object:Gem::Requirement