action-texter 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f8dfd865343beb264241472cba4b659104168417
4
+ data.tar.gz: 3e21b57d2ada99c9d2036c21064e4018ebf1fd34
5
+ SHA512:
6
+ metadata.gz: 4ea82f29f05c3d950e1c84152cab0488f3608946bfb4f7ef3f766865d2dfb9a4b7d67189ece689c15d441c9c7dce0cb05e349926dfa2dbe2804dc0956ed73b70
7
+ data.tar.gz: 9483e2ffd969de4c3316fc7b7526778a8f3eb2c74cc64e624df1f3bf70732ec29ef5149d2c2a39bc40f03631cbb888480f15f42fb257b39fa64f338f05870f79
@@ -0,0 +1,35 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /vendor/bundle
26
+ /lib/bundler/man/
27
+
28
+ # for a library or gem, you might want to ignore these files since the code is
29
+ # intended to run in multiple environments; otherwise, check them in:
30
+ # Gemfile.lock
31
+ .ruby-version
32
+ .ruby-gemset
33
+
34
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
+ .rvmrc
@@ -0,0 +1,17 @@
1
+ Style/ClassVars:
2
+ Enabled: false
3
+
4
+ Style/Encoding:
5
+ Enabled: false
6
+
7
+ Metrics/CyclomaticComplexity:
8
+ Enabled: false
9
+
10
+ Metrics/LineLength:
11
+ Max: 300
12
+
13
+ Metrics/PerceivedComplexity:
14
+ Enabled: false
15
+
16
+ Documentation:
17
+ Enabled: false
@@ -0,0 +1,70 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2015-12-08 22:41:05 +0100 using RuboCop version 0.35.1.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 2
10
+ Lint/UselessAssignment:
11
+ Exclude:
12
+ - 'lib/action_texter/helper.rb'
13
+ - 'lib/action_texter/request.rb'
14
+
15
+ # Offense count: 4
16
+ Metrics/AbcSize:
17
+ Max: 25
18
+
19
+ # Offense count: 2
20
+ Metrics/CyclomaticComplexity:
21
+ Max: 8
22
+
23
+ # Offense count: 21
24
+ # Configuration parameters: AllowURI, URISchemes.
25
+ Metrics/LineLength:
26
+ Max: 215
27
+
28
+ # Offense count: 1
29
+ Metrics/PerceivedComplexity:
30
+ Max: 8
31
+
32
+ # Offense count: 2
33
+ Style/ClassVars:
34
+ Exclude:
35
+ - 'lib/action_texter/messenger.rb'
36
+
37
+ # Offense count: 12
38
+ # Configuration parameters: Exclude.
39
+ Style/Documentation:
40
+ Exclude:
41
+ - 'spec/**/*'
42
+ - 'test/**/*'
43
+ - 'lib/action-texter.rb'
44
+ - 'lib/action_texter/configuration.rb'
45
+ - 'lib/action_texter/gem_version.rb'
46
+ - 'lib/action_texter/helper.rb'
47
+ - 'lib/action_texter/message.rb'
48
+ - 'lib/action_texter/message_delivery.rb'
49
+ - 'lib/action_texter/messenger.rb'
50
+ - 'lib/action_texter/request.rb'
51
+ - 'lib/action_texter/response.rb'
52
+ - 'lib/action_texter/validator/request.rb'
53
+ - 'lib/action_texter/version.rb'
54
+
55
+ # Offense count: 1
56
+ # Configuration parameters: Exclude.
57
+ Style/FileName:
58
+ Exclude:
59
+ - 'lib/action-texter.rb'
60
+
61
+ # Offense count: 1
62
+ # Configuration parameters: MinBodyLength.
63
+ Style/GuardClause:
64
+ Exclude:
65
+ - 'lib/action_texter/request.rb'
66
+
67
+ # Offense count: 10
68
+ # Configuration parameters: SupportedStyles.
69
+ Style/RaiseArgs:
70
+ EnforcedStyle: compact
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in action-texter.gemspec
4
+ gemspec
5
+
6
+ gem 'tins', '1.5.4', require: false, group: :test
7
+ gem 'simplecov', require: false, group: :test
8
+ gem 'coveralls', require: false, group: :test
@@ -0,0 +1,81 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ action-texter (0.0.1)
5
+ json
6
+ phony (~> 2.12)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.3.8)
12
+ coveralls (0.8.5)
13
+ json (~> 1.8)
14
+ rest-client (>= 1.6.8, < 2)
15
+ simplecov (~> 0.10.0)
16
+ term-ansicolor (~> 1.3)
17
+ thor (~> 0.19.1)
18
+ crack (0.4.3)
19
+ safe_yaml (~> 1.0.0)
20
+ diff-lcs (1.2.5)
21
+ docile (1.1.5)
22
+ domain_name (0.5.25)
23
+ unf (>= 0.0.5, < 1.0.0)
24
+ hashdiff (0.2.3)
25
+ http-cookie (1.0.2)
26
+ domain_name (~> 0.5)
27
+ json (1.8.3)
28
+ mime-types (2.99)
29
+ netrc (0.11.0)
30
+ phony (2.15.9)
31
+ rake (10.4.2)
32
+ rest-client (1.8.0)
33
+ http-cookie (>= 1.0.2, < 2.0)
34
+ mime-types (>= 1.16, < 3.0)
35
+ netrc (~> 0.7)
36
+ rspec (3.4.0)
37
+ rspec-core (~> 3.4.0)
38
+ rspec-expectations (~> 3.4.0)
39
+ rspec-mocks (~> 3.4.0)
40
+ rspec-core (3.4.1)
41
+ rspec-support (~> 3.4.0)
42
+ rspec-expectations (3.4.0)
43
+ diff-lcs (>= 1.2.0, < 2.0)
44
+ rspec-support (~> 3.4.0)
45
+ rspec-mocks (3.4.0)
46
+ diff-lcs (>= 1.2.0, < 2.0)
47
+ rspec-support (~> 3.4.0)
48
+ rspec-support (3.4.1)
49
+ safe_yaml (1.0.4)
50
+ simplecov (0.10.0)
51
+ docile (~> 1.1.0)
52
+ json (~> 1.8)
53
+ simplecov-html (~> 0.10.0)
54
+ simplecov-html (0.10.0)
55
+ term-ansicolor (1.3.2)
56
+ tins (~> 1.0)
57
+ thor (0.19.1)
58
+ tins (1.5.4)
59
+ unf (0.1.4)
60
+ unf_ext
61
+ unf_ext (0.0.7.1)
62
+ webmock (1.22.3)
63
+ addressable (>= 2.3.6)
64
+ crack (>= 0.3.2)
65
+ hashdiff
66
+
67
+ PLATFORMS
68
+ ruby
69
+
70
+ DEPENDENCIES
71
+ action-texter!
72
+ bundler (~> 1.10)
73
+ coveralls
74
+ rake (~> 10.0)
75
+ rspec (~> 3.0)
76
+ simplecov
77
+ tins (= 1.5.4)
78
+ webmock (~> 1.0)
79
+
80
+ BUNDLED WITH
81
+ 1.10.6
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 HitFox Group GmbH
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.
22
+
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 itschn
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
13
+ all 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
21
+ THE SOFTWARE.
@@ -0,0 +1,110 @@
1
+ ![alt text](http://www.hitfoxgroup.com/downloads/hitfox_logo_with_tag_two_colors_WEB.png "Logo Hitfox Group")
2
+
3
+
4
+ action-texter
5
+ =======
6
+
7
+
8
+ Description
9
+ -----------
10
+
11
+ Send text messages by means of the HTTP protocol with the service of https://www.messagebird.com, from your ruby app.
12
+
13
+ Usage
14
+ ------------
15
+
16
+ ### Configuration
17
+
18
+ Use `ActionTexter.configure` to set `product_token`, `endpoint` and `path`
19
+
20
+ ```ruby
21
+ ActionTexter.configure do |config|
22
+ config.product_token = 'YOUR_MESSAGEBIRD_API_TOKEN'
23
+ config.endpoint = 'https://rest.messagebird.com' # Messagebird default
24
+ config.path = '/messages' # Messagebird default
25
+ end
26
+ ```
27
+
28
+ Create a class that is inherited from `ActionTexter::Messenger`.
29
+
30
+ ```ruby
31
+ class TextMessageNotifier < ActionTexter::Messenger
32
+ end
33
+ ```
34
+
35
+ Now you can add your first welcome message.
36
+ This can be as simple as:
37
+
38
+ ```ruby
39
+ class TextMessageNotifier < ActionTexter::Messenger
40
+ default from: 'some string or mobile number'
41
+
42
+ def welcome(recipient)
43
+ @recipient = recipient
44
+
45
+ content(to: recipient.mobile_number, body: 'Some text, reference: recipient.id)
46
+ end
47
+ end
48
+ ```
49
+ ### Setting defaults
50
+
51
+ It is possible to set default values that will be used in every method in your ActionTexter Messenger class. To implement this functionality, you just call the public class method default which is inherited from ActionTexter::Messenger. This method accepts a Hash as the parameter. You can use :from, :to and :body as the key.
52
+
53
+ Note that every value you set with this method will get overwritten if you use the same key in your mailer method.
54
+
55
+ Example:
56
+
57
+ ```ruby
58
+ class TextMessageNotifier < ActionTexter::Messenger
59
+ default from: "Quentin", "00491710000000"
60
+ .....
61
+ end
62
+ ```
63
+ ### Deliver messages
64
+
65
+ In order to send your sms, you simply call the method and then call `deliver_now` on the return value.
66
+
67
+ Calling the method returns a ActionTexter Message object:
68
+ ```ruby
69
+ message = TextMessageNotifier.welcome(User.first) # => Returns a ActionTexter::Message object
70
+ message.deliver_now
71
+ ```
72
+
73
+ Installation
74
+ ------------
75
+
76
+ If you user bundler, then just add
77
+ ```ruby
78
+ $ gem 'action-texter'
79
+ ```
80
+ to your Gemfile and execute
81
+ ```
82
+ $ bundle install
83
+ ```
84
+ or without bundler
85
+ ```
86
+ $ gem install action-texter
87
+ ```
88
+
89
+ Upgrade
90
+ -------
91
+ ```
92
+ $ bundle update action-texter
93
+ ```
94
+ or without bundler
95
+
96
+ ```
97
+ $ gem update action-texter
98
+ ```
99
+
100
+ Changelog
101
+ ---------
102
+
103
+ ## Contributing
104
+
105
+ Bug reports and pull requests are welcome on GitHub at https://github.com/HitFox/action-texter. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
106
+
107
+
108
+ ## License
109
+
110
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'action_texter/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'action-texter'
8
+ spec.version = ActionTexter.version
9
+ spec.authors = ['oliverzeyen']
10
+ spec.email = ['oliver.zeyen@hitfoxgroup.com']
11
+
12
+ spec.summary = 'Foundation for API driven sms delivery'
13
+ spec.description = 'Send text messages by means of the HTTP protocol via a HTTP driven sms provider'
14
+ spec.homepage = 'https://github.com/HitFox/action-texter'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.10'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'rspec', '~> 3.0'
25
+ spec.add_development_dependency 'webmock', '~> 1.0'
26
+
27
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0')
28
+ spec.add_runtime_dependency 'phony', '~> 2.12'
29
+ spec.add_runtime_dependency 'json'
30
+ else
31
+ spec.add_dependency 'phony', '~> 2.15'
32
+ spec.add_dependency 'json'
33
+ end
34
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'action_texter'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,21 @@
1
+ require 'action_texter/configuration'
2
+
3
+ module ActionTexter
4
+ autoload :Messenger, 'action_texter/messenger'
5
+ autoload :Message, 'action_texter/message'
6
+ autoload :Request, 'action_texter/request'
7
+ autoload :Helper, 'action_texter/helper'
8
+ autoload :MessageDelivery, 'action_texter/message_delivery'
9
+
10
+ class << self
11
+ def configure
12
+ yield(configuration)
13
+ end
14
+
15
+ def configuration
16
+ @configuration ||= Configuration.new
17
+ end
18
+
19
+ alias_method :config, :configuration
20
+ end
21
+ end
@@ -0,0 +1,17 @@
1
+ module ActionTexter
2
+ class Configuration
3
+ attr_accessor :from, :to, :endpoint, :path, :product_token, :content_type
4
+
5
+ alias_method :api_key=, :product_token=
6
+
7
+ def defaults
8
+ @defaults ||= { from: from, to: to, content_type: content_type }
9
+ end
10
+
11
+ def initialize
12
+ @endpoint = 'https://rest.sms-service.com'
13
+ @path = '/messages'
14
+ @content_type = 'application/json'
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ module ActionTexter
2
+ # Returns the version of the currently loaded Action Mailer as a <tt>Gem::Version</tt>
3
+ def self.gem_version
4
+ Gem::Version.new VERSION::STRING
5
+ end
6
+
7
+ module VERSION
8
+ MAJOR = 0
9
+ MINOR = 0
10
+ TINY = 1
11
+ PRE = nil
12
+
13
+ STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
14
+ end
15
+ end
@@ -0,0 +1,10 @@
1
+ module ActionTexter
2
+ class Helper
3
+ def self.underscore(camel_cased_word)
4
+ camel_cased_word.to_s.gsub(/::/, '/')
5
+ .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
6
+ .gsub(/([a-z\d])([A-Z])/, '\1_\2')
7
+ .tr('-', '_').downcase
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,38 @@
1
+ require 'phony'
2
+ require 'action_texter/request'
3
+ require 'action_texter/validator/message'
4
+
5
+ module ActionTexter
6
+ class Message
7
+ attr_accessor :from, :to, :body, :reference
8
+
9
+ def initialize(attributes = {})
10
+ @from = attributes[:from]
11
+ @to = attributes[:to]
12
+ @body = attributes[:body]
13
+ @reference = attributes[:reference]
14
+ end
15
+
16
+ def request
17
+ Request.new(to_json)
18
+ end
19
+
20
+ def deliver
21
+ request.perform if valid?
22
+ end
23
+
24
+ def deliver!
25
+ deliver if valid?
26
+ end
27
+
28
+ def valid?
29
+ ActionTexter::Validator::Message.new self
30
+ end
31
+
32
+ def to_json
33
+ JSON.generate(recipients: to,
34
+ originator: from,
35
+ body: body)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,38 @@
1
+ require 'delegate'
2
+
3
+ module ActionTexter
4
+ class MessageDelivery < Delegator
5
+ def initialize(messenger, message_method, *args) #:nodoc:
6
+ @messenger = messenger
7
+ @message_method = message_method
8
+ @args = args
9
+ end
10
+
11
+ def __getobj__ #:nodoc:
12
+ @obj ||= @messenger.send(:new).send(@message_method, *@args).message
13
+ end
14
+
15
+ alias_method :message, :__getobj__
16
+
17
+ def __setobj__(obj) #:nodoc:
18
+ @obj = obj
19
+ end
20
+
21
+ def deliver_now!
22
+ message.deliver!
23
+ end
24
+
25
+ def deliver_now
26
+ message.deliver
27
+ end
28
+
29
+ def inspect
30
+ prefix = "#<#{self.class}:0x#{__id__.to_s(16)}"
31
+ parts = instance_variables.map { |var| "#{var}=#{instance_variable_get(var).inspect}" }
32
+ str = [prefix, parts, ']>'].join(' ')
33
+
34
+ str.taint if tainted?
35
+ str
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,48 @@
1
+ module ActionTexter
2
+ class Messenger
3
+ attr_accessor :from, :to, :body, :dcs, :reference
4
+
5
+ def initialize(attributes = {})
6
+ self.class.default_params ||= {}
7
+
8
+ @from = attributes[:from] || self.class.default_params[:from]
9
+ @to = attributes[:to] || self.class.default_params[:to]
10
+ @body = attributes[:body]
11
+ @reference = attributes[:reference]
12
+ end
13
+
14
+ def content(attributes = {})
15
+ attributes.each { |attr, value| send("#{attr}=", value) }
16
+ self
17
+ end
18
+
19
+ def message
20
+ @message ||= ActionTexter::Message.new(from: from, to: to, dcs: dcs, body: body, reference: reference)
21
+ end
22
+
23
+ def self.method_missing(method_name, *args) # :nodoc:
24
+ if new.respond_to?(method_name.to_s)
25
+ ActionTexter::MessageDelivery.new(self, method_name, *args)
26
+ else
27
+ super
28
+ end
29
+ end
30
+
31
+ def self.respond_to_missing?(method_name, *args) # :nodoc:
32
+ new.respond_to?(method_name.to_s) || super
33
+ end
34
+
35
+ def self.default_params
36
+ @@default_params ||= ActionTexter.config.defaults
37
+ end
38
+
39
+ def self.default_params=(params = {})
40
+ @@default_params = params
41
+ end
42
+
43
+ def self.default(hash = {})
44
+ self.default_params = ActionTexter.config.defaults.merge(hash).freeze
45
+ default_params
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,22 @@
1
+ require 'action_texter/response'
2
+ require 'action_texter/validator/request'
3
+
4
+ module ActionTexter
5
+ class Request
6
+ attr_accessor :body
7
+
8
+ attr_reader :response
9
+
10
+ def initialize(body)
11
+ @body = body
12
+ end
13
+
14
+ def perform
15
+ fail NotImplementedError if valid?
16
+ end
17
+
18
+ def valid?
19
+ ActionTexter::Validator::Request.new
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,23 @@
1
+ module ActionTexter
2
+ class Response
3
+ attr_reader :net_http_response, :body, :code
4
+
5
+ def initialize(net_http_response)
6
+ @net_http_response = net_http_response
7
+ @body = @net_http_response.body
8
+ @code = @net_http_response.code
9
+ end
10
+
11
+ def success?
12
+ body.to_s.strip.empty? && code.to_i == 200
13
+ end
14
+
15
+ def failure?
16
+ !success?
17
+ end
18
+
19
+ def error
20
+ body.sub('Error: ERROR', '').strip
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,53 @@
1
+ module ActionTexter
2
+ module Validator
3
+ class Message
4
+ class FromTooLong < ArgumentError; end
5
+ class FromMissing < ArgumentError; end
6
+ class ToMissing < ArgumentError; end
7
+ class BodyMissing < ArgumentError; end
8
+ class BodyTooLong < ArgumentError; end
9
+ class ToUnplausible < ArgumentError; end
10
+
11
+ attr_reader :message
12
+
13
+ def initialize(message)
14
+ @message = message
15
+
16
+ fail FromMissing, 'The value for the from attribute is missing.' unless sender_present?
17
+ fail FromTooLong, 'The value for the sender attribute must contain 1..11 characters.' unless sender_length?
18
+ fail ToMissing, 'The value for the to attribute is missing.' unless receiver_present?
19
+ fail BodyMissing, 'The body of the message is missing.' unless body_present?
20
+ fail BodyTooLong, 'The body of the message has a length greater than 160.' unless body_correct_length?
21
+ fail ToUnplausible, "The given value for the to attribute is not a plausible phone number.\nMaybe the country code is missing." unless receiver_plausible?
22
+ end
23
+
24
+ def receiver_plausible?
25
+ receiver_present? && Phony.plausible?(message.to)
26
+ end
27
+
28
+ def receiver_present?
29
+ !message.to.nil? && !message.to.empty?
30
+ end
31
+
32
+ def sender_present?
33
+ !message.from.nil? && !message.from.empty?
34
+ end
35
+
36
+ def sender_length?
37
+ sender_present? && message.from.length <= 11
38
+ end
39
+
40
+ def body_present?
41
+ !message.body.nil? && !message.body.empty?
42
+ end
43
+
44
+ def body_correct_length?
45
+ body_present? && message.body.length <= 160
46
+ end
47
+
48
+ def product_token_present?
49
+ !ActionTexter.config.product_token.nil? && !ActionTexter.config.product_token.empty?
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,26 @@
1
+ module ActionTexter
2
+ module Validator
3
+ class Request
4
+ class ProductTokenMissing < ArgumentError; end
5
+ class EndpointMissing < ArgumentError; end
6
+ class PathMissing < ArgumentError; end
7
+ class ContentTypeMissing < ArgumentError; end
8
+
9
+ def initialize
10
+ @endpoint = ActionTexter.config.endpoint
11
+ @path = ActionTexter.config.path
12
+ @content_type = ActionTexter.config.content_type
13
+ @api_key = ActionTexter.config.product_token
14
+
15
+ validate
16
+ end
17
+
18
+ def validate
19
+ fail EndpointMissing, "Please provide an valid api endpoint.\nIf you leave this config blank, the default will be set to https://rest.sms-service.org ." if @endpoint.nil? || @endpoint.empty?
20
+ fail ContentTypeMissing, 'Please provide a valid content_type! Defaults to application/json' if @content_type.nil? || @content_type.empty?
21
+ fail PathMissing, "Please provide an valid api path.\nIf you leave this config blank, the default will be set to /message." if @path.nil? || @path.empty?
22
+ fail ProductTokenMissing, "Please provide an valid product key.\nAfter signup at https://www.messagebird.com/, you will find one in your settings." if @api_key.nil?
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,7 @@
1
+ require_relative 'gem_version'
2
+
3
+ module ActionTexter
4
+ def self.version
5
+ gem_version
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,154 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: action-texter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - oliverzeyen
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-12-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
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.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: phony
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.12'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.12'
83
+ - !ruby/object:Gem::Dependency
84
+ name: json
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Send text messages by means of the HTTP protocol via a HTTP driven sms
98
+ provider
99
+ email:
100
+ - oliver.zeyen@hitfoxgroup.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rubocop.yml"
107
+ - ".rubocop_todo.yml"
108
+ - CODE_OF_CONDUCT.md
109
+ - Gemfile
110
+ - Gemfile.lock
111
+ - LICENSE
112
+ - LICENSE.txt
113
+ - README.md
114
+ - Rakefile
115
+ - action-texter.gemspec
116
+ - bin/console
117
+ - bin/setup
118
+ - lib/action_texter.rb
119
+ - lib/action_texter/configuration.rb
120
+ - lib/action_texter/gem_version.rb
121
+ - lib/action_texter/helper.rb
122
+ - lib/action_texter/message.rb
123
+ - lib/action_texter/message_delivery.rb
124
+ - lib/action_texter/messenger.rb
125
+ - lib/action_texter/request.rb
126
+ - lib/action_texter/response.rb
127
+ - lib/action_texter/validator/message.rb
128
+ - lib/action_texter/validator/request.rb
129
+ - lib/action_texter/version.rb
130
+ homepage: https://github.com/HitFox/action-texter
131
+ licenses:
132
+ - MIT
133
+ metadata: {}
134
+ post_install_message:
135
+ rdoc_options: []
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ required_rubygems_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ requirements: []
149
+ rubyforge_project:
150
+ rubygems_version: 2.4.8
151
+ signing_key:
152
+ specification_version: 4
153
+ summary: Foundation for API driven sms delivery
154
+ test_files: []