nexmo 5.4.0 → 5.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: acbd01437020690fe8cfd847124290e384ea7ad151f373aafb7cb043197941a7
4
- data.tar.gz: a12a717b8dacd66dc993c237120a1a54dee43305fdf6f5ed93565eb4d4a6a517
3
+ metadata.gz: 7339e40c57dc348e205411f04ffdb1d5f96bd0bb41fd481a4781c6a91b9c06c0
4
+ data.tar.gz: cb033f687f94529c18faf2b9bee41f7e9383fdc7954e9cf38f3cf15642d1bbeb
5
5
  SHA512:
6
- metadata.gz: 5a6540019a076be34194d8185b77417155cd00bc295fbc6983f7b6b58cd9b7ae68a0abad6001f4af202afbaeb5e94296b17558f31461508dd9f33ff5647f040e
7
- data.tar.gz: 761584429c830e57c493f78292fe17842c4a327305b480144e91bbe2cbb263e27f7d1394e876a9d4552822dcb84f22ff38e4317c2f74e47d35639a65adec551b
6
+ metadata.gz: bbddc5433b0356fc806c999dbfc1185b5e5d90989cb1e1742812713e0624d3b7ed07fb21e333c55d0c774e44aec42e00c7bcc3e15f1b5079b4e3b1f626441c57
7
+ data.tar.gz: c56b00b6a05d095268289cb2238ee4d38f05b8da67f2d4c0d839f4ae89f09462fd44138b9e880187e75b01dbd356ed74dfad5038aefcf7588f93776a1ff408b5
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2016 Nexmo Inc
3
+ Copyright (c) 2016-2018 Nexmo Inc
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person
6
6
  obtaining a copy of this software and associated documentation
data/README.md CHANGED
@@ -53,7 +53,7 @@ Then construct a client object with your key and secret:
53
53
  client = Nexmo::Client.new(api_key: 'YOUR-API-KEY', api_secret: 'YOUR-API-SECRET')
54
54
  ```
55
55
 
56
- You can now use the client object to [send a text message](#send-a-text-message),
56
+ You can now use the client object to [send an SMS](#send-an-sms),
57
57
  [start a verification](#start-a-verification), or [create an application](#create-an-application).
58
58
 
59
59
  For production you can specify the `NEXMO_API_KEY` and `NEXMO_API_SECRET`
@@ -153,7 +153,7 @@ Docs: [https://developer.nexmo.com/api/voice#startStream](https://developer.nexm
153
153
  ### Stop playing an audio file into a call
154
154
 
155
155
  ```ruby
156
- response = client.stream.stop(uuid)
156
+ response = client.calls.stream.stop(uuid)
157
157
  ```
158
158
 
159
159
  Docs: [https://developer.nexmo.com/api/voice#stopStream](https://developer.nexmo.com/api/voice?utm_source=DEV_REL&utm_medium=github&utm_campaign=ruby-client-library#stopStream)
@@ -161,7 +161,7 @@ Docs: [https://developer.nexmo.com/api/voice#stopStream](https://developer.nexmo
161
161
  ### Play text to speech into a call
162
162
 
163
163
  ```ruby
164
- response = client.talk.start(uuid, text: 'Hello')
164
+ response = client.calls.talk.start(uuid, text: 'Hello')
165
165
  ```
166
166
 
167
167
  Docs: [https://developer.nexmo.com/api/voice#startTalk](https://developer.nexmo.com/api/voice?utm_source=DEV_REL&utm_medium=github&utm_campaign=ruby-client-library#startTalk)
@@ -169,7 +169,7 @@ Docs: [https://developer.nexmo.com/api/voice#startTalk](https://developer.nexmo.
169
169
  ### Stop text to speech in a call
170
170
 
171
171
  ```ruby
172
- response = client.talk.stop(uuid)
172
+ response = client.calls.talk.stop(uuid)
173
173
  ```
174
174
 
175
175
  Docs: [https://developer.nexmo.com/api/voice#stopTalk](https://developer.nexmo.com/api/voice?utm_source=DEV_REL&utm_medium=github&utm_campaign=ruby-client-library#stopTalk)
@@ -1,12 +1,14 @@
1
1
  require 'nexmo/version'
2
2
  require 'nexmo/params'
3
3
  require 'nexmo/form_data'
4
+ require 'nexmo/http'
4
5
  require 'nexmo/json'
5
6
  require 'nexmo/jwt'
6
7
  require 'nexmo/signature'
7
8
  require 'nexmo/user_agent'
8
9
  require 'nexmo/entity'
9
10
  require 'nexmo/keys'
11
+ require 'nexmo/problem'
10
12
  require 'nexmo/errors/error'
11
13
  require 'nexmo/errors/client_error'
12
14
  require 'nexmo/errors/server_error'
@@ -1,5 +1,5 @@
1
1
  module Nexmo
2
- class AbstractAuthentication
2
+ class AbstractAuthentication # :nodoc:
3
3
  def initialize(client)
4
4
  @client = client
5
5
  end
@@ -1,5 +1,5 @@
1
1
  module Nexmo
2
- class Basic < AbstractAuthentication
2
+ class Basic < AbstractAuthentication # :nodoc:
3
3
  def update(object)
4
4
  return unless object.is_a?(Net::HTTPRequest)
5
5
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nexmo
4
- class BearerToken < AbstractAuthentication
4
+ class BearerToken < AbstractAuthentication # :nodoc:
5
5
  def update(object)
6
6
  return unless object.is_a?(Net::HTTPRequest)
7
7
 
@@ -1,5 +1,5 @@
1
1
  module Nexmo
2
- class KeySecretParams < AbstractAuthentication
2
+ class KeySecretParams < AbstractAuthentication # :nodoc:
3
3
  def update(object)
4
4
  return unless object.is_a?(Hash)
5
5
 
@@ -1,5 +1,5 @@
1
1
  module Nexmo
2
- class KeySecretQuery < AbstractAuthentication
2
+ class KeySecretQuery < AbstractAuthentication # :nodoc:
3
3
  def update(object)
4
4
  return unless object.is_a?(URI)
5
5
 
@@ -25,9 +25,17 @@ module Nexmo
25
25
 
26
26
  @user_agent = UserAgent.string(options[:app_name], options[:app_version])
27
27
 
28
+ self.http_options = options[:http]
29
+
28
30
  self.logger = options[:logger] || (defined?(Rails.logger) && Rails.logger)
29
31
  end
30
32
 
33
+ attr_reader :http_options
34
+
35
+ def http_options=(hash)
36
+ @http_options = HTTP::Options.new(hash)
37
+ end
38
+
31
39
  def logger
32
40
  @logger
33
41
  end
@@ -1,4 +1,31 @@
1
+ # frozen_string_literal: true
2
+ require 'json'
3
+
1
4
  module Nexmo
2
5
  class Error < StandardError
6
+ def self.parse(response) # :nodoc:
7
+ exception_class = case response
8
+ when Net::HTTPUnauthorized
9
+ AuthenticationError
10
+ when Net::HTTPClientError
11
+ ClientError
12
+ when Net::HTTPServerError
13
+ ServerError
14
+ else
15
+ Error
16
+ end
17
+
18
+ message = if content_type = response['Content-Type']
19
+ case content_type.split(';').first
20
+ when 'application/problem+json'
21
+ Problem.parse(response.body)
22
+ when 'application/json'
23
+ hash = ::JSON.parse(response.body)
24
+ hash['error_title']
25
+ end
26
+ end
27
+
28
+ exception_class.new(message)
29
+ end
3
30
  end
4
31
  end
@@ -1,5 +1,5 @@
1
1
  module Nexmo
2
- module FormData
2
+ module FormData # :nodoc:
3
3
  def self.update(http_request, params)
4
4
  http_request.form_data = params
5
5
  end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+ require 'net/http'
3
+
4
+ module Nexmo
5
+ module HTTP # :nodoc:
6
+ class Options
7
+ def initialize(hash)
8
+ @hash = hash || {}
9
+
10
+ @hash.each_key do |name|
11
+ next if defined_options.key?(name)
12
+
13
+ raise ArgumentError, "#{name.inspect} is not a valid option"
14
+ end
15
+ end
16
+
17
+ def set(http)
18
+ @hash.each do |name, value|
19
+ http.public_send(defined_options.fetch(name), value)
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def defined_options
26
+ @defined_options ||= Net::HTTP.instance_methods.grep(/\w=\z/).each_with_object({}) do |name, hash|
27
+ hash[name.to_s.chomp('=').to_sym] = name
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -2,7 +2,7 @@
2
2
  require 'json'
3
3
 
4
4
  module Nexmo
5
- module JSON
5
+ module JSON # :nodoc:
6
6
  def self.update(http_request, params)
7
7
  http_request['Content-Type'] = 'application/json'
8
8
  http_request.body = ::JSON.generate(params)
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nexmo
4
- module Keys
4
+ module Keys # :nodoc:
5
5
  if {}.respond_to?(:transform_keys)
6
6
  def hyphenate(hash)
7
7
  hash.transform_keys { |k| hyphenate_key(k) }
@@ -3,7 +3,7 @@ require 'logger'
3
3
  require 'forwardable'
4
4
 
5
5
  module Nexmo
6
- class Logger
6
+ class Logger # :nodoc:
7
7
  def initialize(logger)
8
8
  @logger = logger || ::Logger.new(nil)
9
9
  end
@@ -3,7 +3,7 @@ require 'net/http'
3
3
  require 'json'
4
4
 
5
5
  module Nexmo
6
- class Namespace
6
+ class Namespace # :nodoc:
7
7
  def initialize(client)
8
8
  @client = client
9
9
 
@@ -11,8 +11,10 @@ module Nexmo
11
11
 
12
12
  @host = self.class.host
13
13
 
14
- @http = Net::HTTP.new(@host, Net::HTTP.https_default_port)
14
+ @http = Net::HTTP.new(@host, Net::HTTP.https_default_port, p_addr = nil)
15
15
  @http.use_ssl = true
16
+
17
+ @client.http_options.set(@http)
16
18
  end
17
19
 
18
20
  def self.host
@@ -91,14 +93,8 @@ module Nexmo
91
93
  else
92
94
  response
93
95
  end
94
- when Net::HTTPUnauthorized
95
- raise AuthenticationError
96
- when Net::HTTPClientError
97
- raise ClientError
98
- when Net::HTTPServerError
99
- raise ServerError
100
96
  else
101
- raise Error
97
+ Error.parse(response)
102
98
  end
103
99
  end
104
100
  end
@@ -2,7 +2,7 @@
2
2
  require 'cgi'
3
3
 
4
4
  module Nexmo
5
- module Params
5
+ module Params # :nodoc:
6
6
  def self.encode(params)
7
7
  params.flat_map { |k, vs| Array(vs).map { |v| "#{escape(k)}=#{escape(v)}" } }.join('&')
8
8
  end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+ require 'json'
3
+
4
+ module Nexmo
5
+ module Problem # :nodoc:
6
+ extend self
7
+
8
+ def parse(body)
9
+ problem = ::JSON.parse(body)
10
+
11
+ title = problem['title']
12
+
13
+ detail = problem['detail']
14
+
15
+ url = problem['type']
16
+
17
+ "#{title}. #{detail} See #{url} for more info, or email support@nexmo.com if you have any questions."
18
+ end
19
+ end
20
+ end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nexmo
4
- module UserAgent
4
+ module UserAgent # :nodoc:
5
5
  def self.string(app_name, app_version)
6
6
  identifiers = []
7
7
  identifiers << 'nexmo-ruby/' + VERSION
@@ -1,3 +1,3 @@
1
1
  module Nexmo
2
- VERSION = '5.4.0'
2
+ VERSION = '5.5.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nexmo
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.4.0
4
+ version: 5.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nexmo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-27 00:00:00.000000000 Z
11
+ date: 2018-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jwt
@@ -97,6 +97,7 @@ files:
97
97
  - lib/nexmo/errors/server_error.rb
98
98
  - lib/nexmo/files.rb
99
99
  - lib/nexmo/form_data.rb
100
+ - lib/nexmo/http.rb
100
101
  - lib/nexmo/json.rb
101
102
  - lib/nexmo/jwt.rb
102
103
  - lib/nexmo/keys.rb
@@ -108,6 +109,7 @@ files:
108
109
  - lib/nexmo/params.rb
109
110
  - lib/nexmo/pricing.rb
110
111
  - lib/nexmo/pricing_types.rb
112
+ - lib/nexmo/problem.rb
111
113
  - lib/nexmo/redact.rb
112
114
  - lib/nexmo/secrets.rb
113
115
  - lib/nexmo/signature.rb