tatooine 1.0.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.
Files changed (68) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +22 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +52 -0
  6. data/Rakefile +8 -0
  7. data/lib/tatooine.rb +17 -0
  8. data/lib/tatooine/error.rb +25 -0
  9. data/lib/tatooine/film.rb +6 -0
  10. data/lib/tatooine/middleware/raise_http_error.rb +34 -0
  11. data/lib/tatooine/person.rb +6 -0
  12. data/lib/tatooine/planet.rb +6 -0
  13. data/lib/tatooine/resource.rb +125 -0
  14. data/lib/tatooine/species.rb +6 -0
  15. data/lib/tatooine/starship.rb +6 -0
  16. data/lib/tatooine/vehicle.rb +6 -0
  17. data/lib/tatooine/version.rb +3 -0
  18. data/spec/error_spec.rb +21 -0
  19. data/spec/film_spec.rb +107 -0
  20. data/spec/fixtures/film_schema.json +1 -0
  21. data/spec/fixtures/vcr_cassettes/film_1.yml +57 -0
  22. data/spec/fixtures/vcr_cassettes/film_1_and_schema.yml +57 -0
  23. data/spec/fixtures/vcr_cassettes/film_count.yml +101 -0
  24. data/spec/fixtures/vcr_cassettes/film_list.yml +441 -0
  25. data/spec/fixtures/vcr_cassettes/film_schema.yml +101 -0
  26. data/spec/fixtures/vcr_cassettes/person_1.yml +49 -0
  27. data/spec/fixtures/vcr_cassettes/person_1_and_schema.yml +49 -0
  28. data/spec/fixtures/vcr_cassettes/person_count.yml +58 -0
  29. data/spec/fixtures/vcr_cassettes/person_list.yml +58 -0
  30. data/spec/fixtures/vcr_cassettes/person_next.yml +56 -0
  31. data/spec/fixtures/vcr_cassettes/person_previous.yml +58 -0
  32. data/spec/fixtures/vcr_cassettes/person_schema.yml +58 -0
  33. data/spec/fixtures/vcr_cassettes/planet_1.yml +50 -0
  34. data/spec/fixtures/vcr_cassettes/planet_1_and_schema.yml +50 -0
  35. data/spec/fixtures/vcr_cassettes/planet_count.yml +60 -0
  36. data/spec/fixtures/vcr_cassettes/planet_list.yml +60 -0
  37. data/spec/fixtures/vcr_cassettes/planet_next.yml +63 -0
  38. data/spec/fixtures/vcr_cassettes/planet_previous.yml +60 -0
  39. data/spec/fixtures/vcr_cassettes/planet_schema.yml +60 -0
  40. data/spec/fixtures/vcr_cassettes/species_1.yml +52 -0
  41. data/spec/fixtures/vcr_cassettes/species_1_and_schema.yml +52 -0
  42. data/spec/fixtures/vcr_cassettes/species_count.yml +63 -0
  43. data/spec/fixtures/vcr_cassettes/species_list.yml +63 -0
  44. data/spec/fixtures/vcr_cassettes/species_next.yml +59 -0
  45. data/spec/fixtures/vcr_cassettes/species_previous.yml +63 -0
  46. data/spec/fixtures/vcr_cassettes/species_schema.yml +63 -0
  47. data/spec/fixtures/vcr_cassettes/starship_10.yml +51 -0
  48. data/spec/fixtures/vcr_cassettes/starship_2_and_schema.yml +51 -0
  49. data/spec/fixtures/vcr_cassettes/starship_count.yml +78 -0
  50. data/spec/fixtures/vcr_cassettes/starship_list.yml +78 -0
  51. data/spec/fixtures/vcr_cassettes/starship_next.yml +76 -0
  52. data/spec/fixtures/vcr_cassettes/starship_previous.yml +78 -0
  53. data/spec/fixtures/vcr_cassettes/starship_schema.yml +78 -0
  54. data/spec/fixtures/vcr_cassettes/vehicle_14.yml +50 -0
  55. data/spec/fixtures/vcr_cassettes/vehicle_14_and_schema.yml +50 -0
  56. data/spec/fixtures/vcr_cassettes/vehicle_count.yml +70 -0
  57. data/spec/fixtures/vcr_cassettes/vehicle_list.yml +70 -0
  58. data/spec/fixtures/vcr_cassettes/vehicle_next.yml +68 -0
  59. data/spec/fixtures/vcr_cassettes/vehicle_previous.yml +70 -0
  60. data/spec/fixtures/vcr_cassettes/vehicle_schema.yml +70 -0
  61. data/spec/person_spec.rb +120 -0
  62. data/spec/planet_spec.rb +106 -0
  63. data/spec/spec_helper.rb +21 -0
  64. data/spec/species_spec.rb +111 -0
  65. data/spec/starship_spec.rb +106 -0
  66. data/spec/vehicle_spec.rb +106 -0
  67. data/tatooine.gemspec +30 -0
  68. metadata +272 -0
@@ -0,0 +1,106 @@
1
+ require "./spec/spec_helper"
2
+
3
+ describe Tatooine::Planet do
4
+ describe "#schema" do
5
+ before(:all) do
6
+ VCR.use_cassette("planet schema") do
7
+ @schema = Tatooine::Planet.schema
8
+ end
9
+ end
10
+
11
+ it "should get the description of the class" do
12
+ expect(@schema).to be_instance_of(Hash)
13
+ expect(@schema["description"]).to eq("A planet.")
14
+ end
15
+ end
16
+
17
+ describe "#count" do
18
+ before(:all) do
19
+ VCR.use_cassette("planet count") do
20
+ @count = Tatooine::Planet.count
21
+ end
22
+ end
23
+
24
+ it "should return the correct count" do
25
+ expect(@count).to be(60)
26
+ end
27
+ end
28
+
29
+ describe "#list" do
30
+ before(:all) do
31
+ VCR.use_cassette("planet list") do
32
+ @planets = Tatooine::Planet.list
33
+ end
34
+ end
35
+
36
+ it "gets a list of people" do
37
+ expect(@planets).to be_instance_of(Array)
38
+ expect(@planets.length).to be(10)
39
+ expect(@planets.first).to be_instance_of(Tatooine::Planet)
40
+ end
41
+
42
+ it "gets the next page" do
43
+ VCR.use_cassette("planet next") do
44
+ @next_planets = Tatooine::Planet.next
45
+ expect(@next_planets).to be_instance_of(Array)
46
+ expect(@next_planets.first).to be_instance_of(Tatooine::Planet)
47
+ end
48
+ end
49
+
50
+ it "gets the previous page" do
51
+ VCR.use_cassette("planet previous") do
52
+ @previous_planets = Tatooine::Planet.previous
53
+ expect(@previous_planets.map(&:name)).to match_array(@planets.map(&:name))
54
+ end
55
+ end
56
+ end
57
+
58
+ describe "#get" do
59
+ before(:all) do
60
+ VCR.use_cassette("planet 1") do
61
+ @planet = Tatooine::Planet.get(1)
62
+ end
63
+ end
64
+
65
+ it "gets the url of the planet" do
66
+ expect(@planet.url).to eq("http://swapi.co/api/planets/1/")
67
+ end
68
+
69
+ it "gets the attributes of the planet" do
70
+ expect(@planet.name).to eq("Tatooine")
71
+ end
72
+
73
+ it "gets a list of residents" do
74
+ expect(@planet.residents).to be_instance_of(Array)
75
+ expect(@planet.residents.first).to be_instance_of(Tatooine::Person)
76
+ end
77
+
78
+ it "gets a list of films" do
79
+ expect(@planet.films).to be_instance_of(Array)
80
+ expect(@planet.films.first).to be_instance_of(Tatooine::Film)
81
+ end
82
+ end
83
+
84
+ describe "#new" do
85
+ it "primes an object with a url" do
86
+ VCR.use_cassette("planet schema") do
87
+ @planet = Tatooine::Planet.new(:url => "#{Tatooine::API_BASE}planets/1/")
88
+ expect(@planet).to respond_to(:name)
89
+ end
90
+ end
91
+
92
+ it "gets the object when methods are called" do
93
+ VCR.use_cassette("planet 1 and schema") do
94
+ @planet = Tatooine::Planet.new("url" => "#{Tatooine::API_BASE}planets/1/")
95
+ expect(@planet.name).to eq("Tatooine")
96
+ end
97
+ end
98
+
99
+ it "sets properties from an object" do
100
+ VCR.use_cassette("planet schema") do
101
+ @planet = Tatooine::Planet.new("name" => "Anything, because I said so")
102
+ expect(@planet.name).to eq("Anything, because I said so")
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,21 @@
1
+ require "simplecov"
2
+ SimpleCov.start do
3
+ add_filter "/spec/"
4
+ end
5
+
6
+ require File.expand_path("../../lib/tatooine", __FILE__)
7
+
8
+ require "rspec"
9
+ require "vcr"
10
+ require "webmock/rspec"
11
+
12
+ VCR.configure do |c|
13
+ c.cassette_library_dir = "spec/fixtures/vcr_cassettes"
14
+ c.hook_into :webmock
15
+ end
16
+
17
+ RSpec.configure do |config|
18
+ config.include WebMock::API
19
+ end
20
+
21
+
@@ -0,0 +1,111 @@
1
+ require "./spec/spec_helper"
2
+
3
+ describe Tatooine::Species do
4
+ describe "#schema" do
5
+ before(:all) do
6
+ VCR.use_cassette("species schema") do
7
+ @schema = Tatooine::Species.schema
8
+ end
9
+ end
10
+
11
+ it "should get the description of the class" do
12
+ expect(@schema).to be_instance_of(Hash)
13
+ expect(@schema["description"]).to eq("A species within the Star Wars universe")
14
+ end
15
+ end
16
+
17
+ describe "#count" do
18
+ before(:all) do
19
+ VCR.use_cassette("species count") do
20
+ @count = Tatooine::Species.count
21
+ end
22
+ end
23
+
24
+ it "should return the correct count" do
25
+ expect(@count).to be(37)
26
+ end
27
+ end
28
+
29
+ describe "#list" do
30
+ before(:all) do
31
+ VCR.use_cassette("species list") do
32
+ @species = Tatooine::Species.list
33
+ end
34
+ end
35
+
36
+ it "gets a list of species" do
37
+ expect(@species).to be_instance_of(Array)
38
+ expect(@species.length).to be(10)
39
+ expect(@species.first).to be_instance_of(Tatooine::Species)
40
+ end
41
+
42
+ it "gets the next page" do
43
+ VCR.use_cassette("species next") do
44
+ @next_species = Tatooine::Species.next
45
+ expect(@next_species).to be_instance_of(Array)
46
+ expect(@next_species.first).to be_instance_of(Tatooine::Species)
47
+ end
48
+ end
49
+
50
+ it "gets the previous page" do
51
+ VCR.use_cassette("species previous") do
52
+ @previous_species = Tatooine::Species.previous
53
+ expect(@previous_species.map(&:name)).to match_array(@species.map(&:name))
54
+ end
55
+ end
56
+ end
57
+
58
+ describe "#get" do
59
+ before(:all) do
60
+ VCR.use_cassette("species 1") do
61
+ @species = Tatooine::Species.get(1)
62
+ end
63
+ end
64
+
65
+ it "gets the url of the species" do
66
+ expect(@species.url).to eq("http://swapi.co/api/species/1/")
67
+ end
68
+
69
+ it "gets the attributes of the species" do
70
+ expect(@species.name).to eq("Human")
71
+ end
72
+
73
+ it "gets a planet homeworld" do
74
+ expect(@species.homeworld).to be_instance_of(Tatooine::Planet)
75
+ end
76
+
77
+ it "gets a list of films" do
78
+ expect(@species.films).to be_instance_of(Array)
79
+ expect(@species.films.first).to be_instance_of(Tatooine::Film)
80
+ end
81
+
82
+ # Skipped because the schema doesn't return people right now.
83
+ xit "gets a list of people" do
84
+ expect(@species.people).to be_instance_of(Array)
85
+ expect(@species.people.first).to be_instance_of(Tatooine::Person)
86
+ end
87
+ end
88
+
89
+ describe "#new" do
90
+ it "primes an object with a url" do
91
+ VCR.use_cassette("species schema") do
92
+ @species = Tatooine::Species.new(:url => "#{Tatooine::API_BASE}species/1/")
93
+ expect(@species).to respond_to(:name)
94
+ end
95
+ end
96
+
97
+ it "gets the object when methods are called" do
98
+ VCR.use_cassette("species 1 and schema") do
99
+ @species = Tatooine::Species.new("url" => "#{Tatooine::API_BASE}species/1/")
100
+ expect(@species.name).to eq("Human")
101
+ end
102
+ end
103
+
104
+ it "sets properties from an object" do
105
+ VCR.use_cassette("species schema") do
106
+ @species = Tatooine::Species.new("name" => "Anything, because I said so")
107
+ expect(@species.name).to eq("Anything, because I said so")
108
+ end
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,106 @@
1
+ require "./spec/spec_helper"
2
+
3
+ describe Tatooine::Starship do
4
+ describe "#schema" do
5
+ before(:all) do
6
+ VCR.use_cassette("starship schema") do
7
+ @schema = Tatooine::Starship.schema
8
+ end
9
+ end
10
+
11
+ it "should get the description of the class" do
12
+ expect(@schema).to be_instance_of(Hash)
13
+ expect(@schema["description"]).to eq("A Starship")
14
+ end
15
+ end
16
+
17
+ describe "#count" do
18
+ before(:all) do
19
+ VCR.use_cassette("starship count") do
20
+ @count = Tatooine::Starship.count
21
+ end
22
+ end
23
+
24
+ it "should return the correct count" do
25
+ expect(@count).to be(36)
26
+ end
27
+ end
28
+
29
+ describe "#list" do
30
+ before(:all) do
31
+ VCR.use_cassette("starship list") do
32
+ @starships = Tatooine::Starship.list
33
+ end
34
+ end
35
+
36
+ it "gets a list of people" do
37
+ expect(@starships).to be_instance_of(Array)
38
+ expect(@starships.length).to be(10)
39
+ expect(@starships.first).to be_instance_of(Tatooine::Starship)
40
+ end
41
+
42
+ it "gets the next page" do
43
+ VCR.use_cassette("starship next") do
44
+ @next_starships = Tatooine::Starship.next
45
+ expect(@next_starships).to be_instance_of(Array)
46
+ expect(@next_starships.first).to be_instance_of(Tatooine::Starship)
47
+ end
48
+ end
49
+
50
+ it "gets the previous page" do
51
+ VCR.use_cassette("starship previous") do
52
+ @previous_starships = Tatooine::Starship.previous
53
+ expect(@previous_starships.map(&:name)).to match_array(@starships.map(&:name))
54
+ end
55
+ end
56
+ end
57
+
58
+ describe "#get" do
59
+ before(:all) do
60
+ VCR.use_cassette("starship 10") do
61
+ @starship = Tatooine::Starship.get(10)
62
+ end
63
+ end
64
+
65
+ it "gets the url of the starship" do
66
+ expect(@starship.url).to eq("http://swapi.co/api/starships/10/")
67
+ end
68
+
69
+ it "gets the attributes of the starship" do
70
+ expect(@starship.name).to eq("Millennium Falcon")
71
+ end
72
+
73
+ it "gets a list of residents" do
74
+ expect(@starship.pilots).to be_instance_of(Array)
75
+ expect(@starship.pilots.first).to be_instance_of(Tatooine::Person)
76
+ end
77
+
78
+ it "gets a list of films" do
79
+ expect(@starship.films).to be_instance_of(Array)
80
+ expect(@starship.films.first).to be_instance_of(Tatooine::Film)
81
+ end
82
+ end
83
+
84
+ describe "#new" do
85
+ it "primes an object with a url" do
86
+ VCR.use_cassette("starship schema") do
87
+ @starship = Tatooine::Starship.new(:url => "#{Tatooine::API_BASE}starships/10/")
88
+ expect(@starship).to respond_to(:name)
89
+ end
90
+ end
91
+
92
+ it "gets the object when methods are called" do
93
+ VCR.use_cassette("starship 2 and schema") do
94
+ @starship = Tatooine::Starship.new("url" => "#{Tatooine::API_BASE}starships/10/")
95
+ expect(@starship.name).to eq("Millennium Falcon")
96
+ end
97
+ end
98
+
99
+ it "sets properties from an object" do
100
+ VCR.use_cassette("starship schema") do
101
+ @starship = Tatooine::Starship.new("name" => "Anything, because I said so")
102
+ expect(@starship.name).to eq("Anything, because I said so")
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,106 @@
1
+ require "./spec/spec_helper"
2
+
3
+ describe Tatooine::Vehicle do
4
+ describe "#schema" do
5
+ before(:all) do
6
+ VCR.use_cassette("vehicle schema") do
7
+ @schema = Tatooine::Vehicle.schema
8
+ end
9
+ end
10
+
11
+ it "should get the description of the class" do
12
+ expect(@schema).to be_instance_of(Hash)
13
+ expect(@schema["description"]).to eq("A vehicle.")
14
+ end
15
+ end
16
+
17
+ describe "#count" do
18
+ before(:all) do
19
+ VCR.use_cassette("vehicle count") do
20
+ @count = Tatooine::Vehicle.count
21
+ end
22
+ end
23
+
24
+ it "should return the correct count" do
25
+ expect(@count).to be(39)
26
+ end
27
+ end
28
+
29
+ describe "#list" do
30
+ before(:all) do
31
+ VCR.use_cassette("vehicle list") do
32
+ @vehicles = Tatooine::Vehicle.list
33
+ end
34
+ end
35
+
36
+ it "gets a list of vehicles" do
37
+ expect(@vehicles).to be_instance_of(Array)
38
+ expect(@vehicles.length).to be(10)
39
+ expect(@vehicles.first).to be_instance_of(Tatooine::Vehicle)
40
+ end
41
+
42
+ it "gets the next page" do
43
+ VCR.use_cassette("vehicle next") do
44
+ @next_vehicles = Tatooine::Vehicle.next
45
+ expect(@next_vehicles).to be_instance_of(Array)
46
+ expect(@next_vehicles.first).to be_instance_of(Tatooine::Vehicle)
47
+ end
48
+ end
49
+
50
+ it "gets the previous page" do
51
+ VCR.use_cassette("vehicle previous") do
52
+ @previous_vehicles = Tatooine::Vehicle.previous
53
+ expect(@previous_vehicles.map(&:name)).to match_array(@vehicles.map(&:name))
54
+ end
55
+ end
56
+ end
57
+
58
+ describe "#get" do
59
+ before(:all) do
60
+ VCR.use_cassette("vehicle 14") do
61
+ @vehicle = Tatooine::Vehicle.get(14)
62
+ end
63
+ end
64
+
65
+ it "gets the url of the vehicle" do
66
+ expect(@vehicle.url).to eq("http://swapi.co/api/vehicles/14/")
67
+ end
68
+
69
+ it "gets the attributes of the vehicle" do
70
+ expect(@vehicle.name).to eq("Snowspeeder")
71
+ end
72
+
73
+ it "gets a list of pilots" do
74
+ expect(@vehicle.pilots).to be_instance_of(Array)
75
+ expect(@vehicle.pilots.first).to be_instance_of(Tatooine::Person)
76
+ end
77
+
78
+ it "gets a list of films" do
79
+ expect(@vehicle.films).to be_instance_of(Array)
80
+ expect(@vehicle.films.first).to be_instance_of(Tatooine::Film)
81
+ end
82
+ end
83
+
84
+ describe "#new" do
85
+ it "primes an object with a url" do
86
+ VCR.use_cassette("vehicle schema") do
87
+ @vehicle = Tatooine::Vehicle.new(:url => "#{Tatooine::API_BASE}vehicles/14/")
88
+ expect(@vehicle).to respond_to(:name)
89
+ end
90
+ end
91
+
92
+ it "gets the object when methods are called" do
93
+ VCR.use_cassette("vehicle 14 and schema") do
94
+ @vehicle = Tatooine::Vehicle.new("url" => "#{Tatooine::API_BASE}vehicles/14/")
95
+ expect(@vehicle.name).to eq("Snowspeeder")
96
+ end
97
+ end
98
+
99
+ it "sets properties from an object" do
100
+ VCR.use_cassette("vehicle schema") do
101
+ @vehicle = Tatooine::Vehicle.new("name" => "Anything, because I said so")
102
+ expect(@vehicle.name).to eq("Anything, because I said so")
103
+ end
104
+ end
105
+ end
106
+ end