apple_system_status 0.1.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 699b07d034c247c7e56deeb4e80564a2cedd9436
4
+ data.tar.gz: ba1a0ac556f4947996077d742e390449b9707dc2
5
+ SHA512:
6
+ metadata.gz: 3bd269d340019154702d3bc7b34715bd7be65b25c4b850119fcfef35e8f3d3c1a88b90d8d7ecf10663876ec6806c40c20f5ca89caa09d9f7aefd4f36b139278c
7
+ data.tar.gz: 0647802cbed0fd7247bef80d6b387962e280433ad06f28154367154fe0aa26f25e326ea181048f2e1634481b94f85cf3f8660fdb15ec438ed6db0a5eff1f7b0e
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ repo_token: XxlVodlkDotiEKVG5wO5FTidD71osGzA0
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format progress
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,24 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0
4
+ - 2.1
5
+ - 2.2
6
+ - ruby-head
7
+ before_script:
8
+ - export CI=true
9
+ - export CODECLIMATE_REPO_TOKEN=89b665462d69ce4c873ee8165d496c4a97b9afaaf48e375c1bc3200e4b45b1e7
10
+ before_install: gem install bundler -v 1.10.5
11
+ script: bundle exec rspec
12
+ branches:
13
+ only:
14
+ - master
15
+ notifications:
16
+ email: false
17
+ slack:
18
+ secure: wPazrrt03q4/4YEWTGejm2yB36hROtpeJKSojv4cE1gRQarQceyMZdOZU4gvJ7DP5ehGSikp+PvdhUj8ZGmUoLcaQQu89eCxa5BGf3sofYD2EOZJe33w+di+L++41/cFp6XJ9XRPxbmVjpmPzl28yq2nfzgdI90qhztcswojGyT3Pkj0STB4qu6T+Kmvd5o4vlWUsZlKiv20sAav5/kL86/K4gwakmpyxPYMafG4WcVGbXoHovOlwdHXdml3Ldfuq9IQ35tu0xJ23o6RoPHl38klOgQQj4k7vbtowWmE5UWZFzWkPpH9GDYtS3ML4yCcM7QLj8nEMVWj+QlTsICmKgKfvSpcs9jQtLQEykDS/H43dTu3gyLuGPcbKbR08cXxkOq6lAAuVV7avNkJb5yJV8Nj+1PWksbBbTNwURamjogRTejxX1dTTUsTQITrrCJyKCOM8LvigKTBmpkEiBR6wDZqZoAx6HXEu0O8G9XpT7aI3pJ85/RCxQdYDe193olcg25TQNjlrSaFl6M1VCMB3jzNcCHZkmiM9KnTRjTMSn/5FUxzAnGeaHvxff6wMffcPKS3E/j+2sXkdpsL1Kwtj6b7ejpL/Pbn6P926iWx8mUmH0xC04M8nQgDE1aorMuqHSSH0EPUUMGBdOPvXOjR2CEtEYgqH/ymDPsT/dUub1M=
19
+ matrix:
20
+ allow_failures:
21
+ - rvm: 2.0
22
+ - rvm: ruby-head
23
+ sudo: false
24
+ cache: bundler
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in apple_system_status.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 sue445
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # AppleSystemStatus
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
6
+
7
+ [![Build Status](https://travis-ci.org/sue445/apple_system_status.svg?branch=master)](https://travis-ci.org/sue445/apple_system_status)
8
+ [![Code Climate](https://codeclimate.com/github/sue445/apple_system_status/badges/gpa.svg)](https://codeclimate.com/github/sue445/apple_system_status)
9
+ [![Test Coverage](https://codeclimate.com/github/sue445/apple_system_status/badges/coverage.svg)](https://codeclimate.com/github/sue445/apple_system_status/coverage)
10
+ [![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
+ [![Dependency Status](https://gemnasium.com/sue445/apple_system_status.svg)](https://gemnasium.com/sue445/apple_system_status)
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'apple_system_status'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install apple_system_status
28
+
29
+ ## Usage
30
+
31
+ TODO: Write usage instructions here
32
+
33
+ ## Development
34
+
35
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec apple_system_status` to use the gem in this directory, ignoring other installed copies of this gem.
36
+
37
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
38
+
39
+ ## Contributing
40
+
41
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/apple_system_status.
42
+
43
+
44
+ ## License
45
+
46
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
47
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,41 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'apple_system_status/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "apple_system_status"
8
+ spec.version = AppleSystemStatus::VERSION
9
+ spec.authors = ["sue445"]
10
+ spec.email = ["sue445@sue445.net"]
11
+
12
+ spec.summary = %q{Apple System Status scraping library}
13
+ spec.description = %q{Apple System Status scraping library}
14
+ spec.homepage = "https://github.com/sue445/apple_system_status"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_dependency "capybara"
31
+ spec.add_dependency "poltergeist"
32
+ spec.add_dependency "thor"
33
+
34
+ spec.add_development_dependency "activesupport"
35
+ spec.add_development_dependency "bundler", "~> 1.10"
36
+ spec.add_development_dependency "codeclimate-test-reporter"
37
+ spec.add_development_dependency "coveralls"
38
+ spec.add_development_dependency "pry-byebug"
39
+ spec.add_development_dependency "rake", "~> 10.0"
40
+ spec.add_development_dependency "rspec"
41
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "apple_system_status"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'apple_system_status/cli'
4
+
5
+ AppleSystemStatus::CLI.start(ARGV)
@@ -0,0 +1,19 @@
1
+ require "thor"
2
+ require "apple_system_status"
3
+
4
+ module AppleSystemStatus
5
+ class CLI < Thor
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"
9
+ def fetch
10
+ response = AppleSystemStatus::Crawler.new.perform(options[:country])
11
+ puts AppleSystemStatus.format_response(response, options[:format])
12
+ end
13
+
14
+ desc "version", "Show apple_system_status version"
15
+ def version
16
+ puts AppleSystemStatus::VERSION
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,51 @@
1
+ module AppleSystemStatus
2
+ require "capybara"
3
+ require 'capybara/poltergeist'
4
+
5
+ class Crawler
6
+ 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"
7
+
8
+ def initialize
9
+ Capybara.register_driver :poltergeist do |app|
10
+ Capybara::Poltergeist::Driver.new(app)
11
+ end
12
+ @session = Capybara::Session.new(:poltergeist)
13
+ @session.driver.headers = { "User-Agent" => USER_AGENT }
14
+ end
15
+
16
+ def perform(country = nil)
17
+ @session.visit(apple_url(country))
18
+
19
+ title_parts = [
20
+ @session.find("#key_date_text").text,
21
+ @session.find("#key_date").text,
22
+ @session.find("#key_date_post").text,
23
+ ]
24
+
25
+ response = {
26
+ title: title_parts.join(" ").strip,
27
+ statuses: [],
28
+ }
29
+
30
+ @session.all("#dashboard td").each_with_object(response[:statuses]) do |td, statuses|
31
+ statuses << {
32
+ title: td.find("p[role='text']").text,
33
+ description: td.find("p[role='text']")["aria-label"],
34
+ status: td.find("span")["class"],
35
+ }
36
+ end
37
+
38
+ response
39
+ end
40
+
41
+ private
42
+
43
+ def apple_url(country)
44
+ if country
45
+ "https://www.apple.com/#{country}/support/systemstatus/"
46
+ else
47
+ "https://www.apple.com/support/systemstatus/"
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,3 @@
1
+ module AppleSystemStatus
2
+ VERSION = "0.1.0.beta1"
3
+ end
@@ -0,0 +1,21 @@
1
+ require "apple_system_status/version"
2
+ require "apple_system_status/crawler"
3
+
4
+ module AppleSystemStatus
5
+ def self.format_response(hash, format)
6
+ case format
7
+ when "plain"
8
+ str = "#{hash[:title]}\n"
9
+ hash[:statuses].each do |status|
10
+ str << "#{status[:title]},#{status[:status]},#{status[:description]}\n"
11
+ end
12
+ str
13
+
14
+ when "json"
15
+ hash.to_json
16
+
17
+ else
18
+ raise "Unknown format: #{format}"
19
+ end
20
+ end
21
+ end
metadata ADDED
@@ -0,0 +1,202 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: apple_system_status
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.beta1
5
+ platform: ruby
6
+ authors:
7
+ - sue445
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capybara
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: poltergeist
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.10'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.10'
83
+ - !ruby/object:Gem::Dependency
84
+ name: codeclimate-test-reporter
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: coveralls
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry-byebug
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rake
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '10.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '10.0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rspec
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: Apple System Status scraping library
154
+ email:
155
+ - sue445@sue445.net
156
+ executables:
157
+ - apple_system_status
158
+ extensions: []
159
+ extra_rdoc_files: []
160
+ files:
161
+ - ".coveralls.yml"
162
+ - ".gitignore"
163
+ - ".rspec"
164
+ - ".travis.yml"
165
+ - Gemfile
166
+ - LICENSE.txt
167
+ - README.md
168
+ - Rakefile
169
+ - apple_system_status.gemspec
170
+ - bin/console
171
+ - bin/setup
172
+ - exe/apple_system_status
173
+ - lib/apple_system_status.rb
174
+ - lib/apple_system_status/cli.rb
175
+ - lib/apple_system_status/crawler.rb
176
+ - lib/apple_system_status/version.rb
177
+ homepage: https://github.com/sue445/apple_system_status
178
+ licenses:
179
+ - MIT
180
+ metadata:
181
+ allowed_push_host: https://rubygems.org
182
+ post_install_message:
183
+ rdoc_options: []
184
+ require_paths:
185
+ - lib
186
+ required_ruby_version: !ruby/object:Gem::Requirement
187
+ requirements:
188
+ - - ">="
189
+ - !ruby/object:Gem::Version
190
+ version: '0'
191
+ required_rubygems_version: !ruby/object:Gem::Requirement
192
+ requirements:
193
+ - - ">"
194
+ - !ruby/object:Gem::Version
195
+ version: 1.3.1
196
+ requirements: []
197
+ rubyforge_project:
198
+ rubygems_version: 2.4.5
199
+ signing_key:
200
+ specification_version: 4
201
+ summary: Apple System Status scraping library
202
+ test_files: []