This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def send_fb_message(to, message): | |
post_message_url = 'https://graph.facebook.com/v2.6/me/messages?access_token={token}'.format(token=config.FB_TOKEN) | |
response_message = json.dumps({"recipient":{"id": to}, | |
"message":{"text":message}}) | |
req = requests.post(post_message_url, | |
headers={"Content-Type": "application/json"}, | |
data=response_message) | |
print("[{}] Reply to {}: {}", req.status_code, to, message) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if __name__ == '__main__': | |
context = ('ssl/fullchain.pem', 'ssl/privkey.pem') | |
app.run(host='0.0.0.0', debug=True, ssl_context=context) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.DataInputStream; | |
import java.io.DataOutputStream; | |
import java.io.IOException; | |
import java.net.ServerSocket; | |
import java.net.Socket; | |
import java.util.concurrent.ExecutorService; | |
import java.util.concurrent.Executors; | |
public class Server { | |
public static final int LISTEN_PORT = 5987; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.DataInputStream; | |
import java.io.DataOutputStream; | |
import java.io.IOException; | |
import java.util.Scanner; | |
public class Client { | |
public static void main(String[] args) throws IOException { | |
String host = ""; | |
int port = 5987; | |
Socket socket = null; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static BlockProperties parseWebContent(Parser parser) throws ParserException { | |
NodeList visualBlockNodeList = getVisualBlock(parser); | |
// Output.printNodeList( visualBlockNodeList ); | |
NodeList linkNodeList = findLinkBlock(visualBlockNodeList); | |
NodeList invalidNodeList = findInvalidBlock(visualBlockNodeList); | |
NodeList actionNodeList = findActionBlock(visualBlockNodeList); // NOTE: 因為動作標籤可能沒有包含文字,所以要獨立出來找 | |
Map<String, NodeList> blockNodeMap = new HashMap<String, NodeList>(); | |
blockNodeMap.put(VISUAL_BLOCK, visualBlockNodeList); | |
blockNodeMap.put(LINK_BLOCK, linkNodeList); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class Media(@SerializedName("media_id") val mediaId: String) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
POST /test/api1 | |
Authorization Bearer JWT | |
User-Agent: Make sure to include platform | |
--- | |
200 OK | |
Content-Type: application/json | |
Location: MEDIA_UPLOAD_URL | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Api { | |
fun api1(): Observable<Response<Media>> = | |
ApiHelper.getApi().api1() | |
fun api2(uploadUrl: String): Observable<okhttp3.Response> = | |
Observable.fromCallable { | |
val request = Request.Builder() | |
.url(uploadUrl) | |
.build() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object ApiRepository { | |
fun chainApi1AndApi1(): Observable<okhttp3.Response> { | |
return Api.api1().flatMap { response1 -> | |
if (response1.isSuccessful) { | |
var uploadUrl = response1.headers().get(ApiUtils.Header.LOCATION) | |
uploadUrl?.let { url -> | |
Api.api2(url) | |
} ?: kotlin.run { | |
throw Exceptions.propagate(NullPointerException("Media upload URL is empty")) |