Class: Hobix::API
- Inherits:
-
BaseFacet
- Object
- BasePlugin
- BaseFacet
- Hobix::API
- Defined in:
- lib/hobix/api.rb
Overview
The API facet
Instance Method Summary collapse
- #edit_action ⇒ Object
- #get(app) ⇒ Object
-
#initialize(weblog, defaults = {}) ⇒ API
constructor
A new instance of API.
- #list_action(*inpath) ⇒ Object
- #new_action ⇒ Object
- #post_action(*id) ⇒ Object
- #regen_action ⇒ Object
- #search_action(words, *inpath) ⇒ Object
- #upgen_action ⇒ Object
Methods inherited from BaseFacet
Methods inherited from BasePlugin
Constructor Details
#initialize(weblog, defaults = {}) ⇒ API
Returns a new instance of API.
21 22 23 |
# File 'lib/hobix/api.rb', line 21 def initialize( weblog, defaults = {} ) @weblog = weblog end |
Instance Method Details
#edit_action ⇒ Object
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/hobix/api.rb', line 79 def edit_action case @app.request_method when "GET" @weblog when "POST" config = YAML::load( @app.request_body ) config.save @weblog.hobix_yaml "Weblog configuration saved." end end |
#get(app) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/hobix/api.rb', line 24 def get app if app.respond_to? :action_uri return true unless protect app, @weblog @app = app prefix, action, *args = app.action_uri.split( '/' ) if prefix == "remote" if respond_to? "#{ action }_action" begin @app.puts method( "#{ action }_action" ).call( *args ).to_yaml return true rescue StandardError => e @app.puts e.to_yaml end return true end end end end |
#list_action(*inpath) ⇒ Object
57 58 59 60 |
# File 'lib/hobix/api.rb', line 57 def list_action( *inpath ) inpath = inpath.join '/' @weblog.storage.find( :all => true, :inpath => inpath ) end |
#new_action ⇒ Object
53 54 55 |
# File 'lib/hobix/api.rb', line 53 def new_action @weblog.entry_class.new end |
#post_action(*id) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/hobix/api.rb', line 67 def post_action( *id ) id = id.join '/' case @app.request_method when "GET" @weblog.storage.load_entry id when "POST" entry = YAML::load( @app.request_body ) @weblog.storage.save_entry id, entry "Entry successfully saved." end end |
#regen_action ⇒ Object
48 49 50 51 |
# File 'lib/hobix/api.rb', line 48 def regen_action @weblog.regenerate "Regeneration complete" end |
#search_action(words, *inpath) ⇒ Object
62 63 64 65 |
# File 'lib/hobix/api.rb', line 62 def search_action( words, *inpath ) inpath = inpath.join '/' @weblog.storage.find( :all => true, :inpath => inpath, :search => words.split( ',' ) ) end |
#upgen_action ⇒ Object
43 44 45 46 |
# File 'lib/hobix/api.rb', line 43 def upgen_action @weblog.regenerate( :update ) "Regeneration complete" end |