Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fixed bugs
  • Loading branch information
nov committed May 1, 2009
1 parent aeeb042 commit 64b541a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 20 deletions.
9 changes: 3 additions & 6 deletions 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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/smartfm/models/notification.rb
Expand Up @@ -17,7 +17,7 @@ def initialize(params)
@context = params[:context]
end

private
protected

def to_post_data
{:message => self.message}
Expand Down
4 changes: 2 additions & 2 deletions lib/smartfm/modules/acts_as_likable.rb
Expand Up @@ -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

Expand Down
12 changes: 10 additions & 2 deletions lib/smartfm/modules/private_content.rb
Expand Up @@ -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

Expand Down
13 changes: 8 additions & 5 deletions lib/smartfm/modules/public_content.rb
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions lib/smartfm/rest_clients/base.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 64b541a

Please sign in to comment.