class Manga::Tools::Session
Network Session
class (Session
ID handling + HTTP CRUD handling)
Constants
- DEFAULT_HOST
Attributes
options[R]
@return [Hash] options hash instance
store[R]
@return [SessionStore] the session store instance
Public Class Methods
new()
click to toggle source
# File lib/manga/tools/session.rb, line 19 def initialize @store = Manga::Tools::SessionStore.new @options = {} end
Public Instance Methods
get(path)
click to toggle source
# File lib/manga/tools/session.rb, line 30 def get(path) response = with_session { |session_id| Manga::Tools::Http.get(build_full_url(path), session_id) } JSON.parse(response.body) end
options=(new_options)
click to toggle source
# File lib/manga/tools/session.rb, line 24 def options=(new_options) @base_url = nil @options = new_options store.session_file_name = @options[:session_file_name] if @options[:session_file_name] end
post(path, params)
click to toggle source
# File lib/manga/tools/session.rb, line 35 def post(path, params) response = with_session { |session_id| Manga::Tools::Http.post(build_full_url(path), session_id, params) } JSON.parse(response.body) end
Private Instance Methods
base_url()
click to toggle source
# File lib/manga/tools/session.rb, line 50 def base_url @base_url ||= options[:host] ? "http://#{options[:host]}" : DEFAULT_HOST end
build_full_url(path)
click to toggle source
# File lib/manga/tools/session.rb, line 54 def build_full_url(path) "#{base_url}#{path}" end
with_session() { |session_id| ... }
click to toggle source
# File lib/manga/tools/session.rb, line 42 def with_session session_id = store.load res = yield session_id session_id = res.headers['X-Session-ID'] store.store(session_id) if session_id res end