Class: AssayDepot::Client
- Inherits:
-
Object
- Object
- AssayDepot::Client
- Defined in:
- lib/assaydepot/client.rb
Instance Method Summary collapse
- #get(id, params = {}) ⇒ Object
- #get_url(id, params = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #search(query, facets, params = {}) ⇒ Object
- #search_url(params = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
6 7 8 |
# File 'lib/assaydepot/client.rb', line 6 def initialize(={}) @search_type = [:search_type] || "wares" end |
Instance Method Details
#get(id, params = {}) ⇒ Object
27 28 29 30 |
# File 'lib/assaydepot/client.rb', line 27 def get(id, params={}) params["access_token"] = AssayDepot.access_token JSON.parse(open(get_url(id, params)).read) end |
#get_url(id, params = {}) ⇒ Object
14 15 16 |
# File 'lib/assaydepot/client.rb', line 14 def get_url(id, params={}) "#{AssayDepot.url}/#{@search_type}/#{id}.json?#{params.collect { |k,v| "#{k}=#{v.to_s.gsub(" ","+")}"}.join("&")}" end |
#search(query, facets, params = {}) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/assaydepot/client.rb', line 18 def search(query, facets, params={}) params["access_token"] = AssayDepot.access_token params["q"] = query facets.map do |name,value| params["facets[#{name}][]"] = value end JSON.parse(open(search_url(params)).read) end |
#search_url(params = {}) ⇒ Object
10 11 12 |
# File 'lib/assaydepot/client.rb', line 10 def search_url(params={}) "#{AssayDepot.url}/#{@search_type}.json?#{params.collect { |k,v| "#{k}=#{v.to_s.gsub(" ","+")}"}.join("&")}" end |