smartfm 0.3.0 → 0.3.1

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.
data/ChangeLog CHANGED
@@ -35,4 +35,9 @@
35
35
  == 0.3.0
36
36
 
37
37
  * iKnow! => smart.fm
38
- * now, iKnow! is the name of Flash study application
38
+ * now, iKnow! is the name of Flash study application
39
+
40
+ == 0.3.1
41
+
42
+ * add sessions API support
43
+ * fixed extract API bugs
@@ -64,7 +64,8 @@ puts "# Item API Calls"
64
64
  @recent_items = Smartfm::Item.recent(:include_sentences => true)
65
65
  @item = Smartfm::Item.find(437525)
66
66
  @matched_items = Smartfm::Item.matching('record', :include_sentences => true)
67
- @items = Smartfm::Item.extract("sometimes, often, electrical")
67
+ @items_hash = Smartfm::Item.extract("sometimes, often, electrical")
68
+ @items = Smartfm::Item.extract("sometimes, often, electrical", :words_only => false)
68
69
  @items.first.sentences
69
70
 
70
71
  ## Sentence API
@@ -1,7 +1,7 @@
1
1
  module Smartfm::Version
2
2
  MAJOR = 0
3
3
  MINOR = 3
4
- REVISION = 0
4
+ REVISION = 1
5
5
  class << self
6
6
  def to_version
7
7
  "#{MAJOR}.#{MINOR}.#{REVISION}"
@@ -54,7 +54,11 @@ class Smartfm::Item < Smartfm::Base
54
54
  def self.extract(text, params = {})
55
55
  params[:text] = text
56
56
  hash = Smartfm::RestClient::Item.extract(params)
57
- self.deserialize(hash) || []
57
+ if params[:words_only] == false
58
+ self.deserialize(hash) || []
59
+ else
60
+ hash
61
+ end
58
62
  end
59
63
 
60
64
  def self.create(auth, params = {})
@@ -73,6 +73,10 @@ class Smartfm::User < Smartfm::Base
73
73
  self.deserialize(hash) || []
74
74
  end
75
75
 
76
+ def self.username(auth)
77
+ Smartfm::RestClient::User.username(auth, {})
78
+ end
79
+
76
80
  def initialize(params)
77
81
  @profile = Profile.new(params[:profile])
78
82
  @username = params[:username]
@@ -25,8 +25,13 @@ class Smartfm::RestClient::Base
25
25
  super unless self.valid_action?(action)
26
26
  case self.http_method(action)
27
27
  when :get
28
- path, params = path_with_params(self.path(action), args[0])
29
- http_get(path, params)
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
30
35
  when :post
31
36
  path, params = path_with_params(self.path(action), args[1])
32
37
  http_post(auth(args[0]), path, params)
@@ -136,6 +141,22 @@ class Smartfm::RestClient::Base
136
141
  end
137
142
  end
138
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
+
139
160
  def self.http_post(auth, path, params = {})
140
161
  self.api_key_required
141
162
  params.merge!(:api_key => self.config.api_key)
@@ -7,7 +7,8 @@ class Smartfm::RestClient::User < Smartfm::RestClient::Base
7
7
  :friends => { :path => '/users/__username__/friends' },
8
8
  :followers => { :path => '/users/__username__/followers' },
9
9
  :study_results => { :path => '/users/__username__/study_results/__application__' },
10
- :matching => { :path => '/users/matching/__keyword__' }
10
+ :matching => { :path => '/users/matching/__keyword__' },
11
+ :username => { :path => '/sessions' }
11
12
  }
12
13
 
13
14
  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.3.0
4
+ version: 0.3.1
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-03-05 00:00:00 +09:00
12
+ date: 2009-03-06 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency