Class: Boxcutter::Boxpanel
- Inherits:
-
Object
- Object
- Boxcutter::Boxpanel
- Includes:
- HTTParty
- Defined in:
- lib/bluebox-boxcutter.rb
Overview
a boxpanel HTTP client, which auths with cookies from one’s browser.
Constant Summary collapse
- BASE_URI =
'https://boxpanel.bluebox.net/'
Class Method Summary collapse
-
.cookie_header ⇒ Object
get cookies from browser.
-
.get(path, options = {}, &block) ⇒ Object
wrap the default get method with auth and error handling.
- .get_html(path, options = {}, &block) ⇒ Object
- .machine_url(machine_id) ⇒ Object
-
.post(path, options = {}, &block) ⇒ Object
wrap the default post method with auth and error handling.
Class Method Details
.cookie_header ⇒ Object
get cookies from browser.
61 62 63 64 |
# File 'lib/bluebox-boxcutter.rb', line 61 def self. = Spunkmeyer. BASE_URI .to_a.map { |c| "#{c.first}=#{c.last[:value]}" }.join '; ' end |
.get(path, options = {}, &block) ⇒ Object
wrap the default get method with auth and error handling.
67 68 69 70 71 72 73 |
# File 'lib/bluebox-boxcutter.rb', line 67 def self.get(path, ={}, &block) [:headers] ||= {} [:headers]['Cookie'] = resp = super path, , &block raise "request failed with #{resp.code}: #{path}" unless resp.code == 200 resp.body end |
.get_html(path, options = {}, &block) ⇒ Object
75 76 77 |
# File 'lib/bluebox-boxcutter.rb', line 75 def self.get_html(path, ={}, &block) Nokogiri::HTML Boxcutter::Boxpanel::get(path, , &block) end |
.machine_url(machine_id) ⇒ Object
88 89 90 |
# File 'lib/bluebox-boxcutter.rb', line 88 def self.machine_url(machine_id) BASE_URI + "private/machines/#{machine_id}/edit" end |
.post(path, options = {}, &block) ⇒ Object
wrap the default post method with auth and error handling.
80 81 82 83 84 85 86 |
# File 'lib/bluebox-boxcutter.rb', line 80 def self.post(path, ={}, &block) [:headers] ||= {} [:headers]['Cookie'] = resp = super path, , &block raise "post request failed with #{resp.code}: #{path}" unless resp.code == 200 resp.body end |