voicebase-client-ruby 1.2.4 → 1.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b1876791e35e64f7cfc3137f2c8df6b183954776
4
- data.tar.gz: 95e70c5ae2df8c0b2dec354e1b496fdaedded626
2
+ SHA256:
3
+ metadata.gz: db58cab69d568dc60664a1e7887597eaa872b864e86f61a689fea89dd9a8270b
4
+ data.tar.gz: e022d96cb97446db68e38eed733419d75b1a8c91a56cdb689c2ed83b14db6651
5
5
  SHA512:
6
- metadata.gz: 817ab808bce6353791cd2012a992cb432a250ed821a0fb4a9e68fe7eabf51f3a2aedf9a570d663a9e73aea624a867cfcda937415983c747c9d087906593acddc
7
- data.tar.gz: 8379041f78d9a0b55124e936e06308ab4a180382d77ce6b1f4b404266701de9d68c6eae8dbb5e4786937cfdf60475aa983f5f8b517a023188d32eab0ad77fe70
6
+ metadata.gz: dbd4a41f6f8fbb4692f3f61882b9d70ef603177d45d4f88e1fd3bb35d083441da617397eba1caa112328c0d51dd82b453e084daa12e237fd6905de9b93ae04d2
7
+ data.tar.gz: b1cb90bff2ab8fba5ba50288d10d02543b4ebdde5efaa4f09e13539d52e3e103ab986367b5ee7ac4227e337ecb30f0953560185458ad148f7306824d18ae628c
@@ -1,7 +1,9 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.0
4
3
  - 2.1
5
4
  - 2.2
6
5
  - 2.3.1
6
+ - 2.4
7
+ - 2.5
8
+ - 2.6
7
9
  before_install: gem install bundler -v 1.13.6
@@ -8,6 +8,7 @@ require "voicebase/helpers"
8
8
 
9
9
  require "voicebase/v1"
10
10
  require "voicebase/v2"
11
+ require "voicebase/v3"
11
12
 
12
13
  require "voicebase/client"
13
14
  require "voicebase/client/token"
@@ -1,4 +1,5 @@
1
1
  module VoiceBase
2
+ class UnknownApiVersionError < StandardError; end;
2
3
  class Client
3
4
  include HTTParty
4
5
 
@@ -30,11 +31,16 @@ module VoiceBase
30
31
  @token = VoiceBase::Client::Token.new(ENV['VOICEBASE_BEARER_TOKEN'])
31
32
  end
32
33
 
33
- if @api_version.to_f < 2.0
34
+ if @api_version.to_i < 2
34
35
  self.extend(VoiceBase::V1::Client)
35
- else
36
+ elsif @api_version.to_i == 2
36
37
  self.extend(VoiceBase::V2::Client)
38
+ elsif @api_version.to_i == 3
39
+ self.extend(VoiceBase::V3::Client)
40
+ else
41
+ raise UnknownApiVersionError
37
42
  end
43
+
38
44
  end
39
45
 
40
46
  def uri
@@ -0,0 +1,27 @@
1
+ require "mime/types"
2
+ require_relative "text_part"
3
+
4
+ module VoiceBase
5
+ module Request
6
+ class FilePart < TextPart
7
+ attr_accessor :filepath
8
+
9
+ def initialize(name:, file:)
10
+ @name = name
11
+ @filepath = file.path
12
+ @body = file.read
13
+ end
14
+
15
+ def multipart
16
+ "Content-Disposition: form-data; name=\"#{CGI::escape(name)}\"; filename=\"#{ File.basename(filepath) }\"\r\n" +
17
+ "Content-Type: #{ mime_type.simplified }\r\n\r\n#{ body }\r\n\r\n"
18
+ end
19
+
20
+ private
21
+
22
+ def mime_type
23
+ MIME::Types.type_for(filepath)[0] || MIME::Types["application/octet-stream"][0]
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,13 @@
1
+ require_relative "text_part"
2
+ require "json"
3
+
4
+ module VoiceBase
5
+ module Request
6
+ class HashPart < TextPart
7
+ def initialize(name:, hash:)
8
+ @name = name
9
+ @body = ::JSON.dump(hash)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,32 @@
1
+ require "securerandom"
2
+
3
+ module VoiceBase
4
+ module Request
5
+ class MultipartBuilder
6
+ attr_accessor :parts, :boundary
7
+ def initialize(headers:)
8
+ @headers = headers
9
+ @parts = []
10
+ @boundary = SecureRandom.hex
11
+ end
12
+
13
+ def add(part)
14
+ parts << part
15
+ end
16
+
17
+ def body
18
+ "--#{boundary}\r\n#{multiparts}--#{boundary}--"
19
+ end
20
+
21
+ def headers
22
+ @headers.merge({"Content-Type" => "multipart/form-data; boundary=#{boundary}"})
23
+ end
24
+
25
+ private
26
+
27
+ def multiparts
28
+ parts.map(&:multipart).join("--#{boundary}\r\n")
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,15 @@
1
+ module VoiceBase
2
+ module Request
3
+ class TextPart
4
+ attr_accessor :name, :body
5
+ def initialize(name:, body:)
6
+ @name = name
7
+ @body = body
8
+ end
9
+
10
+ def multipart
11
+ "Content-Disposition: form-data; name=\"#{CGI::escape(name)}\"\r\n\r\n#{body}\r\n"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -7,10 +7,14 @@ module VoiceBase
7
7
 
8
8
  def initialize(http_response, api_version = "1.1")
9
9
  @http_response = http_response
10
- if api_version.to_f < 2
10
+ if api_version.to_i < 2
11
11
  self.extend(VoiceBase::V1::Response)
12
- else
12
+ elsif api_version.to_i == 2
13
13
  self.extend(VoiceBase::V2::Response)
14
+ elsif api_version.to_i == 3
15
+ self.extend(VoiceBase::V3::Response)
16
+ else
17
+ raise UnknownApiVersionError
14
18
  end
15
19
  end
16
20
 
@@ -0,0 +1,10 @@
1
+ module VoiceBase
2
+ module V3; end
3
+ end
4
+
5
+ require "voicebase/v3/client"
6
+ require "voicebase/v3/response"
7
+ require "voicebase/request/multipart_builder"
8
+ require "voicebase/request/text_part"
9
+ require "voicebase/request/file_part"
10
+ require "voicebase/request/hash_part"
@@ -0,0 +1,49 @@
1
+ module VoiceBase
2
+ module V3
3
+ module Client
4
+ include VoiceBase::V2::Client
5
+
6
+ def self.extended(client, args = {})
7
+ client.api_host = client.args[:host] || ENV.fetch('VOICEBASE_V3_API_HOST', 'https://apis.voicebase.com')
8
+ client.api_endpoint = client.args[:api_endpoint] || ENV.fetch('VOICEBASE_V3_API_ENDPOINT', '/v3')
9
+ end
10
+
11
+ def upload_media(args = {}, headers = {})
12
+ require_media_file_or_url!(args)
13
+ r = ::VoiceBase::Request::MultipartBuilder.new(headers: default_headers(headers))
14
+
15
+ if args[:config]
16
+ r.add(VoiceBase::Request::HashPart.new(name: "configuration", hash: args[:config]))
17
+ end
18
+
19
+ if args[:media_url]
20
+ r.add(VoiceBase::Request::TextPart.new(name: "mediaUrl", body: args[:media_url]))
21
+ end
22
+
23
+ if args[:media_file]
24
+ r.add(VoiceBase::Request::FilePart.new(name: "media", file: args[:media_file]))
25
+ end
26
+
27
+ #TODO: make metadata an object
28
+ if args[:metadata]
29
+ r.add(VoiceBase::Request::HashPart.new(name: "metadata", hash: args[:metadata]))
30
+ end
31
+
32
+ response = self.class.post(
33
+ uri + '/media',
34
+ headers: r.headers,
35
+ body: r.body
36
+ )
37
+ VoiceBase::Response.new(response, api_version)
38
+ end
39
+
40
+ private
41
+
42
+ def require_media_file_or_url!(args = {})
43
+ if args[:media_url].nil? && args[:media_file].nil?
44
+ raise ArgumentError, "Missing argument :media_url or :media_file"
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,45 @@
1
+ module VoiceBase
2
+ module V3
3
+ module Response
4
+
5
+ TRANSCRIPT_READY_STATUS = "finished".freeze
6
+
7
+ def success?
8
+ ok?
9
+ end
10
+
11
+ def media_id
12
+ voicebase_response['mediaId']
13
+ end
14
+
15
+ def transcript_ready?
16
+ voicebase_response['status'].downcase == TRANSCRIPT_READY_STATUS
17
+ end
18
+
19
+ def transcript
20
+ # this retrieves the JSON transcript only
21
+ # the plain text transcript is a plain text non-JSON response
22
+ voicebase_response['transcript']['words']
23
+ end
24
+
25
+ def keywords
26
+ knowledge["keywords"]
27
+ end
28
+
29
+ def topics
30
+ knowledge['topics']
31
+ end
32
+
33
+ private
34
+
35
+ def knowledge
36
+ voicebase_response.fetch("knowledge", {}) || {}
37
+ end
38
+
39
+ def voicebase_response
40
+ http_response.parsed_response
41
+ end
42
+
43
+ end
44
+ end
45
+ end
@@ -1,5 +1,5 @@
1
1
  module VoiceBase
2
- VERSION = "1.2.4"
2
+ VERSION = "1.3.0"
3
3
 
4
4
  def self.version; VERSION; end
5
5
  end
@@ -6,7 +6,7 @@ require 'voicebase/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "voicebase-client-ruby"
8
8
  spec.version = VoiceBase::version
9
- spec.authors = ["Juergen Fesslmeier", "April Wensel", "Jerry Hogsett"]
9
+ spec.authors = ["Juergen Fesslmeier", "April Wensel", "Jerry Hogsett", "Perry Lee"]
10
10
  spec.email = ["jerry@usertesting.com", "client-dev@usertesting.com"]
11
11
 
12
12
  spec.summary = %q{Ruby client for VoiceBase API Version 1.x and 2.x.}
metadata CHANGED
@@ -1,16 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: voicebase-client-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juergen Fesslmeier
8
8
  - April Wensel
9
9
  - Jerry Hogsett
10
+ - Perry Lee
10
11
  autorequire:
11
12
  bindir: exe
12
13
  cert_chain: []
13
- date: 2018-03-07 00:00:00.000000000 Z
14
+ date: 2019-10-30 00:00:00.000000000 Z
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
16
17
  name: bundler
@@ -121,6 +122,10 @@ files:
121
122
  - lib/voicebase/helpers.rb
122
123
  - lib/voicebase/json.rb
123
124
  - lib/voicebase/json/word.rb
125
+ - lib/voicebase/request/file_part.rb
126
+ - lib/voicebase/request/hash_part.rb
127
+ - lib/voicebase/request/multipart_builder.rb
128
+ - lib/voicebase/request/text_part.rb
124
129
  - lib/voicebase/response.rb
125
130
  - lib/voicebase/v1.rb
126
131
  - lib/voicebase/v1/client.rb
@@ -128,6 +133,9 @@ files:
128
133
  - lib/voicebase/v2.rb
129
134
  - lib/voicebase/v2/client.rb
130
135
  - lib/voicebase/v2/response.rb
136
+ - lib/voicebase/v3.rb
137
+ - lib/voicebase/v3/client.rb
138
+ - lib/voicebase/v3/response.rb
131
139
  - lib/voicebase/version.rb
132
140
  - voicebase-client-ruby.gemspec
133
141
  homepage: https://github.com/usertesting/voicebase-client-ruby
@@ -149,8 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
157
  - !ruby/object:Gem::Version
150
158
  version: '0'
151
159
  requirements: []
152
- rubyforge_project:
153
- rubygems_version: 2.5.1
160
+ rubygems_version: 3.0.3
154
161
  signing_key:
155
162
  specification_version: 4
156
163
  summary: Ruby client for VoiceBase API Version 1.x and 2.x.