Class: Todoly::RestInterface
- Inherits:
-
Object
- Object
- Todoly::RestInterface
- Defined in:
- lib/todoly/rest_interface.rb
Instance Method Summary collapse
-
#initialize(opt = {}) ⇒ RestInterface
constructor
A new instance of RestInterface.
- #rest_client_with_password(user, password) ⇒ Object
- #rest_client_with_token(token) ⇒ Object
Constructor Details
#initialize(opt = {}) ⇒ RestInterface
Returns a new instance of RestInterface.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/todoly/rest_interface.rb', line 105 def initialize(opt={}) if ENV["https_proxy"] RestClient.proxy = ENV["https_proxy"] elsif ENV["http_proxy"] RestClient.proxy = ENV["http_proxy"] end @api_url = opt[:api_url] || TODOLY_API_URL if opt[:token] @api = rest_client_with_token(token) elsif opt[:email] and opt[:password] @api = rest_client_with_password(opt[:email], opt[:password]) @api = rest_client_with_token(get_token) else raise "Please specify :email and :password or :token" end end |
Instance Method Details
#rest_client_with_password(user, password) ⇒ Object
17 18 19 20 21 |
# File 'lib/todoly/rest_interface.rb', line 17 def rest_client_with_password(user, password) RestClient::Resource.new(@api_url, :user => user, :password => password) end |
#rest_client_with_token(token) ⇒ Object
12 13 14 15 |
# File 'lib/todoly/rest_interface.rb', line 12 def rest_client_with_token(token) RestClient::Resource.new(@api_url, :headers => { :Token => token }) end |