Class: SimpleNote

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/simplenote.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#emailObject (readonly)

Returns the value of attribute email.



7
8
9
# File 'lib/simplenote.rb', line 7

def email
  @email
end

#tokenObject (readonly)

Returns the value of attribute token.



7
8
9
# File 'lib/simplenote.rb', line 7

def token
  @token
end

Instance Method Details

#create_note(content) ⇒ Object



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

def create_note(content)
  self.class.post "/note", :query => request_hash, :body => Base64.encode64(content)
end

#delete_note(key) ⇒ Object



27
28
29
30
31
# File 'lib/simplenote.rb', line 27

def delete_note(key)
  out = self.class.get "/delete", :query => request_hash.merge(:key => key)
  raise "Couldn't delete note" unless out.response.is_a?(Net::HTTPOK)
  out
end

#get_indexObject



18
19
20
# File 'lib/simplenote.rb', line 18

def get_index
  self.class.get "/index", :query => request_hash, :format => :json
end

#get_note(key) ⇒ Object



22
23
24
25
# File 'lib/simplenote.rb', line 22

def get_note(key)
  out = self.class.get "/note", :query => request_hash.merge(:key => key), :format => :plain
  out.response.is_a?(Net::HTTPNotFound) ? nil : out
end

#login(email, password) ⇒ Object



11
12
13
14
15
16
# File 'lib/simplenote.rb', line 11

def (email, password)
  encoded_body = Base64.encode64({:email => email, :password => password}.to_params)
  @email = email
  @token = self.class.post "/login", :body => encoded_body
  raise "Login failed" unless @token.response.is_a?(Net::HTTPOK)
end

#search(search_string, max_results = 10) ⇒ Object



41
42
43
# File 'lib/simplenote.rb', line 41

def search(search_string, max_results=10)
  self.class.get "/search", :query => request_hash.merge(:query => search_string, :results => max_results)
end

#update_note(key, content) ⇒ Object



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

def update_note(key, content)
  self.class.post "/note", :query => request_hash.merge(:key => key), :body => Base64.encode64(content)
end