Class: Kiita::User

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

Constant Summary collapse

@@attributes =
%w[
  name profile_image_url url description website_url organization location
  facebook linkedin twitter github followers following_users items
]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Model

#raw_attributes

Constructor Details

#initialize(url_name, options = {}) ⇒ User

Returns a new instance of User.



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

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

  super(options)
end

Instance Attribute Details

#url_nameObject (readonly)

Returns the value of attribute url_name.



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

def url_name
  @url_name
end

Class Method Details

.find(url_name) ⇒ Object



53
54
55
# File 'lib/kiita/user.rb', line 53

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

.lazy_load(url_name) ⇒ Object



49
50
51
# File 'lib/kiita/user.rb', line 49

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

Instance Method Details

#following_tags(options = {}) ⇒ Object



43
44
45
46
47
# File 'lib/kiita/user.rb', line 43

def following_tags(options = {})
  @following_tags ||= Kiita::API.get("/users/#{url_name}/following_tags", options).map do |tag|
    Kiita::Tag.new(tag)
  end
end

#following_users(options = {}) ⇒ Object



37
38
39
40
41
# File 'lib/kiita/user.rb', line 37

def following_users(options = {})
  @following_users ||= Kiita::API.get("/users/#{url_name}/following_users", options).map do |user|
    Kiita::User.new(user)
  end
end

#posts(options = {}) ⇒ Object



25
26
27
28
29
# File 'lib/kiita/user.rb', line 25

def posts(options = {})
  @posts ||= Kiita::API.get("/users/#{url_name}/items", options).map do |post|
    Kiita::Post.new(post)
  end
end

#stocks(options = {}) ⇒ Object



31
32
33
34
35
# File 'lib/kiita/user.rb', line 31

def stocks(options = {})
  @stocks ||= Kiita::API.get("/users/#{url_name}/stocks", options).map do |post|
    Kiita::Post.new(post)
  end
end