messagebird-texter 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cf440b4e60686b98901f49458beb54cc1821b141
4
+ data.tar.gz: 3aa3f9861a936d7f9d4855ccd2596a50ae3bdd14
5
+ SHA512:
6
+ metadata.gz: 57c4f2f8da6c5c03e97f2e44b175377a20c1cf8a965ee9c8bfbea14e9aec446a1f4ad44941de7b5c0bf818d667d67b04009281047b01d0daeba7e9584f428546
7
+ data.tar.gz: 79a947dcc2293ac3e69f64254ed1a3cf768ae36a5dcc003a0836c6304eded9238ec9e476310a5f161fb6edf4d70a79d9c1587389224e5d09747eee2ec48498a9
data/.gitignore ADDED
@@ -0,0 +1,38 @@
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
36
+
37
+ # examples
38
+ example.rb
data/.rubocop.yml ADDED
@@ -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,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 messagebird-sms.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
data/Gemfile.lock ADDED
@@ -0,0 +1,84 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ messagebird-texter (0.0.1)
5
+ action-texter
6
+ phony (~> 2.12)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ action-texter (0.0.1)
12
+ json
13
+ phony (~> 2.12)
14
+ addressable (2.3.8)
15
+ coveralls (0.8.5)
16
+ json (~> 1.8)
17
+ rest-client (>= 1.6.8, < 2)
18
+ simplecov (~> 0.10.0)
19
+ term-ansicolor (~> 1.3)
20
+ thor (~> 0.19.1)
21
+ crack (0.4.3)
22
+ safe_yaml (~> 1.0.0)
23
+ diff-lcs (1.2.5)
24
+ docile (1.1.5)
25
+ domain_name (0.5.25)
26
+ unf (>= 0.0.5, < 1.0.0)
27
+ hashdiff (0.2.3)
28
+ http-cookie (1.0.2)
29
+ domain_name (~> 0.5)
30
+ json (1.8.3)
31
+ mime-types (2.99)
32
+ netrc (0.11.0)
33
+ phony (2.15.10)
34
+ rake (10.4.2)
35
+ rest-client (1.8.0)
36
+ http-cookie (>= 1.0.2, < 2.0)
37
+ mime-types (>= 1.16, < 3.0)
38
+ netrc (~> 0.7)
39
+ rspec (3.4.0)
40
+ rspec-core (~> 3.4.0)
41
+ rspec-expectations (~> 3.4.0)
42
+ rspec-mocks (~> 3.4.0)
43
+ rspec-core (3.4.1)
44
+ rspec-support (~> 3.4.0)
45
+ rspec-expectations (3.4.0)
46
+ diff-lcs (>= 1.2.0, < 2.0)
47
+ rspec-support (~> 3.4.0)
48
+ rspec-mocks (3.4.0)
49
+ diff-lcs (>= 1.2.0, < 2.0)
50
+ rspec-support (~> 3.4.0)
51
+ rspec-support (3.4.1)
52
+ safe_yaml (1.0.4)
53
+ simplecov (0.10.0)
54
+ docile (~> 1.1.0)
55
+ json (~> 1.8)
56
+ simplecov-html (~> 0.10.0)
57
+ simplecov-html (0.10.0)
58
+ term-ansicolor (1.3.2)
59
+ tins (~> 1.0)
60
+ thor (0.19.1)
61
+ tins (1.5.4)
62
+ unf (0.1.4)
63
+ unf_ext
64
+ unf_ext (0.0.7.1)
65
+ webmock (1.22.3)
66
+ addressable (>= 2.3.6)
67
+ crack (>= 0.3.2)
68
+ hashdiff
69
+
70
+ PLATFORMS
71
+ ruby
72
+
73
+ DEPENDENCIES
74
+ bundler (~> 1.10)
75
+ coveralls
76
+ messagebird-texter!
77
+ rake (~> 10.0)
78
+ rspec (~> 3.0)
79
+ simplecov
80
+ tins (= 1.5.4)
81
+ webmock (~> 1.0)
82
+
83
+ BUNDLED WITH
84
+ 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
+
data/LICENSE.txt ADDED
@@ -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.
data/README.md ADDED
@@ -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
+ messagebird-sms
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 `MessagebirdTexter.configure` to set `product_token`, `endpoint` and `path`
19
+
20
+ ```ruby
21
+ MessagebirdTexter.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 `MessagebirdTexter::Messenger`.
29
+
30
+ ```ruby
31
+ class TextMessageNotifier < MessagebirdTexter::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 < MessagebirdTexter::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 MessagebirdTexter Messenger class. To implement this functionality, you just call the public class method default which is inherited from MessagebirdTexter::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 < MessagebirdTexter::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 MessagebirdTexter Message object:
68
+ ```ruby
69
+ message = TextMessageNotifier.welcome(User.first) # => Returns a MessagebirdTexter::Message object
70
+ message.deliver_now
71
+ ```
72
+
73
+ Installation
74
+ ------------
75
+
76
+ If you user bundler, then just add
77
+ ```ruby
78
+ $ gem 'messagebird-sms'
79
+ ```
80
+ to your Gemfile and execute
81
+ ```
82
+ $ bundle install
83
+ ```
84
+ or without bundler
85
+ ```
86
+ $ gem install messagebird-sms
87
+ ```
88
+
89
+ Upgrade
90
+ -------
91
+ ```
92
+ $ bundle update messagebird-sms
93
+ ```
94
+ or without bundler
95
+
96
+ ```
97
+ $ gem update messagebird-sms
98
+ ```
99
+
100
+ Changelog
101
+ ---------
102
+
103
+ ## Contributing
104
+
105
+ Bug reports and pull requests are welcome on GitHub at https://github.com/HitFox/messagebird-sms. 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).
data/Rakefile ADDED
@@ -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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'messagebird_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
data/bin/setup ADDED
@@ -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,9 @@
1
+ module MessagebirdTexter
2
+ class Configuration < ActionTexter::Configuration
3
+ def initialize
4
+ @endpoint = 'https://rest.messagebird.com'
5
+ @path = '/messages'
6
+ @content_type = 'application/json'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ module MessagebirdTexter
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 = 2
11
+ PRE = nil
12
+
13
+ STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
14
+ end
15
+ end
@@ -0,0 +1,20 @@
1
+ require 'json'
2
+ require 'messagebird_texter/validator/message'
3
+
4
+ module MessagebirdTexter
5
+ class Message < ActionTexter::Message
6
+ def request
7
+ MessagebirdTexter::Request.new(to_json)
8
+ end
9
+
10
+ def to_json
11
+ JSON.generate(recipients: to,
12
+ originator: from,
13
+ body: body)
14
+ end
15
+
16
+ def valid?
17
+ MessagebirdTexter::Validator::Message.new self
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,7 @@
1
+ module MessagebirdTexter
2
+ class Messenger < ActionTexter::Messenger
3
+ def message
4
+ MessagebirdTexter::Message.new(from: from, to: to, body: body, reference: reference)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,30 @@
1
+ require 'messagebird_texter/response'
2
+ require 'messagebird_texter/validator/request'
3
+
4
+ module MessagebirdTexter
5
+ class Request < ActionTexter::Request
6
+ attr_accessor :body
7
+
8
+ attr_reader :response
9
+
10
+ def initialize(body)
11
+ @body = body
12
+ @endpoint = MessagebirdTexter.config.endpoint
13
+ @path = MessagebirdTexter.config.path
14
+ @api_key = MessagebirdTexter.config.product_token
15
+ end
16
+
17
+ def perform
18
+ return unless valid?
19
+ uri = URI.parse(@endpoint)
20
+ Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
21
+ @response = Response.new(http.post(@path, body, 'Authorization' => "AccessKey #{@api_key}", 'Content-Type' => 'application/json'))
22
+ end
23
+ response
24
+ end
25
+
26
+ def valid?
27
+ MessagebirdTexter::Validator::Request.new
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,72 @@
1
+ # rubocop:disable Metrics/AbcSize
2
+ # rubocop:disable MethodLength
3
+ module MessagebirdTexter
4
+ class Response
5
+ class Body
6
+ attr_reader :id,
7
+ :href,
8
+ :direction,
9
+ :type,
10
+ :originator,
11
+ :content,
12
+ :reference,
13
+ :validity,
14
+ :gateway,
15
+ :datacoding,
16
+ :mclass,
17
+ :scheduled_datetime,
18
+ :created_datetime,
19
+ :recipients
20
+
21
+ def initialize(body)
22
+ @parsed_body = JSON.parse(body, symbolize_names: true)
23
+ @id = @parsed_body[:id]
24
+ @href = @parsed_body[:href]
25
+ @direction = @parsed_body[:direction]
26
+ @type = @parsed_body[:type]
27
+ @originator = @parsed_body[:originator]
28
+ @content = @parsed_body[:body]
29
+ @reference = @parsed_body[:reference]
30
+ @validity = @parsed_body[:validity]
31
+ @gateway = @parsed_body[:gateway]
32
+ @datacoding = @parsed_body[:datacoding]
33
+ @mclass = @parsed_body[:mclass]
34
+ @scheduled_datetime = @parsed_body[:scheduledDatetime]
35
+ @created_datetime = @parsed_body[:createdDatetime]
36
+ @recipients = @parsed_body[:recipients]
37
+ end
38
+
39
+ def scheduled_datetime
40
+ Date.parse(@scheduled_datetime) unless @scheduled_datetime.nil?
41
+ end
42
+
43
+ def created_datetime
44
+ Date.parse(@created_datetime) unless @created_datetime.nil?
45
+ end
46
+
47
+ def recipients
48
+ OpenStruct.new(
49
+ total_count: @recipients[:totalCount],
50
+ total_sent_count: @recipients[:totalSentCount],
51
+ total_delivered_count: @recipients[:totalDeliveredCount],
52
+ items: items
53
+
54
+ ) unless @recipients.nil?
55
+ end
56
+
57
+ def items
58
+ @recipients[:items].map do |i|
59
+ OpenStruct.new(item(i))
60
+ end
61
+ end
62
+
63
+ def item(item)
64
+ {
65
+ recipient: item[:recipient],
66
+ status: item[:status],
67
+ status_datetime: Date.parse(item[:statusDatetime])
68
+ }
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,29 @@
1
+ module MessagebirdTexter
2
+ class Response
3
+ class Error
4
+ attr_reader :code, :description
5
+
6
+ ERROR_CODES = {
7
+ 2 => 'Request not allowed',
8
+ 9 => 'Missing params',
9
+ 10 => 'Invalid params',
10
+ 20 => 'Not found',
11
+ 25 => 'Not enough balance',
12
+ 98 => 'API not found',
13
+ 99 => 'Internal error'
14
+ }
15
+
16
+ def initialize(error)
17
+ @errors = JSON.parse(error, symbolize_names: true)[:errors]
18
+ end
19
+
20
+ def errors
21
+ @errors.map { |e| e.merge(error_message: ERROR_CODES[e[:code]]) }
22
+ end
23
+
24
+ def count
25
+ @errors.count
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,29 @@
1
+ require 'messagebird_texter/response/body'
2
+ require 'messagebird_texter/response/error'
3
+ module MessagebirdTexter
4
+ class Response
5
+ attr_reader :net_http_response, :body, :code
6
+
7
+ def initialize(net_http_response)
8
+ @net_http_response = net_http_response
9
+ @body = @net_http_response.body
10
+ @code = @net_http_response.code
11
+ end
12
+
13
+ def success?
14
+ code.to_i == 201
15
+ end
16
+
17
+ def failure?
18
+ !success?
19
+ end
20
+
21
+ def body
22
+ MessagebirdTexter::Response::Body.new(@body) if success?
23
+ end
24
+
25
+ def error
26
+ MessagebirdTexter::Response::Error.new(@body) if failure?
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,57 @@
1
+ require 'phony'
2
+ module MessagebirdTexter
3
+ module Validator
4
+ class Message
5
+ class FromTooLong < ArgumentError; end
6
+ class FromMissing < ArgumentError; end
7
+ class ToMissing < ArgumentError; end
8
+ class BodyMissing < ArgumentError; end
9
+ class BodyTooLong < ArgumentError; end
10
+ class ToUnplausible < ArgumentError; end
11
+
12
+ attr_reader :message
13
+
14
+ def initialize(message)
15
+ @message = message
16
+ validate
17
+ end
18
+
19
+ def validate
20
+ fail FromMissing, 'The value for the from attribute is missing.' unless sender_present?
21
+ fail FromTooLong, 'The value for the sender attribute must contain 1..11 characters.' unless sender_length?
22
+ fail ToMissing, 'The value for the to attribute is missing.' unless receiver_present?
23
+ fail BodyMissing, 'The body of the message is missing.' unless body_present?
24
+ fail BodyTooLong, 'The body of the message has a length greater than 160.' unless body_correct_length?
25
+ fail ToUnplausible, "The given value for the to attribute is not a plausible phone number.\nMaybe the country code is missing." unless receiver_plausible?
26
+ end
27
+
28
+ def receiver_plausible?
29
+ receiver_present? && Phony.plausible?(message.to)
30
+ end
31
+
32
+ def receiver_present?
33
+ !message.to.nil? && !message.to.empty?
34
+ end
35
+
36
+ def sender_present?
37
+ !message.from.nil? && !message.from.empty?
38
+ end
39
+
40
+ def sender_length?
41
+ sender_present? && message.from.length <= 11
42
+ end
43
+
44
+ def body_present?
45
+ !message.body.nil? && !message.body.empty?
46
+ end
47
+
48
+ def body_correct_length?
49
+ body_present? && message.body.length <= 160
50
+ end
51
+
52
+ def product_token_present?
53
+ !MessagebirdTexter.config.product_token.nil? && !MessagebirdTexter.config.product_token.empty?
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,25 @@
1
+ module MessagebirdTexter
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 = MessagebirdTexter.config.endpoint
11
+ @path = MessagebirdTexter.config.path
12
+ @content_type = MessagebirdTexter.config.content_type
13
+ @api_key = MessagebirdTexter.config.product_token
14
+ validate
15
+ end
16
+
17
+ def validate
18
+ 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?
19
+ fail ContentTypeMissing, 'Please provide a valid content_type! Defaults to application/json' if @content_type.nil? || @content_type.empty?
20
+ 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?
21
+ 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?
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,7 @@
1
+ require_relative 'gem_version'
2
+
3
+ module MessagebirdTexter
4
+ def self.version
5
+ gem_version
6
+ end
7
+ end
@@ -0,0 +1,21 @@
1
+ require 'action_texter'
2
+ require 'messagebird_texter/configuration'
3
+
4
+ module MessagebirdTexter
5
+ autoload :Messenger, 'messagebird_texter/messenger'
6
+ autoload :Message, 'messagebird_texter/message'
7
+ autoload :MessageDelivery, 'messagebird_texter/message_delivery'
8
+ autoload :Request, 'messagebird_texter/request'
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,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'messagebird_texter/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'messagebird-texter'
8
+ spec.version = MessagebirdTexter.version
9
+ spec.authors = ['oliverzeyen']
10
+ spec.email = ['oliver.zeyen@hitfoxgroup.com']
11
+
12
+ spec.summary = 'Wrapper for the Messagebird SMS Gateway API.'
13
+ spec.description = 'Send text messages/sms by means of the HTTP protocol with the service of https://www.messagebird.com.'
14
+ spec.homepage = 'https://github.com/HitFox/messagebird-sms'
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 'action-texter'
30
+ else
31
+ spec.add_dependency 'phony', '~> 2.15'
32
+ spec.add_dependency 'action-texter'
33
+ end
34
+ end
metadata ADDED
@@ -0,0 +1,153 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: messagebird-texter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
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: action-texter
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/sms by means of the HTTP protocol with the service
98
+ of https://www.messagebird.com.
99
+ email:
100
+ - oliver.zeyen@hitfoxgroup.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rubocop.yml"
107
+ - CODE_OF_CONDUCT.md
108
+ - Gemfile
109
+ - Gemfile.lock
110
+ - LICENSE
111
+ - LICENSE.txt
112
+ - README.md
113
+ - Rakefile
114
+ - bin/console
115
+ - bin/setup
116
+ - lib/messagebird_texter.rb
117
+ - lib/messagebird_texter/configuration.rb
118
+ - lib/messagebird_texter/gem_version.rb
119
+ - lib/messagebird_texter/message.rb
120
+ - lib/messagebird_texter/messenger.rb
121
+ - lib/messagebird_texter/request.rb
122
+ - lib/messagebird_texter/response.rb
123
+ - lib/messagebird_texter/response/body.rb
124
+ - lib/messagebird_texter/response/error.rb
125
+ - lib/messagebird_texter/validator/message.rb
126
+ - lib/messagebird_texter/validator/request.rb
127
+ - lib/messagebird_texter/version.rb
128
+ - messagebird-sms.gemspec
129
+ homepage: https://github.com/HitFox/messagebird-sms
130
+ licenses:
131
+ - MIT
132
+ metadata: {}
133
+ post_install_message:
134
+ rdoc_options: []
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ requirements: []
148
+ rubyforge_project:
149
+ rubygems_version: 2.4.8
150
+ signing_key:
151
+ specification_version: 4
152
+ summary: Wrapper for the Messagebird SMS Gateway API.
153
+ test_files: []