Code coverage report for src/index.coffee

Statements: 97.22% (35 / 36)      Branches: 50% (3 / 6)      Functions: 100% (12 / 12)      Lines: 100% (17 / 17)      Ignored: none     

All files » src/ » index.coffee
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57  1 1   1 1     1     1 6 6                               2     2 2           2           7           1     1 1  
# Dependencies
Promise= require 'bluebird'
request= require 'request'
 
util= require 'util'
querystring= require 'querystring'
 
# Private
url= 'https://%s:%s@api.voicetext.jp/v1/tts?%s'
 
# Public
class VoiceText
  constructor: (@key= process.env.VOICETEXT_APIKEY)->
    @params=
      text: ''
      speaker: 'hikari'
      format: 'aac'
      emotion: ''
      emotion_level: ''
      pitch: '100'
      speed: '100'
      volume: '100'
 
  fetchVoice: (text)->
    @fetch text
    .then (response)->
      response.body
 
  fetch: (text)->
    E@params.text= text if text?
 
    new Promise (resolve,reject)=>
      uri= @getUri()
      encoding= null
 
      request.post {
        uri
        encoding
      },(error,response)->
        Eunless error
          resolve response
        else
          reject error
 
  set: (name,value)->
    @params[name]= value
    this
 
  get: (name)->
    @params[name]
 
  getUri: ->
    util.format url,@key,'',querystring.stringify @params
 
module.exports= new VoiceText
module.exports.VoiceText= VoiceText