Class: Marginalia::IO::API

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/marginalia-io/api.rb

Instance Method Summary collapse

Constructor Details

#initialize(host = 'www.marginalia.io') ⇒ API

Returns a new instance of API.



15
16
17
18
19
# File 'lib/marginalia-io/api.rb', line 15

def initialize(host='www.marginalia.io')
  credentials = Marginalia::IO::Auth.new(host).get_credentials
  self.class.base_uri "https://#{host}"
  self.class.basic_auth credentials[0], credentials[1]
end

Instance Method Details

#allObject



29
30
31
# File 'lib/marginalia-io/api.rb', line 29

def all
  self.class.get("/notes.json").parsed_response
end

#append(id, body) ⇒ Object



21
22
23
# File 'lib/marginalia-io/api.rb', line 21

def append(id, body)
  self.class.post("/notes/#{id}/append.json", :body => {:body => body})
end

#create(title, body) ⇒ Object



25
26
27
# File 'lib/marginalia-io/api.rb', line 25

def create(title, body)
  self.class.post("/notes.json", :body => {:note => {:body => body, :title => title}})
end

#get(id) ⇒ Object



38
39
40
# File 'lib/marginalia-io/api.rb', line 38

def get(id)
  self.class.get("/notes/#{id}.json")
end

#search(query) ⇒ Object



33
34
35
36
# File 'lib/marginalia-io/api.rb', line 33

def search(query)
  escaped = URI.escape(query)
  self.class.get("/notes/search.json?q=#{escaped}").parsed_response
end

#update(id, body) ⇒ Object



42
43
44
# File 'lib/marginalia-io/api.rb', line 42

def update(id, body)
  puts self.class.put("/notes/#{id}.json", :body => {:note => {:body => body}}).parsed_response
end