class NotionRuby::ResourceProxy
ResourceProxy
lets us create a virtual proxy for any API
resource, utilizing method_missing
to handle passing messages to the real object
Attributes
connection[R]
Make connection and path_prefix
readable
id[R]
Make connection and path_prefix
readable
params[R]
Make connection and path_prefix
readable
path_prefix[R]
Make connection and path_prefix
readable
Public Class Methods
new(connection, path_prefix, params = {}, &block)
click to toggle source
Instantiates proxy with the connection and path_prefix
connection - [NotionRuby::Connection] object path_prefix
- String param - Hash or String
# File lib/notion_ruby/resource_proxy.rb, line 27 def initialize(connection, path_prefix, params = {}, &block) unless params.is_a? Hash @id = params params = {} end @connection = connection @path_prefix = path_prefix @params = params @block = block if block subject if block end
Public Instance Methods
build_prefix(first_argument, endpoint)
click to toggle source
# File lib/notion_ruby/resource_proxy.rb, line 74 def build_prefix(first_argument, endpoint) if !first_argument.is_a?(Hash) && !first_argument.nil? File.join(path_prefix, "/#{endpoint}/#{first_argument}") else File.join(path_prefix, "/#{endpoint}") end end
method_missing(message, *args, &block)
click to toggle source
Method_missing takes any message passed to the ResourceProxy
and sends it to the real object
message - Message object args* - Arguments passed
# File lib/notion_ruby/resource_proxy.rb, line 46 def method_missing(message, *args, &block) subject.send(message, *args, &block) end
raw()
click to toggle source
Raw is the raw response from the faraday Use this if you need access to status codes or header values
# File lib/notion_ruby/resource_proxy.rb, line 58 def raw connection.get(path_prefix) { |req| req.params.merge! params } end
respond_to_missing?(symbol, _include_private)
click to toggle source
# File lib/notion_ruby/resource_proxy.rb, line 50 def respond_to_missing?(symbol, _include_private) subject.keys(symbol) end
subject()
click to toggle source
Subject is the response body parsed as json
Returns json
# File lib/notion_ruby/resource_proxy.rb, line 67 def subject @subject ||= connection.get(path_prefix) do |req| req.params.merge! params @block&.call(req) end.body end