Class: BeetrackAPI::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



16
17
18
19
# File 'lib/beetrackapi.rb', line 16

def initialize(options = {})
    @key = options[:key]
    @url = options[:url] || 'http://app.beetrack.cl/api/external/v1/'
end

Instance Attribute Details

#keyObject

Returns the value of attribute key.



13
14
15
# File 'lib/beetrackapi.rb', line 13

def key
  @key
end

#urlObject (readonly)

Returns the value of attribute url.



14
15
16
# File 'lib/beetrackapi.rb', line 14

def url
  @url
end

Instance Method Details

#createroute(options = {}) ⇒ Object



30
31
32
# File 'lib/beetrackapi.rb', line 30

def createroute(options = {})
    post("routes", options)
end

#getdispatchinfo(dispatch_id) ⇒ Object



34
35
36
# File 'lib/beetrackapi.rb', line 34

def getdispatchinfo(dispatch_id)
    get("dispatches/#{dispatch_id}")
end

#getroute(route_id) ⇒ Object



26
27
28
# File 'lib/beetrackapi.rb', line 26

def getroute(route_id)
    get("routes/#{route_id}")
end

#getroutes(options = {}) ⇒ Object



21
22
23
24
# File 'lib/beetrackapi.rb', line 21

def getroutes(options = {})
    date = options.empty? ? "#{Date.today.strftime("%d-%m-%Y")}" : options[:date]
    get('routes', :date => date)
end

#gettrucksObject



38
39
40
# File 'lib/beetrackapi.rb', line 38

def gettrucks
    get("trucks")
end

#updateroute(route_id, options = {}) ⇒ Object



42
43
44
# File 'lib/beetrackapi.rb', line 42

def updateroute(route_id, options ={})
    put("routes/#{route_id}", options)
end

#upload_file(file, content_type) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/beetrackapi.rb', line 46

def upload_file(file, content_type)
  request = RestClient::Request.new(
      :method => :post,
      :url => "#{url}import",
      :headers => {
        'Content-Type' => content_type,
        'X-AUTH-TOKEN' => @key
        },
      :payload => {
        :multipart => true,
        :file => file
      })
  request.execute
end