smartfm 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/smartfm/core/version.rb +1 -1
- data/lib/smartfm/models/list.rb +3 -6
- data/lib/smartfm/models/notification.rb +1 -1
- data/lib/smartfm/modules/acts_as_likable.rb +2 -2
- data/lib/smartfm/modules/private_content.rb +10 -2
- data/lib/smartfm/modules/public_content.rb +8 -5
- data/lib/smartfm/rest_clients/base.rb +4 -4
- metadata +1 -1
data/lib/smartfm/core/version.rb
CHANGED
data/lib/smartfm/models/list.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
class Smartfm::List < Smartfm::Base
|
2
2
|
ATTRIBUTES = [:id, :title, :description, :icon, :square_icon, :item_count, :user_count, :iknow, :dictation, :brainspeed,
|
3
|
-
:language, :translation_language, :
|
3
|
+
:language, :translation_language, :item_type, :transcript, :embed, :tags, :media_entry,
|
4
4
|
:attribution_license_id, :items, :sentences, :user]
|
5
5
|
READONLY_ATTRIBUTES = [:id, :icon, :item_count, :user_count, :iknow, :dictation, :brainspeed, :user]
|
6
6
|
attr_accessor *(ATTRIBUTES - READONLY_ATTRIBUTES)
|
@@ -50,7 +50,7 @@ class Smartfm::List < Smartfm::Base
|
|
50
50
|
@dictation = Application.new(common_settings.merge(:dictation => params[:dictation]))
|
51
51
|
@brainspeed = Application.new(common_settings.merge(:brainspeed => params[:brainspeed]))
|
52
52
|
end
|
53
|
-
@
|
53
|
+
@item_type = params[:item_type] # for list creation
|
54
54
|
@transcript = params[:transcript] # for list creation
|
55
55
|
@embed = params[:embed] # for list creation
|
56
56
|
@tags = params[:tags] # for list creation
|
@@ -90,10 +90,7 @@ class Smartfm::List < Smartfm::Base
|
|
90
90
|
'list[translation_language]' => self.translation_language || 'ja'
|
91
91
|
}
|
92
92
|
# Optional attributes
|
93
|
-
|
94
|
-
post_data['list[type]'] = self.list_type
|
95
|
-
end
|
96
|
-
[:transcript, :embed, :tags, :media_entry, :author, :author_url, :attribution_license_id ].each do |key|
|
93
|
+
[:transcript, :embed, :tags, :item_type].each do |key|
|
97
94
|
if self.send("#{key}")
|
98
95
|
post_data["list[#{key}]"] = self.send("#{key}")
|
99
96
|
end
|
@@ -5,11 +5,11 @@ module Smartfm::ActsAsLikable
|
|
5
5
|
self.deserialize(hash, :as => Smartfm::Like) || []
|
6
6
|
end
|
7
7
|
|
8
|
-
def like!(auth, params)
|
8
|
+
def like!(auth, params = {})
|
9
9
|
self.rest_client.like!(auth, params.merge(:id => self.id))
|
10
10
|
end
|
11
11
|
|
12
|
-
def unlike!(auth, params)
|
12
|
+
def unlike!(auth, params = {})
|
13
13
|
self.rest_client.unlike!(auth, params.merge(:id => self.id))
|
14
14
|
end
|
15
15
|
|
@@ -12,13 +12,21 @@ module Smartfm::PrivateContent
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def create(auth, params = {})
|
15
|
-
self.new(params).save
|
15
|
+
self.new(params).save(auth)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
module InstanceMethods
|
20
20
|
def save(auth)
|
21
|
-
self.rest_client.create(auth, self.to_post_data)
|
21
|
+
result = self.rest_client.create(auth, self.to_post_data)
|
22
|
+
case result
|
23
|
+
when Hash
|
24
|
+
self.deserialize(result)
|
25
|
+
when String
|
26
|
+
self.find(result)
|
27
|
+
else
|
28
|
+
true
|
29
|
+
end
|
22
30
|
end
|
23
31
|
end
|
24
32
|
|
@@ -34,12 +34,15 @@ module Smartfm::PublicContent
|
|
34
34
|
|
35
35
|
module InstanceMethods
|
36
36
|
def save(auth)
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
37
|
+
result = self.rest_client.create(auth, self.to_post_data)
|
38
|
+
case result
|
39
|
+
when Hash
|
40
|
+
self.deserialize(result)
|
41
|
+
when String
|
42
|
+
self.find(result)
|
43
|
+
else
|
44
|
+
true
|
41
45
|
end
|
42
|
-
self.find(obj_id)
|
43
46
|
end
|
44
47
|
|
45
48
|
def delete(auth)
|
@@ -147,18 +147,18 @@ class Smartfm::RestClient::Base
|
|
147
147
|
case auth.mode
|
148
148
|
when :oauth
|
149
149
|
response = auth.auth_token.get(path, http_header)
|
150
|
-
handle_rest_response(response, :
|
150
|
+
handle_rest_response(response, :json)
|
151
151
|
when :basic_auth
|
152
152
|
http_connect do
|
153
153
|
get_req = Net::HTTP::Get.new(path, http_header)
|
154
154
|
get_req.basic_auth(auth.account.username, auth.account.password)
|
155
|
-
[get_req, :
|
155
|
+
[get_req, :json]
|
156
156
|
end
|
157
157
|
end
|
158
158
|
end
|
159
159
|
|
160
160
|
def self.http_post(auth, path, params = {})
|
161
|
-
|
161
|
+
api_key_required
|
162
162
|
params.merge!(:api_key => self.config.api_key)
|
163
163
|
case auth.mode
|
164
164
|
when :oauth
|
@@ -175,7 +175,7 @@ class Smartfm::RestClient::Base
|
|
175
175
|
end
|
176
176
|
|
177
177
|
def self.http_delete(auth, path, params = {})
|
178
|
-
|
178
|
+
api_key_required
|
179
179
|
params.merge!(:api_key => self.config.api_key)
|
180
180
|
path = "#{path}?#{params.to_http_str}"
|
181
181
|
case auth.mode
|