Class: HackT::HackTNet
- Inherits:
-
Object
- Object
- HackT::HackTNet
- Defined in:
- lib/hackt/net.rb
Class Method Summary collapse
- .Do(http) {|HTTP| ... } ⇒ Object
- .Get(uri, params, prevent_errors = true) ⇒ Object
- .HTTP ⇒ Object
- .Post(uri, params, prevent_errors = true) ⇒ Object
Class Method Details
.Do(http) {|HTTP| ... } ⇒ Object
33 34 35 |
# File 'lib/hackt/net.rb', line 33 def Do(http) yield HTTP end |
.Get(uri, params, prevent_errors = true) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/hackt/net.rb', line 7 def Get(uri, params, prevent_errors = true) uri = URI(HackT::URL + uri) uri.query = URI.encode_www_form(params) response = Net::HTTP.get_response(uri) if response.is_a?(Net::HTTPSuccess) JSON.parse(response.body) else raise HackT::HackTError, "Not OK: #{response.inspect}" unless prevent_errors end rescue raise HackT::HackTError, "Not OK: #{response.inspect}" unless prevent_errors end |
.HTTP ⇒ Object
37 38 39 40 41 42 |
# File 'lib/hackt/net.rb', line 37 def HTTP uri = URI(HackT::URL) Net::HTTP.start(uri.host, uri.port) do |http| http end end |
.Post(uri, params, prevent_errors = true) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/hackt/net.rb', line 21 def Post(uri, params, prevent_errors = true) uri = URI(HackT::URL + uri) response = Net::HTTP.post_form(uri, params) if response.is_a?(Net::HTTPSuccess) JSON.parse(response.body) else raise "Not OK: #{response.inspect}" unless prevent_errors end rescue raise HackT::HackTError, "Not OK: #{response.inspect}" unless prevent_errors end |