Class: Bolide::Account

Inherits:
Object
  • Object
show all
Defined in:
lib/bolide/account.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(account, api_key, url = 'http://live.bolideapp.com') ⇒ Account

Returns a new instance of Account.



10
11
12
13
14
15
16
# File 'lib/bolide/account.rb', line 10

def initialize(, api_key, url = 'http://live.bolideapp.com')
  @account = 
  @api_key = api_key
  @url = url
  @session = Patron::Session.new
  @session.base_url = @url
end

Instance Attribute Details

#accountObject

Returns the value of attribute account.



8
9
10
# File 'lib/bolide/account.rb', line 8

def 
  @account
end

#sessionObject

Returns the value of attribute session.



8
9
10
# File 'lib/bolide/account.rb', line 8

def session
  @session
end

Instance Method Details

#get_q(name, create = true) ⇒ Object



18
19
20
21
22
# File 'lib/bolide/account.rb', line 18

def get_q(name, create = true)
  q = Q.new(self , name)
  q.new_token if create
  q 
end

#headersObject



42
43
44
45
# File 'lib/bolide/account.rb', line 42

def headers
  now = DateTime.now.to_s
  return {'X-Bol-Date'=>now, 'X-Bol-Authentication'=>auth_key(now), 'Content-Type'=>'application/xml'}
end

#marshal_dumpObject



47
48
49
50
51
52
53
# File 'lib/bolide/account.rb', line 47

def marshal_dump
  {
    :account=>@account,
    :api_key=>@api_key,
    :url=>@url,
  }
end

#marshal_load(data) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/bolide/account.rb', line 55

def marshal_load(data)
  @account = data[:account]
  @api_key = data[:api_key]
  @url = data[:url]
  @session = Patron::Session.new
  @session.base_url = @url
end

#send_msg(body, qs = ".*") ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/bolide/account.rb', line 24

def send_msg(body, qs = ".*")
  return false if !qs.kind_of?(String) && !qs.kind_of?(Array)

  msg = create_msg(body, qs)
  resp = session.post('/msg.xml', msg, headers)
  p resp.body
  if resp.status > 400
    xml = Nokogiri::XML(resp.body)

    @error = xml.at_css('error')
    if(@error)
      raise @error.content
    else
      raise resp.body
    end
  end
end