Module: CatchNotes::Base::FinderMethods::ClassMethods

Defined in:
lib/catch_notes/base.rb

Instance Method Summary collapse

Instance Method Details

#allObject



47
48
49
50
# File 'lib/catch_notes/base.rb', line 47

def all
  res = get "/notes"
  build_note_array( res.parsed_response['notes'] ) if send(:ok?, res)
end

#find(id) ⇒ Object



57
58
59
60
61
# File 'lib/catch_notes/base.rb', line 57

def find(id)
  find!(id)
rescue CatchNotes::NotFound
  nil
end

#find!(id) ⇒ Object



52
53
54
55
# File 'lib/catch_notes/base.rb', line 52

def find!(id)
  res = get "/notes/#{id}"
  send(:build_from_hash,res.parsed_response['notes'].first ) if send(:ok?,res)
end

#find_all_by_tag(tag_name) ⇒ Object



68
69
70
71
72
# File 'lib/catch_notes/base.rb', line 68

def find_all_by_tag( tag_name )
  find_all_by_tag!(tag_name)
rescue
  []
end

#find_all_by_tag!(tag_name) ⇒ Object



63
64
65
66
# File 'lib/catch_notes/base.rb', line 63

def find_all_by_tag!( tag_name )
  res = get "/search?q=%23#{tag_name}"
  build_note_array( res.parsed_response['notes'] ) if send(:ok?, res)
end

#find_by_tag(tag_name) ⇒ Object



78
79
80
81
82
# File 'lib/catch_notes/base.rb', line 78

def find_by_tag( tag_name )
  find_all_by_tag!(tag_name).first
rescue
  nil
end

#find_by_tag!(tag_name) ⇒ Object



74
75
76
# File 'lib/catch_notes/base.rb', line 74

def find_by_tag!( tag_name )
  find_all_by_tag!(tag_name).first
end

#firstObject



84
85
86
# File 'lib/catch_notes/base.rb', line 84

def first
  all.first
end

#lastObject



88
89
90
# File 'lib/catch_notes/base.rb', line 88

def last
  all.last
end

#tagsObject



92
93
94
95
96
97
98
99
100
101
# File 'lib/catch_notes/base.rb', line 92

def tags
  res = get "/tags"
  if send(:ok?, res)
    res.parsed_response['tags'].inject({}) do |hash, t|
      hash[t['name']] = Tagging.new t, self
      #hash[t['name'].to_sym] = Tagging.new t, self
      hash
    end
  end
end