Class: BeetrackAPI::Client
- Inherits:
-
Object
- Object
- BeetrackAPI::Client
- Defined in:
- lib/beetrackapi.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
Returns the value of attribute key.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #create_route(options = {}) ⇒ Object (also: #createroute)
- #get_data_export_status(id) ⇒ Object
- #get_dispatch_info(dispatch_id) ⇒ Object (also: #getdispatchinfo)
- #get_route(route_id) ⇒ Object (also: #getroute)
- #get_routes(options = {}) ⇒ Object (also: #getroutes)
- #get_truck(identifier) ⇒ Object (also: #gettruck)
- #get_trucks ⇒ Object (also: #gettrucks)
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #request_data_export(params = {}) ⇒ Object
- #update_route(route_id, options = {}) ⇒ Object (also: #updateroute)
- #upload_file(file, content_type) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
15 16 17 18 19 |
# File 'lib/beetrackapi.rb', line 15 def initialize( = {}) @key = [:key] @url = [:url] || 'https://app.beetrack.cl/api/external/v1/' @url = @url + '/' if @url[-1] != '/' end |
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
12 13 14 |
# File 'lib/beetrackapi.rb', line 12 def key @key end |
#url ⇒ Object (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( = {}) post("routes", ) 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( = {}) date = .empty? ? "#{Date.today.strftime("%d-%m-%Y")}" : [: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_trucks ⇒ Object 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, ={}) put("routes/#{route_id}", ) 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 |