BigBinary BlogWe craft blog posts about what we have learned so far and we have published 609 blog posts about Ruby on Rails, ReactJS, React Native, open source, engineering & design.
When working on the Shrine library for handling file uploads, in multiple places I needed to be able to download a file from URL. If you know the Ruby standard library well, the solution might be obvious to you: open-uri. require "open-uri" result = open("http://example.com/image.jpg") result #=> #<Tempfile:/var/folders/k7/6zx6dx6x7ys3rv3srh0nyfj00000gn/T/20160524-10403-xpdakz> Open-uri is somethi
タイトル長えw さて、HTTP リクエストするとJSON が返ってくるようなAPI でなんやかんや処理をすることが割りとよくあるのだが、すぐに忘れてしまうのでメモメモ。 https://api.example.com/smaple.json にHTTP GET リクエストを投げるとJSON が返ってくる場合を想定します。 Net::HTTP を使うとこんなふうに書ける。 require require 'net/http' require 'uri' require 'json' uri = URI.parse('https://api.example.com/smaple.json') https = Net::HTTP.new(uri.host, uri.port) https.use_ssl = true res = https.start { https.get(uri.reque
『るびま』は、Ruby に関する技術記事はもちろんのこと、Rubyist へのインタビューやエッセイ、その他をお届けするウェブ雑誌です。 Rubyist Magazine について 『Rubyist Magazine』、略して『るびま』は、Rubyist の Rubyist による、Rubyist とそうでない人のためのウェブ雑誌です。 最新号 Rubyist Magazine 0064 号 バックナンバー Rubyist Magazine 0064 号 Rubyist Magazine 0063 号 Rubyist Magazine 0062 号 Kaigi on Rails 特集号 RubyKaigi Takeout 2020 特集号 Rubyist Magazine 0061 号 Rubyist Magazine 0060 号 RubyKaigi 2019 直前特集号 Rubyist
I have this code I use to get avatars from Facebook... if auth.info.image.present? user.update_attribute(:avatar, URI.parse(auth.info.image)) end When I try to load the code now I get this error: A RuntimeError occurred in authentications#create: redirection forbidden: http://graph.facebook.com/672086173/picture?type=square -> https://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn2/t5.0-1/1086349_67
require './open-uri-post.rb' open('http://localhost:9292', {'postdata' => 'name=hamasyou'}).read "CONTENT_LENGTH : 13" "CONTENT_TYPE : application/x-www-form-urlencoded" "GATEWAY_INTERFACE : CGI/1.1" "PATH_INFO : /" "QUERY_STRING : " "REMOTE_ADDR : 127.0.0.1" "REMOTE_HOST : localhost" "REQUEST_METHOD : POST" "REQUEST_URI : http://localhost:9292/" "SCRIPT_NAME : " "SERVER_NAME : localhost" "SERVER_
■ [ruby] open-uriでUTF-8でないページを取得するときの注意 Ruby標準添付のopen-uriライブラリを使うと、HTMLを簡単に取得することができる。 irb> require 'open-uri' irb> url = "http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-dev/43008" irb> html = open(url).read このとき、文字コードがUTF-8でないことが分かっているなら、第二引数でエンコーディング名を指定しておいた方が良いだろう。(あ、ここからはRuby 1.9の話です。) irb> html = open(url, "r:euc-jp").read 読んだあとは、String#encodeでUTF-8に変換することができる。 irb> html = open(url,
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く