Permalink
Browse files

fixed bugs

  • Loading branch information...
nov committed May 1, 2009
1 parent aeeb042 commit 64b541a619b1685f7cbda33684f40341c4291801
@@ -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
@@ -17,7 +17,7 @@ def initialize(params)
@context = params[:context]
end
- private
+ protected
def to_post_data
{:message => self.message}
@@ -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
@@ -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
@@ -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)
@@ -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

0 comments on commit 64b541a

Please sign in to comment.