| Class | Hobix::API |
| In: |
lib/hobix/api.rb
|
| Parent: | BaseFacet |
The API facet
# File lib/hobix/api.rb, line 21
21: def initialize( weblog, defaults = {} )
22: @weblog = weblog
23: end
# File lib/hobix/api.rb, line 79
79: def edit_action
80: case @app.request_method
81: when "GET"
82: @weblog
83: when "POST"
84: config = YAML::load( @app.request_body )
85: config.save @weblog.hobix_yaml
86: "Weblog configuration saved."
87: end
88: end
# File lib/hobix/api.rb, line 24
24: def get app
25: if app.respond_to? :action_uri
26: return true unless protect app, @weblog
27: @app = app
28: prefix, action, *args = app.action_uri.split( '/' )
29: if prefix == "remote"
30: if respond_to? "#{ action }_action"
31: begin
32: @app.puts method( "#{ action }_action" ).call( *args ).to_yaml
33: return true
34: rescue StandardError => e
35: @app.puts e.to_yaml
36: end
37: return true
38: end
39: end
40: end
41: end
# File lib/hobix/api.rb, line 57
57: def list_action( *inpath )
58: inpath = inpath.join '/'
59: @weblog.storage.find( :all => true, :inpath => inpath )
60: end
# File lib/hobix/api.rb, line 67
67: def post_action( *id )
68: id = id.join '/'
69: case @app.request_method
70: when "GET"
71: @weblog.storage.load_entry id
72: when "POST"
73: entry = YAML::load( @app.request_body )
74: @weblog.storage.save_entry id, entry
75: "Entry successfully saved."
76: end
77: end
# File lib/hobix/api.rb, line 48
48: def regen_action
49: @weblog.regenerate
50: "Regeneration complete"
51: end
# File lib/hobix/api.rb, line 62
62: def search_action( words, *inpath )
63: inpath = inpath.join '/'
64: @weblog.storage.find( :all => true, :inpath => inpath, :search => words.split( ',' ) )
65: end