Class: SimpleNote
Instance Attribute Summary collapse
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Class Method Summary collapse
Instance Method Summary collapse
- #create_note(content) ⇒ Object (also: #<<)
- #delete_note(key) ⇒ Object (also: #delete)
- #get_index ⇒ Object
- #get_note(key) ⇒ Object (also: #[])
-
#initialize(*args) ⇒ SimpleNote
constructor
A new instance of SimpleNote.
- #keys ⇒ Object
- #login(email, password) ⇒ Object
- #search(search_string, max_results = 10) ⇒ Object
- #update_note(key, content) ⇒ Object (also: #[]=)
Constructor Details
#initialize(*args) ⇒ SimpleNote
Returns a new instance of SimpleNote.
29 30 31 |
# File 'lib/simplenote.rb', line 29 def initialize(*args) self.login(*args) end |
Instance Attribute Details
#email ⇒ Object (readonly)
Returns the value of attribute email.
7 8 9 |
# File 'lib/simplenote.rb', line 7 def email @email end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
7 8 9 |
# File 'lib/simplenote.rb', line 7 def token @token end |
Class Method Details
.jsonize(method) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/simplenote.rb', line 11 def self.jsonize(method) class_eval do alias_method "_#{method}", method define_method(method) do |*args| Crack::JSON.parse self.send("_#{method}", *args).body end end end |
.textize(method) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/simplenote.rb', line 20 def self.textize(method) class_eval do alias_method "_#{method}", method define_method(method) do |*args| self.send("_#{method}", *args).body end end end |
Instance Method Details
#create_note(content) ⇒ Object Also known as: <<
63 64 65 |
# File 'lib/simplenote.rb', line 63 def create_note(content) self.class.post "/note", :query => request_hash, :body => Base64.encode64(content) end |
#delete_note(key) ⇒ Object Also known as: delete
51 52 53 54 55 |
# File 'lib/simplenote.rb', line 51 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_index ⇒ Object
40 41 42 |
# File 'lib/simplenote.rb', line 40 def get_index self.class.get "/index", :query => request_hash, :format => :json end |
#get_note(key) ⇒ Object Also known as: []
45 46 47 48 |
# File 'lib/simplenote.rb', line 45 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 |
#keys ⇒ Object
73 74 75 76 77 |
# File 'lib/simplenote.rb', line 73 def keys get_index.map do |i| i["key"] end end |
#login(email, password) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/simplenote.rb', line 33 def login(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
68 69 70 |
# File 'lib/simplenote.rb', line 68 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 Also known as: []=
58 59 60 |
# File 'lib/simplenote.rb', line 58 def update_note(key, content) self.class.post "/note", :query => request_hash.merge(:key => key), :body => Base64.encode64(content) end |