Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
module ActionSprout::Facebook
  class HTTPService
    def get(url, options, graph)
      with_error_handling do
        build_response(HTTParty.get(url, options), graph)
      end
    end

    def post(url, options, graph)
      with_error_handling do
        build_response(HTTParty.post(url, options), graph)
      end
    end

    private

    def build_response(httparty_response, graph)
      headers = headers_from_httparty httparty_response
      Response.new httparty_response.code, httparty_response.parsed_response, headers, graph
    end

    def with_error_handling
      yield
    rescue JSON::ParserError => e
      raise ActionSprout::Facebook::RetriableError.new("Facebook Error", e)
    end

    def headers_from_httparty(httparty_response)
      headers_hash = httparty_response.headers.to_h
      headers_hash.each_with_object({}) do |(key, val), object|
        object[key] = val.first
      end
    end

  end
end