• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

eiriksm / finn-transfer-sdk / 7222197529

15 Dec 2023 12:44PM UTC coverage: 69.79% (-0.7%) from 70.48%
7222197529

push

github

web-flow
Added ability to use test mode (#15)

0 of 10 new or added lines in 1 file covered. (0.0%)

1 existing line in 1 file now uncovered.

499 of 715 relevant lines covered (69.79%)

2.57 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Client.php
1
<?php
2

3
namespace eiriksm\FinnTransfer;
4

5
use GuzzleHttp\Psr7\MultipartStream;
6
use GuzzleHttp\Psr7\Request;
7
use GuzzleHttp\Psr7\Utils;
8

9
class Client implements ClientInterface
10
{
11

12
  /**
13
   * @return bool
14
   */
15
    public function isZip()
16
    {
17
        return $this->isZip;
×
18
    }
19

20
  /**
21
   * @param bool $isZip
22
   */
23
    public function setIsZip($isZip)
24
    {
25
        $this->isZip = $isZip;
×
26
    }
27

28
    protected $liveMode = false;
29

30
    private $isZip = false;
31

32
  /**
33
   * @return string
34
   */
35
    public function getRequestBody()
36
    {
37
        return $this->requestBody;
×
38
    }
39

40
  /**
41
   * @var string
42
   */
43
    private $requestBody;
44

45
  /**
46
   * @var Request
47
   */
48
    protected $request;
49

50
    public function setLiveMode()
51
    {
NEW
52
        $this->liveMode = true;
×
53
    }
54

55
  /**
56
   * @return bool
57
   */
58
    public function isLiveMode()
59
    {
NEW
60
        return $this->liveMode;
×
61
    }
62

63
  /**
64
   * @var \GuzzleHttp\Client
65
   */
66
    protected $client;
67

68
  /**
69
   * @return \eiriksm\FinnTransfer\Client
70
   */
71
    public function getClient()
72
    {
73
        return $this->client;
×
74
    }
75

76
  /**
77
   * @param mixed $client
78
   */
79
    public function setClient($client)
80
    {
81
        $this->client = $client;
×
82
    }
83

84
  /**
85
   * Send something.
86
   *
87
   * @param string $body
88
   *
89
   * @return mixed|\Psr\Http\Message\ResponseInterface
90
   */
91
    public function transfer($body, $type = 'xml')
92
    {
93
        $post_body = Utils::streamFor($body);
×
94
        $multipart = new MultipartStream([
×
95
        [
×
96
        'name' => 'fil',
×
97
        'contents' => $post_body,
×
98
        'filename' => "file.$type"
×
99
        ]
×
100
        ]);
×
101

NEW
102
        $headers = [];
×
NEW
103
        if ($this->isLiveMode()) {
×
NEW
104
            $url = 'https://www.finn.no/finn/import/fileimport';
×
105
        } else {
106
            // Test mode.
NEW
107
            $url = 'https://import.finn.no/finn/import/fileimport';
×
NEW
108
            $headers = [
×
NEW
109
                'Authorization' => 'Basic '. base64_encode('partner:testimport'),
×
NEW
110
            ];
×
111
        }
112

NEW
113
        $this->request = new Request('POST', $url, $headers, $multipart);
×
114

115
        if (!$this->isZip) {
×
116
            $this->requestBody = $body;
×
117
        }
118
        $res = $this->client->send($this->request);
×
119

UNCOV
120
        return $res;
×
121
    }
122

123
  /**
124
   * @param string $requestBody
125
   */
126
    public function setRequestBody($requestBody)
127
    {
128
        $this->requestBody = $requestBody;
×
129
    }
130

131
  /**
132
   * @return \GuzzleHttp\Psr7\Request
133
   */
134
    public function getRequest()
135
    {
136
        return $this->request;
×
137
    }
138
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc