Module: Titi::Fetcher::Json::ClassMethods

Defined in:
lib/titi/fetcher/json.rb

Instance Method Summary collapse

Instance Method Details

#from_file(filename) ⇒ Object



25
26
27
# File 'lib/titi/fetcher/json.rb', line 25

def from_file filename
  parse File.open(filename)
end

#get(url) ⇒ Object

Call the twitter API and fetch tweet with given ID

Examples:

tweet = Status.get(12233609555)
tweet.text
#=> "THANK GOODNESS THE LIBRARY OF CONGRESS HAS UNDERSTOOD THE IMPORTANCE OF MY TWEETS what do you mean others are getting in too"


21
22
23
# File 'lib/titi/fetcher/json.rb', line 21

def get url
  parse RestClient.get(url).to_s
end

#parse(raw_json_str) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/titi/fetcher/json.rb', line 5

def parse raw_json_str
  begin
    return JSON.load(raw_json_str)
  rescue StandardError => e
    warn e
    return { }
  end
end