smartfm 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. data/ChangeLog +38 -0
  2. data/README +45 -0
  3. data/Rakefile +155 -0
  4. data/examples/pure_ruby.rb +118 -0
  5. data/lib/ext/hash.rb +52 -0
  6. data/lib/smartfm.rb +16 -0
  7. data/lib/smartfm/core.rb +3 -0
  8. data/lib/smartfm/core/auth.rb +39 -0
  9. data/lib/smartfm/core/config.rb +51 -0
  10. data/lib/smartfm/core/version.rb +14 -0
  11. data/lib/smartfm/model.rb +5 -0
  12. data/lib/smartfm/model/base.rb +26 -0
  13. data/lib/smartfm/model/item.rb +174 -0
  14. data/lib/smartfm/model/list.rb +138 -0
  15. data/lib/smartfm/model/sentence.rb +118 -0
  16. data/lib/smartfm/model/user.rb +108 -0
  17. data/lib/smartfm/rest_client.rb +8 -0
  18. data/lib/smartfm/rest_client/base.rb +173 -0
  19. data/lib/smartfm/rest_client/item.rb +14 -0
  20. data/lib/smartfm/rest_client/list.rb +15 -0
  21. data/lib/smartfm/rest_client/sentence.rb +12 -0
  22. data/lib/smartfm/rest_client/user.rb +13 -0
  23. data/spec/ext/hash_spec.rb +11 -0
  24. data/spec/smartfm/core/auth_spec.rb +39 -0
  25. data/spec/smartfm/core/config_spec.rb +34 -0
  26. data/spec/smartfm/core/version_spec.rb +19 -0
  27. data/spec/smartfm/model/base_spec.rb +40 -0
  28. data/spec/smartfm/model/item_spec.rb +41 -0
  29. data/spec/smartfm/model/list_spec.rb +7 -0
  30. data/spec/smartfm/model/sentence_spec.rb +7 -0
  31. data/spec/smartfm/model/user_spec.rb +90 -0
  32. data/spec/smartfm/rest_client/base_spec.rb +9 -0
  33. data/spec/smartfm/rest_client/item_spec.rb +7 -0
  34. data/spec/smartfm/rest_client/list_spec.rb +7 -0
  35. data/spec/smartfm/rest_client/sentence_spec.rb +7 -0
  36. data/spec/smartfm/rest_client/user_spec.rb +7 -0
  37. data/spec/spec_helper.rb +18 -0
  38. data/test/smartfm_test.rb +8 -0
  39. data/test/test_helper.rb +3 -0
  40. metadata +132 -0
@@ -0,0 +1,40 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
2
+
3
+ subclasses = [ Smartfm::Item, Smartfm::List, Smartfm::Sentence, Smartfm::User ]
4
+
5
+ subclasses.each do |klass|
6
+
7
+ describe klass, '.attributes' do
8
+ it "should return Array of attributes" do
9
+ klass.attributes.should be_a(Array)
10
+ end
11
+ end
12
+
13
+ describe klass, '.find' do
14
+ it "should return nil if NOT FOUND" do
15
+ klass.find(-1).should be_nil
16
+ end
17
+ end
18
+
19
+ if klass.respond_to?(:recent)
20
+ describe klass, '.recent' do
21
+ it "should return Array" do
22
+ klass.recent.should be_a(Array)
23
+ # blank response should be []
24
+ klass.recent(:per_page => 20, :page => 100000000000000).should be_empty
25
+ klass.recent(:per_page => 20, :page => 100000000000000).should_not be_nil
26
+ end
27
+ end
28
+ end
29
+
30
+ if klass.respond_to?(:matching)
31
+ describe klass, '.recent' do
32
+ it "should return Array" do
33
+ klass.matching("hello").should be_a(Array)
34
+ klass.matching(rand_string).should be_empty
35
+ klass.matching(rand_string).should_not be_nil
36
+ end
37
+ end
38
+ end
39
+
40
+ end
@@ -0,0 +1,41 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
2
+
3
+ smart = Smartfm::Item.find(33158, :include_sentences => true)
4
+
5
+ describe Smartfm::Item do
6
+ it "should respond to attribute methods" do
7
+ Smartfm::Item::ATTRIBUTES.each do |attr|
8
+ smart.should respond_to(attr)
9
+ end
10
+ Smartfm::Item::Response::ATTRIBUTES.each do |attr|
11
+ smart.responses.first.should respond_to(attr)
12
+ end
13
+ Smartfm::Item::Cue::ATTRIBUTES.each do |attr|
14
+ smart.cue.should respond_to(attr)
15
+ end
16
+ end
17
+ end
18
+
19
+ describe Smartfm::Item, '#cue' do
20
+ it "should return a instance o Smartfm::Item::Cue" do
21
+ smart.cue.should be_a(Smartfm::Item::Cue)
22
+ end
23
+ end
24
+
25
+ describe Smartfm::Item, '#responses' do
26
+ it "should return a Array of Smartfm::Item::Response" do
27
+ smart.responses.should be_a(Array)
28
+ smart.responses.each do |response|
29
+ response.should be_a(Smartfm::Item::Response)
30
+ end
31
+ end
32
+ end
33
+
34
+ describe Smartfm::Item, '#sentences' do
35
+ it "should return a Array of Smartfm::Sentence" do
36
+ smart.sentences.should be_a(Array)
37
+ smart.sentences.each do |sentence|
38
+ sentence.should be_a(Smartfm::Sentence)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,7 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
2
+
3
+ describe String do
4
+ it "should respond to length" do
5
+ "hoge".should respond_to(:length)
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
2
+
3
+ describe String do
4
+ it "should respond to length" do
5
+ "hoge".should respond_to(:length)
6
+ end
7
+ end
@@ -0,0 +1,90 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
2
+
3
+ matake = Smartfm::User.find('matake')
4
+
5
+ describe Smartfm::User do
6
+ it "should respond to attribute methods" do
7
+ Smartfm::User::ATTRIBUTES.each do |attr|
8
+ matake.should respond_to(attr)
9
+ end
10
+ Smartfm::User::Profile::ATTRIBUTES.each do |attr|
11
+ matake.profile.should respond_to(attr)
12
+ end
13
+ Smartfm::User::Study::ATTRIBUTES.each do |attr|
14
+ matake.study.should respond_to(attr)
15
+ 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
20
+ end
21
+ Smartfm::User::Study::TotalSummary::ATTRIBUTES.each do |attr|
22
+ matake.study.total_summary.should respond_to(attr)
23
+ end
24
+ end
25
+ end
26
+
27
+ describe Smartfm::User, '#items' do
28
+ it "should return a Array of Smartfm::Item or []" do
29
+ matake.items.should be_a(Array)
30
+ matake.items.each do |item|
31
+ item.should be_a(Smartfm::Item)
32
+ end
33
+ matake.items(:page => 10000000000).should be_empty
34
+ matake.items(:page => 10000000000).should_not be_nil
35
+ end
36
+ end
37
+
38
+ describe Smartfm::User, '#lists' do
39
+ it "should return a Array of Smartfm::List or []" do
40
+ matake.lists.should be_a(Array)
41
+ matake.lists.each do |list|
42
+ list.should be_a(Smartfm::List)
43
+ end
44
+ matake.lists(:page => 10000000000).should be_empty
45
+ matake.lists(:page => 10000000000).should_not be_nil
46
+ end
47
+ end
48
+
49
+ describe Smartfm::User, '#friends' do
50
+ it "should return a Array of Smartfm::User" do
51
+ matake.friends.should be_a(Array)
52
+ matake.friends.each do |friend|
53
+ friend.should be_a(Smartfm::User)
54
+ end
55
+ end
56
+ end
57
+
58
+ describe Smartfm::User, '#followers' do
59
+ it "should return a Array of Smartfm::User" do
60
+ matake.followers.should be_a(Array)
61
+ matake.followers.each do |follower|
62
+ follower.should be_a(Smartfm::User)
63
+ end
64
+ end
65
+ end
66
+
67
+ describe Smartfm::User, '#study' do
68
+ 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)
73
+ matake.study(:application => 'fuckin_windows').should be_nil
74
+ end
75
+ end
76
+
77
+ describe Smartfm::User::Study, '#results' do
78
+ 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|
81
+ result.should be_a(Smartfm::User::Study::Result)
82
+ end
83
+ end
84
+ end
85
+
86
+ describe Smartfm::User::Study, '#total_summary' do
87
+ it "should return a Array of Smartfm::User::Study::TotalSummary" do
88
+ matake.study.total_summary.should be_a(Smartfm::User::Study::TotalSummary)
89
+ end
90
+ end
@@ -0,0 +1,9 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
2
+
3
+ subclasses = [ Smartfm::RestClient::Item, Smartfm::RestClient::List, Smartfm::RestClient::Sentence, Smartfm::RestClient::User ]
4
+
5
+ describe Smartfm::RestClient::Base do
6
+ it "should be a Class" do
7
+ true
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
2
+
3
+ describe Smartfm::RestClient::Item, '::ACTIONS' do
4
+ it "should be a Hash" do
5
+ Smartfm::RestClient::Item::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::List, '::ACTIONS' do
4
+ it "should be a Hash" do
5
+ Smartfm::RestClient::List::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::Sentence, '::ACTIONS' do
4
+ it "should be a Hash" do
5
+ Smartfm::RestClient::Sentence::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::User::ACTIONS.should be_a(Hash)
6
+ end
7
+ end
@@ -0,0 +1,18 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ gem 'rspec'
6
+ require 'spec'
7
+ end
8
+ $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")))
9
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'smartfm')
10
+
11
+ def be_a(klass)
12
+ be_is_a(klass)
13
+ end
14
+
15
+ def rand_string(length = 100)
16
+ chars = ('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a
17
+ Array.new(length){ chars[rand(chars.size)] }.join
18
+ end
@@ -0,0 +1,8 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ require "test/unit"
4
+ class SmartfmTest < Test::Unit::TestCase
5
+ def test_truth
6
+ true
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../lib/smartfm'
3
+
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: smartfm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - nov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-03-05 00:00:00 +09:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: json
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: oauth
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ description: A rubygem for smart.fm APIs
36
+ email: developer@smart.fm
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - README
43
+ - ChangeLog
44
+ files:
45
+ - README
46
+ - ChangeLog
47
+ - Rakefile
48
+ - test/smartfm_test.rb
49
+ - test/test_helper.rb
50
+ - spec/ext
51
+ - spec/ext/hash_spec.rb
52
+ - spec/smartfm
53
+ - spec/smartfm/core
54
+ - spec/smartfm/core/auth_spec.rb
55
+ - spec/smartfm/core/config_spec.rb
56
+ - spec/smartfm/core/version_spec.rb
57
+ - spec/smartfm/model
58
+ - spec/smartfm/model/base_spec.rb
59
+ - spec/smartfm/model/item_spec.rb
60
+ - spec/smartfm/model/list_spec.rb
61
+ - spec/smartfm/model/sentence_spec.rb
62
+ - spec/smartfm/model/user_spec.rb
63
+ - spec/smartfm/rest_client
64
+ - spec/smartfm/rest_client/base_spec.rb
65
+ - spec/smartfm/rest_client/item_spec.rb
66
+ - spec/smartfm/rest_client/list_spec.rb
67
+ - spec/smartfm/rest_client/sentence_spec.rb
68
+ - spec/smartfm/rest_client/user_spec.rb
69
+ - spec/spec_helper.rb
70
+ - lib/ext
71
+ - lib/ext/hash.rb
72
+ - lib/smartfm
73
+ - lib/smartfm/core
74
+ - lib/smartfm/core/auth.rb
75
+ - lib/smartfm/core/config.rb
76
+ - lib/smartfm/core/version.rb
77
+ - lib/smartfm/core.rb
78
+ - lib/smartfm/model
79
+ - lib/smartfm/model/base.rb
80
+ - lib/smartfm/model/item.rb
81
+ - lib/smartfm/model/list.rb
82
+ - lib/smartfm/model/sentence.rb
83
+ - lib/smartfm/model/user.rb
84
+ - lib/smartfm/model.rb
85
+ - lib/smartfm/rest_client
86
+ - lib/smartfm/rest_client/base.rb
87
+ - lib/smartfm/rest_client/item.rb
88
+ - lib/smartfm/rest_client/list.rb
89
+ - lib/smartfm/rest_client/sentence.rb
90
+ - lib/smartfm/rest_client/user.rb
91
+ - lib/smartfm/rest_client.rb
92
+ - lib/smartfm.rb
93
+ - examples/pure_ruby.rb
94
+ has_rdoc: true
95
+ homepage: http://smartfm.rubyforge.org
96
+ post_install_message:
97
+ rdoc_options:
98
+ - --title
99
+ - smartfm documentation
100
+ - --charset
101
+ - utf-8
102
+ - --opname
103
+ - index.html
104
+ - --line-numbers
105
+ - --main
106
+ - README
107
+ - --inline-source
108
+ - --exclude
109
+ - ^(examples|extras)/
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: "0"
117
+ version:
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: "0"
123
+ version:
124
+ requirements: []
125
+
126
+ rubyforge_project: smartfm
127
+ rubygems_version: 1.3.1
128
+ signing_key:
129
+ specification_version: 2
130
+ summary: A rubygem for smart.fm APIs
131
+ test_files:
132
+ - test/smartfm_test.rb