Class: Scraper::Crawler::AppleImei
- Inherits:
-
Object
- Object
- Scraper::Crawler::AppleImei
- Defined in:
- lib/scraper/crawler/apple_imei.rb
Overview
AppleImei controls request to the apple site
Constant Summary
- URL =
URI("https://selfsolve.apple.com/wcResults.do")
- USER_AGENT =
"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:38.0) " \ "Gecko/20100101 Firefox/38.0"
Instance Method Summary (collapse)
-
- (Integer) number
Random number.
-
- (String) page
Page content.
-
- (Boolean) parsable?
Is content able for parsing?.
-
- (String) request_imei(imei)
Make request with the given IMEI number.
-
- (Integer) status_code
HTTP response code.
Instance Method Details
- (Integer) number
Note:
We need that number to do the correct imei request.
Random number
54 55 56 |
# File 'lib/scraper/crawler/apple_imei.rb', line 54 def number rand(1000..3000) end |
- (String) page
Page content
33 34 35 |
# File 'lib/scraper/crawler/apple_imei.rb', line 33 def page @res ? @res.body : "" end |
- (Boolean) parsable?
Is content able for parsing?
64 65 66 |
# File 'lib/scraper/crawler/apple_imei.rb', line 64 def parsable? status_code.between?(200, 299) && !!/html/i.match(page) end |
- (String) request_imei(imei)
Make request with the given IMEI number
20 21 22 23 24 25 26 |
# File 'lib/scraper/crawler/apple_imei.rb', line 20 def request_imei(imei) req = Net::HTTP::Post.new(URL, "User-Agent" => USER_AGENT) req.set_form_data(sn: imei, num: number) @res = Net::HTTP.start(URL.hostname, URL.port, use_ssl: true) do |http| http.request(req) end end |
- (Integer) status_code
HTTP response code
42 43 44 |
# File 'lib/scraper/crawler/apple_imei.rb', line 42 def status_code @res ? @res.code.to_i : 0 end |