Completed
Push — master ( b6e3f0...4b6bf0 )
by Nikolai
02:45
created

Glossary::upload()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 3
Bugs 1 Features 2
Metric Value
c 3
b 1
f 2
dl 0
loc 15
ccs 7
cts 7
cp 1
rs 9.4285
cc 2
eloc 8
nc 2
nop 1
crap 2
1
<?php
2
/**
3
 * Crowdin API implementation in PHP.
4
 *
5
 * @copyright  Copyright (C) 2016 Nikolai Plath (elkuku)
6
 * @license    GNU General Public License version 2 or later
7
 */
8
9
namespace ElKuKu\Crowdin\Package;
10
11
use ElKuKu\Crowdin\Package;
12
13
/**
14
 * Class Glossary
15
 *
16
 * @since  1.0.5
17
 */
18
Class Glossary extends Package
19
{
20
	/**
21
	 * Download Crowdin project glossaries as TBX file.
22
	 *
23
	 * @param   boolean  $includeAssigned  Defines whether the assigned glossaries should be included in downloaded TBX file.
24
	 *                                     Acceptable values are: 0, 1.
25
	 *                                     Default is 1.
26
	 *
27
	 * @since 1.0.5
28
	 * @see   https://crowdin.com/page/api/download-glossary
29
	 *
30
	 * @return \Psr\Http\Message\ResponseInterface
31
	 */
32 1
	public function download($includeAssigned = true)
33
	{
34 1
		return $this->getHttpClient()
35 1
			->get($this->getBasePath('download-glossary') . '&include_assigned=' . (int) $includeAssigned);
36
	}
37
38
	/**
39
	 * Upload your Translation Memory for Crowdin Project in TMX file format.
40
	 *
41
	 * @param   string  $file  Full path to file to upload.
42
	 *
43
	 * @since 1.0.5
44
	 * @see   https://crowdin.com/page/api/upload-glossary
45
	 *
46
	 * @return \Psr\Http\Message\ResponseInterface
47
	 */
48 2
	public function upload($file)
49
	{
50 2
		if (false === file_exists($file))
51
		{
52 1
			throw new \UnexpectedValueException('File not found for upload');
53
		}
54
55
		$data = [[
56 1
			'name'     => 'file',
57 1
			'contents' => fopen($file, 'r')
58
		]];
59
60 1
		return $this->getHttpClient()
61 1
			->post($this->getBasePath('upload-glossary'), ['multipart' => $data]);
62
	}
63
}
64