messagebird-rest 3.1.1 → 5.0.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.
- checksums.yaml +4 -4
- data/README.md +9 -8
- data/lib/messagebird/base.rb +2 -0
- data/lib/messagebird/callflow.rb +5 -4
- data/lib/messagebird/client.rb +8 -5
- data/lib/messagebird/conversation_client.rb +3 -3
- data/lib/messagebird/error.rb +8 -0
- data/lib/messagebird/http_client.rb +1 -1
- data/lib/messagebird/list.rb +16 -14
- data/lib/messagebird/message.rb +1 -1
- data/lib/messagebird/request_validator.rb +13 -3
- data/lib/messagebird/version.rb +1 -1
- data/lib/messagebird/voice/call_leg_recording.rb +1 -0
- data/lib/messagebird/voice/list.rb +1 -0
- metadata +17 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb20303b6fdb4eb301b53bd6423e5f0398bd2f74037f53794bb91b09bb0da975
|
4
|
+
data.tar.gz: 201337fdad3472b79cd83fab56def8bcbd503b04a223e414ad4c9098bd5eaac6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fca6980452a534999802b252f07a88fac2b282087cbe40499c88a4b69370eea8172fda5fba0a3282c8dbceaad4857916a69ad2722872f6623a441d5ff5cddcf7
|
7
|
+
data.tar.gz: f0c5f96a9ab18e83291b4ed81758d6fb704b34e01d2c69f8135f77e216af6a00aed266c134b632386c13c976da823f0a8a2dccec71e1499e3e3655034a6d4715
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@ MessageBird's REST API for Ruby
|
|
2
2
|
===============================
|
3
3
|
This repository contains the open source Ruby client for MessageBird's REST API. Documentation can be found at: https://developers.messagebird.com/
|
4
4
|
|
5
|
-
[](https://github.com/messagebird/ruby-rest-api/actions)
|
6
6
|
|
7
7
|
Requirements
|
8
8
|
------------
|
@@ -15,10 +15,11 @@ Installation
|
|
15
15
|
You can either include the following line in your Gemfile:
|
16
16
|
|
17
17
|
```ruby
|
18
|
-
gem 'messagebird-rest', :
|
18
|
+
gem 'messagebird-rest', require: 'messagebird'
|
19
19
|
```
|
20
20
|
|
21
21
|
Or you can just manually install it from the command line:
|
22
|
+
|
22
23
|
```sh
|
23
24
|
$ gem install messagebird-rest
|
24
25
|
```
|
@@ -28,7 +29,7 @@ Examples
|
|
28
29
|
We have put some self-explanatory examples in the *examples* directory, but here is a quick breakdown on how it works. First, you need to create an instance of **MessageBird::Client**. Be sure to replace **YOUR_ACCESS_KEY** with something real in the bottom example.
|
29
30
|
|
30
31
|
```ruby
|
31
|
-
require 'pp'
|
32
|
+
require 'pp' # Only needed for this example
|
32
33
|
require 'messagebird'
|
33
34
|
|
34
35
|
client = MessageBird::Client.new(YOUR_ACCESS_KEY)
|
@@ -54,7 +55,7 @@ Chances are that the most common use you'll have for this API client is the abil
|
|
54
55
|
Optional parameters can be specified as a hash.
|
55
56
|
|
56
57
|
```ruby
|
57
|
-
pp client.message_create('FromMe', '31612345678', 'Hello World', :
|
58
|
+
pp client.message_create('FromMe', '31612345678', 'Hello World', reference: 'MyReference')
|
58
59
|
|
59
60
|
#<MessageBird::Message:0x007f8d5b883520
|
60
61
|
@body="Hello World",
|
@@ -118,7 +119,7 @@ You can send and verify One-Time Passwords through the MessageBird API using the
|
|
118
119
|
|
119
120
|
```ruby
|
120
121
|
# verify_create requires a recipient as a required parameter, and other optional paramaters
|
121
|
-
client.verify_create(31612345678,
|
122
|
+
client.verify_create(31612345678, reference: "YourReference")
|
122
123
|
|
123
124
|
#<MessageBird::Verify:0x007fb3c18c8148
|
124
125
|
@id="080b7f804555213678f14f6o24607735",
|
@@ -143,7 +144,7 @@ MessageBird also offers the ability to send out a text message as a voice messag
|
|
143
144
|
Optional parameters can be specified as a hash.
|
144
145
|
|
145
146
|
```ruby
|
146
|
-
pp client.voice_message_create('31612345678', 'Hello World', :
|
147
|
+
pp client.voice_message_create('31612345678', 'Hello World', reference: 'MyReference')
|
147
148
|
|
148
149
|
#<MessageBird::VoiceMessage:0x000001030101b8
|
149
150
|
@body="Hello World",
|
@@ -179,7 +180,7 @@ client.voice_message('a08e51a0353bd16cea7f298a37405850')
|
|
179
180
|
There is also a Numbers API that allow you to search for and purchase number subscriptions to use as originator in other services.
|
180
181
|
|
181
182
|
```ruby
|
182
|
-
pp client.number_search("NL",
|
183
|
+
pp client.number_search("NL", limit: 52)
|
183
184
|
|
184
185
|
#<List:0x00007fa405130618
|
185
186
|
@count=5,
|
@@ -230,4 +231,4 @@ Complete documentation, instructions, and examples are available at:
|
|
230
231
|
|
231
232
|
License
|
232
233
|
-------
|
233
|
-
The MessageBird REST Client for Ruby is licensed under [The BSD 2-Clause License](http://opensource.org/licenses/BSD-2-Clause). Copyright (c)
|
234
|
+
The MessageBird REST Client for Ruby is licensed under [The BSD 2-Clause License](http://opensource.org/licenses/BSD-2-Clause). Copyright (c) 2025, MessageBird
|
data/lib/messagebird/base.rb
CHANGED
@@ -7,6 +7,8 @@ module MessageBird
|
|
7
7
|
class Base
|
8
8
|
# takes each element from the given hash and apply it to ourselves through an assignment method
|
9
9
|
def map_hash_elements_to_self(hash)
|
10
|
+
return if hash.nil?
|
11
|
+
|
10
12
|
hash.each do |key, value|
|
11
13
|
method_name = key.gsub(/([a-z\d])([A-Z])/, '\1_\2').downcase # convert came case to snake case
|
12
14
|
method_name += '='
|
data/lib/messagebird/callflow.rb
CHANGED
@@ -26,7 +26,8 @@ module MessageBird
|
|
26
26
|
end
|
27
27
|
|
28
28
|
class CallFlowList < List
|
29
|
-
attr_accessor :
|
29
|
+
attr_accessor :per_page, :current_page, :page_count, :total_count
|
30
|
+
|
30
31
|
PER_PAGE = 20
|
31
32
|
CURRENT_PAGE = 1
|
32
33
|
|
@@ -53,8 +54,8 @@ module MessageBird
|
|
53
54
|
|
54
55
|
class CallFlowStepOption < MessageBird::Base
|
55
56
|
attr_accessor :destination, :payload, :language, :voice, :repeat,
|
56
|
-
:media, :length, :
|
57
|
-
:
|
58
|
-
:
|
57
|
+
:media, :length, :max_length, :timeout, :finish_on_key, :transcribe,
|
58
|
+
:transcribe_language, :record, :url, :if_machine, :machine_timeout,
|
59
|
+
:on_finish, :mask
|
59
60
|
end
|
60
61
|
end
|
data/lib/messagebird/client.rb
CHANGED
@@ -30,14 +30,16 @@ require 'messagebird/voice/call'
|
|
30
30
|
require 'messagebird/voice/call_leg'
|
31
31
|
require 'messagebird/voice/call_leg_recording'
|
32
32
|
require 'messagebird/voice/transcription'
|
33
|
-
require 'messagebird/voice/list'
|
34
33
|
|
35
34
|
module MessageBird
|
36
35
|
class ErrorException < StandardError
|
37
36
|
attr_reader :errors
|
38
37
|
|
39
38
|
def initialize(errors)
|
39
|
+
super()
|
40
40
|
@errors = errors
|
41
|
+
message = errors.map(&:message).join(', ')
|
42
|
+
super(message)
|
41
43
|
end
|
42
44
|
end
|
43
45
|
|
@@ -47,7 +49,8 @@ module MessageBird
|
|
47
49
|
class Client
|
48
50
|
attr_reader :access_key, :http_client, :conversation_client, :voice_client
|
49
51
|
|
50
|
-
def initialize(access_key = nil, http_client = nil, conversation_client = nil, voice_client = nil)
|
52
|
+
def initialize(access_key = nil, http_client = nil, conversation_client = nil, voice_client = nil) # rubocop:disable Metrics/ParameterLists
|
53
|
+
super()
|
51
54
|
@access_key = access_key || ENV['MESSAGEBIRD_ACCESS_KEY']
|
52
55
|
@http_client = http_client || HttpClient.new(@access_key)
|
53
56
|
@conversation_client = conversation_client || ConversationClient.new(@access_key)
|
@@ -457,13 +460,13 @@ module MessageBird
|
|
457
460
|
number_request(:delete, "phone-numbers/#{number}")
|
458
461
|
end
|
459
462
|
|
460
|
-
def call_flow_create(
|
463
|
+
def call_flow_create(steps, default, record, params = {})
|
461
464
|
params = params.merge(
|
462
|
-
title: title,
|
463
465
|
steps: steps,
|
464
466
|
default: default,
|
465
467
|
record: record
|
466
468
|
)
|
469
|
+
|
467
470
|
CallFlow.new(voice_request(:post, 'call-flows', params))
|
468
471
|
end
|
469
472
|
|
@@ -490,7 +493,7 @@ module MessageBird
|
|
490
493
|
# JSON by default. See also:
|
491
494
|
# https://developers.messagebird.com/docs/alternatives.
|
492
495
|
|
493
|
-
|
496
|
+
contact_ids.map { |id| "ids[]=#{id}" }.join('&').prepend('_method=PUT&')
|
494
497
|
end
|
495
498
|
|
496
499
|
def add_querystring(path, params)
|
data/lib/messagebird/error.rb
CHANGED
@@ -5,5 +5,13 @@ require 'messagebird/base'
|
|
5
5
|
module MessageBird
|
6
6
|
class Error < MessageBird::Base
|
7
7
|
attr_accessor :code, :description, :parameter
|
8
|
+
|
9
|
+
def message
|
10
|
+
if parameter
|
11
|
+
"#{description} (error code: #{code}, parameter: #{parameter})"
|
12
|
+
else
|
13
|
+
"#{description} (error code: #{code})"
|
14
|
+
end
|
15
|
+
end
|
8
16
|
end
|
9
17
|
end
|
@@ -33,7 +33,7 @@ module MessageBird
|
|
33
33
|
http
|
34
34
|
end
|
35
35
|
|
36
|
-
def request(method, path, params = {}, check_json
|
36
|
+
def request(method, path, params = {}, check_json: true)
|
37
37
|
uri = URI.join(endpoint, path)
|
38
38
|
http = build_http_client(uri)
|
39
39
|
request = build_request(method, uri, params)
|
data/lib/messagebird/list.rb
CHANGED
@@ -2,23 +2,25 @@
|
|
2
2
|
|
3
3
|
require 'messagebird/base'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
module MessageBird
|
6
|
+
class List < MessageBird::Base
|
7
|
+
attr_accessor :offset, :limit, :count, :total_count, :links
|
8
|
+
attr_reader :items
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
# type will be used to create objects for the items, e.g.
|
11
|
+
# List.new(Contact, {}).
|
12
|
+
def initialize(type, json)
|
13
|
+
@type = type
|
13
14
|
|
14
|
-
|
15
|
-
|
15
|
+
super(json)
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
def items=(value)
|
19
|
+
@items = value.map { |i| @type.new i }
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
22
|
+
def [](index)
|
23
|
+
@items[index]
|
24
|
+
end
|
23
25
|
end
|
24
26
|
end
|
data/lib/messagebird/message.rb
CHANGED
@@ -6,7 +6,7 @@ require 'messagebird/recipient'
|
|
6
6
|
module MessageBird
|
7
7
|
class Message < MessageBird::Base
|
8
8
|
attr_accessor :id, :href, :direction, :type, :originator, :body, :reference,
|
9
|
-
:validity, :gateway, :
|
9
|
+
:validity, :gateway, :type_details, :datacoding, :mclass
|
10
10
|
attr_reader :scheduled_date_time, :created_datetime, :recipients
|
11
11
|
|
12
12
|
def scheduled_date_time=(value)
|
@@ -20,7 +20,7 @@ module MessageBird
|
|
20
20
|
#
|
21
21
|
# @param [string] signature_key customer signature key. Can be retrieved through <a href="https://dashboard.messagebird.com/developers/settings">Developer Settings</a>. This is NOT your API key.
|
22
22
|
# @param [bool] skip_url_validation whether url_hash claim validation should be skipped. Note that when true, no query parameters should be trusted.
|
23
|
-
def initialize(signature_key, skip_url_validation
|
23
|
+
def initialize(signature_key, skip_url_validation: false)
|
24
24
|
@signature_key = signature_key
|
25
25
|
@skip_url_validation = skip_url_validation
|
26
26
|
end
|
@@ -71,14 +71,14 @@ module MessageBird
|
|
71
71
|
|
72
72
|
def validate_url(url, url_hash)
|
73
73
|
expected_url_hash = Digest::SHA256.hexdigest url
|
74
|
-
unless
|
74
|
+
unless secure_compare(expected_url_hash, url_hash)
|
75
75
|
raise ValidationError, 'invalid jwt: claim url_hash is invalid'
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
79
|
def validate_payload(body, payload_hash)
|
80
80
|
if !body.to_s.empty? && !payload_hash.to_s.empty?
|
81
|
-
unless
|
81
|
+
unless secure_compare(Digest::SHA256.hexdigest(body), payload_hash)
|
82
82
|
raise ValidationError, 'invalid jwt: claim payload_hash is invalid'
|
83
83
|
end
|
84
84
|
elsif !body.to_s.empty?
|
@@ -87,5 +87,15 @@ module MessageBird
|
|
87
87
|
raise ValidationError, 'invalid jwt: claim payload_hash is set but actual payload is missing'
|
88
88
|
end
|
89
89
|
end
|
90
|
+
|
91
|
+
# Adaption of https://github.com/rails/rails/blob/cf6ff17e9a3c6c1139040b519a341f55f0be16cf/activesupport/lib/active_support/security_utils.rb#L33
|
92
|
+
# Copied here so as to avoid adding a dependency on ActiveSupport to this gem
|
93
|
+
#
|
94
|
+
# Note that unlike `fixed_length_secure_compare` in the above url we don't fall back to a custom implementation
|
95
|
+
# of fixed_length_secure_compare, since OpenSSL.fixed_length_secure_compare is present in OpenSSL 2.2
|
96
|
+
# https://github.com/ruby/openssl/blob/master/History.md#version-220 which is included in Ruby 3.0 and above
|
97
|
+
def secure_compare(first, second)
|
98
|
+
first.bytesize == second.bytesize && OpenSSL.fixed_length_secure_compare(first, second)
|
99
|
+
end
|
90
100
|
end
|
91
101
|
end
|
data/lib/messagebird/version.rb
CHANGED
metadata
CHANGED
@@ -1,71 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: messagebird-rest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maurice Nonnekes
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jwt
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "<"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '4'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "<"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '4'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 3.
|
33
|
+
version: 3.11.0
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 3.
|
40
|
+
version: 3.11.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rubocop
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 1.26.1
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 1.26.1
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: webmock
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 3.
|
61
|
+
version: 3.14.0
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 3.
|
68
|
+
version: 3.14.0
|
69
69
|
description: A simple REST API for MessageBird in Ruby
|
70
70
|
email: maurice@messagebird.com
|
71
71
|
executables: []
|
@@ -120,7 +120,7 @@ homepage: https://github.com/messagebird/ruby-rest-api
|
|
120
120
|
licenses:
|
121
121
|
- BSD-2-Clause
|
122
122
|
metadata: {}
|
123
|
-
post_install_message:
|
123
|
+
post_install_message:
|
124
124
|
rdoc_options: []
|
125
125
|
require_paths:
|
126
126
|
- lib
|
@@ -128,15 +128,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
128
128
|
requirements:
|
129
129
|
- - ">="
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: '
|
131
|
+
version: '3.0'
|
132
132
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
133
|
requirements:
|
134
134
|
- - ">="
|
135
135
|
- !ruby/object:Gem::Version
|
136
136
|
version: '0'
|
137
137
|
requirements: []
|
138
|
-
rubygems_version: 3.
|
139
|
-
signing_key:
|
138
|
+
rubygems_version: 3.4.20
|
139
|
+
signing_key:
|
140
140
|
specification_version: 4
|
141
141
|
summary: MessageBird's REST API
|
142
142
|
test_files: []
|