diff --git a/bin/poeditor b/bin/poeditor old mode 100644 new mode 100755 diff --git a/lib/poeditor/core.rb b/lib/poeditor/core.rb index 037840c..6705731 100644 --- a/lib/poeditor/core.rb +++ b/lib/poeditor/core.rb @@ -22,11 +22,10 @@ def initialize(configuration) # @param options [Hash{Sting => Object}] # # @return [Net::HTTPResponse] The response object of API request - # + # # @see https://poeditor.com/api_reference/ POEditor API Reference def api(action, api_token, options={}) - uri = URI("https://poeditor.com/api/") - options["action"] = action + uri = URI("https://api.poeditor.com/v2/#{action}") options["api_token"] = api_token return Net::HTTP.post_form(uri, options) end @@ -67,7 +66,7 @@ def export(api_key:, project_id:, language:, type:, tags:nil) "type" => type, "tags" => (tags || []).join(","), } - response = self.api("export", api_key, options) + response = self.api("projects/export", api_key, options) data = JSON(response.body) unless data["response"]["status"] == "success" code = data["response"]["code"] @@ -75,7 +74,7 @@ def export(api_key:, project_id:, language:, type:, tags:nil) raise POEditor::Exception.new "#{message} (#{code})" end - download_uri = URI(data["item"]) + download_uri = URI(data["result"]["url"]) content = Net::HTTP.get(download_uri) case type diff --git a/lib/poeditor/version.rb b/lib/poeditor/version.rb index 5ec9946..d6fb86e 100644 --- a/lib/poeditor/version.rb +++ b/lib/poeditor/version.rb @@ -1,3 +1,3 @@ module POEditor - VERSION = "0.3.2" + VERSION = "0.4.0" end diff --git a/test/test.rb b/test/test.rb index 0d7cbb1..089c401 100644 --- a/test/test.rb +++ b/test/test.rb @@ -8,21 +8,22 @@ class Test < Minitest::Test def stub_api(request_action, request_body_include=nil, response_body) request_body_include = request_body_include || {} - request_body_include["action"] = request_action - stub_request(:post, "https://poeditor.com/api/") + stub_request(:post, "https://api.poeditor.com/v2/#{request_action}") .with(:body => hash_including(request_body_include)) .to_return(:body => response_body) end def stub_api_export(language, body) - stub_api "export", {"language" => language}, <<~BODY + stub_api "projects/export", {"language" => language}, <<~BODY { "response": { "status": "success", "code": "200", "message": "OK" }, - "item": "https://poeditor.com/api/download/file/#{language}" + "result": { + "url": "https://poeditor.com/api/download/file/#{language}" + } } BODY stub_request(:get, "https://poeditor.com/api/download/file/#{language}")