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.
Files changed (43) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +56 -8
  3. data/lib/messagebird.rb +10 -5
  4. data/lib/messagebird/balance.rb +2 -0
  5. data/lib/messagebird/base.rb +12 -7
  6. data/lib/messagebird/call_flow.rb +22 -0
  7. data/lib/messagebird/call_flow/step.rb +9 -0
  8. data/lib/messagebird/callflow.rb +60 -0
  9. data/lib/messagebird/client.rb +290 -85
  10. data/lib/messagebird/contact.rb +10 -8
  11. data/lib/messagebird/contact_reference.rb +3 -1
  12. data/lib/messagebird/conversation.rb +16 -14
  13. data/lib/messagebird/conversation_channel.rb +8 -7
  14. data/lib/messagebird/conversation_client.rb +9 -6
  15. data/lib/messagebird/conversation_message.rb +6 -5
  16. data/lib/messagebird/conversation_webhook.rb +4 -2
  17. data/lib/messagebird/custom_details.rb +2 -0
  18. data/lib/messagebird/error.rb +2 -0
  19. data/lib/messagebird/group.rb +7 -5
  20. data/lib/messagebird/group_reference.rb +3 -1
  21. data/lib/messagebird/hlr.rb +7 -5
  22. data/lib/messagebird/http_client.rb +34 -34
  23. data/lib/messagebird/list.rb +4 -2
  24. data/lib/messagebird/lookup.rb +7 -5
  25. data/lib/messagebird/message.rb +7 -5
  26. data/lib/messagebird/message_reference.rb +3 -1
  27. data/lib/messagebird/number.rb +18 -0
  28. data/lib/messagebird/number_client.rb +22 -0
  29. data/lib/messagebird/recipient.rb +5 -3
  30. data/lib/messagebird/signed_request.rb +24 -21
  31. data/lib/messagebird/verify.rb +7 -5
  32. data/lib/messagebird/version.rb +7 -0
  33. data/lib/messagebird/voice/base.rb +16 -0
  34. data/lib/messagebird/voice/call.rb +22 -0
  35. data/lib/messagebird/voice/call_leg.rb +11 -0
  36. data/lib/messagebird/voice/call_leg_recording.rb +20 -0
  37. data/lib/messagebird/voice/client.rb +22 -0
  38. data/lib/messagebird/voice/list.rb +24 -0
  39. data/lib/messagebird/voice/transcription.rb +15 -0
  40. data/lib/messagebird/voice/webhook.rb +11 -0
  41. data/lib/messagebird/voice_client.rb +25 -0
  42. data/lib/messagebird/voicemessage.rb +8 -6
  43. metadata +52 -10
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'messagebird/base'
2
4
 
3
5
  module MessageBird
4
6
  class MessageReference < MessageBird::Base
5
- attr_accessor :href, :totalCount
7
+ attr_accessor :href, :total_count
6
8
  end
7
9
  end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'messagebird/base'
4
+
5
+ module MessageBird
6
+ class Number < MessageBird::Base
7
+ attr_accessor :number, :country, :region, :locality, :features, :tags, :type, :status
8
+ attr_reader :created_at, :renewal_at
9
+
10
+ def created_at=(value)
11
+ @created_at = Time.parse(value)
12
+ end
13
+
14
+ def renewal_at=(value)
15
+ @renewal_at = Time.parse(value)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'net/https'
4
+ require 'uri'
5
+ require 'pp'
6
+ require 'json'
7
+ require 'messagebird/http_client'
8
+
9
+ module MessageBird
10
+ class NumberClient < HttpClient
11
+ ENDPOINT = 'https://numbers.messagebird.com/v1/'
12
+
13
+ def endpoint
14
+ ENDPOINT
15
+ end
16
+
17
+ def prepare_request(request, params = {})
18
+ request.body = params.to_json
19
+ request
20
+ end
21
+ end
22
+ end
@@ -1,12 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'messagebird/base'
2
4
 
3
5
  module MessageBird
4
6
  class Recipient < MessageBird::Base
5
7
  attr_accessor :recipient, :status
6
- attr_reader :statusDatetime
8
+ attr_reader :status_date_time
7
9
 
8
- def statusDatetime=(value)
9
- @statusDatetime = value_to_time(value)
10
+ def status_date_time=(value)
11
+ @status_date_time = value_to_time(value)
10
12
  end
11
13
  end
12
14
  end
@@ -1,47 +1,50 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'base64'
2
4
  require 'digest'
3
5
  require 'time'
4
6
 
5
7
  module MessageBird
6
- class ValidationException < TypeError;
8
+ class ValidationException < TypeError
7
9
  end
8
10
 
9
11
  class SignedRequest
10
- def initialize(queryParameters, signature, requestTimestamp, body)
11
-
12
- if !queryParameters.is_a? Hash
13
- raise ValidationException, 'The "queryParameters" value is invalid.'
12
+ def initialize(query_parameters, signature, request_timestamp, body)
13
+ unless query_parameters.is_a? Hash
14
+ raise ValidationException, 'The "query_parameters" value is invalid.'
14
15
  end
15
- if !signature.is_a? String
16
+ unless signature.is_a? String
16
17
  raise ValidationException, 'The "signature" value is invalid.'
17
18
  end
18
- if !requestTimestamp.is_a? Integer
19
- raise ValidationException, 'The "requestTimestamp" value is invalid.'
19
+ unless request_timestamp.is_a? Integer
20
+ raise ValidationException, 'The "request_timestamp" value is invalid.'
20
21
  end
21
- if !body.is_a? String
22
+ unless body.is_a? String
22
23
  raise ValidationException, 'The "body" value is invalid.'
23
24
  end
24
25
 
25
- @queryParameters, @signature, @requestTimestamp, @body = queryParameters, signature, requestTimestamp, body
26
+ @query_parameters = query_parameters
27
+ @signature = signature
28
+ @request_timestamp = request_timestamp
29
+ @body = body
26
30
  end
27
31
 
28
- def verify(signingKey)
29
- calculatedSignature = OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'), signingKey, buildPayload)
30
- expectedSignature = Base64.decode64(@signature)
31
- calculatedSignature.bytes == expectedSignature.bytes
32
+ def verify(signing_key)
33
+ calculated_signature = OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'), signing_key, build_payload)
34
+ expected_signature = Base64.decode64(@signature)
35
+ calculated_signature.bytes == expected_signature.bytes
32
36
  end
33
37
 
34
- def buildPayload
38
+ def build_payload
35
39
  parts = []
36
- parts.push(@requestTimestamp)
37
- parts.push(URI.encode_www_form(@queryParameters.sort))
38
- parts.push(Digest::SHA256.new.digest @body)
40
+ parts.push(@request_timestamp)
41
+ parts.push(URI.encode_www_form(@query_parameters.sort))
42
+ parts.push(Digest::SHA256.new.digest(@body))
39
43
  parts.join("\n")
40
44
  end
41
45
 
42
- def isRecent(offset = 10)
43
- (Time.now.getutc.to_i - @requestTimestamp) < offset;
46
+ def recent?(offset = 10)
47
+ (Time.now.getutc.to_i - @request_timestamp) < offset
44
48
  end
45
-
46
49
  end
47
50
  end
@@ -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 Verify < MessageBird::Base
7
9
  attr_accessor :id, :recipient, :reference, :status, :href
8
- attr_reader :createdDatetime, :validUntilDatetime
10
+ attr_reader :created_datetime, :valid_until_date_time
9
11
 
10
- def createdDatetime=(value)
11
- @createdDatetime = value_to_time(value)
12
+ def created_datetime=(value)
13
+ @created_datetime = value_to_time(value)
12
14
  end
13
15
 
14
- def validUntilDatetime=(value)
15
- @validUntilDatetime = value_to_time(value)
16
+ def valid_until_date_time=(value)
17
+ @valid_until_date_time = value_to_time(value)
16
18
  end
17
19
  end
18
20
  end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MessageBird
4
+ module Version
5
+ STRING = '2.0.0'
6
+ end
7
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MessageBird
4
+ module Voice
5
+ class Base < MessageBird::Base
6
+ def initialize(json)
7
+ params = json.include?('data') ? json['data'].first : json
8
+ super(params)
9
+ handle_links(json['_links'])
10
+ end
11
+
12
+ # intentional empty method, objects may not want to deal with _links
13
+ def handle_links(json) end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'messagebird/voice/base'
4
+ require 'messagebird/voice/webhook'
5
+
6
+ module MessageBird
7
+ module Voice
8
+ class Call < MessageBird::Base
9
+ attr_accessor :id, :status, :source, :destination, :created_at, :updated_at, :ended_at, :call_flow
10
+ attr_reader :webhook
11
+
12
+ def initialize(json)
13
+ params = json.include?('data') ? json['data'].first : json
14
+ super(params)
15
+ end
16
+
17
+ def webhook=(webhook)
18
+ @webhook = Voice::Webhook.new(webhook)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'messagebird/voice/base'
4
+
5
+ module MessageBird
6
+ module Voice
7
+ class CallLeg < MessageBird::Voice::Base
8
+ attr_accessor :id, :call_id, :source, :destination, :status, :direction, :cost, :currency, :duration, :created_at, :updated_at, :answered_at, :ended_at
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'messagebird/voice/base'
4
+
5
+ module MessageBird
6
+ module Voice
7
+ class CallLegRecording < MessageBird::Voice::Base
8
+ # default attributes from the API
9
+ attr_accessor :id, :format, :type, :leg_id, :status, :duration
10
+ attr_accessor :created_at, :updated_at
11
+
12
+ # further processed attributes for convenience
13
+ attr_accessor :_links, :uri
14
+ # Grab the URI to the downloadable file and provide it as a direct attribute
15
+ def handle_links(links_object)
16
+ @uri = links_object['file']
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'net/https'
4
+ require 'uri'
5
+ require 'json'
6
+ require 'messagebird/http_client'
7
+
8
+ module MessageBird
9
+ class VoiceClient < HttpClient
10
+ ENDPOINT = 'https://voice.messagebird.com/'
11
+
12
+ def endpoint
13
+ ENDPOINT
14
+ end
15
+
16
+ def prepare_request(request, params = {})
17
+ request['Content-Type'] = 'application/json'
18
+ request.body = params.to_json
19
+ request
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'messagebird/list'
4
+
5
+ module MessageBird
6
+ module Voice
7
+ class List < List
8
+ attr_accessor :per_page, :current_page, :page_count, :total_count
9
+ PER_PAGE = 20
10
+ CURRENT_PAGE = 1
11
+ def data=(value)
12
+ # Call List API retruns data object instead of items
13
+ # to make it consistence with the rest of the SDK we shall
14
+ # propagate it to items= method
15
+ self.items = value.nil? ? [] : value
16
+ end
17
+
18
+ # map the pagination data to root level properties
19
+ def pagination=(value)
20
+ map_hash_elements_to_self(value)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'messagebird/base'
4
+
5
+ module MessageBird
6
+ module Voice
7
+ class Transcription < MessageBird::Voice::Base
8
+ attr_accessor :id, :recording_id, :error, :created_at, :updated_at, :_links, :uri
9
+
10
+ def handle_links(links_object)
11
+ @uri = links_object['file']
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'messagebird/voice/base'
4
+
5
+ module MessageBird
6
+ module Voice
7
+ class Webhook < MessageBird::Voice::Base
8
+ attr_accessor :id, :url, :token, :created_at, :updated_at
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'net/https'
4
+ require 'uri'
5
+ require 'json'
6
+ require 'messagebird/http_client'
7
+
8
+ module MessageBird
9
+ class VoiceClient < HttpClient
10
+ attr_reader :endpoint
11
+
12
+ BASE_ENDPOINT = 'https://voice.messagebird.com/'
13
+
14
+ def initialize(access_key)
15
+ super(access_key)
16
+ @endpoint = BASE_ENDPOINT
17
+ end
18
+
19
+ def prepare_request(request, params = {})
20
+ request['Content-Type'] = 'application/json'
21
+ request.body = params.to_json
22
+ request
23
+ end
24
+ end
25
+ end
@@ -1,17 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'messagebird/base'
2
4
  require 'messagebird/recipient'
3
5
 
4
6
  module MessageBird
5
7
  class VoiceMessage < MessageBird::Base
6
- attr_accessor :id, :href, :originator, :body, :reference, :language, :voice, :repeat, :ifMachine
7
- attr_reader :scheduledDatetime, :createdDatetime, :recipients
8
+ attr_accessor :id, :href, :originator, :body, :reference, :language, :voice, :repeat, :if_machine
9
+ attr_reader :scheduled_date_time, :created_datetime, :recipients
8
10
 
9
- def scheduledDatetime=(value)
10
- @scheduledDatetime = value_to_time(value)
11
+ def scheduled_date_time=(value)
12
+ @scheduled_date_time = value_to_time(value)
11
13
  end
12
14
 
13
- def createdDatetime=(value)
14
- @createdDatetime = value_to_time(value)
15
+ def created_datetime=(value)
16
+ @created_datetime = value_to_time(value)
15
17
  end
16
18
 
17
19
  def recipients=(json)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: messagebird-rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.2
4
+ version: 2.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: 2019-07-03 00:00:00.000000000 Z
11
+ date: 2021-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -16,14 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '3.8'
19
+ version: 3.10.0
20
20
  type: :development
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: '3.8'
26
+ version: 3.10.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.77.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.77.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: webmock
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.7.5
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.7.5
27
55
  description: A simple REST API for MessageBird in Ruby
28
56
  email: maurice@messagebird.com
29
57
  executables: []
@@ -35,6 +63,9 @@ files:
35
63
  - lib/messagebird.rb
36
64
  - lib/messagebird/balance.rb
37
65
  - lib/messagebird/base.rb
66
+ - lib/messagebird/call_flow.rb
67
+ - lib/messagebird/call_flow/step.rb
68
+ - lib/messagebird/callflow.rb
38
69
  - lib/messagebird/client.rb
39
70
  - lib/messagebird/contact.rb
40
71
  - lib/messagebird/contact_reference.rb
@@ -53,15 +84,27 @@ files:
53
84
  - lib/messagebird/lookup.rb
54
85
  - lib/messagebird/message.rb
55
86
  - lib/messagebird/message_reference.rb
87
+ - lib/messagebird/number.rb
88
+ - lib/messagebird/number_client.rb
56
89
  - lib/messagebird/recipient.rb
57
90
  - lib/messagebird/signed_request.rb
58
91
  - lib/messagebird/verify.rb
92
+ - lib/messagebird/version.rb
93
+ - lib/messagebird/voice/base.rb
94
+ - lib/messagebird/voice/call.rb
95
+ - lib/messagebird/voice/call_leg.rb
96
+ - lib/messagebird/voice/call_leg_recording.rb
97
+ - lib/messagebird/voice/client.rb
98
+ - lib/messagebird/voice/list.rb
99
+ - lib/messagebird/voice/transcription.rb
100
+ - lib/messagebird/voice/webhook.rb
101
+ - lib/messagebird/voice_client.rb
59
102
  - lib/messagebird/voicemessage.rb
60
103
  homepage: https://github.com/messagebird/ruby-rest-api
61
104
  licenses:
62
105
  - BSD-2-Clause
63
106
  metadata: {}
64
- post_install_message:
107
+ post_install_message:
65
108
  rdoc_options: []
66
109
  require_paths:
67
110
  - lib
@@ -69,16 +112,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
69
112
  requirements:
70
113
  - - ">="
71
114
  - !ruby/object:Gem::Version
72
- version: '0'
115
+ version: 1.9.3
73
116
  required_rubygems_version: !ruby/object:Gem::Requirement
74
117
  requirements:
75
118
  - - ">="
76
119
  - !ruby/object:Gem::Version
77
120
  version: '0'
78
121
  requirements: []
79
- rubyforge_project:
80
- rubygems_version: 2.5.2.3
81
- signing_key:
122
+ rubygems_version: 3.2.15
123
+ signing_key:
82
124
  specification_version: 4
83
125
  summary: MessageBird's REST API
84
126
  test_files: []