Class: RSimpy::Client
Instance Method Summary collapse
- #execute(method, uri) ⇒ Object
- #get(uri) ⇒ Object
-
#initialize(user) ⇒ Client
constructor
A new instance of Client.
- #post(uri) ⇒ Object
Constructor Details
#initialize(user) ⇒ Client
Returns a new instance of Client.
14 15 16 17 18 |
# File 'lib/client.rb', line 14 def initialize(user) raise RSimpy::UserNotProvidedError unless user && user.valid? login, pass = user.credentials self.class.basic_auth login, pass end |
Instance Method Details
#execute(method, uri) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/client.rb', line 20 def execute method, uri case method when :get get uri when :post post uri end end |
#get(uri) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/client.rb', line 29 def get uri begin self.class.get uri rescue SocketError => error raise ConnectionError.new "Error connecting to Simpy: #{error.message}" end end |
#post(uri) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/client.rb', line 37 def post uri begin self.class.post uri rescue SocketError => error raise ConnectionError.new "Error connecting to Simpy: #{error.message}" end end |