nov-smartfm 0.4.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 +43 -0
  2. data/README +45 -0
  3. data/Rakefile +155 -0
  4. data/examples/pure_ruby.rb +119 -0
  5. data/lib/ext/hash.rb +52 -0
  6. data/lib/smartfm/core/auth.rb +39 -0
  7. data/lib/smartfm/core/config.rb +51 -0
  8. data/lib/smartfm/core/version.rb +14 -0
  9. data/lib/smartfm/core.rb +3 -0
  10. data/lib/smartfm/model/base.rb +26 -0
  11. data/lib/smartfm/model/item.rb +178 -0
  12. data/lib/smartfm/model/list.rb +138 -0
  13. data/lib/smartfm/model/sentence.rb +118 -0
  14. data/lib/smartfm/model/user.rb +112 -0
  15. data/lib/smartfm/model.rb +5 -0
  16. data/lib/smartfm/rest_client/base.rb +194 -0
  17. data/lib/smartfm/rest_client/item.rb +14 -0
  18. data/lib/smartfm/rest_client/list.rb +15 -0
  19. data/lib/smartfm/rest_client/sentence.rb +12 -0
  20. data/lib/smartfm/rest_client/user.rb +14 -0
  21. data/lib/smartfm/rest_client.rb +8 -0
  22. data/lib/smartfm.rb +16 -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,194 @@
1
+ require 'timeout'
2
+
3
+ class Smartfm::RestClient::Base
4
+
5
+ class RESTError < Exception
6
+ attr_accessor :code, :message
7
+
8
+ def initialize(params = {})
9
+ self.code = params[:code]
10
+ self.message = params[:message]
11
+ end
12
+
13
+ def to_s
14
+ "HTTP #{@code}: #{@message}"
15
+ end
16
+ end
17
+
18
+ def self.valid_action?(action) ; self::ACTIONS.keys.include? action.to_sym end
19
+ def self.path(action) ; self::ACTIONS[action.to_sym][:path] end
20
+ def self.http_method(action) ; self::ACTIONS[action.to_sym][:http_method] || :get end
21
+
22
+ def self.method_missing(action, *args)
23
+ # GET methods are handled here
24
+ # POST and DELETE methods should be implemented in each class
25
+ super unless self.valid_action?(action)
26
+ case self.http_method(action)
27
+ when :get
28
+ if args[0].is_a?(Smartfm::Auth)
29
+ path, params = path_with_params(self.path(action), args[1])
30
+ http_get_with_auth(auth(args[0]), path, params)
31
+ else
32
+ path, params = path_with_params(self.path(action), args[0])
33
+ http_get(path, params)
34
+ end
35
+ when :post
36
+ path, params = path_with_params(self.path(action), args[1])
37
+ http_post(auth(args[0]), path, params)
38
+ when :delete
39
+ path, params = path_with_params(self.path(action), args[1])
40
+ http_delete(auth(args[0]), path, params)
41
+ end
42
+ end
43
+
44
+ private
45
+
46
+ def self.config; Smartfm::Config end
47
+
48
+ def self.auth(auth)
49
+ if auth.is_a?(Smartfm::Auth)
50
+ auth
51
+ else
52
+ raise ArgumentError.new("Authorized Smartfm::Auth instance is required")
53
+ end
54
+ end
55
+
56
+ def self.api_key_required
57
+ raise ArgumentError.new("smart.fm API key is required") if self.config.api_key == ''
58
+ end
59
+
60
+ def self.raise_rest_error(response)
61
+ raise RESTError.new(:code => response.code, :message => response.message)
62
+ end
63
+
64
+ def self.handle_rest_response(response, format)
65
+ raise_rest_error(response) unless response.is_a?(Net::HTTPSuccess)
66
+ case format
67
+ when :json
68
+ handle_json_response(response.body)
69
+ when :nothing
70
+ # success => nothing / failure => json error
71
+ begin
72
+ handle_json_response(response.body)
73
+ rescue Exception => e
74
+ e.is_a?(RESTError) ? raise(e) : :success
75
+ end
76
+ else
77
+ begin
78
+ handle_json_response(response.body)
79
+ rescue Exception => e
80
+ e.is_a?(RESTError) ? raise(e) : response.body
81
+ end
82
+ end
83
+ end
84
+
85
+ def self.handle_json_response(json_response)
86
+ hash = JSON.parse(json_response)
87
+ unless (hash['error'].nil? rescue :success) # success response may be Array, not Hash.
88
+ if hash['error']['code'] == 404
89
+ return nil
90
+ else
91
+ raise RESTError.new(:code => hash['error']['code'], :message => hash['error']['message'])
92
+ end
93
+ end
94
+ hash
95
+ end
96
+
97
+ def self.http_header
98
+ @@http_header ||= {
99
+ 'User-Agent' => "#{self.config.application_name} v#{Smartfm::Version.to_version} [#{self.config.user_agent}]",
100
+ 'Accept' => 'text/x-json',
101
+ 'X-smartfm-Gem-Client' => self.config.application_name,
102
+ 'X-smartfm-Gem-Client-Version' => self.config.application_version,
103
+ 'X-smartfm-Gem-Client-URL' => self.config.application_url,
104
+ }
105
+ end
106
+
107
+ def self.http_connect
108
+ http = Net::HTTP.new(self.config.api_host, self.config.api_port)
109
+ http.start do |conn|
110
+ request, format = yield
111
+ begin
112
+ timeout(self.config.timeout) do
113
+ response = conn.request(request)
114
+ handle_rest_response(response, format)
115
+ end
116
+ rescue
117
+ raise RESTError.new(:code => 408, :message => "smart.fm Gem Timeout (#{self.config.timeout} [sec])")
118
+ end
119
+ end
120
+ end
121
+
122
+ def self.path_with_params(path, params = {})
123
+ path_with_params = path.clone
124
+ unless params.empty?
125
+ params.each do |key, value|
126
+ if path_with_params=~/__#{key}__/
127
+ path_with_params.sub!(/__#{key}__/, URI.encode(value.to_s))
128
+ params.delete(key)
129
+ end
130
+ end
131
+ end
132
+ return path_with_params, params
133
+ end
134
+
135
+ def self.http_get(path, params = {})
136
+ http_connect do
137
+ params.merge!(:api_key => self.config.api_key) unless self.config.api_key == ''
138
+ path = (params.size > 0) ? "#{path}?#{params.to_http_str}" : path
139
+ get_req = Net::HTTP::Get.new(path, http_header)
140
+ [get_req, :json]
141
+ end
142
+ end
143
+
144
+ def self.http_get_with_auth(auth, path, params = {})
145
+ params.merge!(:api_key => self.config.api_key) unless self.config.api_key == ''
146
+ path = (params.size > 0) ? "#{path}?#{params.to_http_str}" : path
147
+ case auth.mode
148
+ when :oauth
149
+ response = auth.auth_token.get(path, http_header)
150
+ handle_rest_response(response, :text)
151
+ when :basic_auth
152
+ http_connect do
153
+ get_req = Net::HTTP::Get.new(path, http_header)
154
+ get_req.basic_auth(auth.account.username, auth.account.password)
155
+ [get_req, :text]
156
+ end
157
+ end
158
+ end
159
+
160
+ def self.http_post(auth, path, params = {})
161
+ self.api_key_required
162
+ params.merge!(:api_key => self.config.api_key)
163
+ case auth.mode
164
+ when :oauth
165
+ response = auth.auth_token.post(path, params, http_header)
166
+ handle_rest_response(response, :text)
167
+ when :basic_auth
168
+ http_connect do
169
+ post_req = Net::HTTP::Post.new(path, http_header)
170
+ post_req.body = params.to_http_str
171
+ post_req.basic_auth(auth.account.username, auth.account.password)
172
+ [post_req, :text]
173
+ end
174
+ end
175
+ end
176
+
177
+ def self.http_delete(auth, path, params = {})
178
+ self.api_key_required
179
+ params.merge!(:api_key => self.config.api_key)
180
+ path = "#{path}?#{params.to_http_str}"
181
+ case auth.mode
182
+ when :oauth
183
+ response = auth.auth_token.delete(path, params.stringfy_keys!.stringfy_values!)
184
+ handle_rest_response(response, :nothing)
185
+ when :basic_auth
186
+ http_connect do
187
+ delete_req = Net::HTTP::Delete.new(path, http_header)
188
+ delete_req.basic_auth(auth.account.username, auth.account.password)
189
+ [delete_req, :nothing]
190
+ end
191
+ end
192
+ end
193
+
194
+ end
@@ -0,0 +1,14 @@
1
+ class Smartfm::RestClient::Item < Smartfm::RestClient::Base
2
+
3
+ ACTIONS = {
4
+ :recent => { :path => '/items' },
5
+ :find => { :path => '/items/__id__' },
6
+ :matching => { :path => '/items/matching/__keyword__' },
7
+ :extract => { :path => '/items/extract', },
8
+ :create => { :path => '/items', :http_method => :post },
9
+ :add_image => { :path => '/items/__id__/images', :http_method => :post },
10
+ :add_sound => { :path => '/items/__id__/sounds', :http_method => :post },
11
+ :add_tags => { :path => '/items/__id__/tags', :http_method => :post }
12
+ }
13
+
14
+ end
@@ -0,0 +1,15 @@
1
+ class Smartfm::RestClient::List < Smartfm::RestClient::Base
2
+
3
+ ACTIONS = {
4
+ :recent => { :path => '/lists' },
5
+ :find => { :path => '/lists/__id__' },
6
+ :items => { :path => '/lists/__id__/items' },
7
+ :sentences => { :path => '/lists/__id__/sentences' },
8
+ :matching => { :path => '/lists/matching/__keyword__' },
9
+ :create => { :path => '/lists', :http_method => :post },
10
+ :delete => { :path => '/lists/__id__', :http_method => :delete },
11
+ :add_item => { :path => '/lists/__list_id__/items', :http_method => :post },
12
+ :delete_item => { :path => '/lists/__list_id__/items/__id__', :http_method => :delete }
13
+ }
14
+
15
+ end
@@ -0,0 +1,12 @@
1
+ class Smartfm::RestClient::Sentence < Smartfm::RestClient::Base
2
+
3
+ ACTIONS = {
4
+ :recent => { :path => '/sentences' },
5
+ :find => { :path => '/sentences/__id__' },
6
+ :matching => { :path => '/sentences/matching/__keyword__' },
7
+ :create => { :path => '/sentences', :http_method => :post },
8
+ :add_image => { :path => '/sentences/__id__/images', :http_method => :post },
9
+ :add_sound => { :path => '/sentences/__id__/sounds', :http_method => :post }
10
+ }
11
+
12
+ end
@@ -0,0 +1,14 @@
1
+ class Smartfm::RestClient::User < Smartfm::RestClient::Base
2
+
3
+ ACTIONS = {
4
+ :find => { :path => '/users/__username__' },
5
+ :lists => { :path => '/users/__username__/lists' },
6
+ :items => { :path => '/users/__username__/items' },
7
+ :friends => { :path => '/users/__username__/friends' },
8
+ :followers => { :path => '/users/__username__/followers' },
9
+ :study_results => { :path => '/users/__username__/study_results/__application__' },
10
+ :matching => { :path => '/users/matching/__keyword__' },
11
+ :username => { :path => '/sessions' }
12
+ }
13
+
14
+ end
@@ -0,0 +1,8 @@
1
+ module Smartfm::RestClient
2
+ end
3
+
4
+ require 'smartfm/rest_client/base'
5
+ require 'smartfm/rest_client/user'
6
+ require 'smartfm/rest_client/list'
7
+ require 'smartfm/rest_client/item'
8
+ require 'smartfm/rest_client/sentence'
data/lib/smartfm.rb ADDED
@@ -0,0 +1,16 @@
1
+ module Smartfm
2
+ end
3
+
4
+ require 'date'
5
+ require 'net/https'
6
+ require 'uri'
7
+
8
+ require 'rubygems'
9
+ require 'json'
10
+
11
+ require 'ext/hash'
12
+ require 'smartfm/core'
13
+ require 'smartfm/rest_client'
14
+ require 'smartfm/model'
15
+
16
+ Smartfm::Config.init
@@ -0,0 +1,11 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ describe Hash, "#to_http_str" do
4
+ before do
5
+ @params = {:page => 3, :per_page => 100}
6
+ end
7
+ it "should return http_parameter as String" do
8
+ @params.to_http_str.should be_a(String)
9
+ @params.to_http_str.should match(/^(page=3&per_page=100|per_page=100&page=3)$/)
10
+ end
11
+ end
@@ -0,0 +1,39 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
2
+
3
+ basic_auth_params = { :username => 'matake', :password => 'password' }
4
+ oauth_params = { :token => '1a2b3c4d5', :secret => 'z0y9x8w7v6' }
5
+
6
+ describe Smartfm::Auth, '.new' do
7
+ before do
8
+ @basic_auth = Smartfm::Auth.new(basic_auth_params)
9
+ @oauth = Smartfm::Auth.new(oauth_params)
10
+ end
11
+
12
+ it "should choose #{:basic_auth} mode" do
13
+ @basic_auth.mode.should equal(:basic_auth)
14
+ @basic_auth.should respond_to(:account)
15
+ @basic_auth.account.should respond_to(:username)
16
+ @basic_auth.account.should respond_to(:password)
17
+ @basic_auth.account.should_not respond_to(:token)
18
+ @basic_auth.account.should_not respond_to(:secret)
19
+ end
20
+
21
+ it "should choose #{:oauth} mode" do
22
+ @oauth.mode.should equal(:oauth)
23
+ @oauth.should respond_to(:auth_token)
24
+ @oauth.auth_token.should respond_to(:token)
25
+ @oauth.auth_token.should respond_to(:secret)
26
+ @oauth.auth_token.should_not respond_to(:username)
27
+ @oauth.auth_token.should_not respond_to(:password)
28
+ end
29
+ end
30
+
31
+ describe Smartfm::Auth, '.consumer' do
32
+ it "should be an instance of OAuth::Consumer" do
33
+ Smartfm::Auth.consumer.should be_a(OAuth::Consumer)
34
+ end
35
+
36
+ it "should be for http://api.smart.fm" do
37
+ Smartfm::Auth.consumer.site.should eql("http://api.smart.fm")
38
+ end
39
+ end
@@ -0,0 +1,34 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
2
+
3
+ describe Smartfm::Config, ".init" do
4
+ before do
5
+ Smartfm::Config.init
6
+ end
7
+
8
+ it "should return init config" do
9
+ Smartfm::Config.init.should equal(Smartfm::Config.instance)
10
+ end
11
+
12
+ it "should change config with block" do
13
+ Smartfm::Config.init do |conf|
14
+ Smartfm::Config::ATTRIBUTES.each do |method|
15
+ conf.send("#{method}=", "fuckin_windows!")
16
+ end
17
+ end
18
+ Smartfm::Config::ATTRIBUTES.each do |method|
19
+ Smartfm::Config.send("#{method}").should eql("fuckin_windows!")
20
+ end
21
+ end
22
+
23
+ after do
24
+ Smartfm::Config.init
25
+ end
26
+ end
27
+
28
+ (Smartfm::Config::ATTRIBUTES + [:base_url, :api_base_url]).each do |method|
29
+ describe Smartfm::Config, ".#{method}" do
30
+ it "should be same with Smartfm::Config.instance.#{method}" do
31
+ Smartfm::Config.send(method).should eql(Smartfm::Config.instance.send(method))
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,19 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
2
+
3
+ version_params = [Smartfm::Version::MAJOR, Smartfm::Version::MINOR, Smartfm::Version::REVISION]
4
+ expected = {
5
+ :version => version_params.join('.'),
6
+ :name => version_params.join('_')
7
+ }
8
+
9
+ describe Smartfm::Version, ".to_version" do
10
+ it "should return #{expected[:version]}" do
11
+ Smartfm::Version.to_version.should eql(expected[:version])
12
+ end
13
+ end
14
+
15
+ describe Smartfm::Version, ".to_name" do
16
+ it "should return #{expected[:name]}" do
17
+ Smartfm::Version.to_name.should eql(expected[:name])
18
+ end
19
+ end
@@ -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
+