10 Commits 0ecbf00fd9 ... 568aa860c2

Autor SHA1 Mensaje Fecha
  Endes 568aa860c2 Update haxelib and README hace 6 años
  Endes 111c98539f Implemented Room menberships, profiles and some events hace 6 años
  Endes 70f5c6b656 Implemented getting/setting event to a room, creating it, adding alias and fixes. hace 6 años
  Endes 7f0b457666 Implementacion Filtros, Paginacion y sincronazacion de eventos hace 6 años
  Endes 78c25e6a1a Implemeted account, made some fixes and some improvments hace 6 años
  Endes 5f27c9cc65 Implamented server administration hace 7 años
  Endes ce59fcb63e Implemented UIA, session management and maked tests hace 7 años
  Endes c59b338521 Change http library, created test Unit, create class connection hace 7 años
  Endes 9b684f4bbd Implemented enums hace 7 años
  Endes 0053a32e8f Setup lib hace 7 años

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+bin/

+ 37 - 1
README.md

@@ -1,3 +1,39 @@
 # haxe-matrix-im
 
-Implementation of client-server matrix API in haxe using HaxeHttpClient.
+Implementation of client-server matrix API in haxe using akifox-asynchttp. Because of it, tecnically only works on **CPP/NEKO/JAVA/FLASH** and not in **JAVASCRIPT**
+because **JAVASCRIPT** only support *POST and Get* Methods. But, is only tested on neko Platform, if you test in other, let me know.
+
+## Usage
+Importing:
+```haxe
+import beartek.matrix_im.client.Conection;
+```
+
+Login in:
+```haxe
+var con = new Conection(server);
+con.on_error = function( e : Dynamic ) : Void {
+  throw 'Error: ' + e;
+}
+
+con.session.login_with_pass(user, password, device_name, function( respose : Dynamic ) : Void {
+  trace(respose.access_token); //The access_token will be actumaticaly stored for duture request until you logout.
+});
+```
+
+Log out:
+```haxe
+con.session.logout(function() : Void {
+  //Logued out
+});
+```
+
+For more examples see the `Test_client` class in *test/beartek/matrix_im/client* and for more info see [Matrix Client-Server API docs](https://matrix.org/docs/spec/client_server/r0.3.0.html) (This library does not implement the API equal than described in the matrix docs).
+
+## TODO
+- Implement [modules](https://matrix.org/docs/spec/client_server/r0.3.0.html#modules).
+- Add documetation to the class, types and functions.
+- Make better README.
+
+---
+by [NetaLabTek](https://netalab.tk/)

+ 11 - 0
build-test.hxml

@@ -0,0 +1,11 @@
+-cp src/
+-cp test/
+
+-main beartek.matrix_im.client.Test_unit
+
+-lib akifox-asynchttp
+-lib mohxa
+
+#-debug
+
+-neko bin/test.n

+ 14 - 0
haxelib.json

@@ -0,0 +1,14 @@
+{
+    "name": "matrix-im",
+    "url" : "https://notabug.org/Tamaimo/haxe-matrix-im",
+    "tags": ["matrix", "chat", "im", "client-server", "API"],
+    "license": "GPL",
+    "releasenote": "Alpha release",
+    "description": "Implementation of client-server matrix API in haxe using HaxeHttpClient.",
+    "version": "0.1.0",
+    "classPath": "src/",
+    "contributors": ["endes"],
+    "dependencies": {
+      "akifox-asynchttp" : "0.4.7"
+    }
+}

+ 22 - 0
src/beartek/matrix_im/client/Check_reply.hx

@@ -0,0 +1,22 @@
+//Under GNU AGPL v3, see LICENCE
+package beartek.matrix_im.client;
+
+
+class Check_reply {
+  static public function is_error( t : Dynamic ) : Bool {
+    if( Reflect.field(t, 'errcode') == null ) {
+      return false;
+    } else {
+      return true;
+    }
+  }
+
+  static public function is_UIA( t : Dynamic ) : Bool {
+    if( Reflect.field(t, 'flows') == null ) {
+      return false;
+    } else {
+      return true;
+    }
+  }
+
+}

+ 121 - 0
src/beartek/matrix_im/client/Conection.hx

@@ -0,0 +1,121 @@
+//Under GNU AGPL v3, see LICENCE
+package beartek.matrix_im.client;
+
+import com.akifox.asynchttp.*;
+import beartek.matrix_im.client.handlers.*;
+import beartek.matrix_im.client.Check_reply;
+import beartek.matrix_im.client.types.replys.Error;
+
+
+class Conection {
+  public var server : Server_adm;
+  public var session : Session;
+  public var account : Account;
+  public var filters : Filters;
+  public var sync : Sync;
+  public var rooms : Rooms;
+  public var profile : Profile;
+
+  public var server_url(default, null) : String;
+  var responses_handlers : Map<Int,Array<Int -> Dynamic -> Bool>> = new Map();
+
+  public function new( server_url : String ) {
+    this.server_url = server_url;
+
+    this.session = new Session(this.on_responses, this.send_request, server_url);
+
+    this.server = new Server_adm(this.on_responses, this.send_request, server_url);
+    this.server.get_versions();
+
+    this.account = new Account(this.on_responses, this.send_request, server_url);
+
+    this.filters = new Filters(this.on_responses, this.send_request, server_url);
+
+    this.sync = new Sync(this.on_responses, this.send_request, server_url);
+
+    this.rooms = new Rooms(this.on_responses, this.send_request, server_url);
+
+    this.profile = new Profile(this.on_responses, this.send_request, server_url);
+  }
+
+  public static function to_object_map<T>( o : Dynamic ) : Map<String,T> {
+    var result : Map<String,T> = new Map();
+    for( field in Reflect.fields(o) ) {
+      result.set(field,Reflect.field(o, field));
+    }
+    return result;
+  }
+
+  public static function make_request( method : String, url : String, data : Dynamic ) : HttpRequest {
+    var request = new HttpRequest({
+      url: url,
+      method: method,
+      contentType: if(data != null) "application/json" else null,
+      content: if(data != null) haxe.Json.stringify(data) else null
+    });
+    return request;
+  }
+
+  private function send_request( request : HttpRequest, on_response : Int -> Dynamic -> Void, ignore_errors : Bool = false ) : Void {
+    if( this.session.access_token != null ) {
+    if( request.url.querystring == '' ) {
+      request.url = new URL(request.url.toString() + '?access_token=' + this.session.access_token);
+    } else {
+      request.url = new URL(request.url.toString() + '&access_token=' + this.session.access_token);
+    }
+    }
+    #if debug
+    trace( 'sending request: ' + request.content );
+    #end
+    request.callback = function( response : HttpResponse ) : Void {
+      #if debug
+      trace( 'callback called' );
+      #end
+      if( this.on_responses(response.status, response.toJson(), ignore_errors) ) {
+        on_response(response.status, response.toJson());
+      }
+    };
+    request.async = false;
+    request.send();
+  }
+
+  private function on_responses( status_code : Int, response : Dynamic, ignore_errors : Bool = false ) : Bool {
+    #if debug
+    trace( 'recived reply: ' + status_code + ', ' + response );
+    #end
+    switch status_code {
+    case 400 | 403 | 429 | 404:
+      if( Check_reply.is_error(response) ) {
+        this.on_error(response);
+      }
+
+      if(ignore_errors) return true else return false;
+    case 401 | 200 | 302 :
+      var is_all_true : Bool = true;
+      if( responses_handlers[status_code] != null ) {
+        for( func in responses_handlers[status_code] ) {
+          if( func(status_code, response) == false ) {
+            is_all_true = false;
+          }
+        }
+        return is_all_true;
+      } else {
+        return true;
+      }
+    case 0:
+      return false;
+    case _:
+      this.on_fatal_error('Unexcepted status code recived: ' + status_code + ', error: ' + response);
+      return false;
+    }
+  }
+
+  public dynamic function on_error( error : Error ) {
+    trace( 'Error: ' + error );
+  }
+
+  public dynamic function on_fatal_error( error : String ) {
+    throw error;
+  }
+
+}

+ 10 - 0
src/beartek/matrix_im/client/UIA_config.hx

@@ -0,0 +1,10 @@
+//Under GNU AGPL v3, see LICENCE
+package beartek.matrix_im.client;
+
+import beartek.matrix_im.client.types.enums.Auths;
+
+class UIA_config {
+  static public var sessions : Map<String,Array<Auths>> = new Map();
+  static public var evite : Array<Auths> = [Recaptcha];
+
+}

+ 11 - 0
src/beartek/matrix_im/client/auths/Auth.hx

@@ -0,0 +1,11 @@
+//Under GNU AGPL v3, see LICENCE
+package beartek.matrix_im.client.auths;
+
+import com.akifox.asynchttp.HttpRequest;
+import beartek.matrix_im.client.types.replys.UIA;
+
+@:keep class Auth {
+  public var request : HttpRequest;
+  dynamic public function send_request( request : HttpRequest, on_response : Int -> Dynamic -> Void, ignore_errors : Bool = true ) : Void {};
+  dynamic public function on_response( status_code : Int, response : Dynamic ) : Void {};
+}

+ 25 - 0
src/beartek/matrix_im/client/auths/M_login_dummy.hx

@@ -0,0 +1,25 @@
+//Under GNU AGPL v3, see LICENCE
+package beartek.matrix_im.client.auths;
+
+import com.akifox.asynchttp.HttpRequest;
+import beartek.matrix_im.client.types.replys.UIA;
+import beartek.matrix_im.client.types.enums.Auths;
+
+@:keep class M_login_dummy extends Auth {
+  var session : String;
+  var auth : String;
+
+  public function new( session : String, params : Dynamic ) {
+    if( params != null ) {
+      throw 'unknow params recived: ' + params;
+    }
+
+    this.session = session;
+  }
+
+  public function make_pet() : Void {
+    request = UIA.add_auth(request, {type: Dummy, session: this.session});
+    this.send_request(request, this.on_response);
+  };
+
+}

+ 0 - 0
src/beartek/matrix_im/client/auths/M_login_email_identity.hx


Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio