Class: MyBitcasa::Connection
- Inherits:
-
Faraday::Connection
- Object
- Faraday::Connection
- MyBitcasa::Connection
- Defined in:
- lib/my_bitcasa/connection.rb
Instance Attribute Summary collapse
-
#cookie ⇒ Object
Returns the value of attribute cookie.
- #login_engine ⇒ Object
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(user: nil, password: nil, multipart: false) ⇒ Connection
constructor
A new instance of Connection.
- #loggedin? ⇒ Boolean
- #login(user, password) ⇒ Object
- #logout! ⇒ Object
- #multipart ⇒ Object
Constructor Details
#initialize(user: nil, password: nil, multipart: false) ⇒ Connection
Returns a new instance of Connection.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/my_bitcasa/connection.rb', line 16 def initialize(user: nil, password: nil, multipart: false) super(:url => 'https://my.bitcasa.com') do |conn| conn.use FaradayMiddleware::FollowRedirects if multipart conn.request :multipart else conn.request :url_encoded end #conn.response :logger conn.response :my_bitcasa conn.adapter Faraday.default_adapter end @headers[:user_agent] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:10.0.2) Gecko/20100101 Firefox/10.0.2" yield self if block_given? login(user, password) if user && password ensure #ObjectSpace.define_finalizer(self) { logout! } end |
Instance Attribute Details
#cookie ⇒ Object
Returns the value of attribute cookie.
14 15 16 |
# File 'lib/my_bitcasa/connection.rb', line 14 def @cookie end |
#login_engine ⇒ Object
37 38 39 |
# File 'lib/my_bitcasa/connection.rb', line 37 def login_engine @login_engine ||= LoginEngine.autodetect.new end |
Class Method Details
.uri_encode(path) ⇒ Object
97 98 99 |
# File 'lib/my_bitcasa/connection.rb', line 97 def uri_encode(path) URI.encode(path).gsub("[", "%5B").gsub("]", "%5D") end |
Instance Method Details
#loggedin? ⇒ Boolean
46 47 48 |
# File 'lib/my_bitcasa/connection.rb', line 46 def loggedin? !!@cookie end |
#login(user, password) ⇒ Object
41 42 43 44 |
# File 'lib/my_bitcasa/connection.rb', line 41 def login(user, password) login_engine.login(user, password) @cookie = login_engine. end |
#logout! ⇒ Object
50 51 52 53 54 55 |
# File 'lib/my_bitcasa/connection.rb', line 50 def logout! if loggedin? self.get("/logout") @cookie = nil end end |
#multipart ⇒ Object
78 79 80 81 82 |
# File 'lib/my_bitcasa/connection.rb', line 78 def multipart @multipart ||= self.class.new(multipart: true) @multipart. = self. @multipart end |