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

Glossary::download()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
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