Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add sessions API support & fixed extract API bugs

  • Loading branch information...
commit 511dc6cc1f141fa87f2a8bf38ce1f26c3bf84e5b 1 parent 54f08ae
nov authored
View
3  examples/pure_ruby.rb
@@ -64,7 +64,8 @@
@recent_items = Smartfm::Item.recent(:include_sentences => true)
@item = Smartfm::Item.find(437525)
@matched_items = Smartfm::Item.matching('record', :include_sentences => true)
-@items = Smartfm::Item.extract("sometimes, often, electrical")
+@items_hash = Smartfm::Item.extract("sometimes, often, electrical")
+@items = Smartfm::Item.extract("sometimes, often, electrical", :words_only => false)
@items.first.sentences
## Sentence API
View
6 lib/smartfm/model/item.rb
@@ -54,7 +54,11 @@ def self.matching(keyword, params = {})
def self.extract(text, params = {})
params[:text] = text
hash = Smartfm::RestClient::Item.extract(params)
- self.deserialize(hash) || []
+ if params[:words_only] == false
+ self.deserialize(hash) || []
+ else
+ hash
+ end
end
def self.create(auth, params = {})
View
4 lib/smartfm/model/user.rb
@@ -73,6 +73,10 @@ def self.matching(keyword, params = {})
self.deserialize(hash) || []
end
+ def self.username(auth)
+ Smartfm::RestClient::User.username(auth, {})
+ end
+
def initialize(params)
@profile = Profile.new(params[:profile])
@username = params[:username]
View
25 lib/smartfm/rest_client/base.rb
@@ -25,8 +25,13 @@ def self.method_missing(action, *args)
super unless self.valid_action?(action)
case self.http_method(action)
when :get
- path, params = path_with_params(self.path(action), args[0])
- http_get(path, params)
+ if args[0].is_a?(Smartfm::Auth)
+ path, params = path_with_params(self.path(action), args[1])
+ http_get_with_auth(auth(args[0]), path, params)
+ else
+ path, params = path_with_params(self.path(action), args[0])
+ http_get(path, params)
+ end
when :post
path, params = path_with_params(self.path(action), args[1])
http_post(auth(args[0]), path, params)
@@ -136,6 +141,22 @@ def self.http_get(path, params = {})
end
end
+ def self.http_get_with_auth(auth, path, params = {})
+ params.merge!(:api_key => self.config.api_key) unless self.config.api_key == ''
+ path = (params.size > 0) ? "#{path}?#{params.to_http_str}" : path
+ case auth.mode
+ when :oauth
+ response = auth.auth_token.get(path, http_header)
+ handle_rest_response(response, :text)
+ when :basic_auth
+ http_connect do
+ get_req = Net::HTTP::Get.new(path, http_header)
+ get_req.basic_auth(auth.account.username, auth.account.password)
+ [get_req, :text]
+ end
+ end
+ end
+
def self.http_post(auth, path, params = {})
self.api_key_required
params.merge!(:api_key => self.config.api_key)
View
3  lib/smartfm/rest_client/user.rb
@@ -7,7 +7,8 @@ class Smartfm::RestClient::User < Smartfm::RestClient::Base
:friends => { :path => '/users/__username__/friends' },
:followers => { :path => '/users/__username__/followers' },
:study_results => { :path => '/users/__username__/study_results/__application__' },
- :matching => { :path => '/users/matching/__keyword__' }
+ :matching => { :path => '/users/matching/__keyword__' },
+ :username => { :path => '/sessions' }
}
end
Please sign in to comment.
Something went wrong with that request. Please try again.