Class: Octobat::FileUpload

Inherits:
APIResource show all
Extended by:
APIOperations::List
Includes:
APIOperations::Create
Defined in:
lib/octobat/file_upload.rb

Instance Attribute Summary

Attributes inherited from OctobatObject

#api_key, #parent_obj

Class Method Summary collapse

Instance Method Summary collapse

Methods included from APIOperations::List

list, set_parent_resource

Methods included from APIOperations::Create

included

Methods inherited from APIResource

class_name, retrieve, #url

Methods inherited from OctobatObject

#[], #[]=, #_dump, _load, #as_json, construct_from, #each, #initialize, #inspect, #keys, #refresh_from, #respond_to?, #to_hash, #to_json, #to_s, #values

Constructor Details

This class inherits a constructor from Octobat::OctobatObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Octobat::OctobatObject

Class Method Details

.create(params = {}, opts = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/octobat/file_upload.rb', line 11

def self.create(params = {}, opts = {})
  if params[:attachment] && !params[:attachment].is_a?(String)
    unless params[:attachment].respond_to?(:read)
      raise ArgumentError, "attachment must respond to `#read`"
    end
  end
  
  api_key, headers = Util.parse_opts(opts)
  headers = headers.merge(content_type: MultipartEncoder::MULTIPART_FORM_DATA)
  
  response, api_key = Octobat.request(:post, self.url, api_key, params, headers, Octobat.uploads_base)
  Util.convert_to_octobat_object(response, api_key)
  
end

.list(filters = {}, opts = {}) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/octobat/file_upload.rb', line 32

def self.list(filters={}, opts={})
  set_parent_resource(filters)
  api_key, headers = Util.parse_opts(opts)
  
  api_key ||= @api_key

  f = filters.select{|request_filter| !@parent_resource.has_key?(request_filter)}

  response, api_key = Octobat.request(:get, url, api_key, f, headers, Octobat.uploads_base)
  obj = ListObject.construct_from(response, api_key)

  obj.filters = filters.dup
  obj.cursors[:ending_before] = obj.filters.delete(:ending_before)
  obj.cursors[:starting_after] = obj.filters.delete(:starting_after)

  obj.filters.delete(:expand)
  obj.parent_resource = @parent_resource

  obj
end

.urlObject



6
7
8
# File 'lib/octobat/file_upload.rb', line 6

def self.url
  "/files"
end

Instance Method Details

#refreshObject



26
27
28
29
# File 'lib/octobat/file_upload.rb', line 26

def refresh
  response, api_key = Octobat.request(:get, url, @api_key, @retrieve_options, @headers, Octobat.uploads_base)
  refresh_from(response, api_key)
end