Class: Boxcutter::Boxpanel

Inherits:
Object
  • Object
show all
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

Class Method Details

get cookies from browser.



61
62
63
64
# File 'lib/bluebox-boxcutter.rb', line 61

def self.cookie_header
  cookies = Spunkmeyer.cookies BASE_URI
  cookies.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, options={}, &block)
  options[:headers] ||= {}
  options[:headers]['Cookie'] = cookie_header
  resp = super path, options, &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, options={}, &block)
  Nokogiri::HTML Boxcutter::Boxpanel::get(path, options, &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, options={}, &block)
  options[:headers] ||= {}
  options[:headers]['Cookie'] = cookie_header
  resp = super path, options, &block
  raise "post request failed with #{resp.code}: #{path}" unless resp.code == 200
  resp.body
end