Class: Oos4ruby::Contact
- Inherits:
-
Bean::BeanClass
- Object
- Bean::BeanClass
- Oos4ruby::Contact
- Includes:
- Bean
- Defined in:
- lib/oos4ruby/contact.rb
Instance Attribute Summary collapse
-
#trusted ⇒ Object
writeonly
Sets the attribute trusted.
Class Method Summary collapse
- .dump!(opts, slug) ⇒ Object
-
.find_by_user(auth, slug, opts = {}) ⇒ Object
find all user contacts.
Instance Method Summary collapse
-
#data ⇒ Object
returns the user associated with this contact.
-
#initialize(xml, auth, slug) ⇒ Contact
constructor
A new instance of Contact.
- #trusted? ⇒ Boolean
Methods included from Bean
Methods inherited from Bean::BeanClass
#author, #contains?, #delete!, #to_s, #to_xml, #update!
Constructor Details
#initialize(xml, auth, slug) ⇒ Contact
Returns a new instance of Contact.
11 12 13 14 15 |
# File 'lib/oos4ruby/contact.rb', line 11 def initialize(xml, auth, slug) @xml = xml @auth = auth @slug = slug end |
Instance Attribute Details
#trusted=(value) ⇒ Object (writeonly)
Sets the attribute trusted
7 8 9 |
# File 'lib/oos4ruby/contact.rb', line 7 def trusted=(value) @trusted = value end |
Class Method Details
.dump!(opts, slug) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/oos4ruby/contact.rb', line 45 def Contact.dump!(opts, slug) include Bean entry = create_entry add_element entry, 'author/name', slug updated = DateTime::now.strftime("%Y-%m-%dT%H:%M:%S%z").sub(/(..)$/, ':\1') add_element entry, 'updated', updated add_element entry, 'id', make_id add_element entry, 'title', (opts[:contact] || opts[:slug] || opts[:title]) add_element entry, 'content', '' if opts[:trusted] if opts[:trusted].is_a?REXML::Element entry.add_element opts[:trusted] else add_category entry, opts[:trusted], TRUSTED_URL end end entry end |
.find_by_user(auth, slug, opts = {}) ⇒ Object
find all user contacts
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/oos4ruby/contact.rb', line 20 def Contact.find_by_user( auth, slug, opts = {} ) raise Oos4ruby::UnknownUser if slug.nil? uri = CONTACTS_URL + "/#{slug}" getter = HTTPInvoker.new(uri, auth) worked = getter.get Contacts.new(Feed.read(getter.body), auth, slug) if worked end |
Instance Method Details
#data ⇒ Object
returns the user associated with this contact
35 36 37 |
# File 'lib/oos4ruby/contact.rb', line 35 def data @data ||= User.find @auth, @xml.link('userInfo') end |
#trusted? ⇒ Boolean
39 40 41 42 43 |
# File 'lib/oos4ruby/contact.rb', line 39 def trusted? trusted = @xml.first("./atom:category[@scheme=\"#{TRUSTED_URL}\"]") trusted = Category.new trusted trusted.term.downcase == 'true' end |