smartfm 0.4.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/ChangeLog +6 -2
  2. data/README +3 -10
  3. data/lib/smartfm.rb +3 -2
  4. data/lib/smartfm/core/version.rb +2 -2
  5. data/lib/smartfm/models.rb +7 -0
  6. data/lib/smartfm/{model → models}/base.rb +2 -1
  7. data/lib/smartfm/{model → models}/item.rb +18 -86
  8. data/lib/smartfm/models/like.rb +20 -0
  9. data/lib/smartfm/{model → models}/list.rb +35 -64
  10. data/lib/smartfm/models/notification.rb +26 -0
  11. data/lib/smartfm/models/sentence.rb +70 -0
  12. data/lib/smartfm/{model → models}/user.rb +54 -16
  13. data/lib/smartfm/modules.rb +4 -0
  14. data/lib/smartfm/modules/acts_as_likable.rb +16 -0
  15. data/lib/smartfm/modules/media_support.rb +37 -0
  16. data/lib/smartfm/modules/private_content.rb +25 -0
  17. data/lib/smartfm/modules/public_content.rb +51 -0
  18. data/lib/smartfm/rest_clients.rb +9 -0
  19. data/lib/smartfm/{rest_client → rest_clients}/base.rb +0 -0
  20. data/lib/smartfm/rest_clients/item.rb +17 -0
  21. data/lib/smartfm/rest_clients/like.rb +7 -0
  22. data/lib/smartfm/rest_clients/list.rb +18 -0
  23. data/lib/smartfm/rest_clients/notification.rb +8 -0
  24. data/lib/smartfm/rest_clients/sentence.rb +14 -0
  25. data/lib/smartfm/rest_clients/user.rb +20 -0
  26. data/spec/smartfm/{model → models}/base_spec.rb +5 -3
  27. data/spec/smartfm/{model → models}/item_spec.rb +24 -5
  28. data/spec/smartfm/models/like_spec.rb +19 -0
  29. data/spec/smartfm/models/list_spec.rb +70 -0
  30. data/spec/smartfm/models/notification_spec.rb +11 -0
  31. data/spec/smartfm/models/sentence_spec.rb +11 -0
  32. data/spec/smartfm/{model → models}/user_spec.rb +53 -19
  33. data/spec/smartfm/{rest_client → rest_clients}/base_spec.rb +0 -0
  34. data/spec/smartfm/{rest_client → rest_clients}/item_spec.rb +0 -0
  35. data/spec/smartfm/rest_clients/like_spec.rb +7 -0
  36. data/spec/smartfm/{rest_client → rest_clients}/list_spec.rb +0 -0
  37. data/spec/smartfm/rest_clients/notification_spec.rb +7 -0
  38. data/spec/smartfm/{rest_client → rest_clients}/sentence_spec.rb +0 -0
  39. data/spec/smartfm/{rest_client → rest_clients}/user_spec.rb +0 -0
  40. metadata +37 -24
  41. data/lib/smartfm/model.rb +0 -5
  42. data/lib/smartfm/model/sentence.rb +0 -118
  43. data/lib/smartfm/rest_client.rb +0 -8
  44. data/lib/smartfm/rest_client/item.rb +0 -14
  45. data/lib/smartfm/rest_client/list.rb +0 -15
  46. data/lib/smartfm/rest_client/sentence.rb +0 -12
  47. data/lib/smartfm/rest_client/user.rb +0 -14
  48. data/spec/smartfm/model/list_spec.rb +0 -7
  49. data/spec/smartfm/model/sentence_spec.rb +0 -7
@@ -0,0 +1,70 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
2
+
3
+ core_2000 = Smartfm::List.find(705)
4
+
5
+ Smartfm::List::ATTRIBUTES.each do |attr|
6
+ describe Smartfm::List, "##{attr}" do
7
+ it "should be accessible" do
8
+ core_2000.should respond_to(attr)
9
+ end
10
+ end
11
+ end
12
+
13
+ Smartfm::List::READONLY_ATTRIBUTES.each do |attr|
14
+ describe Smartfm::List, "##{attr}" do
15
+ it "should not be nil" do
16
+ core_2000.should_not be_nil
17
+ end
18
+ end
19
+ end
20
+
21
+ [:iknow, :dictation, :brainspeed].each do |application|
22
+ Smartfm::List::Application::ATTRIBUTES.each do |attr|
23
+ describe Smartfm::List::Application, "##{attr}" do
24
+ it "should be accessible for #{application}" do
25
+ core_2000.send(application).should respond_to(attr)
26
+ end
27
+ it "should not be nil for #{application}" do
28
+ core_2000.send(application).send(attr).should_not be_nil unless attr == :progress
29
+ end
30
+ end
31
+ end
32
+ describe Smartfm::List::Application, "#available?" do
33
+ it "should be true for #{application}" do
34
+ core_2000.send(application).available?.should be_true
35
+ end
36
+ end
37
+ end
38
+
39
+ describe Smartfm::List::Application, "#progress" do
40
+ it "should be nil for brainspeed" do
41
+ core_2000.brainspeed.progress.should be_nil
42
+ end
43
+ end
44
+
45
+ describe Smartfm::List, '#items' do
46
+ it "should return a Array of Smartfm::Item" do
47
+ core_2000.items.should be_a(Array)
48
+ core_2000.items.each do |item|
49
+ item.should be_a(Smartfm::Item)
50
+ end
51
+ end
52
+ end
53
+
54
+ describe Smartfm::List, '#sentences' do
55
+ it "should return a Array of Smartfm::Sentence" do
56
+ core_2000.sentences.should be_a(Array)
57
+ core_2000.sentences.each do |sentence|
58
+ sentence.should be_a(Smartfm::Sentence)
59
+ end
60
+ end
61
+ end
62
+
63
+ describe Smartfm::List, '#likes' do
64
+ it "should return a Array of Smartfm::Like" do
65
+ core_2000.likes.should be_a(Array)
66
+ core_2000.likes.each do |like|
67
+ like.should be_a(Smartfm::Like)
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,11 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
2
+
3
+ matake_notifications = Smartfm::User.find('matake').notifications
4
+
5
+ Smartfm::Notification::ATTRIBUTES.each do |attr|
6
+ describe Smartfm::Notification, "##{attr}" do
7
+ it "should be accessible" do
8
+ matake_notifications.first.should respond_to(attr)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
2
+
3
+ smartest = Smartfm::Sentence.find(10828)
4
+
5
+ Smartfm::Sentence::ATTRIBUTES.each do |attr|
6
+ describe Smartfm::Sentence, "##{attr}" do
7
+ it "should be accessible" do
8
+ smartest.should respond_to(attr)
9
+ end
10
+ end
11
+ end
@@ -1,25 +1,44 @@
1
1
  require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
2
2
 
3
3
  matake = Smartfm::User.find('matake')
4
+ matake_study = matake.study
4
5
 
5
- describe Smartfm::User do
6
- it "should respond to attribute methods" do
7
- Smartfm::User::ATTRIBUTES.each do |attr|
6
+ Smartfm::User::ATTRIBUTES.each do |attr|
7
+ describe Smartfm::User, "##{attr}" do
8
+ it "should be accessible" do
8
9
  matake.should respond_to(attr)
9
10
  end
10
- Smartfm::User::Profile::ATTRIBUTES.each do |attr|
11
+ end
12
+ end
13
+
14
+ Smartfm::User::Profile::ATTRIBUTES.each do |attr|
15
+ describe Smartfm::User::Profile, "##{attr}" do
16
+ it "should be accessible" do
11
17
  matake.profile.should respond_to(attr)
12
18
  end
13
- Smartfm::User::Study::ATTRIBUTES.each do |attr|
14
- matake.study.should respond_to(attr)
19
+ end
20
+ end
21
+
22
+ Smartfm::User::Study::ATTRIBUTES.each do |attr|
23
+ describe Smartfm::User::Study, "##{attr}" do
24
+ it "should be accessible" do
25
+ matake_study.should respond_to(attr)
15
26
  end
16
- Smartfm::User::Study::Result::ATTRIBUTES.each do |attr|
17
- matake.study.results.each do |result|
18
- result.should respond_to(attr)
19
- end
27
+ end
28
+ end
29
+
30
+ Smartfm::User::Study::Result::ATTRIBUTES.each do |attr|
31
+ describe Smartfm::User::Study::Result, "##{attr}" do
32
+ it "should be accessible" do
33
+ matake_study.results.first.should respond_to(attr)
20
34
  end
21
- Smartfm::User::Study::TotalSummary::ATTRIBUTES.each do |attr|
22
- matake.study.total_summary.should respond_to(attr)
35
+ end
36
+ end
37
+
38
+ Smartfm::User::Study::TotalSummary::ATTRIBUTES.each do |attr|
39
+ describe Smartfm::User::Study::TotalSummary, "##{attr}" do
40
+ it "shoud be accessible" do
41
+ matake_study.total_summary.should respond_to(attr)
23
42
  end
24
43
  end
25
44
  end
@@ -64,20 +83,35 @@ describe Smartfm::User, '#followers' do
64
83
  end
65
84
  end
66
85
 
86
+ describe Smartfm::User, '#likes' do
87
+ it "should return a Array of Smartfm::Like" do
88
+ matake.likes.should be_a(Array)
89
+ matake.likes.each do |like|
90
+ like.should be_a(Smartfm::Like)
91
+ end
92
+ end
93
+ end
94
+
95
+ describe Smartfm::User, '#notifications' do
96
+ it "should return a Array of Smartfm::Notification" do
97
+ matake.notifications.should be_a(Array)
98
+ matake.notifications.each do |notification|
99
+ notification.should be_a(Smartfm::Notification)
100
+ end
101
+ end
102
+ end
103
+
67
104
  describe Smartfm::User, '#study' do
68
105
  it "should return a instance of Smartfm::User::Study" do
69
- matake.study.should be_a(Smartfm::User::Study)
70
- matake.study(:application => 'iknow').should be_a(Smartfm::User::Study)
71
- matake.study(:application => 'dictation').should be_a(Smartfm::User::Study)
72
- matake.study(:application => 'brainspeed').should be_a(Smartfm::User::Study)
106
+ matake_study.should be_a(Smartfm::User::Study)
73
107
  matake.study(:application => 'fuckin_windows').should be_nil
74
108
  end
75
109
  end
76
110
 
77
111
  describe Smartfm::User::Study, '#results' do
78
112
  it "should return a Array of Smartfm::User::Study::Result" do
79
- matake.study.results.should be_a(Array)
80
- matake.study.results.each do |result|
113
+ matake_study.results.should be_a(Array)
114
+ matake_study.results.each do |result|
81
115
  result.should be_a(Smartfm::User::Study::Result)
82
116
  end
83
117
  end
@@ -85,6 +119,6 @@ end
85
119
 
86
120
  describe Smartfm::User::Study, '#total_summary' do
87
121
  it "should return a Array of Smartfm::User::Study::TotalSummary" do
88
- matake.study.total_summary.should be_a(Smartfm::User::Study::TotalSummary)
122
+ matake_study.total_summary.should be_a(Smartfm::User::Study::TotalSummary)
89
123
  end
90
124
  end
@@ -0,0 +1,7 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
2
+
3
+ describe Smartfm::RestClient::User, '::ACTIONS' do
4
+ it "should be a Hash" do
5
+ Smartfm::RestClient::Like::ACTIONS.should be_a(Hash)
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
2
+
3
+ describe Smartfm::RestClient::User, '::ACTIONS' do
4
+ it "should be a Hash" do
5
+ Smartfm::RestClient::Notification::ACTIONS.should be_a(Hash)
6
+ end
7
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smartfm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - nov
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-29 00:00:00 +09:00
12
+ date: 2009-05-01 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -51,34 +51,47 @@ files:
51
51
  - spec/smartfm/core/auth_spec.rb
52
52
  - spec/smartfm/core/config_spec.rb
53
53
  - spec/smartfm/core/version_spec.rb
54
- - spec/smartfm/model/base_spec.rb
55
- - spec/smartfm/model/item_spec.rb
56
- - spec/smartfm/model/list_spec.rb
57
- - spec/smartfm/model/sentence_spec.rb
58
- - spec/smartfm/model/user_spec.rb
59
- - spec/smartfm/rest_client/base_spec.rb
60
- - spec/smartfm/rest_client/item_spec.rb
61
- - spec/smartfm/rest_client/list_spec.rb
62
- - spec/smartfm/rest_client/sentence_spec.rb
63
- - spec/smartfm/rest_client/user_spec.rb
54
+ - spec/smartfm/models/base_spec.rb
55
+ - spec/smartfm/models/item_spec.rb
56
+ - spec/smartfm/models/like_spec.rb
57
+ - spec/smartfm/models/list_spec.rb
58
+ - spec/smartfm/models/notification_spec.rb
59
+ - spec/smartfm/models/sentence_spec.rb
60
+ - spec/smartfm/models/user_spec.rb
61
+ - spec/smartfm/rest_clients/base_spec.rb
62
+ - spec/smartfm/rest_clients/item_spec.rb
63
+ - spec/smartfm/rest_clients/like_spec.rb
64
+ - spec/smartfm/rest_clients/list_spec.rb
65
+ - spec/smartfm/rest_clients/notification_spec.rb
66
+ - spec/smartfm/rest_clients/sentence_spec.rb
67
+ - spec/smartfm/rest_clients/user_spec.rb
64
68
  - spec/spec_helper.rb
65
69
  - lib/ext/hash.rb
66
70
  - lib/smartfm/core/auth.rb
67
71
  - lib/smartfm/core/config.rb
68
72
  - lib/smartfm/core/version.rb
69
73
  - lib/smartfm/core.rb
70
- - lib/smartfm/model/base.rb
71
- - lib/smartfm/model/item.rb
72
- - lib/smartfm/model/list.rb
73
- - lib/smartfm/model/sentence.rb
74
- - lib/smartfm/model/user.rb
75
- - lib/smartfm/model.rb
76
- - lib/smartfm/rest_client/base.rb
77
- - lib/smartfm/rest_client/item.rb
78
- - lib/smartfm/rest_client/list.rb
79
- - lib/smartfm/rest_client/sentence.rb
80
- - lib/smartfm/rest_client/user.rb
81
- - lib/smartfm/rest_client.rb
74
+ - lib/smartfm/models/base.rb
75
+ - lib/smartfm/models/item.rb
76
+ - lib/smartfm/models/like.rb
77
+ - lib/smartfm/models/list.rb
78
+ - lib/smartfm/models/notification.rb
79
+ - lib/smartfm/models/sentence.rb
80
+ - lib/smartfm/models/user.rb
81
+ - lib/smartfm/models.rb
82
+ - lib/smartfm/modules/acts_as_likable.rb
83
+ - lib/smartfm/modules/media_support.rb
84
+ - lib/smartfm/modules/private_content.rb
85
+ - lib/smartfm/modules/public_content.rb
86
+ - lib/smartfm/modules.rb
87
+ - lib/smartfm/rest_clients/base.rb
88
+ - lib/smartfm/rest_clients/item.rb
89
+ - lib/smartfm/rest_clients/like.rb
90
+ - lib/smartfm/rest_clients/list.rb
91
+ - lib/smartfm/rest_clients/notification.rb
92
+ - lib/smartfm/rest_clients/sentence.rb
93
+ - lib/smartfm/rest_clients/user.rb
94
+ - lib/smartfm/rest_clients.rb
82
95
  - lib/smartfm.rb
83
96
  - examples/pure_ruby.rb
84
97
  has_rdoc: true
data/lib/smartfm/model.rb DELETED
@@ -1,5 +0,0 @@
1
- require 'smartfm/model/base'
2
- require 'smartfm/model/user'
3
- require 'smartfm/model/list'
4
- require 'smartfm/model/item'
5
- require 'smartfm/model/sentence'
@@ -1,118 +0,0 @@
1
- class Smartfm::Sentence < Smartfm::Base
2
- ATTRIBUTES = [:sound, :image, :square_image, :text, :language, :id, :transliterations, :translations, :item, :list]
3
- READONLY_ATTRIBUTES = [:id]
4
- attr_accessor *(ATTRIBUTES - READONLY_ATTRIBUTES)
5
- attr_reader *READONLY_ATTRIBUTES
6
-
7
- def self.recent(params = {})
8
- hash = Smartfm::RestClient::Sentence.recent(params)
9
- self.deserialize(hash) || []
10
- end
11
-
12
- def self.find(sentence_id, params = {})
13
- params[:id] = sentence_id
14
- hash = Smartfm::RestClient::Sentence.find(params)
15
- self.deserialize(hash)
16
- end
17
-
18
- def self.matching(keyword, params = {})
19
- params[:keyword] = keyword
20
- hash = Smartfm::RestClient::Sentence.matching(params)
21
- self.deserialize(hash) || []
22
- end
23
-
24
- def self.create(auth, params = {})
25
- self.new(params).save(auth)
26
- end
27
-
28
- def initialize(params = {})
29
- params[:translations] = [params[:translation]] if params[:translation]
30
- params[:transliterations] = [params[:transliteration]] if params[:transliteration]
31
- @id = params[:id]
32
- @item = params[:item]
33
- @list = params[:list]
34
- @sound = params[:sound]
35
- @image = params[:image]
36
- @square_image = params[:square_image]
37
- @text = params[:text]
38
- @language = params[:language]
39
- @transliterations = params[:transliterations]
40
- @translations = self.deserialize(params[:translations], :as => Smartfm::Sentence)
41
- end
42
-
43
- def save(auth)
44
- begin
45
- sentence_id = Smartfm::RestClient::Sentence.create(auth, self.to_post_data)
46
- rescue
47
- return false
48
- end
49
- Smartfm::Sentence.find(sentence_id)
50
- end
51
-
52
- def add_image(auth, params)
53
- post_params = if params.is_a?(String)
54
- {'image[url]' => params}
55
- else
56
- {'image[url]' => params[:url], 'image[list_id]' => params[:list_id]}.merge(attribution_params(params[:attribution]))
57
- end
58
- Smartfm::RestClient::Sentence.add_image(auth, post_params.merge(:id => self.id))
59
- end
60
-
61
- def add_sound(auth, params)
62
- post_params = if params.is_a?(String)
63
- {'sound[url]' => params}
64
- else
65
- {'sound[url]' => params[:url], 'sound[list_id]' => params[:list_id]}.merge(attribution_params(params[:attribution]))
66
- end
67
- Smartfm::RestClient::Sentence.add_sound(auth, post_params.merge(:id => self.id))
68
- end
69
-
70
- protected
71
-
72
- def to_post_data
73
- self.validate
74
- post_data = {
75
- 'item_id' => self.item.id,
76
- 'sentence[text]' => self.text
77
- }
78
- # Optional attributes
79
- if self.list
80
- post_data['sentence[list_id]'] = self.list.id
81
- end
82
- [:language, :transliteration].each do |key|
83
- if self.send("#{key}")
84
- post_data["sentence[#{key}]"] = self.send("#{key}")
85
- end
86
- end
87
- if self.translation
88
- [:text, :language, :transliteration].each do |key|
89
- if self.translation.send("#{key}")
90
- post_data["translation[#{key}]"] = self.translation.send("#{key}")
91
- end
92
- end
93
- end
94
- post_data
95
- end
96
-
97
- def validate
98
- raise ArgumentError.new("Item is required.") unless self.item
99
- raise ArgumentError.new("Sentence text is required.") if self.text.nil? or self.text.empty?
100
- end
101
-
102
- def translation
103
- self.translations.first rescue nil
104
- end
105
-
106
- def transliteration
107
- self.transliterations.first rescue nil
108
- end
109
-
110
- def attribution_params(attr_params)
111
- return {} unless attr_params
112
- {'attribution[medias_entity]' => attr_params[:media_entity],
113
- 'attribution[author]' => attr_params[:author],
114
- 'attribution[author_url]' => attr_params[:author_url],
115
- 'attributions[attribution_license_id]' => attr_params[:attribution_license_id] }
116
- end
117
-
118
- end