current_astronauts 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ea9a0aea97e05539d58cb73ff828f28014117dcd
4
+ data.tar.gz: 2a54100d6bcc0f91a2e6b8f7a8e4bfebcc9d3c41
5
+ SHA512:
6
+ metadata.gz: 9e99e0d34009c3a34edb00cb1ed97906ef49c29e966687ad0eca7854bbfec009ac76e4c08d713eda0465589a1e49182785502e8b00ead772767c7904bde1696c
7
+ data.tar.gz: bc03d5169aad9f363d0d359c8db81198a7a93534d1508cc76f6f16860d79ab17c330a71ed3c55e6b85103c1b3f3ce554a2b5e1ae2ca3a50f805d8f65d330e7fd
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.vendor/
3
+ /vendor/
4
+ /.yardoc
5
+ /Gemfile.lock
6
+ /_yardoc/
7
+ /coverage/
8
+ /doc/
9
+ /pkg/
10
+ /spec/reports/
11
+ /tmp/
12
+ .rspec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in current_astronauts.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Chris Horton
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,97 @@
1
+ [![CircleCI](https://circleci.com/gh/hortoncd/current_astronauts.svg?style=svg)](https://circleci.com/gh/hortoncd/current_astronauts)
2
+
3
+ # CurrentAstronauts
4
+
5
+ Small gem to work with the list of current astronauts in space from http://api.open-notify.org/astros.json.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'current_astronauts'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install current_astronauts
22
+
23
+ ## Usage
24
+
25
+ require the gem, and optionally include the module for simplicity
26
+ ```ruby
27
+ require 'current_astronauts'
28
+
29
+ include CurrentAstronauts
30
+ ```
31
+
32
+ Instantiate an object and fetch data. If success?, use the data as desired.
33
+ ```ruby
34
+ a = Astronauts.new
35
+ a.fetch
36
+ if a.success?
37
+ # do something here
38
+ end
39
+ ```
40
+
41
+ The URL source defaults to http://api.open-notify.org/astros.json, but if you set ENV['OPEN_NOTIFY_URL'] before instantiating the object, it will use the set URL instead.
42
+
43
+ ```ruby
44
+ ENV['OPEN_NOTIFY_URL']
45
+ a = Astronauts.new
46
+ ```
47
+
48
+ a.data contains the full data as returned in a hash. There are methods to work with smaller portions of the data.
49
+
50
+ How many astronauts are currently in space?
51
+ ```ruby
52
+ puts "there are currently #{a.num} astronauts currently in space."
53
+ ```
54
+
55
+ Use the 'people' method to work with the list of astronauts and their associated craft. It is an array of hashes.
56
+ ```ruby
57
+ people = a.people
58
+ first = a.people.first
59
+
60
+ puts "a.people returns a list of people and their associated craft as an #{people.class} of type #{first.class}."
61
+ puts
62
+ puts "#{first['name']} is currently on: #{first['craft']}."
63
+ ```
64
+
65
+ Print a formatted list of astronauts and their associated craft.
66
+ ```ruby
67
+ a.print
68
+ ```
69
+
70
+ Formatted list appears as follows.
71
+
72
+ ```
73
+ Name | Craft
74
+ ------------------|-------------
75
+ Anatoly Ivanishin | ISS
76
+ Takuya Onishi | ISS
77
+ Kate Rubins | ISS
78
+ Jing Haipeng | Shenzhou 11
79
+ Chen Dong | Shenzhou 11
80
+ Sergey Rizhikov | ISS
81
+ Andrey Borisenko | ISS
82
+ Shane Kimbrough | ISS
83
+ ```
84
+
85
+ ## Development
86
+
87
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
88
+
89
+ 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).
90
+
91
+ ## Contributing
92
+
93
+ Bug reports and pull requests are welcome on GitHub at https://github.com/hortoncd/current_astronauts.
94
+
95
+ ## License
96
+
97
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec) do |t|
6
+ t.pattern = Dir.glob('spec/**/*_spec.rb')
7
+ end
8
+
9
+ task :default => :spec
10
+ task :test => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "current_astronauts"
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,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'current_astronauts/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "current_astronauts"
8
+ spec.version = CurrentAstronauts::VERSION
9
+ spec.authors = ["Chris Horton"]
10
+ spec.email = ["hortoncd@gmail.com"]
11
+
12
+ spec.summary = %q{Work worth list of astronauts currently in space}
13
+ spec.description = %q{Work worth list of astronauts currently in space. Raw JSON data is available, along with a few methods for accessing specific portions of the data and print out a formatted list.}
14
+ spec.homepage = "https://github.com/hortoncd/current_astronauts"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ #if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
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_development_dependency "bundler", "~> 1.12"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "rspec", "~> 3.5"
33
+ spec.add_development_dependency "webmock", "~> 2.1.0"
34
+ spec.add_dependency "httparty", "~> 0.14.0"
35
+ end
data/examples/usage.rb ADDED
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'current_astronauts'
4
+ include CurrentAstronauts
5
+
6
+ a = Astronauts.new
7
+ a.fetch
8
+ if a.success?
9
+ puts "a is an instance of an #{a.class} class."
10
+ puts
11
+ puts "a.data is a #{a.data.class}."
12
+ puts
13
+
14
+ puts "a.num tells you how many astronauts are currently in space (#{a.num})."
15
+ puts
16
+
17
+ # use the list of people and craft as hash
18
+ people = a.people
19
+ first = a.people.first
20
+
21
+ puts "a.people returns a list of people and their associated craft as an #{people.class} of type #{first.class}."
22
+ puts
23
+ puts "#{first['name']} is currently on: #{first['craft']}."
24
+ puts
25
+
26
+ # print out a list of people and craft
27
+ puts "a.print prints out a formatted list of astronautes and their associated craft."
28
+ a.print
29
+ else
30
+ puts "Failed to fetch list of astronauts"
31
+ end
@@ -0,0 +1,6 @@
1
+ {
2
+ "message": "fail",
3
+ "number": 0,
4
+ "people": [
5
+ ]
6
+ }
@@ -0,0 +1,38 @@
1
+ {
2
+ "message": "success",
3
+ "number": 8,
4
+ "people": [
5
+ {
6
+ "craft": "ISS",
7
+ "name": "Anatoly Ivanishin"
8
+ },
9
+ {
10
+ "craft": "ISS",
11
+ "name": "Takuya Onishi"
12
+ },
13
+ {
14
+ "craft": "ISS",
15
+ "name": "Kate Rubins"
16
+ },
17
+ {
18
+ "craft": "Shenzhou 11",
19
+ "name": "Jing Haipeng"
20
+ },
21
+ {
22
+ "craft": "Shenzhou 11",
23
+ "name": "Chen Dong"
24
+ },
25
+ {
26
+ "craft": "ISS",
27
+ "name": "Sergey Rizhikov"
28
+ },
29
+ {
30
+ "craft": "ISS",
31
+ "name": "Andrey Borisenko"
32
+ },
33
+ {
34
+ "craft": "ISS",
35
+ "name": "Shane Kimbrough"
36
+ }
37
+ ]
38
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "message": "success",
3
+ "number": 2,
4
+ "people": [
5
+ {
6
+ "craft": "ISS",
7
+ "name": "Anatoly Ivanishin"
8
+ },
9
+ {
10
+ "craft": "Shenzhou 11",
11
+ "name": "Jing Haipeng"
12
+ }
13
+ ]
14
+ }
@@ -0,0 +1,10 @@
1
+ Name | Craft
2
+ ------------------|-------------
3
+ Anatoly Ivanishin | ISS
4
+ Takuya Onishi | ISS
5
+ Kate Rubins | ISS
6
+ Jing Haipeng | Shenzhou 11
7
+ Chen Dong | Shenzhou 11
8
+ Sergey Rizhikov | ISS
9
+ Andrey Borisenko | ISS
10
+ Shane Kimbrough | ISS
@@ -0,0 +1,77 @@
1
+ require 'current_astronauts/version'
2
+
3
+ require 'httparty'
4
+
5
+ module CurrentAstronauts
6
+ class Astronauts
7
+ attr_reader :data
8
+
9
+ def initialize
10
+ if ENV['OPEN_NOTIFY_URL']
11
+ @url = ENV['OPEN_NOTIFY_URL']
12
+ else
13
+ @url = 'http://api.open-notify.org/astros.json'
14
+ end
15
+ @data = nil
16
+ end
17
+
18
+ # Let's go get some data
19
+ def fetch
20
+ response = HTTParty.get(@url)
21
+ if response.success?
22
+ @data = response.parsed_response
23
+ end
24
+ response.code
25
+ end
26
+
27
+ # Fetch succeeded and data message is 'success'
28
+ def success?
29
+ stat = false
30
+ if @data and @data['message'] == 'success'
31
+ stat = true
32
+ end
33
+ return stat
34
+ end
35
+
36
+ # How many astronauts in space?
37
+ def num
38
+ success? ? @data['number'] : nil
39
+ end
40
+
41
+ # List of astronauts and their craft, as an array of hashes
42
+ def people
43
+ success? ? @data['people'] : nil
44
+ end
45
+
46
+ # Print a formatted list of astronauts and their craft
47
+ def print
48
+ unless success?
49
+ return nil
50
+ end
51
+ nlen = "Name".length
52
+ clen = "Craft".length
53
+ @data['people'].each do |p|
54
+ nlen = p['name'].length > nlen ? p['name'].length : nlen
55
+ clen = p['craft'].length > clen ? p['craft'].length : clen
56
+ end
57
+
58
+ print_header(nlen, clen)
59
+ @data['people'].each do |p|
60
+ print_line(nlen, p['name'], clen, p['craft'])
61
+ end
62
+ end
63
+
64
+ private
65
+
66
+ # print header with appropriate spacing
67
+ def print_header(nlen, clen)
68
+ print_line(nlen, "Name", clen, "Craft")
69
+ puts "%-#{nlen}s-|-%-#{clen}s-" % ["-" * nlen, "-" * clen]
70
+ end
71
+
72
+ # print individual lines with appropriate spacing
73
+ def print_line(nlen, n, clen, c)
74
+ puts "%-#{nlen}s | %-#{clen}s " % [n, c]
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,3 @@
1
+ module CurrentAstronauts
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: current_astronauts
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Chris Horton
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-10-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.1.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.1.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: httparty
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.14.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.14.0
83
+ description: Work worth list of astronauts currently in space. Raw JSON data is available,
84
+ along with a few methods for accessing specific portions of the data and print out
85
+ a formatted list.
86
+ email:
87
+ - hortoncd@gmail.com
88
+ executables: []
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - ".gitignore"
93
+ - Gemfile
94
+ - LICENSE
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - current_astronauts.gemspec
100
+ - examples/usage.rb
101
+ - fixtures/astros-fail.json
102
+ - fixtures/astros.json
103
+ - fixtures/astros2.json
104
+ - fixtures/print_output.txt
105
+ - lib/current_astronauts.rb
106
+ - lib/current_astronauts/version.rb
107
+ homepage: https://github.com/hortoncd/current_astronauts
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.6.6
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Work worth list of astronauts currently in space
131
+ test_files: []