diff --git a/lib/smartfm/models/list.rb b/lib/smartfm/models/list.rb index 105c586..635fb38 100644 --- a/lib/smartfm/models/list.rb +++ b/lib/smartfm/models/list.rb @@ -1,6 +1,6 @@ class Smartfm::List < Smartfm::Base ATTRIBUTES = [:id, :title, :description, :icon, :square_icon, :item_count, :user_count, :iknow, :dictation, :brainspeed, - :language, :translation_language, :list_type, :transcript, :embed, :tags, :media_entry, + :language, :translation_language, :item_type, :transcript, :embed, :tags, :media_entry, :attribution_license_id, :items, :sentences, :user] READONLY_ATTRIBUTES = [:id, :icon, :item_count, :user_count, :iknow, :dictation, :brainspeed, :user] attr_accessor *(ATTRIBUTES - READONLY_ATTRIBUTES) @@ -50,7 +50,7 @@ def initialize(params = {}) @dictation = Application.new(common_settings.merge(:dictation => params[:dictation])) @brainspeed = Application.new(common_settings.merge(:brainspeed => params[:brainspeed])) end - @list_type = params[:list_type] # for list creation + @item_type = params[:item_type] # for list creation @transcript = params[:transcript] # for list creation @embed = params[:embed] # for list creation @tags = params[:tags] # for list creation @@ -90,10 +90,7 @@ def to_post_data 'list[translation_language]' => self.translation_language || 'ja' } # Optional attributes - if self.list_type - post_data['list[type]'] = self.list_type - end - [:transcript, :embed, :tags, :media_entry, :author, :author_url, :attribution_license_id ].each do |key| + [:transcript, :embed, :tags, :item_type].each do |key| if self.send("#{key}") post_data["list[#{key}]"] = self.send("#{key}") end diff --git a/lib/smartfm/models/notification.rb b/lib/smartfm/models/notification.rb index 63b545d..8d7b3a9 100644 --- a/lib/smartfm/models/notification.rb +++ b/lib/smartfm/models/notification.rb @@ -17,7 +17,7 @@ def initialize(params) @context = params[:context] end - private + protected def to_post_data {:message => self.message} diff --git a/lib/smartfm/modules/acts_as_likable.rb b/lib/smartfm/modules/acts_as_likable.rb index 1043d1c..748f41c 100644 --- a/lib/smartfm/modules/acts_as_likable.rb +++ b/lib/smartfm/modules/acts_as_likable.rb @@ -5,11 +5,11 @@ def likes(params = {}) self.deserialize(hash, :as => Smartfm::Like) || [] end - def like!(auth, params) + def like!(auth, params = {}) self.rest_client.like!(auth, params.merge(:id => self.id)) end - def unlike!(auth, params) + def unlike!(auth, params = {}) self.rest_client.unlike!(auth, params.merge(:id => self.id)) end diff --git a/lib/smartfm/modules/private_content.rb b/lib/smartfm/modules/private_content.rb index 139bfae..bdcfae3 100644 --- a/lib/smartfm/modules/private_content.rb +++ b/lib/smartfm/modules/private_content.rb @@ -12,13 +12,21 @@ def of_current(auth, params = {}) end def create(auth, params = {}) - self.new(params).save + self.new(params).save(auth) end end module InstanceMethods def save(auth) - self.rest_client.create(auth, self.to_post_data) + result = self.rest_client.create(auth, self.to_post_data) + case result + when Hash + self.deserialize(result) + when String + self.find(result) + else + true + end end end diff --git a/lib/smartfm/modules/public_content.rb b/lib/smartfm/modules/public_content.rb index cf08873..38c93d7 100644 --- a/lib/smartfm/modules/public_content.rb +++ b/lib/smartfm/modules/public_content.rb @@ -34,12 +34,15 @@ def delete(obj_id) module InstanceMethods def save(auth) - begin - obj_id = self.rest_client.create(auth, self.to_post_data) - rescue - return false + result = self.rest_client.create(auth, self.to_post_data) + case result + when Hash + self.deserialize(result) + when String + self.find(result) + else + true end - self.find(obj_id) end def delete(auth) diff --git a/lib/smartfm/rest_clients/base.rb b/lib/smartfm/rest_clients/base.rb index 93cd72d..3beeabc 100644 --- a/lib/smartfm/rest_clients/base.rb +++ b/lib/smartfm/rest_clients/base.rb @@ -147,18 +147,18 @@ def self.http_get_with_auth(auth, path, params = {}) case auth.mode when :oauth response = auth.auth_token.get(path, http_header) - handle_rest_response(response, :text) + handle_rest_response(response, :json) when :basic_auth http_connect do get_req = Net::HTTP::Get.new(path, http_header) get_req.basic_auth(auth.account.username, auth.account.password) - [get_req, :text] + [get_req, :json] end end end def self.http_post(auth, path, params = {}) - self.api_key_required + api_key_required params.merge!(:api_key => self.config.api_key) case auth.mode when :oauth @@ -175,7 +175,7 @@ def self.http_post(auth, path, params = {}) end def self.http_delete(auth, path, params = {}) - self.api_key_required + api_key_required params.merge!(:api_key => self.config.api_key) path = "#{path}?#{params.to_http_str}" case auth.mode