Skip to content

Commit

Permalink
Implement UPLOAD a file
Browse files Browse the repository at this point in the history
  • Loading branch information
dunyakirkali committed Jan 1, 2020
1 parent e3e86ac commit e7836b0
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ config :onesky,
**String**
- **File**
- ~~LIST uploaded files~~
- UPLOAD a file
- ~~UPLOAD a file~~
- ~~DELETE a file~~
- **Translation**
- EXPORT translations in files
Expand Down
2 changes: 2 additions & 0 deletions fixture/files/Main.strings
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* Class = "UIButton"; normalTitle = "Get Started"; ObjectID = "qs4-6I-gUp"; */
"qs4-6I-gUp.normalTitle" = "Get Started";
32 changes: 32 additions & 0 deletions fixture/vcr_cassettes/file#upload.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[
{
"request": {
"body": "",
"headers": [],
"method": "post",
"options": [],
"request_body": "",
"url": "https://platform.api.onesky.io/1/projects/314254/files?api_key=.*&timestamp=.*&dev_hash=.*"
},
"response": {
"binary": false,
"body": "{\"meta\":{\"status\":201},\"data\":{\"name\":\"string.po\",\"format\":\"GNU_PO\",\"language\":{\"code\":\"en-US\",\"english_name\":\"English(UnitedStates)\",\"local_name\":\"English(UnitedStates)\",\"locale\":\"en\",\"region\":\"US\"},\"import\":{\"id\":154,\"created_at\":\"2013-10-07T15:27:10+0000\",\"created_at_timestamp\":1381159630}}}",
"headers": {
"Access-Control-Allow-Headers": "Authorization, X-Authorization, Origin, Accept, Content-Type, X-Requested-With, X-HTTP-Method-Override",
"Access-Control-Allow-Methods": "PUT, GET, POST, DELETE, OPTIONS",
"Access-Control-Allow-Origin": "*",
"Cache-Control": "no-store, no-cache, must-revalidate, post-check=0, pre-check=0",
"Content-Type": "application/json",
"Date": "Wed, 21 Nov 2018 21:05:08 GMT",
"Expires": "Thu, 19 Nov 1981 08:52:00 GMT",
"Pragma": "no-cache",
"Server": "Apache",
"Set-Cookie": "PHPSESSID=un76cfch89c2b9kou1717arou3; path=/",
"Content-Length": "83",
"Connection": "keep-alive"
},
"status_code": 201,
"type": "ok"
}
}
]
7 changes: 7 additions & 0 deletions lib/onesky/resources/file.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ defmodule Onesky.File do
Tesla.get(client, "/projects/#{project_id}/files")
end

@doc """
UPLOAD a file
"""
def upload_file(client, project_id, file) do
Tesla.post(client, "/projects/#{project_id}/files", file)
end

@doc """
DELETE a file
"""
Expand Down
23 changes: 23 additions & 0 deletions test/onesky/resources/file_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,29 @@ defmodule FileTest do
end
end

test "upload_file" do
use_cassette "file#upload" do
translation_file = "fixture/files/Main.strings" |> File.read! |> Base.encode64()
file = [
%{
"file" => translation_file,
"file_format" => "IOS_STRINGS",
"locale" => "zh-TW",
"is_keeping_all_strings" => true,
"is_allow_translation_same_as_original" => false
}
]
{:ok, %Tesla.Env{} = env} = Onesky.client() |> Onesky.File.upload_file(314_254, file)

assert env.status == 201

assert env.body["meta"]["status"] == 201

assert env.body["data"]["name"] == "string.po"
assert env.body["data"]["format"] == "GNU_PO"
end
end

test "delete_file" do
use_cassette "file#delete" do
file = %{"file_name" => "gettext_po_sample_file.po"}
Expand Down

0 comments on commit e7836b0

Please sign in to comment.