Class: LocalUnfuddleNotebook::Notebook
- Inherits:
-
RestClient::Resource
- Object
- RestClient::Resource
- LocalUnfuddleNotebook::Notebook
- Defined in:
- lib/local_unfuddle_notebook/notebook.rb
Instance Attribute Summary collapse
-
#last_updated_at ⇒ Object
Returns the value of attribute last_updated_at.
Class Method Summary collapse
- .attributes_path ⇒ Object
- .local ⇒ Object
- .local_pages_path ⇒ Object
- .saved_attributes ⇒ Object
- .with_attributes(attributes) ⇒ Object
Instance Method Summary collapse
- #local_attributes ⇒ Object
- #local_pages ⇒ Object
- #notebook_id ⇒ Object
- #project_id ⇒ Object
- #protocol ⇒ Object
- #pull ⇒ Object
- #push(message) ⇒ Object
- #remote_pages ⇒ Object
- #subdomain ⇒ Object
- #update_attributes_file ⇒ Object
- #url_with_basic_auth(suburl) ⇒ Object
Instance Attribute Details
#last_updated_at ⇒ Object
Returns the value of attribute last_updated_at.
32 33 34 |
# File 'lib/local_unfuddle_notebook/notebook.rb', line 32 def last_updated_at @last_updated_at end |
Class Method Details
.attributes_path ⇒ Object
7 8 9 |
# File 'lib/local_unfuddle_notebook/notebook.rb', line 7 def attributes_path ".local_unfuddle_notebook.yaml" end |
.local ⇒ Object
11 12 13 |
# File 'lib/local_unfuddle_notebook/notebook.rb', line 11 def local with_attributes(saved_attributes) end |
.local_pages_path ⇒ Object
15 16 17 |
# File 'lib/local_unfuddle_notebook/notebook.rb', line 15 def local_pages_path "pages" end |
.saved_attributes ⇒ Object
19 20 21 |
# File 'lib/local_unfuddle_notebook/notebook.rb', line 19 def saved_attributes YAML::load(Pow(attributes_path).read) if Pow(attributes_path).file? end |
.with_attributes(attributes) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/local_unfuddle_notebook/notebook.rb', line 23 def with_attributes(attributes) attributes[:protocol] ||= 'http' url = "#{attributes[:protocol]}://#{attributes[:subdomain]}.unfuddle.com/api/v1/projects/#{attributes[:project_id]}/notebooks/#{attributes[:notebook_id]}" Notebook.new(url, attributes[:username], attributes[:password]).tap do |notebook| notebook.last_updated_at = attributes[:last_updated_at] end end |
Instance Method Details
#local_attributes ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/local_unfuddle_notebook/notebook.rb', line 34 def local_attributes { :subdomain => subdomain, :username => user, :password => password, :project_id => project_id, :notebook_id => notebook_id, :last_updated_at => last_updated_at, :protocol => protocol } end |
#local_pages ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/local_unfuddle_notebook/notebook.rb', line 46 def local_pages Pow(Notebook.local_pages_path).files.map do |file| Page.new(YAML.load(file.read)).tap do |page| page.notebook = self page.local_file = file end end end |
#notebook_id ⇒ Object
55 56 57 |
# File 'lib/local_unfuddle_notebook/notebook.rb', line 55 def notebook_id url.match(%r{notebooks/(\d+)})[1].to_i end |
#project_id ⇒ Object
59 60 61 |
# File 'lib/local_unfuddle_notebook/notebook.rb', line 59 def project_id url.match(%r{projects/(\d+)})[1].to_i end |
#protocol ⇒ Object
63 64 65 |
# File 'lib/local_unfuddle_notebook/notebook.rb', line 63 def protocol url.match(%r{^(\w*)://})[1] end |
#pull ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/local_unfuddle_notebook/notebook.rb', line 67 def pull if Pow(self.class.local_pages_path).exists? Pow(self.class.local_pages_path).delete! end remote_pages.each do |page| page.save end self.last_updated_at = Time.now self.update_attributes_file end |
#push(message) ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'lib/local_unfuddle_notebook/notebook.rb', line 80 def push() local_pages.select{|page| page.changed?}.each do |page| page. = page.push end pull end |
#remote_pages ⇒ Object
89 90 91 92 93 94 95 96 |
# File 'lib/local_unfuddle_notebook/notebook.rb', line 89 def remote_pages Crack::XML.parse(self["pages/unique"].get)['pages'].map do |remote_page_hash| page_attributes = remote_page_hash.delete_if{|k, v| ! Page.attributes.include?(k.to_sym) } Page.new(page_attributes).tap do |page| page.notebook = self end end end |
#subdomain ⇒ Object
98 99 100 |
# File 'lib/local_unfuddle_notebook/notebook.rb', line 98 def subdomain url.match(%r{http.*://(.*)\.unfuddle.com})[1] end |
#update_attributes_file ⇒ Object
102 103 104 |
# File 'lib/local_unfuddle_notebook/notebook.rb', line 102 def update_attributes_file Pow(self.class.attributes_path).write local_attributes.to_yaml end |
#url_with_basic_auth(suburl) ⇒ Object
106 107 108 |
# File 'lib/local_unfuddle_notebook/notebook.rb', line 106 def url_with_basic_auth(suburl) self[suburl].url.sub("#{protocol}://", "#{protocol}://#{user}:#{password}@") end |