apple_system_status 0.1.0.beta2 → 0.1.0.beta3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cec83e535718f501b5e3bf6c060dd37192602928
4
- data.tar.gz: 8fd5d5181088475c848f544a94700846faad5b79
3
+ metadata.gz: ae7c1bc4d64eafd171c4df528eb028503d0bbcb0
4
+ data.tar.gz: e698795a06cc3d33a780127d3b7694237d590d7f
5
5
  SHA512:
6
- metadata.gz: ef57e3d11fe603cffb80ecedadd4ee80a8c89513e5e92baa040c3465072a8d4785da3976278134970194747aa8b6b7b4779dbdcc186ffc14f4dcffefe429f69b
7
- data.tar.gz: 49644aac9a4f59599fac69ada461b586cd01e42634806783df4fe72500e9c514f8924890bd5582345323f94fa2c0e9d3ad7039a787179191e0134ab04a542e4b
6
+ metadata.gz: 974279679d2a8f7c5d4d007bd30bbde61e004228ceda0d2e96c21eecf94a2110e3a7612aee4fef8a76a5b678333383dc851cf8aeb8f14e81f2c2a9ae29aeab3c
7
+ data.tar.gz: 4bf9c7f3215565003d2f2b5394a6002c08985fb8327fd8d5f7461a234d754fea921532b3fc83467584e497013f64df6c88635a74d4b46caa91bf5d34fc0ef2f7
data/.travis.yml CHANGED
@@ -1,6 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.0
4
3
  - 2.1
5
4
  - 2.2
6
5
  - ruby-head
@@ -18,7 +17,6 @@ notifications:
18
17
  secure: wPazrrt03q4/4YEWTGejm2yB36hROtpeJKSojv4cE1gRQarQceyMZdOZU4gvJ7DP5ehGSikp+PvdhUj8ZGmUoLcaQQu89eCxa5BGf3sofYD2EOZJe33w+di+L++41/cFp6XJ9XRPxbmVjpmPzl28yq2nfzgdI90qhztcswojGyT3Pkj0STB4qu6T+Kmvd5o4vlWUsZlKiv20sAav5/kL86/K4gwakmpyxPYMafG4WcVGbXoHovOlwdHXdml3Ldfuq9IQ35tu0xJ23o6RoPHl38klOgQQj4k7vbtowWmE5UWZFzWkPpH9GDYtS3ML4yCcM7QLj8nEMVWj+QlTsICmKgKfvSpcs9jQtLQEykDS/H43dTu3gyLuGPcbKbR08cXxkOq6lAAuVV7avNkJb5yJV8Nj+1PWksbBbTNwURamjogRTejxX1dTTUsTQITrrCJyKCOM8LvigKTBmpkEiBR6wDZqZoAx6HXEu0O8G9XpT7aI3pJ85/RCxQdYDe193olcg25TQNjlrSaFl6M1VCMB3jzNcCHZkmiM9KnTRjTMSn/5FUxzAnGeaHvxff6wMffcPKS3E/j+2sXkdpsL1Kwtj6b7ejpL/Pbn6P926iWx8mUmH0xC04M8nQgDE1aorMuqHSSH0EPUUMGBdOPvXOjR2CEtEYgqH/ymDPsT/dUub1M=
19
18
  matrix:
20
19
  allow_failures:
21
- - rvm: 2.0
22
20
  - rvm: ruby-head
23
21
  sudo: false
24
22
  cache: bundler
data/.yardopts ADDED
@@ -0,0 +1,2 @@
1
+ --markup markdown
2
+ --no-private
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # AppleSystemStatus
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/apple_system_status`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ [Apple System Status](https://www.apple.com/support/systemstatus/) scraping library
6
4
 
7
5
  [![Build Status](https://travis-ci.org/sue445/apple_system_status.svg?branch=master)](https://travis-ci.org/sue445/apple_system_status)
8
6
  [![Code Climate](https://codeclimate.com/github/sue445/apple_system_status/badges/gpa.svg)](https://codeclimate.com/github/sue445/apple_system_status)
@@ -10,6 +8,10 @@ TODO: Delete this and the text above, and describe your gem
10
8
  [![Coverage Status](https://coveralls.io/repos/sue445/apple_system_status/badge.svg?branch=master&service=github)](https://coveralls.io/github/sue445/apple_system_status?branch=master)
11
9
  [![Dependency Status](https://gemnasium.com/sue445/apple_system_status.svg)](https://gemnasium.com/sue445/apple_system_status)
12
10
 
11
+ ## Requirements
12
+ * Ruby 2.1+
13
+ * [Phantomjs](http://phantomjs.org/)
14
+
13
15
  ## Installation
14
16
 
15
17
  Add this line to your application's Gemfile:
@@ -26,9 +28,59 @@ Or install it yourself as:
26
28
 
27
29
  $ gem install apple_system_status
28
30
 
29
- ## Usage
31
+ ## Usage (via. ruby)
32
+ ```ruby
33
+ crawler = AppleSystemStatus::Crawler.new
34
+
35
+ # English
36
+ pp crawler.perform
37
+
38
+ {:title=>"System Status as of 12:51 AM JST",
39
+ :services=>
40
+ [{:title=>"App Store",
41
+ :description=>"No Issues: App Store",
42
+ :status=>"allgood"},
43
+ {:title=>"iCloud Account & Sign In",
44
+ :description=>"No Issues: iCloud Account & Sign In",
45
+ :status=>"allgood"},
46
+ # ...
47
+ ]}
48
+
49
+ # Japanese
50
+ pp crawler.perform("jp")
51
+
52
+ {:title=>"00:53 JST 時点のシステム状況",
53
+ :services=>
54
+ [{:title=>"App Store", :description=>"問題なし: App Store", :status=>"allgood"},
55
+ {:title=>"iCloud ストレージアップグレード",
56
+ :description=>"問題なし: iCloud ストレージアップグレード",
57
+ :status=>"allgood"},
58
+ {:title=>"iTunes Store",
59
+ :description=>"問題なし: iTunes Store",
60
+ :status=>"allgood"},
61
+ # ...
62
+ ]}
63
+ ```
30
64
 
31
- TODO: Write usage instructions here
65
+ ## Usage (via. shell)
66
+ ```sh
67
+ $ apple_system_status help
68
+ Commands:
69
+ apple_system_status fetch # Fetch apple system status
70
+ apple_system_status help [COMMAND] # Describe available commands or one specific command
71
+ apple_system_status version # Show apple_system_status version
72
+
73
+ $ apple_system_status help fetch
74
+ Usage:
75
+ apple_system_status fetch
76
+
77
+ Options:
78
+ [--country=COUNTRY] # country code. (ex. jp, ca, fr)
79
+ # Default: us
80
+ [--title=TITLE] # If specified, narrow the service title
81
+ [--format=FORMAT] # output format. (ex. plain, json)
82
+ # Default: plain
83
+ ```
32
84
 
33
85
  ## Development
34
86
 
@@ -38,7 +90,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
38
90
 
39
91
  ## Contributing
40
92
 
41
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/apple_system_status.
93
+ Bug reports and pull requests are welcome on GitHub at https://github.com/sue445/apple_system_status.
42
94
 
43
95
 
44
96
  ## License
@@ -27,15 +27,17 @@ Gem::Specification.new do |spec|
27
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
28
  spec.require_paths = ["lib"]
29
29
 
30
+ spec.add_dependency "activesupport"
30
31
  spec.add_dependency "capybara"
31
32
  spec.add_dependency "poltergeist"
32
33
  spec.add_dependency "thor"
33
34
 
34
- spec.add_development_dependency "activesupport"
35
35
  spec.add_development_dependency "bundler", "~> 1.10"
36
36
  spec.add_development_dependency "codeclimate-test-reporter"
37
37
  spec.add_development_dependency "coveralls"
38
38
  spec.add_development_dependency "pry-byebug"
39
39
  spec.add_development_dependency "rake", "~> 10.0"
40
40
  spec.add_development_dependency "rspec"
41
+ spec.add_development_dependency "rspec-parameterized"
42
+ spec.add_development_dependency "yard"
41
43
  end
@@ -6,8 +6,8 @@ module AppleSystemStatus
6
6
  case format
7
7
  when "plain"
8
8
  str = "#{hash[:title]}\n"
9
- hash[:statuses].each do |status|
10
- str << "#{status[:title]},#{status[:status]},#{status[:description]}\n"
9
+ hash[:services].each do |service|
10
+ str << "#{service[:title]},#{service[:status]},#{service[:description]}\n"
11
11
  end
12
12
  str
13
13
 
@@ -4,10 +4,14 @@ require "apple_system_status"
4
4
  module AppleSystemStatus
5
5
  class CLI < Thor
6
6
  desc "fetch", "Fetch apple system status"
7
- option :country, desc: "country code. (ex. jp, ca, fr)"
8
- option :format, desc: "output format. (ex. plain, json)", default: "plain"
7
+ option :country, desc: "country code. (ex. jp, ca, fr)", default: "us"
8
+ option :title, desc: "If specified, narrow the service title"
9
+ option :format, desc: "output format. (ex. plain, json)", default: "plain"
9
10
  def fetch
10
- response = AppleSystemStatus::Crawler.new.perform(options[:country])
11
+ response = AppleSystemStatus::Crawler.new.perform(
12
+ country: options[:country],
13
+ title: options[:title],
14
+ )
11
15
  puts AppleSystemStatus.format_response(response, options[:format])
12
16
  end
13
17
 
@@ -1,6 +1,7 @@
1
1
  module AppleSystemStatus
2
2
  require "capybara"
3
3
  require 'capybara/poltergeist'
4
+ require "active_support/core_ext/object/blank"
4
5
 
5
6
  class Crawler
6
7
  USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36"
@@ -13,7 +14,18 @@ module AppleSystemStatus
13
14
  @session.driver.headers = { "User-Agent" => USER_AGENT }
14
15
  end
15
16
 
16
- def perform(country = nil)
17
+ # crawl apple system status page
18
+ # @param country [String] country code. (ex. jp, ca, fr. default. us)
19
+ # @param title [String] If specified, narrow the service title
20
+ # @return [Hash]
21
+ # @example response format
22
+ # {
23
+ # title: ,
24
+ # services: [
25
+ # { title: , description: , status: }
26
+ # ]
27
+ # }
28
+ def perform(country: nil, title: nil)
17
29
  @session.visit(apple_url(country))
18
30
 
19
31
  title_parts = [
@@ -24,12 +36,12 @@ module AppleSystemStatus
24
36
 
25
37
  response = {
26
38
  title: title_parts.join(" ").strip,
27
- statuses: [],
39
+ services: [],
28
40
  }
29
41
 
30
- @session.all("#dashboard td").each_with_object(response[:statuses]) do |td, statuses|
42
+ @session.all("#dashboard td").each_with_object(response[:services]) do |td, services|
31
43
  begin
32
- statuses << {
44
+ services << {
33
45
  title: td.find("p[role='text']").text,
34
46
  description: td.find("p[role='text']")["aria-label"],
35
47
  status: td.find("span")["class"],
@@ -39,16 +51,20 @@ module AppleSystemStatus
39
51
  end
40
52
  end
41
53
 
54
+ unless title.blank?
55
+ response[:services].select! { |service| service[:title] == title }
56
+ end
57
+
58
+ response[:services].sort_by! { |service| service[:title] }
59
+
42
60
  response
43
61
  end
44
62
 
45
- private
46
-
47
63
  def apple_url(country)
48
- if country
49
- "https://www.apple.com/#{country}/support/systemstatus/"
50
- else
64
+ if country.blank? || country == "us"
51
65
  "https://www.apple.com/support/systemstatus/"
66
+ else
67
+ "https://www.apple.com/#{country}/support/systemstatus/"
52
68
  end
53
69
  end
54
70
  end
@@ -1,3 +1,3 @@
1
1
  module AppleSystemStatus
2
- VERSION = "0.1.0.beta2"
2
+ VERSION = "0.1.0.beta3"
3
3
  end
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apple_system_status
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.beta2
4
+ version: 0.1.0.beta3
5
5
  platform: ruby
6
6
  authors:
7
7
  - sue445
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-07-25 00:00:00.000000000 Z
11
+ date: 2015-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: capybara
14
+ name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: poltergeist
28
+ name: capybara
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: thor
42
+ name: poltergeist
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -53,13 +53,13 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: activesupport
56
+ name: thor
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
- type: :development
62
+ type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
@@ -150,6 +150,34 @@ dependencies:
150
150
  - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rspec-parameterized
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: yard
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
153
181
  description: Apple System Status scraping library
154
182
  email:
155
183
  - sue445@sue445.net
@@ -162,6 +190,7 @@ files:
162
190
  - ".gitignore"
163
191
  - ".rspec"
164
192
  - ".travis.yml"
193
+ - ".yardopts"
165
194
  - Gemfile
166
195
  - LICENSE.txt
167
196
  - README.md
@@ -200,3 +229,4 @@ signing_key:
200
229
  specification_version: 4
201
230
  summary: Apple System Status scraping library
202
231
  test_files: []
232
+ has_rdoc: