Class: Remotely::Application
- Inherits:
-
Object
- Object
- Remotely::Application
- Defined in:
- lib/remotely/application.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#authorization(type = nil, token = nil) ⇒ Object
Set or get a custom Authorization header.
-
#basic_auth(user = nil, password = nil) ⇒ Object
Set or get BasicAuth credentials.
-
#connection ⇒ Object
Connection to the application (with BasicAuth if it was set).
-
#initialize(name, &block) ⇒ Application
constructor
A new instance of Application.
- #middleware ⇒ Object
-
#token_auth(token = nil, options = {}) ⇒ Object
Set or get the Authorization header.
-
#url(url = nil) ⇒ Object
Set or get the applications base url.
- #use_middleware(klass, options = {}) ⇒ Object
Constructor Details
#initialize(name, &block) ⇒ Application
Returns a new instance of Application.
5 6 7 8 |
# File 'lib/remotely/application.rb', line 5 def initialize(name, &block) @name = name instance_eval(&block) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/remotely/application.rb', line 3 def name @name end |
Instance Method Details
#authorization(type = nil, token = nil) ⇒ Object
Set or get a custom Authorization header.
- As seen here: https://github.com/lostisland/faraday/blob/master/lib/faraday/connection.rb#L227
46 47 48 49 |
# File 'lib/remotely/application.rb', line 46 def (type=nil, token=nil) return @authorization unless type && token @authorization = [type, token] end |
#basic_auth(user = nil, password = nil) ⇒ Object
Set or get BasicAuth credentials.
24 25 26 27 |
# File 'lib/remotely/application.rb', line 24 def basic_auth(user=nil, password=nil) return @basic_auth unless user && password @basic_auth = [user, password] end |
#connection ⇒ Object
Connection to the application (with BasicAuth if it was set).
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/remotely/application.rb', line 61 def connection return unless @url @connection ||= Faraday::Connection.new(@url) do |b| middleware.each { |m, opts| b.use(m, opts) } b.request :url_encoded b.adapter :net_http end @connection.basic_auth(*@basic_auth) if @basic_auth @connection.token_auth(*@token_auth) if @token_auth @connection.(*@authorization) if @authorization @connection end |
#middleware ⇒ Object
55 56 57 |
# File 'lib/remotely/application.rb', line 55 def middleware @middleware ||= [] end |
#token_auth(token = nil, options = {}) ⇒ Object
Set or get the Authorization header.
- As seen here: https://github.com/lostisland/faraday/blob/master/lib/faraday/connection.rb#L204
35 36 37 38 |
# File 'lib/remotely/application.rb', line 35 def token_auth(token=nil, ={}) return @token_auth unless token @token_auth = [token, ] end |
#url(url = nil) ⇒ Object
Set or get the applications base url.
14 15 16 17 |
# File 'lib/remotely/application.rb', line 14 def url(url=nil) return @url unless url @url = URI.parse(set_scheme(url)).to_s end |
#use_middleware(klass, options = {}) ⇒ Object
51 52 53 |
# File 'lib/remotely/application.rb', line 51 def use_middleware(klass, = {}) middleware << [klass, ] end |