Class: Middleman::Tapirgo::Syncer
- Inherits:
-
Object
- Object
- Middleman::Tapirgo::Syncer
- Defined in:
- lib/middleman-tapirgo/syncer.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Syncer
constructor
A new instance of Syncer.
- #inst ⇒ Object
- #send_to_tapirgo(item) ⇒ Object
- #sync ⇒ Object
- #syncable_items ⇒ Object
- #uri ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Syncer
Returns a new instance of Syncer.
7 8 9 |
# File 'lib/middleman-tapirgo/syncer.rb', line 7 def initialize(={}) @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/middleman-tapirgo/syncer.rb', line 6 def @options end |
Instance Method Details
#inst ⇒ Object
11 12 13 |
# File 'lib/middleman-tapirgo/syncer.rb', line 11 def inst ::Middleman::Application.server.inst end |
#send_to_tapirgo(item) ⇒ Object
38 39 40 41 42 |
# File 'lib/middleman-tapirgo/syncer.rb', line 38 def send_to_tapirgo(item) req = Net::HTTP::Post.new(uri.path, initheader = {'Content-Type' =>'application/json'}) req.body = JSON.generate(item) Net::HTTP.new(uri.host, uri.port).start {|http| http.request(req) } end |
#sync ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/middleman-tapirgo/syncer.rb', line 23 def sync return unless [:api_key] syncable_items.each do |r| syncable_item = Middleman::Tapirgo::SyncableItem.new(r) response = send_to_tapirgo(syncable_item) if response.code != '200' puts "Failed sending #{syncable_item.link} to TapirGo" puts "Response #{response.code} #{response.}" break end end puts "Synced #{syncable_items.length} items to TapirGo" end |
#syncable_items ⇒ Object
19 20 21 |
# File 'lib/middleman-tapirgo/syncer.rb', line 19 def syncable_items @syncable_items ||= inst.sitemap.resources.select { |r| r.ext == '.html' } end |
#uri ⇒ Object
15 16 17 |
# File 'lib/middleman-tapirgo/syncer.rb', line 15 def uri URI("http://tapirgo.com/api/1/push_article.json?secret=#{[:api_key]}") end |