Class: Cellcom::Request
- Inherits:
-
Object
- Object
- Cellcom::Request
- Defined in:
- lib/cellcom/request.rb
Constant Summary collapse
- API_URL =
'http://www.cellcom.be/data/bulkHTTP.php'
Instance Method Summary collapse
- #connection(opts = {}) ⇒ Object
- #get(opts = {}) ⇒ Object
-
#initialize(params = {}) ⇒ Request
constructor
A new instance of Request.
- #uri ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Request
Returns a new instance of Request.
8 9 10 |
# File 'lib/cellcom/request.rb', line 8 def initialize(params={}) @params = params end |
Instance Method Details
#connection(opts = {}) ⇒ Object
16 17 18 19 20 |
# File 'lib/cellcom/request.rb', line 16 def connection(opts={}) Net::HTTP.new(uri.host, uri.port).tap do |http| http.open_timeout = http.read_timeout = opts[:timeout] if opts.key? :timeout end end |
#get(opts = {}) ⇒ Object
12 13 14 |
# File 'lib/cellcom/request.rb', line 12 def get(opts={}) connection(opts).start { |conn| conn.request(Net::HTTP::Get.new(uri)) } end |
#uri ⇒ Object
22 23 24 25 26 |
# File 'lib/cellcom/request.rb', line 22 def uri URI(API_URL).tap do |uri| uri.query = URI.encode_www_form(@params) end end |