Class: FreebaseAPI::Session
- Inherits:
-
Object
- Object
- FreebaseAPI::Session
- Includes:
- HTTParty
- Defined in:
- lib/freebase_api/session.rb
Constant Summary collapse
- API_URL =
URIs of the Freebase API
"https://www.googleapis.com/freebase/v1"
- SANDBOX_API_URL =
"https://www.googleapis.com/freebase/v1sandbox"
- DEFAULT_LIMIT =
Freebase default values
10
- DEFAULT_LANGUAGE =
:en
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#query_options ⇒ Object
readonly
Returns the value of attribute query_options.
Instance Method Summary collapse
-
#image(id, options = {}) ⇒ Hash
Execute a Image Service query.
-
#initialize(options = {}) ⇒ Session
constructor
A new instance of Session.
-
#mqlread(query, options = {}) ⇒ Hash
Execute a MQL read query.
-
#search(query, options = {}) ⇒ Hash
Execute a Search query.
-
#topic(id, options = {}) ⇒ Hash
Execute a Topic query.
Constructor Details
#initialize(options = {}) ⇒ Session
Returns a new instance of Session.
19 20 21 22 23 24 25 |
# File 'lib/freebase_api/session.rb', line 19 def initialize(={}) = { :env => :stable, :query_options => { :limit => DEFAULT_LIMIT, :lang => DEFAULT_LANGUAGE } }.deep_merge() @env = [:env] @key = [:key] || ENV['GOOGLE_API_KEY'] @query_options = [:query_options] @proxy_options = ([:proxy]) end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
9 10 11 |
# File 'lib/freebase_api/session.rb', line 9 def env @env end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
9 10 11 |
# File 'lib/freebase_api/session.rb', line 9 def key @key end |
#query_options ⇒ Object (readonly)
Returns the value of attribute query_options.
9 10 11 |
# File 'lib/freebase_api/session.rb', line 9 def @query_options end |
Instance Method Details
#image(id, options = {}) ⇒ Hash
Execute a Image Service query
68 69 70 71 |
# File 'lib/freebase_api/session.rb', line 68 def image(id, ={}) params = get(surl('image') + id, params).body end |
#mqlread(query, options = {}) ⇒ Hash
Execute a MQL read query
33 34 35 36 37 |
# File 'lib/freebase_api/session.rb', line 33 def mqlread(query, ={}) params = { :query => query.to_json, :lang => "/lang/#{@query_options[:lang]}", :limit => @query_options[:limit] }.merge() response = get(surl('mqlread'), params, format: :json) response['result'] end |
#search(query, options = {}) ⇒ Hash
Execute a Search query
45 46 47 48 49 |
# File 'lib/freebase_api/session.rb', line 45 def search(query, ={}) params = { :query => query, :lang => @query_options[:lang], :limit => @query_options[:limit] }.merge() response = get(surl('search'), params, format: :json) response['result'] end |
#topic(id, options = {}) ⇒ Hash
Execute a Topic query
57 58 59 60 |
# File 'lib/freebase_api/session.rb', line 57 def topic(id, ={}) params = { :lang => @query_options[:lang], :limit => @query_options[:limit] }.merge() get(surl('topic') + id, params, format: :json).parsed_response end |