Class: Kiita::Post

Inherits:
Object
  • Object
show all
Includes:
Model
Defined in:
lib/kiita/post.rb

Constant Summary collapse

@@attributes =
%w[
  id title body created_at updated_at created_at_in_words updated_at_in_words
  stock_count stock_users comment_count url gist_url private stocked
]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Model

#raw_attributes

Constructor Details

#initialize(uuid, options = {}) ⇒ Post

Returns a new instance of Post.



14
15
16
17
18
19
20
21
22
23
# File 'lib/kiita/post.rb', line 14

def initialize(uuid, options = {})
  if uuid.is_a?(Hash)
    options = uuid
    @uuid = options["uuid"]
  else
    @uuid = uuid
  end

  super(options)
end

Instance Attribute Details

#uuidObject (readonly)

Returns the value of attribute uuid.



4
5
6
# File 'lib/kiita/post.rb', line 4

def uuid
  @uuid
end

Class Method Details

.all(options = {}) ⇒ Object



25
26
27
# File 'lib/kiita/post.rb', line 25

def self.all(options = {})
  Kiita::API.get("/items", options).map{|post| Kiita::Post.new(post) }
end

.find(uuid) ⇒ Object



37
38
39
# File 'lib/kiita/post.rb', line 37

def self.find(uuid)
  new(uuid, Kiita::API.get("/items/#{uuid}").merge!(loaded: true))
end

.lazy_load(uuid) ⇒ Object



33
34
35
# File 'lib/kiita/post.rb', line 33

def self.lazy_load(uuid)
  new(uuid)
end

.search(keyword, options = {}) ⇒ Object



29
30
31
# File 'lib/kiita/post.rb', line 29

def self.search(keyword, options = {})
  Kiita::API.get("/search", options.merge!(q: keyword)).map{|post| Kiita::Post.new(post) }
end