Smartling / api-sdk-ruby

SDK for integrating with the Smartling API. The Smartling API allows developers to upload language specific resource files and download the translations of those files for easy integration within their application.
http://docs.smartling.com
Other
13 stars 15 forks source link

Uploading files does not seem to work at all #2

Closed Voxar closed 10 years ago

Voxar commented 10 years ago
simple_json_string = '{"key":"value"}'
file = Tempfile.new("json")
file.write(simple_json_string)
file.flush
sl = Smartling::File.sandbox(:apiKey => API_KEY, :projectId => PROJECT_ID)
sl.upload(file.path, 'test/simple_json_file.json', 'json')

api.rb:53: in `check_response': API error: VALIDATION_ERROR File is required (RuntimeError)

$ ruby --version
ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin12.2.0]

$ gem list | grep -E 'smartling|rest-client|multi_json'
multi_json (1.7.6, 1.7.2, 1.5.0, 1.3.7, 1.3.6)
rest-client (1.6.7)
smartling (0.5.1)
paiv commented 10 years ago

@Voxar , can you please run your code with logger?

To configure logger: require 'logger' l = Logger.new($stderr) l.level = 0 sl.log = l

I cannot reproduce your error, so would like to see logs of your http requests.

paiv commented 10 years ago

@Voxar also: file .pos should be reset to 0 before reading, I believe. Check with rest-client.

up: this should not matter, since you are passing file path, not the stream.

Voxar commented 10 years ago

api key and project id redacted

RestClient.post "https://sandbox-api.smartling.com/v1/file/upload?apiKey=<REDACTED>&projectId=<REDACTED>&fileUri=test/simple_json_file.json&fileType=json", "--513915\r\nContent-Disposition: form-data; name=\"file\"; filename=\"json20131022-64970-8ax3jb\"\r\nContent-Type: text/plain\r\n\r\n{\"key\":\"value\"}\r\n--513915--\r\n", "Accept"=>"*/*; q=0.5, application/xml", "Accept-Encoding"=>"gzip, deflate", "Content-Length"=>"150", "Content-Type"=>"multipart/form-data; boundary=513915"
"--513915\r\nContent-Disposition: form-data; name=\"file\"; filename=\"json20131022-64970-8ax3jb\"\r\nContent-Type: text/plain\r\n\r\n{\"key\":\"value\"}\r\n--513915--\r\n"
# => 400 BadRequest | application/json 84 bytes
/Users/voxar/.rvm/gems/ruby-1.9.3-p327/gems/smartling-0.5.1/lib/smartling/api.rb:53:in `check_response': API error: VALIDATION_ERROR File is required (RuntimeError)
    from /Users/voxar/.rvm/gems/ruby-1.9.3-p327/gems/smartling-0.5.1/lib/smartling/api.rb:57:in `process'
    from /Users/voxar/.rvm/gems/ruby-1.9.3-p327/gems/smartling-0.5.1/lib/smartling/api.rb:90:in `block in post'
    from /Users/voxar/.rvm/gems/ruby-1.9.3-p327/gems/rest-client-1.6.7/lib/restclient/request.rb:229:in `call'
    from /Users/voxar/.rvm/gems/ruby-1.9.3-p327/gems/rest-client-1.6.7/lib/restclient/request.rb:229:in `process_result'
    from /Users/voxar/.rvm/gems/ruby-1.9.3-p327/gems/rest-client-1.6.7/lib/restclient/request.rb:179:in `block in transmit'
    from /Users/voxar/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/net/http.rb:745:in `start'
    from /Users/voxar/.rvm/gems/ruby-1.9.3-p327/gems/rest-client-1.6.7/lib/restclient/request.rb:172:in `transmit'
    from /Users/voxar/.rvm/gems/ruby-1.9.3-p327/gems/rest-client-1.6.7/lib/restclient/request.rb:64:in `execute'
    from /Users/voxar/.rvm/gems/ruby-1.9.3-p327/gems/rest-client-1.6.7/lib/restclient/request.rb:33:in `execute'
    from /Users/voxar/.rvm/gems/ruby-1.9.3-p327/gems/rest-client-1.6.7/lib/restclient.rb:72:in `post'
    from /Users/voxar/.rvm/gems/ruby-1.9.3-p327/gems/smartling-0.5.1/lib/smartling/api.rb:89:in `post'
    from /Users/voxar/.rvm/gems/ruby-1.9.3-p327/gems/smartling-0.5.1/lib/smartling/fileapi.rb:53:in `upload'
    from smartling lib error test.rb:15:in `<main>'
Voxar commented 10 years ago

@paiv Are streams supported? StringIO object doesn't work, thus the tempfile.

junky commented 10 years ago

@Voxar could you confirm that body request is duplicated in your logs?

RestClient.post "https://sandbox-api.smartling.com/v1/file/upload?apiKey=&projectId=&fileUri=test/simple_json_file.json&fileType=json", "--513915\r\nContent-Disposition: form-data; name=\"file\"; filename=\"json20131022-64970-8ax3jb\"\r\nContent-Type: text/plain\r\n\r\n{\"key\":\"value\"}\r\n--513915--\r\n", "Accept"=>"*/*; q=0.5, application/xml", "Accept-Encoding"=>"gzip, deflate", "Content-Length"=>"150", "Content-Type"=>"multipart/form-data; boundary=513915" "--513915\r\nContent-Disposition: form-data; name=\"file\"; filename=\"json20131022-64970-8ax3jb\"\r\nContent-Type: text/plain\r\n\r\n{\"key\":\"value\"}\r\n--513915--\r\n"
Voxar commented 10 years ago

I noticed the second occurrence did not print to stderr so I started suspecting something might be wrong with gems. I reinstalled and it works now -.-

Thank you for your help.