line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Iugu::MarketPlace; |
2
|
|
|
|
|
|
|
$Net::Iugu::MarketPlace::VERSION = '0.000002'; |
3
|
8
|
|
|
8
|
|
35
|
use Moo; |
|
8
|
|
|
|
|
9
|
|
|
8
|
|
|
|
|
35
|
|
4
|
|
|
|
|
|
|
extends 'Net::Iugu::Request'; |
5
|
|
|
|
|
|
|
|
6
|
8
|
|
|
8
|
|
1864
|
use HTTP::Headers; |
|
8
|
|
|
|
|
13
|
|
|
8
|
|
|
|
|
173
|
|
7
|
8
|
|
|
8
|
|
34
|
use HTTP::Request; |
|
8
|
|
|
|
|
21
|
|
|
8
|
|
|
|
|
181
|
|
8
|
8
|
|
|
8
|
|
8973
|
use File::LibMagic; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use JSON qw{ from_json to_json }; |
11
|
|
|
|
|
|
|
use File::Slurp qw{ read_file }; |
12
|
|
|
|
|
|
|
use MIME::Base64 qw{ encode_base64 }; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub create_account { |
15
|
|
|
|
|
|
|
my ( $self, $data ) = @_; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $uri = $self->base_uri . '/marketplace/create_account'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
return $self->request( POST => $uri, $data ); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub request_account_verification { |
23
|
|
|
|
|
|
|
my ( $self, $user_token, $account_id, $data ) = @_; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my @parts = ( |
26
|
|
|
|
|
|
|
$self->base_uri, ## |
27
|
|
|
|
|
|
|
'accounts', ## |
28
|
|
|
|
|
|
|
$account_id, ## |
29
|
|
|
|
|
|
|
'request_verification', ## |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my $uri = join '/', @parts; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
if ( exists $data->{files} ) { |
35
|
|
|
|
|
|
|
foreach my $key ( keys %{ $data->{files} } ) { |
36
|
|
|
|
|
|
|
my $path = $data->{files}{$key}; |
37
|
|
|
|
|
|
|
my $bytes = read_file( $path, { binmode => ':raw' } ); |
38
|
|
|
|
|
|
|
my $encoded = encode_base64( $bytes, '' ); |
39
|
|
|
|
|
|
|
my $info = File::LibMagic->new->info_from_filename($path); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my $mime = |
42
|
|
|
|
|
|
|
$info->{mime_type} =~ m#(image/.+?;)# |
43
|
|
|
|
|
|
|
? $1 |
44
|
|
|
|
|
|
|
: 'image/jpeg;'; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
$data->{files}{$key} = 'data:' . $mime . 'base64,' . $encoded; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
my $auth = 'Basic ' . encode_base64( $user_token . ':', '' ); |
51
|
|
|
|
|
|
|
my $headers = HTTP::Headers->new( |
52
|
|
|
|
|
|
|
'Authorization' => $auth, |
53
|
|
|
|
|
|
|
'Content-Type' => 'application/json', |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
my $content = to_json $data; |
57
|
|
|
|
|
|
|
my $req = HTTP::Request->new( |
58
|
|
|
|
|
|
|
POST => $uri, |
59
|
|
|
|
|
|
|
$headers, |
60
|
|
|
|
|
|
|
$content, |
61
|
|
|
|
|
|
|
); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
my $res = $self->ua->request($req); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
return from_json $res->content; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub account_info { |
69
|
|
|
|
|
|
|
my ( $self, $account_id ) = @_; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
my $uri = $self->base_uri . '/accounts/' . $account_id; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
return $self->request( GET => $uri ); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub configurate_account { |
77
|
|
|
|
|
|
|
my ( $self, $user_token, $data ) = @_; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
my $uri = $self->base_uri . '/accounts/configuration'; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
my $auth = 'Basic ' . encode_base64( $user_token . ':', '' ); |
82
|
|
|
|
|
|
|
my $headers = HTTP::Headers->new( |
83
|
|
|
|
|
|
|
'Authorization' => $auth, |
84
|
|
|
|
|
|
|
'Content-Type' => 'application/json', |
85
|
|
|
|
|
|
|
); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
my $content = to_json $data; |
88
|
|
|
|
|
|
|
my $req = HTTP::Request->new( |
89
|
|
|
|
|
|
|
POST => $uri, |
90
|
|
|
|
|
|
|
$headers, |
91
|
|
|
|
|
|
|
$content, |
92
|
|
|
|
|
|
|
); |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
my $res = $self->ua->request($req); |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
return from_json $res->content; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub request_withdraw { |
100
|
|
|
|
|
|
|
my ( $self, $account_id, $amount ) = @_; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
my @parts = ( |
103
|
|
|
|
|
|
|
$self->base_uri, ## |
104
|
|
|
|
|
|
|
'accounts', ## |
105
|
|
|
|
|
|
|
$account_id, ## |
106
|
|
|
|
|
|
|
'request_withdraw', ## |
107
|
|
|
|
|
|
|
); |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
my $uri = join '/', @parts; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
return $self->request( POST => $uri, { amount => $amount } ); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
1; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
# ABSTRACT: Net::Iugu::MarketPlace - Methods to manage marketplaces |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
__END__ |