class CrunchApi::Supplier

Attributes

contact_name[R]
default_expense_type[R]
email[R]
fax[R]
id[R]
name[R]
telephone[R]
uri[R]
website[R]

Public Class Methods

all() click to toggle source
# File lib/crunch-api/supplier.rb, line 26
def self.all
  consumer = OAuth::Consumer.new(CrunchApi.options[:consumer_key], CrunchApi.options[:consumer_secret], {})
  token = OAuth::AccessToken.new(consumer, CrunchApi.options[:oauth_token], CrunchApi.options[:oauth_token_secret])

  uri = "#{CrunchApi.options[:endpoint]}#{path}"

  response = token.get(uri)

  parse_xml(response.body).collect{|attributes| new(attributes)}
end
for_id(id) click to toggle source
# File lib/crunch-api/supplier.rb, line 37
def self.for_id(id)
  consumer = OAuth::Consumer.new(CrunchApi.options[:consumer_key], CrunchApi.options[:consumer_secret], {})
  token = OAuth::AccessToken.new(consumer, CrunchApi.options[:oauth_token], CrunchApi.options[:oauth_token_secret])

  uri = "#{CrunchApi.options[:endpoint]}#{path}/#{id}"

  response = token.get(uri)

  new(parse_xml(response.body)) unless errors?(response.body)
end
new(xml) click to toggle source
# File lib/crunch-api/supplier.rb, line 9
def initialize(xml)
  @id = xml[:@supplierId]
  @uri = xml[:@resourceUrl]
  @default_expense_type = xml[:@defaultExpenseType]
  @unknown_supplier_flag = xml[:@unknownSupplier] == "true"
  @name = xml[:name]
  @contact_name = xml[:contact_name]
  @email = xml[:email]
  @website = xml[:website]
  @telephone = xml[:telephone]
  @fax = xml[:fax]
end

Private Class Methods

errors?(xml) click to toggle source
# File lib/crunch-api/supplier.rb, line 62
def self.errors?(xml)
  to_hash(xml)[:crunch_message].fetch(:errors, []).length > 0
end
parse_xml(xml) click to toggle source
# File lib/crunch-api/supplier.rb, line 54
def self.parse_xml(xml)
  to_hash(xml)[:crunch_message][:suppliers][:supplier]
end
path() click to toggle source
# File lib/crunch-api/supplier.rb, line 50
def self.path
  "/crunch-core/seam/resource/rest/api/suppliers"
end
to_hash(xml) click to toggle source
# File lib/crunch-api/supplier.rb, line 58
def self.to_hash(xml)
  Nori.new(:convert_tags_to => lambda { |tag| tag.snakecase.to_sym }).parse(xml)
end

Public Instance Methods

unknown_supplier?() click to toggle source
# File lib/crunch-api/supplier.rb, line 22
def unknown_supplier?
  @unknown_supplier_flag
end