Class: T2Airtime::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/t2_airtime/base.rb

Direct Known Subclasses

API

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, password, url) ⇒ Base

Returns a new instance of Base.



8
9
10
11
12
13
# File 'lib/t2_airtime/base.rb', line 8

def initialize(user, password, url)
  @user = user
  @password = password
  @url = url
  @params = {}
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



3
4
5
# File 'lib/t2_airtime/base.rb', line 3

def params
  @params
end

#passwordObject (readonly)

Returns the value of attribute password.



3
4
5
# File 'lib/t2_airtime/base.rb', line 3

def password
  @password
end

#urlObject (readonly)

Returns the value of attribute url.



3
4
5
# File 'lib/t2_airtime/base.rb', line 3

def url
  @url
end

#userObject (readonly)

Returns the value of attribute user.



3
4
5
# File 'lib/t2_airtime/base.rb', line 3

def user
  @user
end

Class Method Details

.apiObject



15
16
17
18
19
20
21
# File 'lib/t2_airtime/base.rb', line 15

def self.api
  @api ||= new(
    ENV['T2_SHOP_USER'],
    ENV['T2_AIRTIME_KEY'],
    "https://#{T2Airtime::AIRTIME_DN}.#{T2Airtime::DOMAIN}/#{T2Airtime::ENDPOINT}"
  )
end

Instance Method Details

#run_action(name, method = :get) ⇒ Object



23
24
25
26
27
28
# File 'lib/t2_airtime/base.rb', line 23

def run_action(name, method = :get)
  request = T2Airtime::Request.new(@user, @password, @url, name, @params)
  request.run(method).on_complete do |reply|
    return T2Airtime::Reply.new(reply)
  end
end