messagebird-rest 1.4.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +56 -8
- data/lib/messagebird.rb +10 -5
- data/lib/messagebird/balance.rb +2 -0
- data/lib/messagebird/base.rb +12 -7
- data/lib/messagebird/call_flow.rb +22 -0
- data/lib/messagebird/call_flow/step.rb +9 -0
- data/lib/messagebird/callflow.rb +60 -0
- data/lib/messagebird/client.rb +290 -85
- data/lib/messagebird/contact.rb +10 -8
- data/lib/messagebird/contact_reference.rb +3 -1
- data/lib/messagebird/conversation.rb +16 -14
- data/lib/messagebird/conversation_channel.rb +8 -7
- data/lib/messagebird/conversation_client.rb +9 -6
- data/lib/messagebird/conversation_message.rb +6 -5
- data/lib/messagebird/conversation_webhook.rb +4 -2
- data/lib/messagebird/custom_details.rb +2 -0
- data/lib/messagebird/error.rb +2 -0
- data/lib/messagebird/group.rb +7 -5
- data/lib/messagebird/group_reference.rb +3 -1
- data/lib/messagebird/hlr.rb +7 -5
- data/lib/messagebird/http_client.rb +34 -34
- data/lib/messagebird/list.rb +4 -2
- data/lib/messagebird/lookup.rb +7 -5
- data/lib/messagebird/message.rb +7 -5
- data/lib/messagebird/message_reference.rb +3 -1
- data/lib/messagebird/number.rb +18 -0
- data/lib/messagebird/number_client.rb +22 -0
- data/lib/messagebird/recipient.rb +5 -3
- data/lib/messagebird/signed_request.rb +24 -21
- data/lib/messagebird/verify.rb +7 -5
- data/lib/messagebird/version.rb +7 -0
- data/lib/messagebird/voice/base.rb +16 -0
- data/lib/messagebird/voice/call.rb +22 -0
- data/lib/messagebird/voice/call_leg.rb +11 -0
- data/lib/messagebird/voice/call_leg_recording.rb +20 -0
- data/lib/messagebird/voice/client.rb +22 -0
- data/lib/messagebird/voice/list.rb +24 -0
- data/lib/messagebird/voice/transcription.rb +15 -0
- data/lib/messagebird/voice/webhook.rb +11 -0
- data/lib/messagebird/voice_client.rb +25 -0
- data/lib/messagebird/voicemessage.rb +8 -6
- metadata +52 -10
data/lib/messagebird/contact.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'messagebird/base'
|
2
4
|
require 'messagebird/custom_details'
|
3
5
|
require 'messagebird/group_reference'
|
@@ -5,11 +7,11 @@ require 'messagebird/message_reference'
|
|
5
7
|
|
6
8
|
module MessageBird
|
7
9
|
class Contact < MessageBird::Base
|
8
|
-
attr_accessor :id, :href, :msisdn, :
|
9
|
-
attr_reader :
|
10
|
+
attr_accessor :id, :href, :msisdn, :first_name, :last_name
|
11
|
+
attr_reader :custom_details, :groups, :messages, :created_datetime, :updated_datetime
|
10
12
|
|
11
|
-
def
|
12
|
-
@
|
13
|
+
def custom_details=(value)
|
14
|
+
@custom_details = MessageBird::CustomDetails.new(value)
|
13
15
|
end
|
14
16
|
|
15
17
|
def groups=(value)
|
@@ -20,12 +22,12 @@ module MessageBird
|
|
20
22
|
@messages = MessageBird::MessageReference.new(value)
|
21
23
|
end
|
22
24
|
|
23
|
-
def
|
24
|
-
@
|
25
|
+
def created_datetime=(value)
|
26
|
+
@created_datetime = value_to_time(value)
|
25
27
|
end
|
26
28
|
|
27
|
-
def
|
28
|
-
@
|
29
|
+
def updated_datetime=(value)
|
30
|
+
@updated_datetime = value_to_time(value)
|
29
31
|
end
|
30
32
|
end
|
31
33
|
end
|
@@ -1,12 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'messagebird/base'
|
2
4
|
require 'messagebird/contact'
|
3
5
|
require 'messagebird/conversation_channel'
|
4
6
|
|
5
|
-
module MessageBird
|
7
|
+
module MessageBird
|
6
8
|
class Conversation < MessageBird::Base
|
7
|
-
attr_accessor :id, :status, :
|
8
|
-
attr_reader :contact, :channels, :messages, :
|
9
|
-
:
|
9
|
+
attr_accessor :id, :status, :last_used_channel_id, :contact_id
|
10
|
+
attr_reader :contact, :channels, :messages, :created_datetime,
|
11
|
+
:updated_datetime, :last_received_datetime
|
10
12
|
|
11
13
|
CONVERSATION_STATUS_ACTIVE = 'active'
|
12
14
|
CONVERSATION_STATUS_ARCHIVED = 'archived'
|
@@ -24,19 +26,19 @@ module MessageBird
|
|
24
26
|
end
|
25
27
|
|
26
28
|
def messages=(value)
|
27
|
-
@messages = MessageBird::MessageReference.new(value)
|
29
|
+
@messages = MessageBird::MessageReference.new(value)
|
28
30
|
end
|
29
|
-
|
30
|
-
def
|
31
|
-
@
|
31
|
+
|
32
|
+
def created_datetime=(value)
|
33
|
+
@created_datetime = value_to_time(value)
|
32
34
|
end
|
33
35
|
|
34
|
-
def
|
35
|
-
@
|
36
|
+
def updated_datetime=(value)
|
37
|
+
@updated_datetime = value_to_time(value)
|
36
38
|
end
|
37
39
|
|
38
|
-
def
|
39
|
-
@
|
40
|
+
def last_received_datetime=(value)
|
41
|
+
@last_received_datetime = value_to_time(value)
|
40
42
|
end
|
41
|
-
end
|
42
|
-
end
|
43
|
+
end
|
44
|
+
end
|
@@ -1,17 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'messagebird/base'
|
2
4
|
|
3
5
|
module MessageBird
|
4
6
|
class ConversationChannel < MessageBird::Base
|
5
|
-
attr_accessor :id, :name, :
|
6
|
-
attr_reader :
|
7
|
+
attr_accessor :id, :name, :platform_id, :status
|
8
|
+
attr_reader :created_datetime, :updated_datetime
|
7
9
|
|
8
|
-
def
|
9
|
-
@
|
10
|
+
def created_datetime=(value)
|
11
|
+
@created_datetime = value_to_time(value)
|
10
12
|
end
|
11
13
|
|
12
|
-
def
|
13
|
-
@
|
14
|
+
def updated_datetime=(value)
|
15
|
+
@updated_datetime = value_to_time(value)
|
14
16
|
end
|
15
|
-
|
16
17
|
end
|
17
18
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'net/https'
|
2
4
|
require 'uri'
|
3
5
|
require 'json'
|
@@ -5,15 +7,16 @@ require 'messagebird/http_client'
|
|
5
7
|
|
6
8
|
module MessageBird
|
7
9
|
class ConversationClient < HttpClient
|
8
|
-
ENDPOINT
|
9
|
-
|
10
|
-
def endpoint()
|
11
|
-
ENDPOINT
|
12
|
-
end
|
10
|
+
ENDPOINT = 'https://conversations.messagebird.com/v1/'
|
13
11
|
|
14
|
-
def prepare_request(request, params={})
|
12
|
+
def prepare_request(request, params = {})
|
13
|
+
request['Content-Type'] = 'application/json'
|
15
14
|
request.body = params.to_json
|
16
15
|
request
|
17
16
|
end
|
18
17
|
end
|
18
|
+
|
19
|
+
def endpoint
|
20
|
+
ENDPOINT
|
21
|
+
end
|
19
22
|
end
|
@@ -1,9 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'messagebird/base'
|
2
4
|
|
3
|
-
module MessageBird
|
5
|
+
module MessageBird
|
4
6
|
class ConversationMessage < MessageBird::Base
|
5
|
-
attr_accessor :id, :
|
6
|
-
:type, :content, :
|
7
|
-
|
7
|
+
attr_accessor :id, :conversation_id, :channel_id, :direction, :status,
|
8
|
+
:type, :content, :created_datetime, :updated_datetime, :fallback
|
8
9
|
end
|
9
|
-
end
|
10
|
+
end
|
@@ -1,7 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'messagebird/base'
|
2
4
|
|
3
|
-
module MessageBird
|
5
|
+
module MessageBird
|
4
6
|
class ConversationWebhook < MessageBird::Base
|
5
|
-
attr_accessor :id, :events, :
|
7
|
+
attr_accessor :id, :events, :channel_id, :url, :status, :created_datetime, :updated_datetime
|
6
8
|
end
|
7
9
|
end
|
data/lib/messagebird/error.rb
CHANGED
data/lib/messagebird/group.rb
CHANGED
@@ -1,21 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'messagebird/base'
|
2
4
|
require 'messagebird/contact_reference'
|
3
5
|
|
4
6
|
module MessageBird
|
5
7
|
class Group < MessageBird::Base
|
6
8
|
attr_accessor :id, :href, :name
|
7
|
-
attr_reader :contacts, :
|
9
|
+
attr_reader :contacts, :created_datetime, :updated_datetime
|
8
10
|
|
9
11
|
def contacts=(value)
|
10
12
|
@contacts = MessageBird::ContactReference.new(value)
|
11
13
|
end
|
12
14
|
|
13
|
-
def
|
14
|
-
@
|
15
|
+
def created_datetime=(value)
|
16
|
+
@created_datetime = value_to_time(value)
|
15
17
|
end
|
16
18
|
|
17
|
-
def
|
18
|
-
@
|
19
|
+
def updated_datetime=(value)
|
20
|
+
@updated_datetime = value_to_time(value)
|
19
21
|
end
|
20
22
|
end
|
21
23
|
end
|
data/lib/messagebird/hlr.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'time'
|
2
4
|
|
3
5
|
require 'messagebird/base'
|
@@ -5,14 +7,14 @@ require 'messagebird/base'
|
|
5
7
|
module MessageBird
|
6
8
|
class HLR < MessageBird::Base
|
7
9
|
attr_accessor :id, :href, :msisdn, :network, :reference, :status, :details
|
8
|
-
attr_reader :
|
10
|
+
attr_reader :created_datetime, :status_datetime
|
9
11
|
|
10
|
-
def
|
11
|
-
@
|
12
|
+
def created_datetime=(value)
|
13
|
+
@created_datetime = value_to_time(value)
|
12
14
|
end
|
13
15
|
|
14
|
-
def
|
15
|
-
@
|
16
|
+
def status_datetime=(value)
|
17
|
+
@status_datetime = value_to_time(value)
|
16
18
|
end
|
17
19
|
end
|
18
20
|
end
|
@@ -1,36 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'net/https'
|
2
4
|
require 'uri'
|
3
5
|
|
4
6
|
module MessageBird
|
5
|
-
|
6
|
-
class InvalidPhoneNumberException < TypeError; end
|
7
|
+
class ServerException < StandardError; end
|
7
8
|
class InvalidResponseException < StandardError; end
|
8
9
|
class MethodNotAllowedException < ArgumentError; end
|
9
10
|
|
10
11
|
class HttpClient
|
11
12
|
attr_reader :access_key
|
12
13
|
|
14
|
+
VALID_RESPONSE_CODES = [200, 201, 202, 204, 401, 404, 405, 422].freeze
|
13
15
|
ENDPOINT = 'https://rest.messagebird.com/'
|
16
|
+
SUBMIT_METHODS = [:patch, :post, :put].freeze
|
17
|
+
ALLOWED_METHODS = SUBMIT_METHODS.dup + [:get, :delete].freeze
|
14
18
|
|
15
19
|
def initialize(access_key)
|
16
20
|
@access_key = access_key
|
17
21
|
end
|
18
22
|
|
19
|
-
def endpoint
|
23
|
+
def endpoint
|
20
24
|
ENDPOINT
|
21
25
|
end
|
22
26
|
|
23
|
-
def
|
24
|
-
uri = URI.join(endpoint, path)
|
25
|
-
|
26
|
-
# Set up the HTTP object.
|
27
|
+
def build_http_client(uri)
|
27
28
|
http = Net::HTTP.new(uri.host, uri.port)
|
28
29
|
http.use_ssl = true
|
29
30
|
|
30
|
-
unless ENV['DEBUG_MB_HTTP_CLIENT'].nil?
|
31
|
-
|
32
|
-
|
31
|
+
http.set_debug_output($stdout) unless ENV['DEBUG_MB_HTTP_CLIENT'].nil?
|
32
|
+
|
33
|
+
http
|
34
|
+
end
|
33
35
|
|
36
|
+
def request(method, path, params = {}, check_json = true)
|
37
|
+
uri = URI.join(endpoint, path)
|
38
|
+
http = build_http_client(uri)
|
34
39
|
request = build_request(method, uri, params)
|
35
40
|
|
36
41
|
# Execute the request and fetch the response.
|
@@ -42,44 +47,41 @@ module MessageBird
|
|
42
47
|
response.body
|
43
48
|
end
|
44
49
|
|
45
|
-
def
|
46
|
-
|
50
|
+
def request_block(method, path, params = {}, &block)
|
51
|
+
uri = URI.join(endpoint, path)
|
52
|
+
http = build_http_client(uri)
|
53
|
+
request = build_request(method, uri, params)
|
54
|
+
|
55
|
+
http.request(request, block)
|
56
|
+
end
|
57
|
+
|
58
|
+
def prepare_request(request, params = {})
|
59
|
+
request.set_form_data(params)
|
60
|
+
|
47
61
|
request
|
48
62
|
end
|
49
63
|
|
50
|
-
def build_request(method, uri, params={})
|
64
|
+
def build_request(method, uri, params = {})
|
51
65
|
# Construct the HTTP request.
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
when :get
|
56
|
-
request = Net::HTTP::Get.new(uri.request_uri)
|
57
|
-
when :patch
|
58
|
-
request = Net::HTTP::Patch.new(uri.request_uri)
|
59
|
-
when :post
|
60
|
-
request = Net::HTTP::Post.new(uri.request_uri)
|
61
|
-
else
|
62
|
-
raise MethodNotAllowedException
|
63
|
-
end
|
66
|
+
raise MethodNotAllowedException unless ALLOWED_METHODS.include?(method)
|
67
|
+
|
68
|
+
request = Class.const_get("Net::HTTP::#{method.to_s.capitalize}").new(uri.request_uri)
|
64
69
|
|
65
70
|
request['Accept'] = 'application/json'
|
66
71
|
request['Authorization'] = "AccessKey #{@access_key}"
|
67
|
-
request['User-Agent'] = "MessageBird/ApiClient/#{
|
72
|
+
request['User-Agent'] = "MessageBird/ApiClient/#{Version::STRING} Ruby/#{RUBY_VERSION}"
|
68
73
|
|
69
|
-
if
|
74
|
+
if SUBMIT_METHODS.include?(method) && !params.empty?
|
70
75
|
prepare_request(request, params)
|
71
76
|
end
|
77
|
+
|
72
78
|
request
|
73
79
|
end
|
74
80
|
|
75
81
|
# Throw an exception if the response code is not one we expect from the
|
76
82
|
# MessageBird API.
|
77
83
|
def assert_valid_response_code(code)
|
78
|
-
|
79
|
-
# needed to maintain backwards compatibility. See issue:
|
80
|
-
# https://github.com/messagebird/ruby-rest-api/issues/17
|
81
|
-
expected_codes = [200, 201, 202, 204, 401, 404, 405, 422]
|
82
|
-
raise InvalidPhoneNumberException, 'Unknown response from server' unless expected_codes.include? code
|
84
|
+
raise ServerException, 'Unknown response from server' unless VALID_RESPONSE_CODES.include? code
|
83
85
|
end
|
84
86
|
|
85
87
|
# Throw an exception if the response's content type is not JSON. This only
|
@@ -89,7 +91,5 @@ module MessageBird
|
|
89
91
|
# for equality: some API's may append the charset to this header.
|
90
92
|
raise InvalidResponseException, 'Response is not JSON' unless content_type.start_with? 'application/json'
|
91
93
|
end
|
92
|
-
|
93
94
|
end
|
94
|
-
|
95
95
|
end
|
data/lib/messagebird/list.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'messagebird/base'
|
2
4
|
|
3
5
|
class List < MessageBird::Base
|
4
|
-
attr_accessor :offset, :limit, :count, :
|
6
|
+
attr_accessor :offset, :limit, :count, :total_count, :links
|
7
|
+
attr_reader :items
|
5
8
|
|
6
9
|
# type will be used to create objects for the items, e.g.
|
7
10
|
# List.new(Contact, {}).
|
@@ -18,5 +21,4 @@ class List < MessageBird::Base
|
|
18
21
|
def [](index)
|
19
22
|
@items[index]
|
20
23
|
end
|
21
|
-
|
22
24
|
end
|
data/lib/messagebird/lookup.rb
CHANGED
@@ -1,18 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'time'
|
2
4
|
|
3
5
|
require 'messagebird/base'
|
4
6
|
|
5
7
|
module MessageBird
|
6
8
|
class Lookup < MessageBird::Base
|
7
|
-
attr_accessor :href, :
|
9
|
+
attr_accessor :href, :country_code, :country_prefix, :phone_number, :type
|
8
10
|
attr_reader :formats, :hlr
|
9
11
|
|
10
|
-
def formats=(
|
11
|
-
@formats = Formats.new(
|
12
|
+
def formats=(new_formats)
|
13
|
+
@formats = Formats.new(new_formats)
|
12
14
|
end
|
13
15
|
|
14
|
-
def hlr=(
|
15
|
-
@hlr = HLR.new(
|
16
|
+
def hlr=(new_hlr)
|
17
|
+
@hlr = HLR.new(new_hlr)
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
data/lib/messagebird/message.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'messagebird/base'
|
2
4
|
require 'messagebird/recipient'
|
3
5
|
|
@@ -5,14 +7,14 @@ module MessageBird
|
|
5
7
|
class Message < MessageBird::Base
|
6
8
|
attr_accessor :id, :href, :direction, :type, :originator, :body, :reference,
|
7
9
|
:validity, :gateway, :typeDetails, :datacoding, :mclass
|
8
|
-
attr_reader :
|
10
|
+
attr_reader :scheduled_date_time, :created_datetime, :recipients
|
9
11
|
|
10
|
-
def
|
11
|
-
@
|
12
|
+
def scheduled_date_time=(value)
|
13
|
+
@scheduled_date_time = value_to_time(value)
|
12
14
|
end
|
13
15
|
|
14
|
-
def
|
15
|
-
@
|
16
|
+
def created_datetime=(value)
|
17
|
+
@created_datetime = value_to_time(value)
|
16
18
|
end
|
17
19
|
|
18
20
|
def recipients=(json)
|