Class: Powncer::Connection
- Inherits:
-
Object
- Object
- Powncer::Connection
- Defined in:
- lib/powncer/connection.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#authenticated ⇒ Object
Returns the value of attribute authenticated.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #get(uri, use_auth = false) ⇒ Object
-
#initialize(is_auth = false) ⇒ Connection
constructor
A new instance of Connection.
Constructor Details
#initialize(is_auth = false) ⇒ Connection
Returns a new instance of Connection.
7 8 9 10 |
# File 'lib/powncer/connection.rb', line 7 def initialize(is_auth=false) @url = "#{Powncer::Version::API_URL}/#{Powncer::Version::API_VERSION}" @authenticated = is_auth end |
Instance Attribute Details
#authenticated ⇒ Object
Returns the value of attribute authenticated.
5 6 7 |
# File 'lib/powncer/connection.rb', line 5 def authenticated @authenticated end |
#url ⇒ Object
Returns the value of attribute url.
5 6 7 |
# File 'lib/powncer/connection.rb', line 5 def url @url end |
Instance Method Details
#get(uri, use_auth = false) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/powncer/connection.rb', line 12 def get(uri, use_auth=false) endpoint = "#{@url}#{uri}" begin if use_auth response = Authentication::Basic.open(endpoint, Powncer.connect!.) else response = open(endpoint) end case response.status when ["200", "OK"] response.read else raise BadResponse end rescue raise ConnectionUnavailable end end |