vonage_rails 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1e57188ca719587ccc849ea056ba617f3765e4791725f46a2c9a35b678d3aa15
4
+ data.tar.gz: a93c1f0c1f393db3b848acbaf79411920d8de7afbe18658cc2eaac9f64fbd63f
5
+ SHA512:
6
+ metadata.gz: 45c47ada2204ab3223290f8f1df0e82cabe701ddccbdde70057ccb0197c9e2d74a421fa625dd2496f0b3453f294b7cf5e217478203f1dfa9d41060aa22319bc1
7
+ data.tar.gz: 585125e6ddfb45c94bfabc8178ce4c5b44915479f6d48f19f9f9f7e13588cf84e7b45fd4eb7393c2e0ecb354a4ca736ba42eb355bef3d12819c6aeaf3e073563
data/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright 2020 Vonage
4
+
5
+ Permission is hereby granted, free of charge, to any person
6
+ obtaining a copy of this software and associated documentation
7
+ files (the "Software"), to deal in the Software without
8
+ restriction, including without limitation the rights to use,
9
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the
11
+ Software is furnished to do so, subject to the following
12
+ conditions:
13
+
14
+ The above copyright notice and this permission notice shall be
15
+ included in all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,108 @@
1
+ # Vonage Rails Gem
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/vonage_rails.svg)](https://badge.fury.io/rb/vonage_rails) [![Coverage Status](https://coveralls.io/repos/github/Nexmo/nexmo-rails/badge.svg?branch=master)](https://coveralls.io/github/Nexmo/nexmo-rails?branch=master) [![Build Status](https://api.travis-ci.org/Nexmo/nexmo-rails.svg?branch=master)](https://travis-ci.org/Nexmo/nexmo-rails)
4
+
5
+ <img src="https://developer.nexmo.com/assets/images/Vonage_Nexmo.svg" height="48px" alt="Nexmo is now known as Vonage" />
6
+
7
+ This is the Vonage Rails Gem for Vonage APIs. To use it you'll
8
+ need a Vonage account. Sign up [for free at vonage.com](https://dashboard.nexmo.com/sign-up?utm_source=DEV_REL&utm_medium=github&utm_campaign=nexmo-rails).
9
+
10
+ * [Requirements](#requirements)
11
+ * [Installation](#installation)
12
+ * [Usage](#usage)
13
+ * [License](#license)
14
+
15
+ ## Requirements
16
+
17
+ Vonage Rails requires:
18
+
19
+ * Rails 5.2+
20
+ * Ruby 2.5.3+
21
+ * To use the Vonage APIs, you [need an account](https://dashboard.nexmo.com/sign-up?utm_source=DEV_REL&utm_medium=github&utm_campaign=nexmo-rails)
22
+
23
+ ## Installation
24
+
25
+ To install the Vonage Rails gem add it to your project's Gemfile:
26
+
27
+ ```ruby
28
+
29
+ gem 'vonage_rails'
30
+
31
+ ```
32
+
33
+ Then, run `bundle install` from the command line.
34
+
35
+ ## Usage
36
+
37
+ The Vonage Rails gem will initialize a new instance of the Vonage client inside your Rails application and make it globally accessible. To make this happen, you must supply it with your Vonage API credentials. You can do so either as environemnt variables or as part of your Rails credentials.
38
+
39
+ ### With Environment Variables
40
+
41
+ To add your Vonage API credentials as environment variables, first add the desired Vonage credentials to your `.env` file. For example, if you are using only the `API_KEY` and `API_SECRET`, then add the following:
42
+
43
+ ```
44
+
45
+ VONAGE_API_KEY = your_api_key
46
+ VONAGE_API_SECRET = your_api_secret
47
+
48
+ ```
49
+
50
+ If you are also using a `SIGNATURE`, `APPLICATION_ID` and/or a `PRIVATE_KEY`, then add them as appropriate to your `.env` file:
51
+
52
+ ```
53
+
54
+ VONAGE_API_SIGNATURE = your_signature
55
+ VONAGE_PRIVATE_KEY = your_private_key_file_path
56
+ VONAGE_APPLICATION_ID = your_application_id
57
+
58
+ ```
59
+
60
+ Make sure you have the `dotenv-rails` Gem installed in your application and that your `.env` file is included in `.gitignore` so as not to commit your credentials to version control.
61
+
62
+ ### With Rails Credentials
63
+
64
+ To add your Vonage API credentials to your Rails Credentials, go ahead and open your encrypted credentials file with the following command:
65
+
66
+ ```console
67
+
68
+ $ EDITOR="code --wait" rails credentials:edit
69
+
70
+ ```
71
+
72
+ You can replace the `EDITOR` variable with your preferred editor. Once the credentials file is open, you are able to add the Vonage credentials with the following namespacing:
73
+
74
+ ```yaml
75
+
76
+ vonage:
77
+ api_key:
78
+ api_secret:
79
+
80
+ ```
81
+
82
+ You may add any of the Vonage API credentials your application needs nested within the `vonage:` namespace.
83
+
84
+ ### Running the Initializer
85
+
86
+ To initialize your global Vonage client in your application, run the following from your terminal:
87
+
88
+ ```console
89
+
90
+ $ rails generate vonage_initializer
91
+
92
+ ```
93
+
94
+ This will create a `./config/initializers/vonage.rb` file in your application that will make the variable `Vonage` available across your application, which contains your fully credentialed Vonage client.
95
+
96
+ At this point, you can access any of the Vonage APIs by simply referring to `Vonage` in your code. For example, instead of first initializing a Vonage client with your credentials to send an SMS, all you need to do is add the following to your application:
97
+
98
+ ```ruby
99
+
100
+ Vonage.sms.send(from: 'YOUR_NUMBER', to: 'NUMBER', text: 'Hello world')
101
+
102
+ ```
103
+
104
+ More information on the Vonage Ruby Server SDK and how to use it with the Vonage APIs can be found [here](https://github.com/Vonage/vonage-ruby-sdk).
105
+
106
+ ## License
107
+
108
+ This project is under the [MIT License](LICENSE).
@@ -0,0 +1,28 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'VonageRails'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ require 'bundler/gem_tasks'
18
+
19
+ require 'rspec/core/rake_task'
20
+ require 'coveralls/rake/task'
21
+
22
+ RSpec::Core::RakeTask.new(:test)
23
+
24
+ Coveralls::RakeTask.new
25
+
26
+ task default: :test
27
+
28
+ task :test_with_coveralls => [:test, 'coveralls:push']
@@ -0,0 +1,43 @@
1
+ require 'rails/all'
2
+
3
+ class VonageInitializerGenerator < Rails::Generators::Base
4
+ source_root File.expand_path('../templates', __FILE__)
5
+
6
+ desc "This generator creates a Vonage initializer file at config/initializers and makes a configured Vonage client globally available"
7
+
8
+ def create_vonage_initializer
9
+ if Rails.application.credentials.vonage
10
+ return credentials_initializer
11
+ end
12
+
13
+ env_initializer
14
+ end
15
+
16
+ private
17
+
18
+ def credentials_initializer
19
+ initializer "vonage.rb" do <<~HEREDOC
20
+ Vonage.setup do |config|
21
+ config.api_key = Rails.application.credentials.vonage[:api_key]
22
+ config.api_secret = Rails.application.credentials.vonage[:api_secret]
23
+ config.signature_secret = Rails.application.credentials.vonage[:api_signature]
24
+ config.application_id = Rails.application.credentials.vonage[:application_id]
25
+ config.private_key = Rails.application.credentials.vonage[:private_key]
26
+ end
27
+ HEREDOC
28
+ end
29
+ end
30
+
31
+ def env_initializer
32
+ initializer "vonage.rb" do <<~HEREDOC
33
+ Vonage.setup do |config|
34
+ config.api_key = ENV['VONAGE_API_KEY']
35
+ config.api_secret = ENV['VONAGE_API_SECRET']
36
+ config.signature_secret = ENV['VONAGE_API_SIGNATURE']
37
+ config.application_id = ENV['VONAGE_APPLICATION_ID']
38
+ config.private_key = ENV['VONAGE_PRIVATE_KEY']
39
+ end
40
+ HEREDOC
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,28 @@
1
+ require 'vonage'
2
+ require 'forwardable'
3
+
4
+ module Vonage
5
+ class << self
6
+ extend Forwardable
7
+
8
+ attr_accessor :client
9
+
10
+ def_delegators :@client, :account, :alerts, :applications,
11
+ :voice, :conversations, :conversions,
12
+ :files, :messages, :numbers,
13
+ :number_insight, :pricing, :redact, :secrets,
14
+ :sms, :signature, :tfa, :verify
15
+
16
+ def setup(&block)
17
+ config = OpenStruct.new
18
+ config.instance_eval(&block)
19
+ self.client = ::Vonage::Client.new(
20
+ api_key: config.api_key,
21
+ api_secret: config.api_secret,
22
+ signature_secret: config.signature_secret,
23
+ application_id: config.application_id,
24
+ private_key: config.private_key.present? && File.exist?(config.private_key) ? File.read(config.private_key) : config.private_key
25
+ )
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,5 @@
1
+ # :nocov:
2
+ module VonageRails
3
+ VERSION = '1.0.0'
4
+ end
5
+ # :nocov:
metadata ADDED
@@ -0,0 +1,166 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vonage_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Vonage
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-09-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jwt
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: vonage
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 7.2.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 7.2.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: dotenv-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '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: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: generator_spec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.16'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.16'
111
+ - !ruby/object:Gem::Dependency
112
+ name: coveralls
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.8.15
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.8.15
125
+ description: Rails Initializer for Vonage's Ruby Server SDK
126
+ email:
127
+ - devrel@vonage.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - LICENSE
133
+ - README.md
134
+ - Rakefile
135
+ - lib/generators/vonage_initializer/vonage_initializer_generator.rb
136
+ - lib/vonage_rails.rb
137
+ - lib/vonage_rails/version.rb
138
+ homepage: https://github.com/Nexmo/nexmo-rails
139
+ licenses:
140
+ - MIT
141
+ metadata:
142
+ homepage: https://github.com/Nexmo/nexmo-rails
143
+ source_code_uri: https://github.com/Nexmo/nexmo-rails
144
+ bug_tracker_uri: https://github.com/Nexmo/nexmo-rails/issues
145
+ changelog_uri: https://github.com/Nexmo/nexmo-rails/blog/master/CHANGES.md
146
+ post_install_message:
147
+ rdoc_options: []
148
+ require_paths:
149
+ - lib
150
+ required_ruby_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ required_rubygems_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ requirements: []
161
+ rubygems_version: 3.0.0
162
+ signing_key:
163
+ specification_version: 4
164
+ summary: This is a Rails initializer for Vonage's Ruby Gem. To use it you'll need
165
+ a Vonage account. Sign up for free at https://www.vonage.com
166
+ test_files: []