Method: AP::Article.new_from_api_data
- Defined in:
- lib/ap/article.rb
.new_from_api_data(data) ⇒ Object
Creates a new object from data returned by the API
24 25 26 27 28 29 30 31 32 |
# File 'lib/ap/article.rb', line 24 def self.new_from_api_data(data) if data["author"].is_a?(Hash) = [ data["author"]["name"] ] elsif data["author"].is_a?(Array) = data["author"].collect{ |x| x["name"] } end categories = data["category"] ? data["category"].collect { |x| x["label"] } : [] return new(:id => data["id"].split(":").last, :title => data["title"], :authors => , :tags => categories, :link => data["link"]["href"], :content => data["content"], :updated => Time.parse(data["updated"])) end |