Skip to content

Commit

Permalink
Add project#create
Browse files Browse the repository at this point in the history
  • Loading branch information
dunyakirkali committed Nov 22, 2018
1 parent f46c152 commit a0e9d30
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
34 changes: 34 additions & 0 deletions fixture/vcr_cassettes/project#create.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[
{
"request": {
"body": "{\"description\":\"The best company\",\"name\":\"Ahtung\",\"project_type\":\"website\"}",
"headers": {
"content-type": "application/json"
},
"method": "post",
"options": [],
"request_body": "",
"url": "https://platform.api.onesky.io/1/project-groups/142066/projects?api_key=ZE92t9FPVxtoP463kN2B3MYD66eNKu7A&timestamp=1542893082&dev_hash=38ef37b5413a653de0aa39e13529ab4d"
},
"response": {
"binary": false,
"body": "\n{\n \"meta\": {\"status\":201},\n \"data\": {\"id\":322910,\"project_type\":{\"code\":\"website\",\"name\":\"Regular Website\"},\"name\":\"Ahtung\",\"description\":\"The best company\"}}",
"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": "Thu, 22 Nov 2018 13:24:43 GMT",
"Expires": "Thu, 19 Nov 1981 08:52:00 GMT",
"Pragma": "no-cache",
"Server": "Apache",
"Set-Cookie": "PHPSESSID=mt35o8q7hgqf2ld7pmjduo30q7; path=/",
"Content-Length": "165",
"Connection": "keep-alive"
},
"status_code": 201,
"type": "ok"
}
}
]
7 changes: 7 additions & 0 deletions lib/onesky/resources/project.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,11 @@ defmodule Onesky.Project do
def show_project_details(client, project_id) do
Tesla.get(client, "/projects/#{project_id}")
end

@doc """
CREATE a new project
"""
def create_project(client, project_group_id, project) do
Tesla.post(client, "/project-groups/#{project_group_id}/projects", project)
end
end
15 changes: 15 additions & 0 deletions test/onesky/resources/project_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,19 @@ defmodule ProjectTest do
assert env.body["data"]["word_count"] == 2478
end
end

test "create_project" do
use_cassette "project#create" do
project = %{"project_type" => "website", "name" => "Ahtung", "description" => "The best company"}
{:ok, %Tesla.Env{} = env} = Onesky.client() |> Onesky.Project.create_project(142066, project)

assert env.status == 201

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

assert env.body["data"]["id"] == 322910
assert env.body["data"]["name"] == "Ahtung"
assert env.body["data"]["description"] == "The best company"
end
end
end

0 comments on commit a0e9d30

Please sign in to comment.