aboutsummaryrefslogtreecommitdiffstats
path: root/examples/client
diff options
context:
space:
mode:
Diffstat (limited to 'examples/client')
-rw-r--r--examples/client/synchronous.rb24
-rw-r--r--examples/client/twitter.rb10
2 files changed, 30 insertions, 4 deletions
diff --git a/examples/client/synchronous.rb b/examples/client/synchronous.rb
new file mode 100644
index 0000000..6701e1e
--- /dev/null
+++ b/examples/client/synchronous.rb
@@ -0,0 +1,24 @@
+# frozen-string-literal: true
+# client/synchronous.rb: download 3 files in sequence
+$LOAD_PATH.unshift File.expand_path("../../../lib", __FILE__)
+require "plum"
+require "zlib"
+
+client = Plum::Client.start("http2.golang.org", 443)
+
+reqinfo = client.get("/reqinfo").join
+puts "/reqinfo: #{reqinfo.status}"
+
+test = "test"
+crc32 = client.put("/crc32", test).join
+puts "/crc32{#{test}}: #{crc32.body}"
+puts "Zlib.crc32: #{Zlib.crc32(test).to_s(16)}"
+
+client.get("/clockstream")
+ .on_headers { |res|
+ puts "status: #{res.status}, headers: #{res.headers}"
+ }.on_chunk { |chunk|
+ puts chunk
+ }.on_finish {
+ puts "finish!"
+ }.join
diff --git a/examples/client/twitter.rb b/examples/client/twitter.rb
index d31c15a..a67fad3 100644
--- a/examples/client/twitter.rb
+++ b/examples/client/twitter.rb
@@ -41,10 +41,12 @@ Plum::Client.start("userstream.twitter.com", 443) { |streaming|
if /にゃーん/ =~ json["text"]
args = { "status" => "@#{json["user"]["screen_name"]} にゃーん",
"in_reply_to_status_id" => json["id"].to_s }
- rest.post!("/1.1/statuses/update.json",
- args.map { |k, v| "#{k}=#{CGI.escape(v)}" }.join("&"),
- headers: { "authorization" => SimpleOAuth::Header.new(:post, "https://api.twitter.com/1.1/statuses/update.json", args, credentials).to_s,
- "content-type" => "application/x-www-form-urlencoded" })
+ rest.post(
+ "/1.1/statuses/update.json",
+ args.map { |k, v| "#{k}=#{CGI.escape(v)}" }.join("&"),
+ headers: { "authorization" => SimpleOAuth::Header.new(:post, "https://api.twitter.com/1.1/statuses/update.json", args, credentials).to_s,
+ "content-type" => "application/x-www-form-urlencoded" }
+ ).join
end
end
}