Class: Shelr::Publisher

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

Instance Method Summary collapse

Instance Method Details

#dump(id) ⇒ Object



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

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, priv = false) ⇒ Object



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

def publish(id, priv = false)
  @private = priv
  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