Module: Graphiti::Resource::Remote
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/graphiti/resource/remote.rb
Instance Method Summary collapse
- #before_resolve(scope, query) ⇒ Object
- #destroy(*args) ⇒ Object
- #make_request(url) ⇒ Object
- #remote_url ⇒ Object
-
#request_headers ⇒ Object
Forward all headers.
- #save(model, meta) ⇒ Object
Instance Method Details
#before_resolve(scope, query) ⇒ Object
34 35 36 37 |
# File 'lib/graphiti/resource/remote.rb', line 34 def before_resolve(scope, query) scope[:params] = Util::RemoteParams.generate(self, query, scope[:foreign_key]) scope end |
#destroy(*args) ⇒ Object
30 31 32 |
# File 'lib/graphiti/resource/remote.rb', line 30 def destroy(*args) raise Errors::RemoteWrite.new(self.class) end |
#make_request(url) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/graphiti/resource/remote.rb', line 56 def make_request(url) headers = request_headers.dup headers["Content-Type"] = "application/vnd.api+json" faraday.get(url, nil, headers) do |req| yield req if block_given? # for super do ... end req..timeout = timeout if timeout req..open_timeout = open_timeout if open_timeout end end |
#remote_url ⇒ Object
52 53 54 |
# File 'lib/graphiti/resource/remote.rb', line 52 def remote_url self.class.remote_url end |
#request_headers ⇒ Object
Forward all headers
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/graphiti/resource/remote.rb', line 40 def request_headers {}.tap do |headers| # TODO: Maybe handle this in the Rails integration if defined?(::Rails) && context raw = context.request.headers.to_h if (auth = raw["HTTP_AUTHORIZATION"]) headers["Authorization"] = auth end end end end |
#save(model, meta) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/graphiti/resource/remote.rb', line 22 def save(model, ) if [:attributes].except(:id) == {} && [:method] == :update model else raise Errors::RemoteWrite.new(self.class) end end |