Class: AN::Client
- Inherits:
-
Object
- Object
- AN::Client
- Defined in:
- lib/an.rb
Overview
Client idea taken from github.com/soveran/rel
Instance Attribute Summary collapse
-
#http ⇒ Object
readonly
Returns the value of attribute http.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(uri) ⇒ Client
constructor
A new instance of Client.
- #post(params, *args) ⇒ Object
- #reply(res) ⇒ Object
Constructor Details
#initialize(uri) ⇒ Client
Returns a new instance of Client.
148 149 150 151 152 |
# File 'lib/an.rb', line 148 def initialize(uri) @path = uri.path @http = Net::HTTP.new(uri.host, uri.port) @http.use_ssl = true if uri.scheme == "https" end |
Instance Attribute Details
#http ⇒ Object (readonly)
Returns the value of attribute http.
145 146 147 |
# File 'lib/an.rb', line 145 def http @http end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
146 147 148 |
# File 'lib/an.rb', line 146 def path @path end |
Class Method Details
.connect(url) ⇒ Object
164 165 166 |
# File 'lib/an.rb', line 164 def self.connect(url) new(URI.parse(url)) end |
Instance Method Details
#post(params, *args) ⇒ Object
154 155 156 |
# File 'lib/an.rb', line 154 def post(params, *args) reply(http.post(path, params, *args)) end |
#reply(res) ⇒ Object
158 159 160 161 162 |
# File 'lib/an.rb', line 158 def reply(res) raise RuntimeError, res.inspect unless res.code == "200" res.body end |