class MyJohnDeere::Requestable

Attributes

access_token[RW]

Public Class Methods

get_created_id_from_response_headers(resource, response) click to toggle source
# File lib/myjohndeere/requestable.rb, line 27
def self.get_created_id_from_response_headers(resource, response)
  # 201 is the expected response code
  # The lowercase location shouldn't be needed but sometimes it is returned as lowercase...
  created_id = response.http_headers["Location"] || response.http_headers["location"]
  if !created_id.nil? then
    created_id = /#{resource}\/([^\/]+)\Z/.match(created_id)[1]
  else
    # didn't succeed
    MyJohnDeere.logger.info("Failed to create a #{resource}: #{response}")
    return nil
  end
end
new(json_object = {}, access_token = nil) click to toggle source
# File lib/myjohndeere/requestable.rb, line 5
def initialize(json_object = {}, access_token = nil)
  self.links = json_object["links"] || []
  self.access_token = access_token
  approved_class = MyJohnDeere::AccessToken
  if !self.access_token.nil? && !self.access_token.is_a?(approved_class) then
    raise ArgumentError.new("Expected a #{approved_class}, do not know how to handle #{self.access_token.class}")
  end
end

Public Instance Methods

has_access_to?(rel_link_name) click to toggle source
# File lib/myjohndeere/requestable.rb, line 14
def has_access_to?(rel_link_name)
  self.links.any? {|i| i["rel"] == rel_link_name}
end