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.



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

def initialize(options = {})
    @key = options[:key]
    @url = options[:url] || 'https://app.beetrack.cl/api/external/v1/'
    @url = @url + '/' if @url[-1] != '/'
end

Instance Attribute Details

#keyObject

Returns the value of attribute key.



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

def key
  @key
end

#urlObject (readonly)

Returns the value of attribute url.



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

def url
  @url
end

Instance Method Details

#create_route(options = {}) ⇒ Object Also known as: createroute



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

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

#get_data_export_status(id) ⇒ Object



84
85
86
# File 'lib/beetrackapi.rb', line 84

def get_data_export_status(id)
  get("data_exports/#{id}")
end

#get_dispatch_info(dispatch_id) ⇒ Object Also known as: getdispatchinfo



40
41
42
# File 'lib/beetrackapi.rb', line 40

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

#get_route(route_id) ⇒ Object Also known as: getroute



28
29
30
# File 'lib/beetrackapi.rb', line 28

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

#get_routes(options = {}) ⇒ Object Also known as: getroutes



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

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

#get_truck(identifier) ⇒ Object Also known as: gettruck



52
53
54
# File 'lib/beetrackapi.rb', line 52

def get_truck(identifier)
    get("trucks/#{identifier}")
end

#get_trucksObject Also known as: gettrucks



46
47
48
# File 'lib/beetrackapi.rb', line 46

def get_trucks
    get("trucks")
end

#request_data_export(params = {}) ⇒ Object



80
81
82
# File 'lib/beetrackapi.rb', line 80

def request_data_export(params = {})
  post('data_exports', params)
end

#update_route(route_id, options = {}) ⇒ Object Also known as: updateroute



58
59
60
# File 'lib/beetrackapi.rb', line 58

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

#upload_file(file, content_type) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/beetrackapi.rb', line 64

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
      },
      ssl_version: 'TLSv1_2')
  request.execute
end