class StashAPI::Resource
Public Class Methods
add_resource_to_chain(index, resource, key = nil)
click to toggle source
# File lib/stash_api/resource.rb, line 39 def self.add_resource_to_chain(index, resource, key = nil) @@resources[index] = "#{resource}" @@resource_ids[index] = key end
create_resource(payload, options = {})
click to toggle source
# File lib/stash_api/resource.rb, line 18 def self.create_resource(payload, options = {}) raise "set a domain first 'StashAPI::Base.domain(<domain>)'" unless StashAPI::Options.option(:domain) options[:body] = payload.to_json options[:headers] = {'Content-Type' => 'application/json'} response = HTTP::Client.post resource_path, options reset_resource_chain response end
fetch(query = {})
click to toggle source
# File lib/stash_api/resource.rb, line 6 def self.fetch(query = {}) raise "set a domain first 'StashAPI::Base.domain(<domain>)'" unless StashAPI::Options.option(:domain) options = {} options[:query] = query response = HTTP::Client.get resource_path, options reset_resource_chain response end
raise_resource_key_missing()
click to toggle source
# File lib/stash_api/resource.rb, line 57 def self.raise_resource_key_missing raise 'previous resource has no key to allow chaining' end
reset_resource_chain()
click to toggle source
# File lib/stash_api/resource.rb, line 44 def self.reset_resource_chain @@resources = [] @@resource_ids = [] end
resource(pos)
click to toggle source
# File lib/stash_api/resource.rb, line 49 def self.resource(pos) @@resources[pos] end
resource_id(pos)
click to toggle source
# File lib/stash_api/resource.rb, line 53 def self.resource_id(pos) @@resource_ids[pos] end
resource_path()
click to toggle source
# File lib/stash_api/resource.rb, line 30 def self.resource_path path = '/api/1.0' for i in 0..@@resources.size path << "/#{@@resources[i]}" if @@resources[i] path << "/#{@@resource_ids[i]}" if @@resource_ids[i] end path end