Class: Trello::Member

Inherits:
Object
  • Object
show all
Defined in:
lib/trello-lite/member.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Member

to keep things pragmatic, @attributes holds the json a cool feature in the future is to use metaprogramming to automatically create instance methods, including an #instance_methods method to help the user better understand the API.



9
10
11
12
13
# File 'lib/trello-lite/member.rb', line 9

def initialize(attrs = {})
  @attributes = attrs
  @boards = []
  @organizations = []
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



3
4
5
# File 'lib/trello-lite/member.rb', line 3

def attributes
  @attributes
end

Class Method Details

.find(username) ⇒ Object



19
20
21
22
# File 'lib/trello-lite/member.rb', line 19

def self.find(username)
  @username = username
  Trello.find_member(username)
end

Instance Method Details

#bioObject



34
35
36
# File 'lib/trello-lite/member.rb', line 34

def bio
  attributes[:bio]
end

#boards(number = "none") ⇒ Object

just returns an array for now - would be cool to use activemodel



43
44
45
46
47
48
49
50
51
# File 'lib/trello-lite/member.rb', line 43

def boards(number = "none")
  attributes[:idBoards].each_with_index do |id_board, idx|
    number == "none" ? number = attributes[:idBoards].size : number
    board_number = idx + 1
    @boards << Board.new(id_board)
    break if board_number == number
  end
  @boards
end

#credentialsObject



15
16
17
# File 'lib/trello-lite/member.rb', line 15

def credentials
  Trello.credentials
end

#find(username) ⇒ Object



24
25
26
27
28
# File 'lib/trello-lite/member.rb', line 24

def find(username)
  url = "https://api.trello.com/1/members/#{username}?fields=all&organizations=members&organization_fields=all&#{credentials}"
  @attributes = Trello.parse(url)
  self
end

#find_board(name) ⇒ Object



53
54
55
56
57
58
59
60
61
# File 'lib/trello-lite/member.rb', line 53

def find_board(name)
  board = nil
  attributes[:idBoards].each_with_index do |id_board, idx|
    board_number = idx + 1
    Board.new(id_board).name.downcase.include?(name.downcase) ? board = Board.new(id_board) : next
    break
  end
  board
end

#full_nameObject



30
31
32
# File 'lib/trello-lite/member.rb', line 30

def full_name
  attributes[:fullName]
end

#get_orgs_by_name(name) ⇒ Object



70
71
72
# File 'lib/trello-lite/member.rb', line 70

def get_orgs_by_name(name)
  organizations.select { |org| org.display_name.include?(name) }
end

#organizationsObject



63
64
65
66
67
68
# File 'lib/trello-lite/member.rb', line 63

def organizations
  attributes[:organizations].each do |org|
    @organizations << Organization.new(org)
  end
  @organizations
end

#usernameObject



38
39
40
# File 'lib/trello-lite/member.rb', line 38

def username
  @username ||= attributes[:username]
end