RubyMotionでWeb APIを叩いてJSONファイルを取得ヘ(^o^)ノ
BubbleWrapが便利→BubbleWrap-GitHub
でも、RubyMotion1.24では動かない…
んじゃ、スクラッチで実装すればイイじゃね?
って事で、サンプルコードを書いてみたヽ(´ー`)ノ
app/app_delegate.rb
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
#connpass api
url = "http://connpass.com/api/v1/event/?keyword=rubymotion"
Dispatch::Queue.concurrent.async do
error_ptr = Pointer.new(:object)
data = NSData.alloc.initWithContentsOfURL(NSURL.URLWithString(url), options:NSDataReadingUncached, error:error_ptr)
json = NSJSONSerialization.JSONObjectWithData(data, options:0, error:error_ptr)
#JSONファイルの内容を表示
p json
end
true
end
end
rakeするとコンソールにJSONファイルの内容が表示されたはず♪
RubyMotionではAPI を直接叩けるのでホントに便利ヽ(´ー`)ノ
0 件のコメント:
コメントを投稿