Class: CrunchApi::Supplier

Inherits:
Object
  • Object
show all
Defined in:
lib/crunch-api/supplier.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml) ⇒ Supplier

Returns a new instance of Supplier.



9
10
11
12
13
14
15
16
17
18
19
20
# 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

Instance Attribute Details

#contact_nameObject (readonly)

Returns the value of attribute contact_name.



7
8
9
# File 'lib/crunch-api/supplier.rb', line 7

def contact_name
  @contact_name
end

#default_expense_typeObject (readonly)

Returns the value of attribute default_expense_type.



7
8
9
# File 'lib/crunch-api/supplier.rb', line 7

def default_expense_type
  @default_expense_type
end

#emailObject (readonly)

Returns the value of attribute email.



7
8
9
# File 'lib/crunch-api/supplier.rb', line 7

def email
  @email
end

#faxObject (readonly)

Returns the value of attribute fax.



7
8
9
# File 'lib/crunch-api/supplier.rb', line 7

def fax
  @fax
end

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'lib/crunch-api/supplier.rb', line 7

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/crunch-api/supplier.rb', line 7

def name
  @name
end

#telephoneObject (readonly)

Returns the value of attribute telephone.



7
8
9
# File 'lib/crunch-api/supplier.rb', line 7

def telephone
  @telephone
end

#uriObject (readonly)

Returns the value of attribute uri.



7
8
9
# File 'lib/crunch-api/supplier.rb', line 7

def uri
  @uri
end

#websiteObject (readonly)

Returns the value of attribute website.



7
8
9
# File 'lib/crunch-api/supplier.rb', line 7

def website
  @website
end

Class Method Details

.allObject



26
27
28
29
30
31
32
33
34
35
# 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) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# 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

Instance Method Details

#unknown_supplier?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/crunch-api/supplier.rb', line 22

def unknown_supplier?
  @unknown_supplier_flag
end