redmine api
https://www.redmine.org/projects/redmine/wiki/Rest_api
demo
报表代码太多发不出来,下面是封装的redmine代码
class zcl_redmine definition
public
final
create public .
public section.
types:begin of ty_tracker,
* id(10),
name(20),
end of ty_tracker.
types:begin of ty_status,
name(20),
end of ty_status.
types:begin of ty_project,
* id(10),
name(20),
end of ty_project.
types:
begin of ty_user,
name(20),
end of ty_user,
begin of ty_priority,
name(20),
end of ty_priority,
begin of ty_author,
name(20),
end of ty_author,
begin of ty_assigned_to,
name(20),
end of ty_assigned_to,
begin of ty_details,
property(20),
name(20),
old_value(200),
new_value(200),
end of ty_details,
begin of ty_custom_fields,
name(10),
value(255),
end of ty_custom_fields,
begin of ty_journals,
user type ty_user,
notes(50),
created_on(20),
details type table of ty_details with non-unique default key,
end of ty_journals,
ty_t_jounrnals type table of ty_journals with non-unique default key,
begin of ty_issue,
id(10),
project type ty_project,
subject(100),
tracker type ty_tracker,
status type ty_status,
priority type ty_priority,
author type ty_author,
assigned_to type ty_assigned_to,
description(200),
start_date(20),
due_date(20),
estimated_hours type i,
custom_fields type table of ty_custom_fields with non-unique default key,
created_on(20),
updated_on(20),
closed_on(20),
end of ty_issue,
begin of ty_parameters,
attr(30),
value type string,
end of ty_parameters,
begin of ty_issuse_json,
issue type ty_issue,
issues type table of ty_issue with non-unique default key,
total_count type i, "多行时才有
offset type i, "多行时才有
limit type i, "多行时才有
end of ty_issuse_json.
data s_issuse_json type ty_issuse_json.
methods:
constructor,
issues_fetch,
parameters_convertion
importing
es_parameters type ty_parameters.
protected section.
private section.
data v_url(200).
data v_parameter type string.
endclass.
class zcl_redmine implementation.
method constructor.
v_url = 'ip/redmine/issues.json?key=key在用户页面能啊看到&project_id=8&status_id=*'.
endmethod.
method issues_fetch.
data: lv_url type string,
lo_http_client type ref to if_http_client,
lv_response type string,
lv_offset type i,
lv_limit type i value 100,
ls_issuse_json type ty_issuse_json.
do .
clear ls_issuse_json.
lv_url = v_url && '&offset=' && lv_offset && '&limit=' && lv_limit.
lv_url = lv_url && v_parameter.
*创建http客户端
call method cl_http_client=>create_by_url
exporting
url = lv_url
importing
client = lo_http_client
exceptions
argument_not_found = 1
plugin_not_active = 2
internal_error = 3
others = 4.
*设置http method 为Get
lo_http_client->request->set_method( if_http_request=>co_request_method_get ).
* 发送
call method lo_http_client->send
exceptions
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3
http_invalid_timeout = 4
others = 5.
* 接收
call method lo_http_client->receive
exceptions
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3.
* 获取接口返回的数据
lv_response = lo_http_client->response->get_cdata( ).
condense lv_response no-gaps.
call method /ui2/cl_json=>deserialize
exporting
json = lv_response
changing
data = ls_issuse_json.
if ls_issuse_json-issue is not initial.
append ls_issuse_json-issue to s_issuse_json-issues.
else.
append lines of ls_issuse_json-issues to s_issuse_json-issues.
endif.
if lv_offset + lv_limit >= ls_issuse_json-total_count.
exit.
else.
lv_offset = lv_offset + 100.
endif.
enddo.
endmethod.
method parameters_convertion.
data: lv_escaped type string.
call method cl_http_utility=>escape_url
exporting
unescaped = es_parameters-value
receiving
escaped = lv_escaped.
case es_parameters-attr.
when 'cf_32'.
v_parameter = '&cf_32=' && lv_escaped.
endcase.
endmethod.
endclass.