Class: ServiceCall

Inherits:
Object
  • Object
show all
Defined in:
lib/etvnet_seek/core/service_call.rb

Direct Known Subclasses

AccessPage, LoginPage, Page

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ ServiceCall

Returns a new instance of ServiceCall.



20
21
22
# File 'lib/etvnet_seek/core/service_call.rb', line 20

def initialize(url)
  @url = url
end

Instance Attribute Details

#urlObject (readonly)

Returns the value of attribute url.



18
19
20
# File 'lib/etvnet_seek/core/service_call.rb', line 18

def url
  @url
end

Instance Method Details

#getObject



24
25
26
# File 'lib/etvnet_seek/core/service_call.rb', line 24

def get
  open(url, "User-Agent" => "Ruby/#{RUBY_VERSION}")
end

#post(params, headers, url = @url) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/etvnet_seek/core/service_call.rb', line 28

def post params, headers, url = @url
  request = Net::HTTP::Post.new(url, headers.merge({"User-Agent" => "Ruby/#{RUBY_VERSION}"}))
  request.set_form_data(params)
  #request.basic_auth(un, pw)
  #"Content-Type"=>"application/x-www-form-urlencoded",
  #"Authorization" => "Basic " + Base64::encode64("account:password")
  response = request(request, url)

  if response.class == Net::HTTPMovedPermanently
    response = handle_redirect response['location'], params, headers
  end

  response
end