Module: Supplejack::Request
- Extended by:
- ActiveSupport::Concern
- Included in:
- Item, ItemRelation, Search, User, UserSet, UserSetRelation
- Defined in:
- lib/supplejack/request.rb
Instance Method Summary collapse
- #delete(path, params = {}, options = {}) ⇒ Object
- #get(path, params = {}, options = {}) ⇒ Object
- #post(path, params = {}, payload = {}, options = {}) ⇒ Object
- #put(path, params = {}, payload = {}, options = {}) ⇒ Object
Instance Method Details
#delete(path, params = {}, options = {}) ⇒ Object
45 46 47 48 49 |
# File 'lib/supplejack/request.rb', line 45 def delete(path, params={}, ={}) log_request(:delete, path, params, {}) do RestClient::Request.execute(:url => full_url(path, nil, params), :method => :delete, :timeout => timeout()) end end |
#get(path, params = {}, options = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/supplejack/request.rb', line 14 def get(path, params={}, ={}) params ||= {} url = full_url(path, [:format], params) started = Time.now payload = {:path => path, :params => params, :options => } begin result = RestClient::Request.execute(:url => url, :method => :get, :timeout => timeout()) result = JSON.parse(result) if result rescue StandardError => e payload[:exception] = [e.class.name, e.] raise e ensure duration = (Time.now - started)*1000 # Convert to miliseconds solr_request_params = result["search"]['solr_request_params'] if result && result['search'] @subscriber = Supplejack::LogSubscriber.new @subscriber.log_request(duration, payload, solr_request_params) end result end |
#post(path, params = {}, payload = {}, options = {}) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/supplejack/request.rb', line 37 def post(path, params={}, payload={}, ={}) payload ||= {} log_request(:post, path, params, payload) do response = RestClient::Request.execute(:url => full_url(path, nil, params), :method => :post, :payload => payload.to_json, :timeout => timeout(), :headers => {:content_type => :json, :accept => :json}) JSON.parse(response) rescue {}.to_json end end |
#put(path, params = {}, payload = {}, options = {}) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/supplejack/request.rb', line 51 def put(path, params={}, payload={}, ={}) payload ||= {} log_request(:put, path, params, payload) do response = RestClient::Request.execute(:url => full_url(path, nil, params), :method => :put, :payload => payload.to_json, :timeout => timeout(), :headers => {:content_type => :json, :accept => :json}) JSON.parse(response) rescue {}.to_json end end |