Class: Dronetrack::Track

Inherits:
RestService show all
Defined in:
lib/dronetrack/track.rb

Instance Method Summary collapse

Methods inherited from RestService

#all, #create, #get, #remove, #update

Constructor Details

#initialize(baseUrl, accessToken) ⇒ Track

Returns a new instance of Track.



3
4
5
# File 'lib/dronetrack/track.rb', line 3

def initialize (baseUrl, accessToken)
    super(baseUrl, "/track", accessToken)
end

Instance Method Details

#add_points(id, points = []) ⇒ Object



11
12
13
# File 'lib/dronetrack/track.rb', line 11

def add_points (id, points=[])
    makeRequest "#{@path}/#{id}/points", :post, {:body => points.to_json, :headers=>{'Content-Type' => 'application/json'}}
end

#get_points(id) ⇒ Object



7
8
9
# File 'lib/dronetrack/track.rb', line 7

def get_points (id)
    makeRequest "#{@path}/#{id}/points", :get
end

#import_points_from_files(id, files, format = :csv) ⇒ Object

Raises:

  • (ArgumentError)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/dronetrack/track.rb', line 15

def import_points_from_files (id, files, format=:csv)
    f = format.to_s().upcase()
    raise ArgumentError, "Format #{f} is not supported" if f != "CSV" && f != "KML"
    body = {}
    i = 1
    mime = "application/vnd.google-earth.kml+xml"
    mime = "text/csv" if format == :csv
    files.each do |file|
      body["file#{i}".to_sym] = Faraday::UploadIO.new(file, mime)
      i = i + 1
    end
    r = createNewRequest do |con|
      con.request :multipart
      con.request :url_encoded
      con.adapter :net_http
    end
    r.post "#{@path}/#{id}/points/import#{f}", {:body => body, :headers => {"Accept" => "application/json"}}
end