Class: Sistrix::Credits

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/sistrix/credits.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Base

#base_uri, #fetch, #method_name

Constructor Details

#initialize(options = {}) ⇒ Credits

Returns a new instance of Credits.



10
11
12
13
14
15
16
17
18
# File 'lib/sistrix/credits.rb', line 10

def initialize(options = {})
  @options = {
    'api_key' => Sistrix.config.api_key,
  }

  if Sistrix.config.proxy
    RestClient.proxy = Sistrix.config.proxy
  end
end

Instance Attribute Details

#creditsObject (readonly)

Returns the value of attribute credits.



8
9
10
# File 'lib/sistrix/credits.rb', line 8

def credits
  @credits
end

#credits_availableObject (readonly)

Returns the value of attribute credits_available.



8
9
10
# File 'lib/sistrix/credits.rb', line 8

def credits_available
  @credits_available
end

Instance Method Details

#call(options = {}) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/sistrix/credits.rb', line 20

def call(options = {})
  data = fetch(options)

  @credits = data.xpath('/response/credits').first['used'].to_i
  @credits_available = data.xpath('/response/answer/credits').first['value'].to_s.strip.to_i

  self
end