diff --git a/Gemfile b/Gemfile index 0beeab037..b143865a4 100644 --- a/Gemfile +++ b/Gemfile @@ -73,6 +73,7 @@ gem 'jammit', '0.6.5' gem 'json', '1.5.2' gem 'vanna', :git => 'git://github.com/MikeSofaer/vanna.git' +gem 'acts_as_api' # localization diff --git a/Gemfile.lock b/Gemfile.lock index c121db9f4..98cf90f56 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -85,6 +85,10 @@ GEM activemodel (= 3.0.11) activesupport (= 3.0.11) activesupport (3.0.11) + acts_as_api (0.3.11) + activemodel (>= 3.0.0) + activesupport (>= 3.0.0) + rack (>= 1.1.0) addressable (2.2.4) archive-tar-minitar (0.5.2) arel (2.0.10) @@ -450,6 +454,7 @@ DEPENDENCIES SystemTimer (= 1.2.3) activerecord-import acts-as-taggable-on! + acts_as_api addressable (= 2.2.4) bundler (>= 1.0.0) capistrano (~> 2.9.0) diff --git a/app/controllers/multis_controller.rb b/app/controllers/multis_controller.rb index 9d65a015f..2bf913ce1 100644 --- a/app/controllers/multis_controller.rb +++ b/app/controllers/multis_controller.rb @@ -13,7 +13,8 @@ class MultisController < ApplicationController respond_with do |format| format.html{ default_stream_action(Stream::Multi) } - format.json{ render :json => stream(Stream::Multi).stream_posts.to_json(:include => {:author => {:include => :profile}}) } + #format.json{ render :json => stream(Stream::Multi).stream_posts.to_json(:include => {:author => {:include => :profile}}) } + format.json{ render_for_api :backbone, :json => stream(Stream::Multi).stream_posts } end end end diff --git a/app/models/person.rb b/app/models/person.rb index 86a4d4121..cd914166d 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -10,13 +10,25 @@ class Person < ActiveRecord::Base include Encryptor::Public include Diaspora::Guid + # NOTE API V1 to be extracted + acts_as_api + api_accessible :post do |t| + t.add :id + t.add :name + t.add lambda { |person| + {:small => person.profile.image_url(:small), + :medium => person.profile.image_url(:medium), + :large => person.profile.image_url(:large) } + }, :as => :avatar + end + xml_attr :diaspora_handle xml_attr :url xml_attr :profile, :as => Profile xml_attr :exported_key has_one :profile, :dependent => :destroy - delegate :last_name, :to => :profile + delegate :last_name, :image_url, :to => :profile accepts_nested_attributes_for :profile before_validation :downcase_diaspora_handle diff --git a/app/models/post.rb b/app/models/post.rb index 109943797..8c3f3e638 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -9,6 +9,16 @@ class Post < ActiveRecord::Base include Diaspora::Commentable include Diaspora::Shareable + # NOTE API V1 to be extracted + acts_as_api + api_accessible :backbone do |t| + t.add :id + t.add :guid + t.add :text + t.add :created_at + t.add :author, :template => :post + end + xml_attr :provider_display_name has_many :mentions, :dependent => :destroy diff --git a/app/models/profile.rb b/app/models/profile.rb index 4978bc80a..f2dd39068 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -29,10 +29,10 @@ class Profile < ActiveRecord::Base before_save :strip_names after_validation :strip_names - + validates :first_name, :length => { :maximum => 32 } validates :last_name, :length => { :maximum => 32 } - + validates_format_of :first_name, :with => /\A[^;]+\z/, :allow_blank => true validates_format_of :last_name, :with => /\A[^;]+\z/, :allow_blank => true validate :max_tags diff --git a/app/views/shared/_stream_element.html.underscore b/app/views/shared/_stream_element.html.underscore index 8a7be0157..d0757bcf9 100644 --- a/app/views/shared/_stream_element.html.underscore +++ b/app/views/shared/_stream_element.html.underscore @@ -1,6 +1,4 @@ -<% var post = typeof(status_message) === "undefined" ? (typeof(reshare) === "undefined" ? photo : reshare) : status_message; %> - -
+
@@ -15,32 +13,32 @@
- - + +
- - <%= post.author.profile.full_name %> + + <%= author.profile.full_name %> - - - +

- <%= post.text %> + <%= text %>

- via <%= post.provider_display_name %> + via <%= provider_display_name %>