osxwarranty 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in osxwarranty.gemspec
4
+ gemspec
5
+
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Anurag Mohanty
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # OSXwarranty
2
+
3
+ This gem brings together glarizza's ruby script for parsing warranty info from Apple and chilcote's ASD check.
4
+ ## Installation
5
+
6
+ Add this line to your application's Gemfile:
7
+
8
+ gem 'osxwarranty'
9
+
10
+ And then execute:
11
+
12
+ $ bundle
13
+
14
+ Or install it yourself as:
15
+
16
+ $ gem install osxwarranty
17
+
18
+ ## Usage
19
+
20
+ If you want warranty info as well as asd info:
21
+
22
+ osx = OSXwarranty::Base.new
23
+
24
+ osx.info("SERIAL_NUMBER")
25
+
26
+ if you want warranty info without the asd info:
27
+ osx = OSXwarranty::Base.new
28
+
29
+ osx.get_warranty_info("SERIAL_NUMBER")
30
+
31
+ If you want just the model info:
32
+ osx = OSXwarranty::Base.new
33
+
34
+ osx.get_model_info("SERIAL_NUMBER")
35
+
36
+
37
+ ## Contributing
38
+
39
+ 1. Fork it
40
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
41
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
42
+ 4. Push to the branch (`git push origin my-new-feature`)
43
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ require "httpclient"
2
+ require "osxwarranty/version"
3
+ require "osxwarranty/base"
4
+ module OSXwarranty
5
+ end
@@ -0,0 +1,49 @@
1
+ require 'httpclient'
2
+ require 'nokogiri'
3
+ module OSXwarranty
4
+ class Base
5
+ # glarizza's get_warranty method (https://github.com/glarizza/scripts/blob/master/ruby/warranty.rb)
6
+ def info(serial = nil)
7
+ @serial = serial
8
+ warranty_info = get_warranty_info(@serial)
9
+ model = get_model_info(serial)
10
+ asdinfo = asdcheck(model)
11
+ warranty_info = warranty_info.merge({:model => model, :asdinfo => asdinfo})
12
+ return warranty_info
13
+ end
14
+ def get_warranty_info(serial)
15
+ uri = "https://selfsolve.apple.com/wcResults.do"
16
+ options = {:sn=>serial, :continue=>"Continue", :cn=>"", :locale=>"", :caller=>"", :num=>"0"}
17
+ response = HTTPClient.post(uri,options)
18
+ response_body = response.content
19
+ repair_covered = response_body.split('warrantyPage.warrantycheck.displayHWSupportInfo').last.split('Repairs and Service Coverage: ')[1] =~ /^Active/ ? true : false
20
+ expiration_date = response_body.split('Estimated Expiration Date: ')[1].split('<')[0] if repair_covered == true
21
+ expiration_date = "EXPIRED" if expiration_date.nil?
22
+ warranty_info = {:repair_covered => repair_covered, :expiration_date => expiration_date}
23
+ return warranty_info
24
+ end
25
+
26
+ def get_model_info(serial)
27
+ serial_size = serial.size
28
+ if serial_size == 12
29
+ search_q = serial[-4,4]
30
+ elsif serial_size == 11
31
+ search_q = serial[-3,3]
32
+ end
33
+ uri = "http://support-sp.apple.com/sp/product?cc=#{search_q}&lang=en_US"
34
+ response = HTTPClient.get(uri)
35
+ nokogiri_data = Nokogiri::XML(response.body)
36
+ model = nokogiri_data.search('configCode').text
37
+ return model
38
+ end
39
+ # chilcote's asdcheck (https://github.com/chilcote/warranty/blob/master/asdcheck)
40
+ def asdcheck(model)
41
+ asd_hash = Hash.new
42
+ HTTPClient.get("https://raw.github.com/tevren/warranty/master/asdcheck").body.each_line do |line|
43
+ asd_array = line.split(":")
44
+ asd_hash[asd_array[0]] = asd_array[1].gsub("\n","")
45
+ end
46
+ return asd_hash[model]
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,3 @@
1
+ module OSXwarranty
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/osxwarranty/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Anurag Mohanty"]
6
+ gem.email = ["anurag@columbia.edu"]
7
+ gem.description = %q{retrieves warranty info for macs based on serial number, uses glarizza's warranty script and chilcote's asdcheck script}
8
+ gem.summary = %q{retrieves warranty info for macs based on serial number}
9
+ gem.homepage = "https://github.com/tevren/osxwarranty"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "osxwarranty"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = OSXwarranty::VERSION
17
+ gem.add_dependency "httpclient"
18
+ gem.add_dependency "nokogiri"
19
+ gem.add_development_dependency "rspec"
20
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe OSXwarranty do
4
+ before :each do
5
+ @warranty = OSXwarranty::Base.new
6
+ @serial = "G86250YSU39"
7
+ @model = "Mac Pro"
8
+ end
9
+
10
+ describe "#get_warranty_info" do
11
+ it "should return the size of the hash returned from #get_warranty_info" do
12
+ @warranty.get_warranty_info(@serial).size.should eql 2
13
+ end
14
+ end
15
+ describe "#get_model_info" do
16
+ it "should not be nil" do
17
+ @warranty.get_model_info(@serial).size.should_not be_nil
18
+ end
19
+ end
20
+ describe "#asdcheck" do
21
+ it "should not be nil" do
22
+ @warranty.asdcheck(@model).size.should_not be_nil
23
+ end
24
+ end
25
+
26
+ describe "#info" do
27
+ it "should return the size of the hash returned from #info" do
28
+ @warranty.info(@serial).size.should eql 4
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,2 @@
1
+ require 'osxwarranty/base'
2
+ require 'yaml'
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: osxwarranty
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Anurag Mohanty
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httpclient
16
+ requirement: &70298041777760 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70298041777760
25
+ - !ruby/object:Gem::Dependency
26
+ name: nokogiri
27
+ requirement: &70298041777340 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70298041777340
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &70298041776920 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70298041776920
47
+ description: retrieves warranty info for macs based on serial number, uses glarizza's
48
+ warranty script and chilcote's asdcheck script
49
+ email:
50
+ - anurag@columbia.edu
51
+ executables: []
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - .gitignore
56
+ - Gemfile
57
+ - LICENSE
58
+ - README.md
59
+ - Rakefile
60
+ - lib/osxwarranty.rb
61
+ - lib/osxwarranty/base.rb
62
+ - lib/osxwarranty/version.rb
63
+ - osxwarranty.gemspec
64
+ - spec/osxwarranty_spec.rb
65
+ - spec/spec_helper.rb
66
+ homepage: https://github.com/tevren/osxwarranty
67
+ licenses: []
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 1.8.10
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: retrieves warranty info for macs based on serial number
90
+ test_files:
91
+ - spec/osxwarranty_spec.rb
92
+ - spec/spec_helper.rb