Class: Tele42::Base
- Inherits:
-
Object
- Object
- Tele42::Base
- Defined in:
- lib/tele42/base.rb
Direct Known Subclasses
Instance Method Summary collapse
- #check_options ⇒ Object
- #connection ⇒ Object
- #default_params ⇒ Object
- #faraday_options ⇒ Object
-
#initialize(options = {}) ⇒ Base
constructor
A new instance of Base.
- #parse_options(args) ⇒ Object
- #server_url ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Base
Returns a new instance of Base.
5 6 7 8 |
# File 'lib/tele42/base.rb', line 5 def initialize( = {}) () end |
Instance Method Details
#check_options ⇒ Object
24 25 26 27 28 |
# File 'lib/tele42/base.rb', line 24 def raise ::Tele42::InvalidUserName, 'username should be set' if @username.nil? || @username.empty? raise ::Tele42::InvalidPassword, 'password should be set' if @password.nil? || @password.empty? raise ::Tele42::InvalidServer, 'server should be set' if @server.nil? || @server.empty? end |
#connection ⇒ Object
50 51 52 53 54 55 |
# File 'lib/tele42/base.rb', line 50 def connection @connection ||= Faraday::Connection.new() do |conn| conn.request :url_encoded conn.adapter Faraday.default_adapter end end |
#default_params ⇒ Object
17 18 19 20 21 22 |
# File 'lib/tele42/base.rb', line 17 def default_params @default_params ||= { 'username' => @username, 'password' => @password } end |
#faraday_options ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/tele42/base.rb', line 40 def { :url => server_url, :headers => { :accept => 'text/html', :user_agent => ::Tele42.user_agent } } end |
#parse_options(args) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/tele42/base.rb', line 10 def (args) %w(username password server route).each do |k| ks = k.to_sym self.instance_variable_set("@#{k}".to_sym, args[ks] || ::Tele42.__send__(ks)) end end |
#server_url ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/tele42/base.rb', line 30 def server_url @server_url ||= begin if @server =~ /http/ @server else "https://#{@server}" end end end |