Class: Bolide::Account
- Inherits:
-
Object
- Object
- Bolide::Account
- Defined in:
- lib/bolide/account.rb
Instance Attribute Summary collapse
-
#account ⇒ Object
Returns the value of attribute account.
-
#session ⇒ Object
Returns the value of attribute session.
Instance Method Summary collapse
- #get_q(name, create = true) ⇒ Object
- #headers ⇒ Object
-
#initialize(account, api_key, url = 'http://live.bolideapp.com') ⇒ Account
constructor
A new instance of Account.
- #marshal_dump ⇒ Object
- #marshal_load(data) ⇒ Object
- #send_msg(body, qs = ".*") ⇒ Object
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(account, api_key, url = 'http://live.bolideapp.com') @account = account @api_key = api_key @url = url @session = Patron::Session.new @session.base_url = @url end |
Instance Attribute Details
#account ⇒ Object
Returns the value of attribute account.
8 9 10 |
# File 'lib/bolide/account.rb', line 8 def account @account end |
#session ⇒ Object
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 |
#headers ⇒ Object
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_dump ⇒ Object
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 |