module SecureShare::Request

Public Instance Methods

get(path, options={}) click to toggle source
# File lib/secureshare/request.rb, line 7
def get path, options={}
  resource = RestClient::Resource.new "#{config.url}#{path}", options
  response = resource.get :authorization => %{Token token="#{config.api_secret}", key="#{config.api_key}"}, :content_type => :json, :accept => :json
  parse_response response
end
post(path, options={}) click to toggle source
# File lib/secureshare/request.rb, line 13
def post path, options={}
  resource = RestClient::Resource.new "#{config.url}#{path}"
  response = resource.post options, {:authorization => %{Token token="#{config.api_secret}", key="#{config.api_key}"}, :content_type => :json, :accept => :json}
  parse_response response
end

Private Instance Methods

parse_response(response) click to toggle source
# File lib/secureshare/request.rb, line 21
def parse_response response
  response_object = JSON.parse(response.body)
  if response_object.is_a?(Enumerable)
    response_object.map do |object|
      OpenStruct.new(object)
    end
  else
    OpenStruct.new(response_object)
  end
end