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
- #createroute(options = {}) ⇒ Object
- #getdispatchinfo(dispatch_id) ⇒ Object
- #getroute(route_id) ⇒ Object
- #getroutes(options = {}) ⇒ Object
- #gettrucks ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #updateroute(route_id, options = {}) ⇒ Object
- #upload_file(filename, content_type) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
16 17 18 19 |
# File 'lib/beetrackapi.rb', line 16 def initialize( = {}) @key = [:key] @url = [:url] || 'http://app.beetrack.cl/api/external/v1/' end |
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
13 14 15 |
# File 'lib/beetrackapi.rb', line 13 def key @key end |
#url ⇒ Object (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( = {}) post("routes", ) 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( = {}) date = .empty? ? "#{Date.today.strftime("%d-%m-%Y")}" : [:date] get('routes', :date => date) end |
#gettrucks ⇒ Object
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, ={}) put("routes/#{route_id}", ) end |
#upload_file(filename, 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(filename, 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.new(filename, 'rb') }) request.execute end |