Class: Hackpad::Migration::API

Inherits:
Object
  • Object
show all
Defined in:
lib/hackpad/migration/api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site, client_id, secret) ⇒ API

Returns a new instance of API.



5
6
7
# File 'lib/hackpad/migration/api.rb', line 5

def initialize(site, client_id, secret)
  @client = OAuth::Consumer.new(client_id, secret, site: site)
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



4
5
6
# File 'lib/hackpad/migration/api.rb', line 4

def client
  @client
end

Instance Method Details

#create(body) ⇒ Object



20
21
22
23
24
# File 'lib/hackpad/migration/api.rb', line 20

def create(body)
  JSON.parse(client.request(:post, '/api/1.0/pad/create', nil, {}, body, {
                              'Content-Type' => 'text/html'
                            }).body)
end

#get(id) ⇒ Object



13
14
15
16
17
18
# File 'lib/hackpad/migration/api.rb', line 13

def get(id)
  body = client.request(:get, "/api/1.0/pad/#{id}/content/latest.html").body
  html_doc = Nokogiri::HTML(body)
  fix_data_missing(body)
  %Q(#{html_doc.at_css('h1:first').text}\n#{body})
end

#listObject



9
10
11
# File 'lib/hackpad/migration/api.rb', line 9

def list
  JSON.parse(client.request(:get, '/api/1.0/pads/all').body)
end

#update(pid, body) ⇒ Object



26
27
28
29
30
# File 'lib/hackpad/migration/api.rb', line 26

def update(pid, body)
  JSON.parse(client.request(:post, "/api/1.0/pad/#{pid}/content", nil, {}, body, {
                              'Content-Type' => 'text/html'
                            }).body)
end