Class: EncodingDotCom::Connection

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/encoding_dot_com/connection.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.loggerObject

Returns the value of attribute logger.



38
39
40
# File 'lib/encoding_dot_com/connection.rb', line 38

def logger
  @logger
end

.s3_keyObject

Returns the value of attribute s3_key.



38
39
40
# File 'lib/encoding_dot_com/connection.rb', line 38

def s3_key
  @s3_key
end

.s3_secretObject

Returns the value of attribute s3_secret.



38
39
40
# File 'lib/encoding_dot_com/connection.rb', line 38

def s3_secret
  @s3_secret
end

.user_idObject

Returns the value of attribute user_id.



38
39
40
# File 'lib/encoding_dot_com/connection.rb', line 38

def user_id
  @user_id
end

.user_keyObject

Returns the value of attribute user_key.



38
39
40
# File 'lib/encoding_dot_com/connection.rb', line 38

def user_key
  @user_key
end

Class Method Details

.call(request_xml_document) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/encoding_dot_com/connection.rb', line 40

def call(request_xml_document)
  if logger
    logger.info("Sending encoding.com request:\n#{request_xml_document}")
  end

  response = post('/', :body => {:xml => request_xml_document})

  if logger
    logger.info("Received encoding.com response:\n#{response.inspect}")
  end
  response = response['response']

  if response['errors']
    message = response['errors']['error']
    case message
      when /Wrong XML/, /No XML/, /Wrong query format/, /Invalid action/, /No formats specified/, /No output format specified/, /Output format .* is not allowed/
        raise(BadRequestError.new(message, request_xml_document))
      when /Wrong user id or key/
        raise(AuthenticationError.new(message, request_xml_document))
      when /Media ID is not indicated/, /Wrong Media ID/
        raise(NotFoundError.new(message, request_xml_document))
      when /Wrong source file url/, /Source file is not indicated/
        raise(BadSourceUrlError.new(message, request_xml_document))
      when /Wrong destination file url/
        raise(BadDestinationUrlError.new(message, request_xml_document))
      else
        raise(EncodingDotComError.new(message, request_xml_document))
    end
  end

  response
end