class Brainspace::Collection

Public Class Methods

all() click to toggle source
# File lib/brainspace/collection.rb, line 19
def self.all
  response = Faraday.get("#{Brainspace.config.host}/collections", apikey: Brainspace.apikey)
  result = JSON.parse(response.body)
  collections = Hashie::Mash.new(result).collections
  collections.map { |collection| new(collection) }
rescue
  []
end
discovery(id) click to toggle source
# File lib/brainspace/collection.rb, line 36
def self.discovery(id)
  response = Faraday.get("#{Brainspace.config.host}/discovery/collection/#{id}", apikey: Brainspace.apikey)
  result = JSON.parse(response.body)
  articles = Hashie::Mash.new(result).data.article_results.articles
  articles.map { |article| Brainspace::Article.new(article) }
rescue
  []
end
find(id) click to toggle source
# File lib/brainspace/collection.rb, line 28
def self.find(id)
  response = Faraday.get("#{Brainspace.config.host}/collections/#{id}", apikey: Brainspace.apikey)
  result = Hashie::Mash.new(JSON.parse(response.body))
  new(result.collection)
rescue
  nil
end
new(attributes) click to toggle source
# File lib/brainspace/collection.rb, line 7
def initialize(attributes)
  @mash = attributes
end

Public Instance Methods

discovery() click to toggle source
# File lib/brainspace/collection.rb, line 15
def discovery
  Brainspace::Collection.discovery(@mash.id)
end
method_missing(method_sym, *arguments, &block) click to toggle source
# File lib/brainspace/collection.rb, line 11
def method_missing(method_sym, *arguments, &block)
  @mash.send(method_sym, *arguments)
end