Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

Commit

Permalink
Merge 8ce4e4a into 1170d02
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Greenberg committed Feb 19, 2020
2 parents 1170d02 + 8ce4e4a commit 8b75285
Show file tree
Hide file tree
Showing 129 changed files with 29,877 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
Gemfile.lock
coverage
doc
sorbet/rbi/hidden-definitions/errors.txt
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
dist: xenial
language: ruby
cache: bundler
rvm:
- 2.5
- 2.6
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ gem 'yard', '~> 0.9'
gem 'simplecov', '~> 0.16'
gem 'coveralls', '~> 0.8'
gem 'json', '~> 2'
gem 'sorbet', :group => :development
2 changes: 2 additions & 0 deletions lib/nexmo.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# typed: false
# frozen_string_literal: true
require 'zeitwerk'
require 'sorbet-runtime'

module Nexmo
loader = Zeitwerk::Loader.new
Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/abstract_authentication.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: ignore
module Nexmo
class AbstractAuthentication
def initialize(config)
Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/account.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

module Nexmo
Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/alerts.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

module Nexmo
Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/applications.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

module Nexmo
Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/applications/list_response.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: ignore
class Nexmo::Applications::ListResponse < Nexmo::Response
include Enumerable

Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/authentication_error.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: strong
module Nexmo
class AuthenticationError < ClientError
end
Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/basic.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: ignore
module Nexmo
class Basic < AbstractAuthentication
def update(object)
Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/bearer_token.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: ignore
# frozen_string_literal: true

module Nexmo
Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/calls.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

module Nexmo
Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/calls/dtmf.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

module Nexmo
Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/calls/list_response.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: ignore
class Nexmo::Calls::ListResponse < Nexmo::Response
include Enumerable

Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/calls/stream.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

module Nexmo
Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/calls/talk.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

module Nexmo
Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/client.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
module Nexmo
class Client
attr_reader :config
Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/client_error.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: strong
module Nexmo
class ClientError < Error
end
Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/config.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true
require 'logger'

Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/conversations.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

module Nexmo
Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/conversations/events.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

module Nexmo
Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/conversations/legs.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

module Nexmo
Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/conversations/members.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

module Nexmo
Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/conversations/users.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

module Nexmo
Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/conversions.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

module Nexmo
Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/entity.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
module Nexmo
class Entity
include Keys
Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/error.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: strong
module Nexmo
class Error < StandardError
end
Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/errors.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: ignore
# frozen_string_literal: true
require 'json'

Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/files.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

module Nexmo
Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/form_data.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: ignore
module Nexmo
module FormData
def self.update(http_request, params)
Expand Down
3 changes: 1 addition & 2 deletions lib/nexmo/gsm7.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: ignore
module Nexmo
module GSM7
CHARACTERS = "\n\f\r !\"\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_abcdefghijklmnopqrstuvwxyz{|}~ ¡£¤¥§¿ÄÅÆÉÑÖØÜßàäåæçèéìñòöøùüΓΔΘΛΞΠΣΦΨΩ€"
Expand All @@ -8,6 +9,4 @@ def self.encoded?(string)
REGEXP =~ string
end
end

private_constant :GSM7
end
1 change: 1 addition & 0 deletions lib/nexmo/http.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: ignore
# frozen_string_literal: true
require 'net/http'

Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/json.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: ignore
# frozen_string_literal: true
require 'json'

Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/jwt.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true
require 'securerandom'
require 'openssl'
Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/key_secret_params.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: ignore
module Nexmo
class KeySecretParams < AbstractAuthentication
def update(object)
Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/keys.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: ignore
# frozen_string_literal: true

module Nexmo
Expand Down
5 changes: 3 additions & 2 deletions lib/nexmo/logger.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: ignore
# frozen_string_literal: true
require 'logger'
require 'forwardable'
Expand All @@ -15,7 +16,7 @@ def initialize(logger)
end

def log_request_info(request)
info do
@logger.info do
format('Nexmo API request', {
method: request.method,
path: request.uri.path
Expand All @@ -24,7 +25,7 @@ def log_request_info(request)
end

def log_response_info(response, host)
info do
@logger.info do
format('Nexmo API response', {
host: host,
status: response.code,
Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/messages.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

module Nexmo
Expand Down
15 changes: 9 additions & 6 deletions lib/nexmo/namespace.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: ignore
# frozen_string_literal: true
require 'net/http'
require 'json'
Expand All @@ -7,8 +8,6 @@ class Namespace
def initialize(config)
@config = config

@logger = config.logger

@host = self.class.host

@http = Net::HTTP.new(@host, Net::HTTP.https_default_port, p_addr = nil)
Expand Down Expand Up @@ -53,7 +52,7 @@ def self.response_class=(response_class)
@response_class = response_class
end

private
protected

Get = Net::HTTP::Get
Put = Net::HTTP::Put
Expand Down Expand Up @@ -86,15 +85,15 @@ def request(path, params: nil, type: Get, response_class: nil, &block)

self.class.request_body.update(message, params) if type::REQUEST_HAS_BODY

@logger.log_request_info(message)
logger.log_request_info(message)

response = @http.request(message, &block)

@logger.log_response_info(response, @host)
logger.log_response_info(response, @host)

return if block

@logger.debug(response.body) if response.body
logger.debug(response.body) if response.body

parse(response, response_class || self.class.response_class)
end
Expand All @@ -115,6 +114,10 @@ def parse(response, response_class)
raise Errors.parse(response)
end
end

def logger
@config.logger
end
end

private_constant :Namespace
Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/number_insight.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

module Nexmo
Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/number_insight/response.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
class Nexmo::NumberInsight::Response < Nexmo::Response
def success?
status.zero?
Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/numbers.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

module Nexmo
Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/numbers/list_response.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: ignore
class Nexmo::Numbers::ListResponse < Nexmo::Response
include Enumerable

Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/numbers/response.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

class Nexmo::Numbers::Response < Nexmo::Response
Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/params.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: ignore
# frozen_string_literal: true
require 'cgi'

Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/pricing.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

module Nexmo
Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/pricing_types.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

module Nexmo
Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/redact.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

module Nexmo
Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/response.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
module Nexmo
class Response
def initialize(entity=nil, http_response=nil)
Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/secrets.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

module Nexmo
Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/secrets/list_response.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: ignore
class Nexmo::Secrets::ListResponse < Nexmo::Response
include Enumerable

Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/server_error.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: strong
module Nexmo
class ServerError < Error
end
Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/signature.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true
require 'openssl'
require 'digest/md5'
Expand Down
8 changes: 6 additions & 2 deletions lib/nexmo/sms.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# typed: strict
# frozen_string_literal: true

module Nexmo
class SMS < Namespace
extend T::Sig
include Keys

self.host = 'rest.nexmo.com'
Expand Down Expand Up @@ -94,20 +96,22 @@ class SMS < Namespace
#
# @see https://developer.nexmo.com/api/sms#send-an-sms
#
sig { params(params: T::Hash[Symbol, T.untyped]).returns(Nexmo::SMS::Response) }
def send(params)
if unicode?(params[:text]) && params[:type] != 'unicode'
if unicode?(params.fetch(:text)) && params[:type] != 'unicode'
message = 'Sending unicode text SMS without setting the type parameter to "unicode". ' \
'See https://developer.nexmo.com/messaging/sms for details, ' \
'or email support@nexmo.com if you have any questions.'

@logger.warn(message)
logger.warn(message)
end

request('/sms/json', params: hyphenate(params), type: Post, response_class: Response)
end

private

sig { params(text: String).returns(T::Boolean) }
def unicode?(text)
!GSM7.encoded?(text)
end
Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/sms/response.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

class Nexmo::SMS::Response < Nexmo::Response
Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/tfa.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

module Nexmo
Expand Down
1 change: 1 addition & 0 deletions lib/nexmo/user_agent.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: ignore
# frozen_string_literal: true

module Nexmo
Expand Down

0 comments on commit 8b75285

Please sign in to comment.