twilio-ruby 4.4.0 → 4.13.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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +85 -0
  3. data/Makefile +3 -0
  4. data/README.md +1 -1
  5. data/issue_template.md +25 -0
  6. data/lib/twilio-ruby/rest/accounts.rb +1 -1
  7. data/lib/twilio-ruby/rest/base_client.rb +3 -2
  8. data/lib/twilio-ruby/rest/ip-messaging/channels.rb +15 -0
  9. data/lib/twilio-ruby/rest/ip-messaging/credentials.rb +19 -0
  10. data/lib/twilio-ruby/rest/ip-messaging/members.rb +8 -0
  11. data/lib/twilio-ruby/rest/ip-messaging/messages.rb +8 -0
  12. data/lib/twilio-ruby/rest/ip-messaging/roles.rb +8 -0
  13. data/lib/twilio-ruby/rest/ip-messaging/services.rb +17 -0
  14. data/lib/twilio-ruby/rest/ip-messaging/users.rb +8 -0
  15. data/lib/twilio-ruby/rest/ip_messaging_client.rb +100 -0
  16. data/lib/twilio-ruby/rest/keys.rb +6 -0
  17. data/lib/twilio-ruby/rest/pricing/messaging.rb +15 -0
  18. data/lib/twilio-ruby/rest/pricing/voice.rb +0 -3
  19. data/lib/twilio-ruby/rest/pricing_client.rb +2 -4
  20. data/lib/twilio-ruby/rest/trunking/credential_lists.rb +8 -0
  21. data/lib/twilio-ruby/rest/trunking/ip_access_control_lists.rb +8 -0
  22. data/lib/twilio-ruby/rest/trunking/origination_urls.rb +8 -0
  23. data/lib/twilio-ruby/rest/trunking/phone_numbers.rb +8 -0
  24. data/lib/twilio-ruby/rest/trunking/trunks.rb +19 -0
  25. data/lib/twilio-ruby/rest/trunking_client.rb +106 -0
  26. data/lib/twilio-ruby/task_router/capability.rb +11 -5
  27. data/lib/twilio-ruby/task_router/workflow_builder.rb +7 -1
  28. data/lib/twilio-ruby/util/access_token.rb +158 -0
  29. data/lib/twilio-ruby/version.rb +1 -1
  30. data/lib/twilio-ruby.rb +22 -0
  31. data/spec/rest/ip-messaging/channel_spec.rb +21 -0
  32. data/spec/rest/ip-messaging/service_spec.rb +30 -0
  33. data/spec/rest/ip_messaging_client_spec.rb +21 -0
  34. data/spec/rest/key_spec.rb +11 -0
  35. data/spec/rest/pricing_client_spec.rb +15 -0
  36. data/spec/rest/trunking/trunk_spec.rb +36 -0
  37. data/spec/task_router/workflow_builder_spec.rb +501 -0
  38. data/spec/task_router_deprecated_spec.rb +15 -6
  39. data/spec/task_router_worker_spec.rb +24 -7
  40. data/spec/util/access_token_spec.rb +161 -0
  41. metadata +35 -3
@@ -0,0 +1,158 @@
1
+ module Twilio
2
+ module Util
3
+ class AccessToken
4
+ attr_accessor :account_sid,
5
+ :signing_key_id,
6
+ :secret,
7
+ :ttl,
8
+ :identity,
9
+ :nbf
10
+
11
+ def initialize(account_sid, signing_key_id, secret, ttl=3600, identity=nil, nbf=nil)
12
+ @account_sid = account_sid
13
+ @signing_key_sid = signing_key_id
14
+ @secret = secret
15
+ @ttl = ttl
16
+ @identity = identity
17
+ @nbf = nbf
18
+ @grants = []
19
+ end
20
+
21
+ def add_grant(grant)
22
+ @grants.push(grant)
23
+ end
24
+
25
+ def to_jwt(algorithm='HS256')
26
+ now = Time.now.to_i - 1
27
+ headers = {
28
+ 'cty' => 'twilio-fpa;v=1',
29
+ }
30
+
31
+ grants = {}
32
+ if @identity
33
+ grants['identity'] = @identity
34
+ end
35
+
36
+ @grants.each { |grant| grants[grant.key] = grant.payload }
37
+
38
+ payload = {
39
+ 'jti' => "#{@signing_key_sid}-#{now}",
40
+ 'iss' => @signing_key_sid,
41
+ 'sub' => @account_sid,
42
+ 'exp' => now + @ttl,
43
+ 'grants' => grants
44
+ }
45
+
46
+ payload['nbf'] = @nbf unless @nbf.nil?
47
+
48
+ JWT.encode payload, @secret, algorithm, headers
49
+ end
50
+
51
+ def to_s
52
+ to_jwt
53
+ end
54
+
55
+ class ConversationsGrant
56
+ attr_accessor :configuration_profile_sid
57
+
58
+ def key
59
+ 'rtc'
60
+ end
61
+
62
+ def payload
63
+ payload = {}
64
+ if @configuration_profile_sid
65
+ payload['configuration_profile_sid'] = @configuration_profile_sid
66
+ end
67
+
68
+ payload
69
+ end
70
+
71
+ end
72
+
73
+ class IpMessagingGrant
74
+ attr_accessor :service_sid,
75
+ :endpoint_id,
76
+ :deployment_role_sid,
77
+ :push_credential_sid
78
+
79
+ def key
80
+ 'ip_messaging'
81
+ end
82
+
83
+ def payload
84
+ payload = {}
85
+ if @service_sid
86
+ payload['service_sid'] = @service_sid
87
+ end
88
+ if @endpoint_id
89
+ payload['endpoint_id'] = @endpoint_id
90
+ end
91
+ if @deployment_role_sid
92
+ payload['deployment_role_sid'] = @deployment_role_sid
93
+ end
94
+ if @push_credential_sid
95
+ payload['push_credential_sid'] = @push_credential_sid
96
+ end
97
+
98
+ payload
99
+ end
100
+
101
+ end
102
+
103
+ class VoiceGrant
104
+ attr_accessor :outgoing_application_sid,
105
+ :outgoing_application_params,
106
+ :push_credential_sid,
107
+ :endpoint_id
108
+
109
+ def key
110
+ 'voice'
111
+ end
112
+
113
+ def payload
114
+ payload = {}
115
+
116
+ if outgoing_application_sid
117
+ outgoing = {}
118
+ outgoing[:application_sid] = outgoing_application_sid
119
+ if outgoing_application_params
120
+ outgoing[:params] = outgoing_application_params
121
+ end
122
+
123
+ payload[:outgoing] = outgoing
124
+ end
125
+
126
+ if push_credential_sid
127
+ payload[:push_credential_sid] = push_credential_sid
128
+ end
129
+
130
+ if endpoint_id
131
+ payload[:endpoint_id] = endpoint_id
132
+ end
133
+
134
+ payload
135
+ end
136
+ end
137
+
138
+ class VideoGrant
139
+ attr_accessor :configuration_profile_sid
140
+
141
+ def key
142
+ 'video'
143
+ end
144
+
145
+ def payload
146
+ payload = {}
147
+
148
+ if configuration_profile_sid
149
+ payload[:configuration_profile_sid] = configuration_profile_sid
150
+ end
151
+
152
+ payload
153
+ end
154
+ end
155
+
156
+ end
157
+ end
158
+ end
@@ -1,3 +1,3 @@
1
1
  module Twilio
2
- VERSION = '4.4.0'
2
+ VERSION = '4.13.0'
3
3
  end
data/lib/twilio-ruby.rb CHANGED
@@ -10,6 +10,7 @@ require 'jwt'
10
10
 
11
11
  require 'twilio-ruby/version' unless defined?(Twilio::VERSION)
12
12
  require 'twilio-ruby/util'
13
+ require 'twilio-ruby/util/access_token'
13
14
  require 'twilio-ruby/util/client_config'
14
15
  require 'twilio-ruby/util/configuration'
15
16
  require 'twilio-ruby/util/request_validator'
@@ -28,6 +29,20 @@ require 'twilio-ruby/rest/accounts'
28
29
  require 'twilio-ruby/rest/calls'
29
30
  require 'twilio-ruby/rest/call_feedback'
30
31
  require 'twilio-ruby/rest/call_feedback_summary'
32
+ require 'twilio-ruby/rest/keys'
33
+ require 'twilio-ruby/rest/pricing'
34
+ require 'twilio-ruby/rest/pricing/countries'
35
+ require 'twilio-ruby/rest/pricing/phone_numbers'
36
+ require 'twilio-ruby/rest/pricing/voice/numbers'
37
+ require 'twilio-ruby/rest/pricing/voice'
38
+ require 'twilio-ruby/rest/pricing/messaging'
39
+ require 'twilio-ruby/rest/ip-messaging/services'
40
+ require 'twilio-ruby/rest/ip-messaging/channels'
41
+ require 'twilio-ruby/rest/ip-messaging/members'
42
+ require 'twilio-ruby/rest/ip-messaging/messages'
43
+ require 'twilio-ruby/rest/ip-messaging/roles'
44
+ require 'twilio-ruby/rest/ip-messaging/users'
45
+ require 'twilio-ruby/rest/ip-messaging/credentials'
31
46
  require 'twilio-ruby/rest/sms'
32
47
  require 'twilio-ruby/rest/sms/short_codes'
33
48
  require 'twilio-ruby/rest/sms/messages'
@@ -52,6 +67,11 @@ require 'twilio-ruby/rest/task_router/workflow_statistics'
52
67
  require 'twilio-ruby/rest/task_router/workflows'
53
68
  require 'twilio-ruby/rest/task_router/workspaces'
54
69
  require 'twilio-ruby/rest/task_router/workspace_statistics'
70
+ require 'twilio-ruby/rest/trunking/credential_lists.rb'
71
+ require 'twilio-ruby/rest/trunking/ip_access_control_lists.rb'
72
+ require 'twilio-ruby/rest/trunking/origination_urls.rb'
73
+ require 'twilio-ruby/rest/trunking/phone_numbers.rb'
74
+ require 'twilio-ruby/rest/trunking/trunks.rb'
55
75
  require 'twilio-ruby/rest/lookups/phone_numbers'
56
76
  require 'twilio-ruby/rest/monitor/events'
57
77
  require 'twilio-ruby/rest/monitor/alerts'
@@ -85,9 +105,11 @@ require 'twilio-ruby/rest/addresses'
85
105
  require 'twilio-ruby/rest/addresses/dependent_phone_numbers'
86
106
  require 'twilio-ruby/rest/client'
87
107
  require 'twilio-ruby/rest/task_router_client'
108
+ require 'twilio-ruby/rest/trunking_client'
88
109
  require 'twilio-ruby/rest/lookups_client'
89
110
  require 'twilio-ruby/rest/pricing_client'
90
111
  require 'twilio-ruby/rest/monitor_client'
112
+ require 'twilio-ruby/rest/ip_messaging_client'
91
113
  require 'rack/twilio_webhook_authentication'
92
114
 
93
115
  module Twilio
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Twilio::REST::IpMessaging::Channels do
4
+ it 'sets up a members resources object' do
5
+ client = Twilio::REST::IpMessagingClient.new 'otherSid', 'otherToken'
6
+ service = Twilio::REST::IpMessaging::Channel.new '/v1/Services/1/Channels/1', client
7
+ expect(service).to respond_to(:members)
8
+ expect(service.members.instance_variable_get('@path')).to eq(
9
+ '/v1/Services/1/Channels/1/Members'
10
+ )
11
+ end
12
+
13
+ it 'sets up a messages resources object' do
14
+ client = Twilio::REST::IpMessagingClient.new 'otherSid', 'otherToken'
15
+ service = Twilio::REST::IpMessaging::Channel.new '/v1/Services/1/Channels/1', client
16
+ expect(service).to respond_to(:messages)
17
+ expect(service.messages.instance_variable_get('@path')).to eq(
18
+ '/v1/Services/1/Channels/1/Messages'
19
+ )
20
+ end
21
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe Twilio::REST::IpMessaging::Services do
4
+ it 'sets up a channels resources object' do
5
+ client = Twilio::REST::IpMessagingClient.new 'otherSid', 'otherToken'
6
+ service = Twilio::REST::IpMessaging::Service.new '/v1/Services', client
7
+ expect(service).to respond_to(:channels)
8
+ expect(service.channels.instance_variable_get('@path')).to eq(
9
+ '/v1/Services/Channels'
10
+ )
11
+ end
12
+
13
+ it 'sets up a roles resources object' do
14
+ client = Twilio::REST::IpMessagingClient.new 'otherSid', 'otherToken'
15
+ service = Twilio::REST::IpMessaging::Service.new '/v1/Services', client
16
+ expect(service).to respond_to(:roles)
17
+ expect(service.roles.instance_variable_get('@path')).to eq(
18
+ '/v1/Services/Roles'
19
+ )
20
+ end
21
+
22
+ it 'sets up a users resources object' do
23
+ client = Twilio::REST::IpMessagingClient.new 'otherSid', 'otherToken'
24
+ service = Twilio::REST::IpMessaging::Service.new '/v1/Services', client
25
+ expect(service).to respond_to(:users)
26
+ expect(service.users.instance_variable_get('@path')).to eq(
27
+ '/v1/Services/Users'
28
+ )
29
+ end
30
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Twilio::REST::IpMessagingClient do
4
+ before do
5
+ @client = Twilio::REST::IpMessagingClient.new('AC123', 'foobar')
6
+ end
7
+
8
+ it 'should set up a services resources object' do
9
+ expect(@client).to respond_to(:services)
10
+ expect(@client.services.instance_variable_get('@path')).to eq(
11
+ '/v1/Services'
12
+ )
13
+ end
14
+
15
+ it 'should set up a credentials resources object' do
16
+ expect(@client).to respond_to(:credentials)
17
+ expect(@client.credentials.instance_variable_get('@path')).to eq(
18
+ '/v1/Credentials'
19
+ )
20
+ end
21
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Twilio::REST::Key do
4
+ before do
5
+ @key = Twilio::REST::Key.new('someUri', 'someClient')
6
+ end
7
+
8
+ it 'has correct path' do
9
+ expect(@key.instance_variable_get('@path')).to eq('someUri')
10
+ end
11
+ end
@@ -42,4 +42,19 @@ describe Twilio::REST::PricingClient do
42
42
  '/v1/PhoneNumbers/Countries'
43
43
  )
44
44
  end
45
+
46
+ it 'should set up a messaging resources object' do
47
+ expect(@client).to respond_to(:messaging)
48
+ expect(@client.messaging.instance_variable_get('@path')).to eq(
49
+ '/v1/Messaging'
50
+ )
51
+ end
52
+
53
+ it 'should set up the country list resource on messaging' do
54
+ messaging = @client.messaging
55
+ expect(messaging).to respond_to(:countries)
56
+ expect(messaging.countries.instance_variable_get('@path')).to eq(
57
+ '/v1/Messaging/Countries'
58
+ )
59
+ end
45
60
  end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe Twilio::REST::Trunking::Trunk do
4
+
5
+ before do
6
+ @trunk = Twilio::REST::Trunking::Trunk.new('someUri', 'someClient')
7
+ end
8
+
9
+ it 'sets up a credential lists resources object' do
10
+ expect(@trunk).to respond_to(:credential_lists)
11
+ expect(@trunk.credential_lists.instance_variable_get('@path')).to eq(
12
+ 'someUri/CredentialLists'
13
+ )
14
+ end
15
+
16
+ it 'sets up a ip access control lists resources object' do
17
+ expect(@trunk).to respond_to(:ip_access_control_lists)
18
+ expect(@trunk.ip_access_control_lists.instance_variable_get('@path')).to eq(
19
+ 'someUri/IpAccessControlLists'
20
+ )
21
+ end
22
+
23
+ it 'sets up a origination urls resources object' do
24
+ expect(@trunk).to respond_to(:origination_urls)
25
+ expect(@trunk.origination_urls.instance_variable_get('@path')).to eq(
26
+ 'someUri/OriginationUrls'
27
+ )
28
+ end
29
+
30
+ it 'sets up a phone numbers resources object' do
31
+ expect(@trunk).to respond_to(:phone_numbers)
32
+ expect(@trunk.phone_numbers.instance_variable_get('@path')).to eq(
33
+ 'someUri/PhoneNumbers'
34
+ )
35
+ end
36
+ end