hey-you-nexmo 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ac3f5da9666d7dfce8e57f80e5a9d12e38369b839b5b8c7f6e8b67a594047001
4
+ data.tar.gz: 80f2f94e1ea2227147c0816580e933ed4cead2326da76e6f4e72e5eb59621dcb
5
+ SHA512:
6
+ metadata.gz: c64da584bcbf15cb9c1d1736c506d16445ba4b4edd6aca778275bd3dcc488db54697036876074d4b0eabf4cbe8b6a8a6292be1e11040dfafc712d3ce23458636
7
+ data.tar.gz: f5fb3c2a24fcc613040acf9fc08c8078ba0cee84aa9096d4bc0559b1a0852a8a7e474f50f66db392ccfadd036a4804ee698c2174aead870ee29016d38bb996fa
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+
11
+ .rspec_status
12
+ .byebug_history
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,12 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ rvm:
5
+ - 2.5.3
6
+ - 2.6.1
7
+ - 2.7.1
8
+ before_install: gem install bundler
9
+ scripts:
10
+ - bundle exec rspec
11
+
12
+
File without changes
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at qnesterr@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in hey-you-nexmo.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
@@ -0,0 +1,72 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ hey-you-nexmo (0.1.0)
5
+ hey-you (~> 1.2)
6
+ nexmo (~> 7.1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.7.0)
12
+ public_suffix (>= 2.0.2, < 5.0)
13
+ concurrent-ruby (1.1.6)
14
+ crack (0.4.3)
15
+ safe_yaml (~> 1.0.0)
16
+ diff-lcs (1.4.3)
17
+ faraday (0.15.4)
18
+ multipart-post (>= 1.2, < 3)
19
+ fcm (0.0.7)
20
+ faraday (= 0.15.4)
21
+ ffaker (2.15.0)
22
+ hashdiff (1.0.1)
23
+ hey-you (1.2.0)
24
+ fcm (~> 0.0.2)
25
+ i18n (~> 1.0)
26
+ mail (~> 2.7)
27
+ i18n (1.8.3)
28
+ concurrent-ruby (~> 1.0)
29
+ jwt (2.2.1)
30
+ mail (2.7.1)
31
+ mini_mime (>= 0.1.1)
32
+ mini_mime (1.0.2)
33
+ multipart-post (2.1.1)
34
+ nexmo (7.1.2)
35
+ jwt (~> 2)
36
+ sorbet-runtime (~> 0.5)
37
+ zeitwerk (~> 2, >= 2.2)
38
+ public_suffix (4.0.4)
39
+ rake (12.3.3)
40
+ rspec (3.9.0)
41
+ rspec-core (~> 3.9.0)
42
+ rspec-expectations (~> 3.9.0)
43
+ rspec-mocks (~> 3.9.0)
44
+ rspec-core (3.9.2)
45
+ rspec-support (~> 3.9.3)
46
+ rspec-expectations (3.9.2)
47
+ diff-lcs (>= 1.2.0, < 2.0)
48
+ rspec-support (~> 3.9.0)
49
+ rspec-mocks (3.9.1)
50
+ diff-lcs (>= 1.2.0, < 2.0)
51
+ rspec-support (~> 3.9.0)
52
+ rspec-support (3.9.3)
53
+ safe_yaml (1.0.5)
54
+ sorbet-runtime (0.5.5794)
55
+ webmock (3.8.3)
56
+ addressable (>= 2.3.6)
57
+ crack (>= 0.3.2)
58
+ hashdiff (>= 0.4.0, < 2.0.0)
59
+ zeitwerk (2.3.1)
60
+
61
+ PLATFORMS
62
+ ruby
63
+
64
+ DEPENDENCIES
65
+ ffaker (~> 2.15)
66
+ hey-you-nexmo!
67
+ rake (~> 12.0)
68
+ rspec (~> 3.0)
69
+ webmock (~> 3.4)
70
+
71
+ BUNDLED WITH
72
+ 2.1.4
@@ -0,0 +1,69 @@
1
+ # Hey, You, Nexmo!
2
+ [![Build Status](https://travis-ci.com/QNester/hey-you-nexmo.svg?branch=master)](https://travis-ci.com/QNester/hey-you-nexmo#)
3
+ [![Gem Version](https://badge.fury.io/rb/hey-you-nexmo.svg)](https://badge.fury.io/rb/hey-you-nexmo)
4
+
5
+ Send Nexmo sms via [hey-you gem](https://github.com/QNester/hey-you). This gem depended on [nexmo-ruby](https://github.com/Nexmo/nexmo-ruby).
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'hey-you-nexmo'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install hey-you-nexmo
22
+
23
+ ## Usage
24
+
25
+ After load gem you can send Nexmo SMS via [hey-you](https://github.com/QNester/hey-you).
26
+
27
+ For example:
28
+ ```yaml
29
+ # config/notifications.yml
30
+ events:
31
+ verified_code:
32
+ # ...
33
+ nexmo:
34
+ text: 'Your verification code: %{code}'
35
+ from: 'bestNumber'
36
+ is_unicode: false # has priority above this setting in config
37
+ ```
38
+
39
+ ```ruby
40
+ # config/initalizers/hey-you.rb
41
+ HeyYou::Config.configure do
42
+ # [String] required - your sender number
43
+ config.nexmo.from = 'myNumber'
44
+
45
+ # [Nexmo::Client] required - Instance of Nexmo client (check https://github.com/Nexmo/nexmo-ruby for more info)
46
+ config.nexmo.client = Nexmo::Client.new(...)
47
+
48
+ # [Boolean] optional - If you will send unicode texts
49
+ config.nexmo.is_unicode = true
50
+
51
+ # Check https://developer.nexmo.com/api/sms#delivery-receipt for more info about settings below
52
+ config.nexmo.ttl = 90000
53
+ config.nexmo.status_report_req = true
54
+ config.nexmo.callback = 'http://my_callback.url/'
55
+ end
56
+ ```
57
+
58
+ ```ruby
59
+ # // somewhere in your app
60
+ builder = Builder.new('events.verified_code', code: verified_code)
61
+ HeyYou::Channels::Nexmo.send!(builder, to: receiver_phone_number) #=> { success: true }
62
+ ```
63
+
64
+ ## Development
65
+
66
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests.
67
+ You can also run `bin/console` for an interactive prompt that will allow you to experiment.
68
+
69
+ To install this gem onto your local machine, run `bundle exec rake install`.
@@ -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,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "hey/you/nexmo"
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(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,34 @@
1
+ require_relative 'lib/hey_you_nexmo/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "hey-you-nexmo"
5
+ spec.version = HeyYouNexmo::VERSION
6
+ spec.authors = ["Sergey Nesterov"]
7
+ spec.email = ["qnesterr@gmail.com"]
8
+
9
+ spec.summary = %q{Nexmo SMS sender via `hey-you`}
10
+ spec.description = %q{This gem extend core gem `hey-you` for send Nexmo SMS.}
11
+ spec.homepage = "https://github.com/QNester/hey-you-nexmo"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
13
+
14
+ spec.metadata["allowed_push_host"] = "https://rubygems.org/"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/QNester/hey-you-nexmo"
18
+ spec.metadata["changelog_uri"] = "https://github.com/QNester/hey-you-nexmo/blob/master/CHANGELOG.md"
19
+
20
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_runtime_dependency "hey-you", '~> 1.2'
28
+ spec.add_runtime_dependency "nexmo", '~> 7.1'
29
+
30
+ spec.add_development_dependency "rake", "~> 13.0"
31
+ spec.add_development_dependency "rspec", "~> 3.0"
32
+ spec.add_development_dependency "webmock", '~> 3.4'
33
+ spec.add_development_dependency "ffaker", '~> 2.15'
34
+ end
@@ -0,0 +1,11 @@
1
+ require 'hey-you'
2
+ require 'hey_you_nexmo/version'
3
+ require_relative 'hey_you/config/nexmo'
4
+ require_relative 'hey_you/builder/nexmo'
5
+ require_relative 'hey_you/channels/nexmo'
6
+
7
+ module HeyYouNexmo
8
+ CHANNEL_NAME = 'nexmo'.freeze
9
+
10
+ HeyYou::Config.instance.registrate_channel(CHANNEL_NAME)
11
+ end
@@ -0,0 +1,17 @@
1
+ module HeyYou
2
+ class Builder
3
+ class Nexmo < Base
4
+ attr_reader :text, :from, :is_unicode
5
+
6
+ def build
7
+ @text = ch_data.fetch('text')
8
+ @from = ch_data.fetch('from', nil)
9
+ @is_unicode = ch_data.fetch('is_unicode', false)
10
+ rescue KeyError => e
11
+ fail MissingRequiredParameter, e
12
+ end
13
+
14
+ class MissingRequiredParameter < StandardError; end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,61 @@
1
+ require 'nexmo'
2
+
3
+ module HeyYou
4
+ module Channels
5
+ class Nexmo < Base
6
+ class ResponseError < StandardError; end
7
+ class CredentialsNotExists < StandardError; end
8
+
9
+ ERROR_MESSAGES = {
10
+ from_required: 'You must pass `from` globally (to configure) or in your notifications',
11
+ config_required: 'You must pass `{%{options}}` to `configure``',
12
+ to_required: 'You must pass `to` as option. Can not send sms to nowhere.',
13
+ callback_required: 'You must pass `callback` to `configure` if `status_report_req` is true'
14
+ }.freeze
15
+
16
+ class << self
17
+ # @param [HeyYou::Builder] builder - builder with notifications texts and settings=
18
+ # @option [String/Symbol] to - msisdn receiver
19
+ def send!(builder, **options)
20
+ raise CredentialsNotExists, ERROR_MESSAGES[:config_required] % { options: required_credentials } unless credentials_present?
21
+ raise CredentialsNotExists, ERROR_MESSAGES[:to_required] unless options[:to]
22
+
23
+ params = build_params(builder, **options)
24
+
25
+ config.nexmo.client.sms.send(params)
26
+ rescue ::Nexmo::Error => e
27
+ fail ResponseError, e
28
+ end
29
+
30
+ private
31
+
32
+ def build_params(builder, **options)
33
+ from = builder.nexmo.from || config.nexmo.from
34
+
35
+ raise CredentialsNotExists, ERROR_MESSAGES[:from_required] unless from
36
+
37
+ if config.nexmo.status_report_req && !config.nexmo.callback
38
+ raise CredentialsNotExists, ERROR_MESSAGES[:callback_required]
39
+ end
40
+
41
+ params = {
42
+ from: from,
43
+ to: options[:to],
44
+ text: builder.nexmo.text,
45
+ status_report_req: config.nexmo.status_report_req,
46
+ ttl: config.nexmo.ttl
47
+ }
48
+
49
+ params.merge!(type: 'unicode') if builder.nexmo.is_unicode || config.nexmo.is_unicode
50
+ params.merge!(callback: config.nexmo.callback) if params[:status_report_req]
51
+
52
+ params
53
+ end
54
+
55
+ def required_credentials
56
+ %i[client]
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,22 @@
1
+ require 'json'
2
+
3
+ module HeyYou
4
+ class Config
5
+ class Nexmo
6
+ extend Configurable
7
+ DEFAULTS = {
8
+ is_unicode: false,
9
+ status_report_req: false,
10
+ ttl: 259200000 # 72 hours
11
+ }.freeze
12
+
13
+ attr_accessor :client, :from, :is_unicode, :ttl, :status_report_req, :callback
14
+
15
+ def initialize
16
+ @is_unicode = DEFAULTS[:is_unicode]
17
+ @status_report_req = DEFAULTS[:status_report_req]
18
+ @ttl = DEFAULTS[:ttl]
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module HeyYouNexmo
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hey-you-nexmo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sergey Nesterov
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-07-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: hey-you
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: nexmo
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '7.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '7.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '13.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '13.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.4'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.4'
83
+ - !ruby/object:Gem::Dependency
84
+ name: ffaker
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.15'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.15'
97
+ description: This gem extend core gem `hey-you` for send Nexmo SMS.
98
+ email:
99
+ - qnesterr@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - CHANGELOG.md
108
+ - CODE_OF_CONDUCT.md
109
+ - Gemfile
110
+ - Gemfile.lock
111
+ - README.md
112
+ - Rakefile
113
+ - bin/console
114
+ - bin/setup
115
+ - hey-you-nexmo.gemspec
116
+ - lib/hey-you-nexmo.rb
117
+ - lib/hey_you/builder/nexmo.rb
118
+ - lib/hey_you/channels/nexmo.rb
119
+ - lib/hey_you/config/nexmo.rb
120
+ - lib/hey_you_nexmo/version.rb
121
+ homepage: https://github.com/QNester/hey-you-nexmo
122
+ licenses: []
123
+ metadata:
124
+ allowed_push_host: https://rubygems.org/
125
+ homepage_uri: https://github.com/QNester/hey-you-nexmo
126
+ source_code_uri: https://github.com/QNester/hey-you-nexmo
127
+ changelog_uri: https://github.com/QNester/hey-you-nexmo/blob/master/CHANGELOG.md
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: 2.5.0
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubygems_version: 3.1.2
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: Nexmo SMS sender via `hey-you`
147
+ test_files: []