Module: Sanity::Http::Query
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#resource_klass ⇒ Object
readonly
Returns the value of attribute resource_klass.
-
#result_wrapper ⇒ Object
readonly
Returns the value of attribute result_wrapper.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#resource_klass ⇒ Object (readonly)
Returns the value of attribute resource_klass.
24 25 26 |
# File 'lib/sanity/http/query.rb', line 24 def resource_klass @resource_klass end |
#result_wrapper ⇒ Object (readonly)
Returns the value of attribute result_wrapper.
24 25 26 |
# File 'lib/sanity/http/query.rb', line 24 def result_wrapper @result_wrapper end |
Class Method Details
.included(base) ⇒ Object
11 12 13 14 15 |
# File 'lib/sanity/http/query.rb', line 11 def included(base) base.extend(ClassMethods) base.extend(Forwardable) base.delegate(%i[project_id api_version dataset token api_subdomain] => :"Sanity.config") end |
Instance Method Details
#call ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/sanity/http/query.rb', line 33 def call http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = uri.scheme == "https" request = Module.const_get("Net::HTTP::#{method.to_s.classify}").new(uri, headers) request.body = request_body http.request(request).then do |result| data = JSON.parse(result.body) block_given? ? yield(result_wrapper.call(data)) : result_wrapper.call(data) end end |