Class: Documents

Inherits:
Object
  • Object
show all
Defined in:
lib/bush_viper/documents.rb

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ Documents

Returns a new instance of Documents.



2
3
4
# File 'lib/bush_viper/documents.rb', line 2

def initialize(connection)
  self.connection = connection
end

Instance Method Details

#allObject



6
7
8
# File 'lib/bush_viper/documents.rb', line 6

def all
  connection.get("documents")
end

#create(params, filepath: nil, url: nil, filename: nil) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/bush_viper/documents.rb', line 14

def create(params, filepath: nil, url: nil, filename: nil)
  if filepath
    File.open(filepath, "rb") do |file|
      result = connection.post("documents/", file.read, filename || File.basename(filepath))
      connection.patch(%Q{documents/#{result["id"]}}, params)
    end
  elsif url
    uri = URI.parse(url)
    content = Net::HTTP.get(uri)
    result = connection.post("documents/", content, filename || File.basename(uri.path))
    connection.patch(%Q{documents/#{result["id"]}}, params)
  end
end

#typesObject



10
11
12
# File 'lib/bush_viper/documents.rb', line 10

def types
  connection.get("document_types")
end