Class: Shelr::Publisher

Inherits:
Object
  • Object
show all
Defined in:
lib/shelr/publisher.rb

Instance Method Summary collapse

Instance Method Details

#dump(id) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/shelr/publisher.rb', line 17

def dump(id)
  with_exception_handler do
    File.open(dump_filename, 'w+') do |f|
      f.puts(prepare(id))
    end
    STDOUT.puts "=> record dumped to #{dump_filename}"
  end
end

#publish(id) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/shelr/publisher.rb', line 7

def publish(id)
  ensure_unlocked(id)
  with_exception_handler do
    uri = URI.parse(Shelr::API_URL + '/records')
    params = { 'record' => prepare(id) }
    params.merge!({'api_key' => Shelr.api_key}) if api_key
    handle_response Net::HTTP.post_form(uri, params)
  end
end