Skip to content

Commit 967bab9

Browse files
committed
Switch to /apmg/ namespace
1 parent 6ab79b6 commit 967bab9

12 files changed

+116
-60
lines changed

.abapgit.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<MIN_RELEASE>750</MIN_RELEASE>
1313
</item>
1414
</REQUIREMENTS>
15-
<VERSION_CONSTANT>ZIF_HTTP_AGENT=&gt;C_VERSION</VERSION_CONSTANT>
15+
<VERSION_CONSTANT>/APMG/IF_HTTP_AGENT=&gt;C_VERSION</VERSION_CONSTANT>
1616
</DATA>
1717
</asx:values>
1818
</asx:abap>

src/#apmg#.nspc.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<abapGit version="v1.0.0" serializer="LCL_OBJECT_NSPC" serializer_version="v1.0.0">
3+
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
4+
<asx:values>
5+
<NSPC>
6+
<NAMESPACE>/APMG/</NAMESPACE>
7+
<REPLICENSE>41813564412598342476</REPLICENSE>
8+
</NSPC>
9+
<NSPC_TEXT>
10+
<SPRAS>E</SPRAS>
11+
<DESCRIPTN>apm</DESCRIPTN>
12+
<OWNER>apm.to Inc.</OWNER>
13+
</NSPC_TEXT>
14+
</asx:values>
15+
</asx:abap>
16+
</abapGit>

src/zcl_http_agent.clas.abap renamed to src/#apmg#cl_http_agent.clas.abap

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CLASS zcl_http_agent DEFINITION
1+
CLASS /apmg/cl_http_agent DEFINITION
22
PUBLIC
33
FINAL
44
CREATE PRIVATE.
@@ -11,11 +11,11 @@ CLASS zcl_http_agent DEFINITION
1111
************************************************************************
1212
PUBLIC SECTION.
1313

14-
INTERFACES zif_http_agent.
14+
INTERFACES /apmg/if_http_agent.
1515

1616
CLASS-METHODS create
1717
RETURNING
18-
VALUE(result) TYPE REF TO zif_http_agent.
18+
VALUE(result) TYPE REF TO /apmg/if_http_agent.
1919

2020
METHODS constructor.
2121

@@ -29,13 +29,13 @@ CLASS zcl_http_agent DEFINITION
2929
request TYPE REF TO if_http_request
3030
payload TYPE any
3131
RAISING
32-
zcx_error.
32+
/apmg/cx_error.
3333

3434
ENDCLASS.
3535

3636

3737

38-
CLASS zcl_http_agent IMPLEMENTATION.
38+
CLASS /apmg/cl_http_agent IMPLEMENTATION.
3939

4040

4141
METHOD attach_payload.
@@ -50,7 +50,7 @@ CLASS zcl_http_agent IMPLEMENTATION.
5050
WHEN cl_abap_typedescr=>typekind_char.
5151
request->set_cdata( |{ payload }| ).
5252
WHEN OTHERS.
53-
RAISE EXCEPTION TYPE zcx_error_text
53+
RAISE EXCEPTION TYPE /apmg/cx_error_text
5454
EXPORTING
5555
text = |Unexpected payload type { payload_type->absolute_name }|.
5656
ENDCASE.
@@ -67,19 +67,19 @@ CLASS zcl_http_agent IMPLEMENTATION.
6767

6868
METHOD create.
6969

70-
result = NEW zcl_http_agent( ).
70+
result = NEW /apmg/cl_http_agent( ).
7171

7272
ENDMETHOD.
7373

7474

75-
METHOD zif_http_agent~global_headers.
75+
METHOD /apmg/if_http_agent~global_headers.
7676

7777
result = global_headers.
7878

7979
ENDMETHOD.
8080

8181

82-
METHOD zif_http_agent~request.
82+
METHOD /apmg/if_http_agent~request.
8383

8484
DATA:
8585
http_client TYPE REF TO if_http_client,
@@ -119,9 +119,9 @@ CLASS zcl_http_agent IMPLEMENTATION.
119119
ENDLOOP.
120120
ENDIF.
121121

122-
IF method = zif_http_agent=>c_method-post
123-
OR method = zif_http_agent=>c_method-put
124-
OR method = zif_http_agent=>c_method-patch.
122+
IF method = /apmg/if_http_agent=>c_method-post
123+
OR method = /apmg/if_http_agent=>c_method-put
124+
OR method = /apmg/if_http_agent=>c_method-patch.
125125
attach_payload(
126126
request = http_client->request
127127
payload = payload ).
@@ -149,7 +149,7 @@ CLASS zcl_http_agent IMPLEMENTATION.
149149
code = status_code
150150
message = message ).
151151

152-
RAISE EXCEPTION TYPE zcx_error_text
152+
RAISE EXCEPTION TYPE /apmg/cx_error_text
153153
EXPORTING
154154
text = |HTTP error: [{ status_code }] { message }|.
155155
ENDIF.

src/zcl_http_agent.clas.locals_imp.abap renamed to src/#apmg#cl_http_agent.clas.locals_imp.abap

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ CLASS lcl_http_response DEFINITION FINAL.
22

33
PUBLIC SECTION.
44

5-
INTERFACES zif_http_response.
5+
INTERFACES /apmg/if_http_response.
66

77
CLASS-METHODS create
88
IMPORTING
99
http_client TYPE REF TO if_http_client
1010
RETURNING
11-
VALUE(result) TYPE REF TO zif_http_response.
11+
VALUE(result) TYPE REF TO /apmg/if_http_response.
1212

1313
PRIVATE SECTION.
1414

@@ -29,32 +29,32 @@ CLASS lcl_http_response IMPLEMENTATION.
2929

3030
ENDMETHOD.
3131

32-
METHOD zif_http_response~close.
32+
METHOD /apmg/if_http_response~close.
3333

3434
http_client->close( ).
3535

3636
ENDMETHOD.
3737

38-
METHOD zif_http_response~is_ok.
38+
METHOD /apmg/if_http_response~is_ok.
3939

40-
DATA(status_code) = zif_http_response~code( ).
40+
DATA(status_code) = /apmg/if_http_response~code( ).
4141
result = xsdbool( status_code >= 200 AND status_code < 300 ).
4242

4343
ENDMETHOD.
4444

45-
METHOD zif_http_response~data.
45+
METHOD /apmg/if_http_response~data.
4646

4747
result = http_response->get_data( ).
4848

4949
ENDMETHOD.
5050

51-
METHOD zif_http_response~cdata.
51+
METHOD /apmg/if_http_response~cdata.
5252

5353
result = http_response->get_cdata( ).
5454

5555
ENDMETHOD.
5656

57-
METHOD zif_http_response~code.
57+
METHOD /apmg/if_http_response~code.
5858

5959
DATA msg TYPE string ##NEEDED.
6060

@@ -65,23 +65,23 @@ CLASS lcl_http_response IMPLEMENTATION.
6565

6666
ENDMETHOD.
6767

68-
METHOD zif_http_response~json.
68+
METHOD /apmg/if_http_response~json.
6969

7070
TRY.
71-
result = zcl_ajson=>parse( zif_http_response~cdata( ) ).
71+
result = zcl_ajson=>parse( /apmg/if_http_response~cdata( ) ).
7272
CATCH zcx_ajson_error INTO DATA(error).
73-
RAISE EXCEPTION TYPE zcx_error_prev EXPORTING previous = error.
73+
RAISE EXCEPTION TYPE /apmg/cx_error_prev EXPORTING previous = error.
7474
ENDTRY.
7575

7676
ENDMETHOD.
7777

78-
METHOD zif_http_response~error.
78+
METHOD /apmg/if_http_response~error.
7979

8080
result = http_response->get_cdata( ).
8181

8282
ENDMETHOD.
8383

84-
METHOD zif_http_response~headers.
84+
METHOD /apmg/if_http_response~headers.
8585

8686
DATA headers TYPE tihttpnvp.
8787

src/zcl_http_agent.clas.xml renamed to src/#apmg#cl_http_agent.clas.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
44
<asx:values>
55
<VSEOCLASS>
6-
<CLSNAME>ZCL_HTTP_AGENT</CLSNAME>
6+
<CLSNAME>/APMG/CL_HTTP_AGENT</CLSNAME>
77
<LANGU>E</LANGU>
88
<DESCRIPT>HTTP Agent</DESCRIPT>
99
<STATE>1</STATE>

src/zcl_http_login_manager.clas.abap renamed to src/#apmg#cl_http_login_manager.clas.abap

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CLASS zcl_http_login_manager DEFINITION
1+
CLASS /apmg/cl_http_login_manager DEFINITION
22
PUBLIC
33
FINAL
44
CREATE PUBLIC.
@@ -44,6 +44,12 @@ CLASS zcl_http_login_manager DEFINITION
4444

4545
CLASS-DATA auths TYPE TABLE OF ty_auth WITH DEFAULT KEY.
4646

47+
CLASS-METHODS get_host
48+
IMPORTING
49+
!host TYPE string
50+
RETURNING
51+
VALUE(result) TYPE string.
52+
4753
CLASS-METHODS append
4854
IMPORTING
4955
!host TYPE string
@@ -53,14 +59,16 @@ ENDCLASS.
5359

5460

5561

56-
CLASS zcl_http_login_manager IMPLEMENTATION.
62+
CLASS /apmg/cl_http_login_manager IMPLEMENTATION.
5763

5864

5965
METHOD append.
6066

61-
IF NOT line_exists( auths[ host = host ] ).
67+
DATA(hostname) = get_host( host ).
68+
69+
IF NOT line_exists( auths[ host = hostname ] ).
6270
APPEND INITIAL LINE TO auths ASSIGNING FIELD-SYMBOL(<auth>).
63-
<auth>-host = host.
71+
<auth>-host = hostname.
6472
<auth>-auth = auth.
6573
ENDIF.
6674

@@ -76,14 +84,31 @@ CLASS zcl_http_login_manager IMPLEMENTATION.
7684

7785
METHOD get.
7886

79-
READ TABLE auths INTO DATA(auth) WITH KEY host = host.
87+
READ TABLE auths INTO DATA(auth) WITH KEY host = get_host( host ).
8088
IF sy-subrc = 0.
8189
result = auth-auth.
8290
ENDIF.
8391

8492
ENDMETHOD.
8593

8694

95+
METHOD get_host.
96+
97+
" If it's a URL, use host:port, otherwise just take the input
98+
TRY.
99+
DATA(url) = /apmg/cl_url=>parse( host ).
100+
101+
result = url->components-host.
102+
IF url->components-port IS NOT INITIAL.
103+
result = |{ result }:{ url->components-port }|.
104+
ENDIF.
105+
CATCH /apmg/cx_error.
106+
result = host.
107+
ENDTRY.
108+
109+
ENDMETHOD.
110+
111+
87112
METHOD save.
88113

89114
IF auth IS NOT INITIAL.
@@ -102,12 +127,10 @@ CLASS zcl_http_login_manager IMPLEMENTATION.
102127
RETURN.
103128
ENDIF.
104129

105-
result = cl_http_utility=>encode_base64( |{ username }:{ password }| ).
106-
107130
IF is_basic = abap_true.
108-
result = |Basic { result }|.
131+
result = |Basic { cl_http_utility=>encode_base64( |{ username }:{ password }| ) }|.
109132
ELSE.
110-
result = |Bearer { result }|.
133+
result = |Bearer { password }|.
111134
ENDIF.
112135

113136
append( host = host

src/zcl_http_login_manager.clas.testclasses.abap renamed to src/#apmg#cl_http_login_manager.clas.testclasses.abap

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,67 +3,84 @@ CLASS ltcl_login_manager DEFINITION FOR TESTING RISK LEVEL HARMLESS DURATION SHO
33
PRIVATE SECTION.
44
CONSTANTS:
55
c_username TYPE string VALUE 'Aladdin',
6-
c_password TYPE string VALUE 'OpenSesame'.
6+
c_password TYPE string VALUE 'OpenSesame',
7+
c_token TYPE string VALUE 'TestToken'.
78

89
METHODS:
910
setup,
1011
teardown,
11-
encoding FOR TESTING,
12-
save FOR TESTING,
13-
same_server FOR TESTING.
12+
basic_auth FOR TESTING RAISING /apmg/cx_error,
13+
bearer_auth FOR TESTING RAISING /apmg/cx_error,
14+
save FOR TESTING RAISING /apmg/cx_error,
15+
same_server FOR TESTING RAISING /apmg/cx_error.
1416

1517
ENDCLASS.
1618

1719
CLASS ltcl_login_manager IMPLEMENTATION.
1820

1921
METHOD setup.
20-
zcl_http_login_manager=>clear( ).
22+
/apmg/cl_http_login_manager=>clear( ).
2123
ENDMETHOD.
2224

2325
METHOD teardown.
24-
zcl_http_login_manager=>clear( ).
26+
/apmg/cl_http_login_manager=>clear( ).
2527
ENDMETHOD.
2628

2729
METHOD save.
2830

2931
CONSTANTS c_host TYPE string VALUE 'https://abapgit.org/foo/bar'.
3032
CONSTANTS c_auth TYPE string VALUE 'foobar'.
3133

32-
zcl_http_login_manager=>save(
34+
/apmg/cl_http_login_manager=>save(
3335
host = c_host
3436
auth = c_auth ).
3537

3638
cl_abap_unit_assert=>assert_equals(
37-
act = zcl_http_login_manager=>get( c_host )
39+
act = /apmg/cl_http_login_manager=>get( c_host )
3840
exp = c_auth ).
3941

4042
ENDMETHOD.
4143

42-
METHOD encoding.
44+
METHOD basic_auth.
4345

44-
DATA(auth) = zcl_http_login_manager=>set(
46+
DATA(auth) = /apmg/cl_http_login_manager=>set(
4547
host = 'https://github.com/abapGit/abapGit.git'
4648
username = c_username
47-
password = c_password ).
49+
password = c_password
50+
is_basic = abap_true ).
4851

4952
cl_abap_unit_assert=>assert_equals(
5053
act = auth
5154
exp = 'Basic QWxhZGRpbjpPcGVuU2VzYW1l' ).
5255

5356
ENDMETHOD.
5457

58+
METHOD bearer_auth.
59+
60+
DATA(auth) = /apmg/cl_http_login_manager=>set(
61+
host = 'https://github.com/abapGit/abapGit.git'
62+
username = c_username
63+
password = c_token
64+
is_basic = abap_false ).
65+
66+
cl_abap_unit_assert=>assert_equals(
67+
act = auth
68+
exp = |Bearer { c_token }| ).
69+
70+
ENDMETHOD.
71+
5572
METHOD same_server.
5673

5774
CONSTANTS: c_github1 TYPE string VALUE 'https://github.com/abapGit/abapGit.git',
5875
c_github2 TYPE string VALUE 'https://github.com/larshp/Foobar.git'.
5976

60-
zcl_http_login_manager=>set(
77+
/apmg/cl_http_login_manager=>set(
6178
host = c_github1
6279
username = c_username
6380
password = c_password ).
6481

65-
DATA(auth1) = zcl_http_login_manager=>get( c_github1 ).
66-
DATA(auth2) = zcl_http_login_manager=>get( c_github2 ).
82+
DATA(auth1) = /apmg/cl_http_login_manager=>get( c_github1 ).
83+
DATA(auth2) = /apmg/cl_http_login_manager=>get( c_github2 ).
6784

6885
cl_abap_unit_assert=>assert_equals(
6986
act = auth1

0 commit comments

Comments
 (0)