919 } |
920 } |
920 |
921 |
921 def execute(method: String, params: JSON.T = JSON.Object.empty): API.Result = |
922 def execute(method: String, params: JSON.T = JSON.Object.empty): API.Result = |
922 API.make_result(execute_raw(method, params = params)) |
923 API.make_result(execute_raw(method, params = params)) |
923 |
924 |
|
925 def execute_search[A]( |
|
926 method: String, params: JSON.Object.T, unapply: JSON.T => Option[A]): List[A] = |
|
927 { |
|
928 val results = new mutable.ListBuffer[A] |
|
929 var after = "" |
|
930 |
|
931 do { |
|
932 val result = |
|
933 execute(method, params = params ++ JSON.optional("after" -> proper_string(after))) |
|
934 results ++= result.get_value(JSON.list(_, "data", unapply)) |
|
935 after = result.get_value(JSON.value(_, "cursor", JSON.string0(_, "after"))) |
|
936 } while (after.nonEmpty) |
|
937 |
|
938 results.toList |
|
939 } |
|
940 |
924 |
941 |
925 /* concrete methods */ |
942 /* concrete methods */ |
926 |
943 |
927 def ping(): String = execute("conduit.ping").get_string |
944 def ping(): String = execute("conduit.ping").get_string |
928 |
945 |
936 (for { |
953 (for { |
937 (key, value) <- List("phids" -> phid, "callsigns" -> callsign, "shortNames" -> short_name) |
954 (key, value) <- List("phids" -> phid, "callsigns" -> callsign, "shortNames" -> short_name) |
938 if value.nonEmpty |
955 if value.nonEmpty |
939 } yield (key, List(value))).toMap |
956 } yield (key, List(value))).toMap |
940 |
957 |
941 execute("diffusion.repository.search", |
958 execute_search("diffusion.repository.search", |
942 JSON.Object("queryKey" -> "active", "constraints" -> constraints)) |
959 JSON.Object("queryKey" -> "active", "constraints" -> constraints), |
943 .get_value(JSON.list(_, "data", data => JSON.value(data, "fields", fields => |
960 data => JSON.value(data, "fields", fields => |
944 for { |
961 for { |
945 vcs_name <- JSON.string(fields, "vcs") |
962 vcs_name <- JSON.string(fields, "vcs") |
946 id <- JSON.long(data, "id") |
963 id <- JSON.long(data, "id") |
947 phid <- JSON.string(data, "phid") |
964 phid <- JSON.string(data, "phid") |
948 name <- JSON.string(fields, "name") |
965 name <- JSON.string(fields, "name") |
949 callsign <- JSON.string0(fields, "callsign") |
966 callsign <- JSON.string0(fields, "callsign") |
950 short_name <- JSON.string0(fields, "shortName") |
967 short_name <- JSON.string0(fields, "shortName") |
951 importing <- JSON.bool(fields, "isImporting") |
968 importing <- JSON.bool(fields, "isImporting") |
952 } |
|
953 yield { |
|
954 val vcs = API.VCS.read(vcs_name) |
|
955 val url_path = if (short_name.isEmpty) "/diffusion/" + id else "/source/" + short_name |
|
956 val ssh_url = |
|
957 vcs match { |
|
958 case API.VCS.hg => hg_url + url_path |
|
959 case API.VCS.git => hg_url + url_path + ".git" |
|
960 case API.VCS.svn => "" |
|
961 } |
969 } |
962 API.Repository(vcs, id, phid, name, callsign, short_name, importing, ssh_url) |
970 yield { |
963 }))) |
971 val vcs = API.VCS.read(vcs_name) |
|
972 val url_path = |
|
973 if (short_name.isEmpty) "/diffusion/" + id else "/source/" + short_name |
|
974 val ssh_url = |
|
975 vcs match { |
|
976 case API.VCS.hg => hg_url + url_path |
|
977 case API.VCS.git => hg_url + url_path + ".git" |
|
978 case API.VCS.svn => "" |
|
979 } |
|
980 API.Repository(vcs, id, phid, name, callsign, short_name, importing, ssh_url) |
|
981 })) |
964 } |
982 } |
965 |
983 |
966 def the_repository(phid: String): API.Repository = |
984 def the_repository(phid: String): API.Repository = |
967 get_repositories(phid = phid) match { |
985 get_repositories(phid = phid) match { |
968 case List(repo) => repo |
986 case List(repo) => repo |