Class: ImeiScrapper::Scrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/imei-scrapper/scrapper.rb

Constant Summary collapse

SCRAP_URL =
'https://selfsolve.apple.com/wcResults.do'
NUMBER_PARAM =

apperantly can be anything, but is required

'blah-blah'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(imei) ⇒ Scrapper

Returns a new instance of Scrapper.



10
11
12
# File 'lib/imei-scrapper/scrapper.rb', line 10

def initialize(imei)
  @imei = imei
end

Instance Attribute Details

#imeiObject

Returns the value of attribute imei.



8
9
10
# File 'lib/imei-scrapper/scrapper.rb', line 8

def imei
  @imei
end

Instance Method Details

#get_infoObject



14
15
16
17
18
19
20
# File 'lib/imei-scrapper/scrapper.rb', line 14

def get_info
  begin
    ImeiScrapper::JSParser.parse_hw_data(request.body)
  rescue ParseException
    return nil
  end
end

#requestObject



22
23
24
25
26
27
28
29
# File 'lib/imei-scrapper/scrapper.rb', line 22

def request
  uri = URI(SCRAP_URL)
  req = Net::HTTP::Post.new(uri)
  req.set_form_data('sn' => @imei, 'num' => NUMBER_PARAM)
  res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
    http.request(req)
  end
end