lotr-sdk 0.1.1

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
+ SHA256:
3
+ metadata.gz: e14a3db3f517bd80e87a7dd2a42c403f2077bb2527475bfdc2a65053eedf4abc
4
+ data.tar.gz: 69c14fa3df2b62893b5d94cbeabbe6cc87851c629328f8cbfb7ddd3aafb9bdde
5
+ SHA512:
6
+ metadata.gz: 03c474b7e6faab9c3a348eb44191d2e8416047ac69d041052211fa255d219b9dbb3787e3dabd4c05bc33100ae37a4a59885b130a46feb0cb33ecdc8d15aad089
7
+ data.tar.gz: 1ff4d9706a7b333ab72748d383121e159fd17452bcaced949c205bc6b41a26131972504a02a62bc14224fa9429bc6203a26904db21aca5cd48f4a69d4fe43726
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-05-22
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at joseph.h.wan@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in lotr-sdk.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 1.21"
data/Gemfile.lock ADDED
@@ -0,0 +1,90 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ lotr-sdk (0.1.1)
5
+ http (~> 5.1)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.8.4)
11
+ public_suffix (>= 2.0.2, < 6.0)
12
+ ast (2.4.2)
13
+ coderay (1.1.3)
14
+ diff-lcs (1.5.0)
15
+ domain_name (0.5.20190701)
16
+ unf (>= 0.0.5, < 1.0.0)
17
+ ffi (1.15.5)
18
+ ffi-compiler (1.0.1)
19
+ ffi (>= 1.0.0)
20
+ rake
21
+ http (5.1.1)
22
+ addressable (~> 2.8)
23
+ http-cookie (~> 1.0)
24
+ http-form_data (~> 2.2)
25
+ llhttp-ffi (~> 0.4.0)
26
+ http-cookie (1.0.5)
27
+ domain_name (~> 0.5)
28
+ http-form_data (2.3.0)
29
+ json (2.6.3)
30
+ llhttp-ffi (0.4.0)
31
+ ffi-compiler (~> 1.0)
32
+ rake (~> 13.0)
33
+ method_source (1.0.0)
34
+ parallel (1.23.0)
35
+ parser (3.2.2.1)
36
+ ast (~> 2.4.1)
37
+ pry (0.14.2)
38
+ coderay (~> 1.1)
39
+ method_source (~> 1.0)
40
+ public_suffix (5.0.1)
41
+ rainbow (3.1.1)
42
+ rake (13.0.6)
43
+ regexp_parser (2.8.0)
44
+ rexml (3.2.5)
45
+ rspec (3.12.0)
46
+ rspec-core (~> 3.12.0)
47
+ rspec-expectations (~> 3.12.0)
48
+ rspec-mocks (~> 3.12.0)
49
+ rspec-core (3.12.2)
50
+ rspec-support (~> 3.12.0)
51
+ rspec-expectations (3.12.3)
52
+ diff-lcs (>= 1.2.0, < 2.0)
53
+ rspec-support (~> 3.12.0)
54
+ rspec-mocks (3.12.5)
55
+ diff-lcs (>= 1.2.0, < 2.0)
56
+ rspec-support (~> 3.12.0)
57
+ rspec-support (3.12.0)
58
+ rubocop (1.51.0)
59
+ json (~> 2.3)
60
+ parallel (~> 1.10)
61
+ parser (>= 3.2.0.0)
62
+ rainbow (>= 2.2.2, < 4.0)
63
+ regexp_parser (>= 1.8, < 3.0)
64
+ rexml (>= 3.2.5, < 4.0)
65
+ rubocop-ast (>= 1.28.0, < 2.0)
66
+ ruby-progressbar (~> 1.7)
67
+ unicode-display_width (>= 2.4.0, < 3.0)
68
+ rubocop-ast (1.28.1)
69
+ parser (>= 3.2.1.0)
70
+ ruby-progressbar (1.13.0)
71
+ unf (0.1.4)
72
+ unf_ext
73
+ unf_ext (0.0.8.2)
74
+ unicode-display_width (2.4.2)
75
+ yard (0.9.34)
76
+
77
+ PLATFORMS
78
+ x86_64-darwin-22
79
+ x86_64-linux
80
+
81
+ DEPENDENCIES
82
+ lotr-sdk!
83
+ pry (~> 0.14)
84
+ rake (~> 13.0)
85
+ rspec (~> 3.0)
86
+ rubocop (~> 1.21)
87
+ yard (~> 0.6)
88
+
89
+ BUNDLED WITH
90
+ 2.4.13
data/MIT-LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2023, Joseph Wan
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # Lotr::Sdk
2
+
3
+ `lotr-sdk` is a Ruby gem that provides a SDK to help The Lord of the Rings lovers consume data about the epic books by J. R. R. Tolkien and the official movie adaptions by Peter Jackson. This SDK leverages [The One API](https://the-one-api.dev) the one API to rule them all.
4
+
5
+ This SDK currently implements methods to work with movies and movie quotes
6
+
7
+ ## Installation
8
+
9
+ Install the gem and add to the application's Gemfile by executing:
10
+
11
+ $ bundle add lotr-sdk
12
+
13
+ ## Usage
14
+
15
+ Get an access token by signing up for an account at [The One API](https://the-one-api.dev/sign-up).
16
+
17
+ ```
18
+ # Provide API access token
19
+ # If you do not provide an access token, Lotr::Sdk looks for checks if you set `THE_ONE_ACCESS_TOKEN` environment variable.
20
+ client = Lotr::Sdk::Client.new(access_token: 'personal_access_token')
21
+
22
+ # Fetch all movies
23
+ movies = client.movies
24
+
25
+ # Fetch quotes belonging to a movie
26
+ client.movie_quotes_from_movie(movie.first)
27
+
28
+ # Note: The One API only provides quotes from these movies:
29
+ - The Fellowship of the Ring (id: "5cd95395de30eff6ebccde5c")
30
+ - The Two Towers (id: "5cd95395de30eff6ebccde5b")
31
+ - The Return of the King (id: "5cd95395de30eff6ebccde5d")
32
+ This version of the API will raise an error if you try to retrieve quotes from other movies. To disable this check, set the `DISABLE_MOVIE_CHECK` env variable to `1`
33
+
34
+ # Fetch all quotes
35
+ client.quotes
36
+ ```
37
+
38
+ You can see the list of available methods with more details by generating and viewing the documentation:
39
+ ```
40
+ bin/yard
41
+ ```
42
+
43
+ ## Development
44
+
45
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
46
+
47
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
48
+
49
+ ## Testing
50
+
51
+ Before running tests, set your access token to `THE_ONE_ACCESS_TOKEN` environment variable.
52
+
53
+ ## Contributing
54
+
55
+ Bug reports and pull requests are welcome on GitHub at https://github.com/joseph1wan/joseph-sdk. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/joseph1wan/joseph-sdk/blob/main/CODE_OF_CONDUCT.md).
56
+
57
+ ## Code of Conduct
58
+
59
+ Everyone interacting in the Lotr::Sdk project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/joseph1wan/joseph-sdk/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: %i[spec]
data/design.md ADDED
@@ -0,0 +1,36 @@
1
+ # SDK Design
2
+
3
+ ## Philosophy
4
+
5
+ I modeled the SDK design after the Octokit philosophy of keeping the SDK
6
+ structure close to the original API. The classes provide getter methods with Ruby-convention naming. I originally planned to allow users to fetch quotes from movies (`Movie.quotes`) and vice-versa, but ultimately removed that functionality since those methods can be costly in API calls if the developer is not careful. Instead, developers should use the Client for all API calls (`Client.movie_quotes(movie_id)`).
7
+
8
+ ## Objectives:
9
+ One of my main objectives in this API design is to prevent my users from running into some of the problem I ran into:
10
+ - Receiving an empty response for a movie that didn't exist
11
+ - Getting a 500 error when the ID wasn't a 24-char string
12
+ - Partial movie-name matching not working until converted to Regex
13
+
14
+ Another important objective of the design was clarity. I spent a good portion of development time writing tests and making sure all methods were documented.
15
+
16
+ ## Areas of improvement
17
+
18
+ ### Schema validation
19
+ Implementing schema validation on the response from The One API would:
20
+ 1. Give early warning about API changes.
21
+ 2. Provide useful data about what changed.
22
+ 3. Make it trivial to update and release a new version of the SDK.
23
+
24
+ ### Meta programming
25
+ Using meta-programming, we could programmatically create class methods with Ruby-convention naming using the keys of the JSON response.
26
+
27
+ For example, we could potentially take advantage of Ruby's `NoMethodError` and infer that `runtime_in_minutes` would be `runtimeInMinutes` and access the data using that key. Essentially defining this method without writing code:
28
+
29
+ ```
30
+ def runtime_in_minutes
31
+ @data["runtimeinMinutes"]
32
+ end
33
+ ```
34
+
35
+ However, I find that this can create more headache than help, depending on edge cases. It also makes it much harder to generate documentation from code (can't use YARD). But it would be handle changes in the source API response with very little
36
+ code change.
@@ -0,0 +1,133 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lotr
4
+ module Sdk
5
+ # Client instantiates an HTTP client and makes all API calls
6
+ class Client
7
+ ID_REGEX = /^[0-9a-f]{24}$/i.freeze
8
+ MOVIES_WITH_QUOTES = %w[5cd95395de30eff6ebccde5c 5cd95395de30eff6ebccde5b 5cd95395de30eff6ebccde5d"].freeze # IDs for the original trilogy
9
+
10
+ # Initialize client with an access token
11
+ # 1. Sign up at https://the-one-api.dev/sign-up
12
+ # 2. Provide the access token.
13
+ # You can pass in you token as a parameter
14
+ # or
15
+ # Set the token to the THE_ONE_ACCESS_TOKEN env variable
16
+ def initialize(access_token: nil)
17
+ @api_url = "https://the-one-api.dev/v2"
18
+ if access_token.nil?
19
+ access_token = ENV["THE_ONE_ACCESS_TOKEN"]
20
+ end
21
+ raise Exception::MissingAccessTokenError if access_token.nil?
22
+
23
+ @client = HTTP.headers(accept: "application/json").auth("Bearer #{access_token}")
24
+ end
25
+
26
+ # Fetch all movies
27
+ # @param q [Object] Hash of query parameters. For example: { name: "Series" }
28
+ # @return [Array<Movie>] A list of all movies
29
+ def movies(q: {})
30
+ endpoint = "movie"
31
+ if q.any?
32
+ endpoint += "?" + transform_query_parameters(q)
33
+ end
34
+ uri = URI("#{@api_url}/#{endpoint}")
35
+ response = JSON.parse(@client.get(uri).body)
36
+ response["docs"].map do |movie_data|
37
+ Movie.new(movie_data)
38
+ end
39
+ end
40
+
41
+ # Fetch a specified movie
42
+ # @param id [String] A 24-char string identifying the movie
43
+ # @return [Movie] The movie corresponding to the ID
44
+ def movie(id)
45
+ id = validate_id(id)
46
+ endpoint = "movie/#{id}"
47
+ uri = URI("#{@api_url}/#{endpoint}")
48
+ response = JSON.parse(@client.get(uri).body)
49
+ raise Exception::ResourceNotFoundError.new(:movie, id) if response["total"].zero?
50
+
51
+ movie_data = response["docs"].first
52
+ Movie.new(movie_data)
53
+ end
54
+
55
+ # Fetch all quotes
56
+ # @param q [Object] Hash of query and pagination parameters. For example: { dialog: "Oooh", page: 2 }
57
+ # @return [Array<Movie>] A list of all movies
58
+ def quotes(q: {})
59
+ endpoint = "/quote"
60
+ if q.any?
61
+ endpoint += "?" + transform_query_parameters(q)
62
+ end
63
+ uri = URI("#{@api_url}/#{endpoint}")
64
+ response = JSON.parse(@client.get(uri).body)
65
+ response["docs"].map do |quote_data|
66
+ Quote.new(quote_data)
67
+ end
68
+ end
69
+
70
+ # Fetch all quotes belonging to a movie.
71
+ # Only Lord of the Rings movie are supported. These movies are:
72
+ # The Fellowship of the Ring
73
+ # The Two Towers
74
+ # The Return of the King
75
+ # @return [Array<Quote>] All quotes belonging to the movie
76
+ def movie_quotes(movie_id, movie = nil)
77
+ raise Exception::MovieNotSupportedError.new(MOVIES_WITH_QUOTES) unless ENV["DISABLE_MOVIE_CHECK"] || MOVIES_WITH_QUOTES.include?(movie_id)
78
+
79
+ endpoint = "/movie/#{movie_id}/quote"
80
+ uri = URI("#{@api_url}/#{endpoint}")
81
+ response = JSON.parse(@client.get(uri).body)
82
+ response["docs"].map do |quote_data|
83
+ Quote.new(quote_data)
84
+ end
85
+ end
86
+
87
+ # Fetch all quotes belonging to a movie.
88
+ # Uses movie_quotes with same limitations
89
+ # @return [Array<Quote>] All quotes belonging to the movie
90
+ def movie_quotes_from_movie(movie)
91
+ movie_quotes(movie.id, movie)
92
+ end
93
+
94
+ # Fetch a specified quote
95
+ # @param id [String] A 24-char string identifying the quote
96
+ # @return [Movie] The quote corresponding to the ID
97
+ def quote(id)
98
+ quote_id = validate_id(id)
99
+ endpoint = "/quote/#{quote_id}"
100
+ uri = URI("#{@api_url}/#{endpoint}")
101
+ response = JSON.parse(@client.get(uri).body)
102
+
103
+ raise Exception::ResourceNotFoundError.new(:quote, id) if response["total"].zero?
104
+
105
+ quote_data = response["docs"].first
106
+ Quote.new(quote_data)
107
+ end
108
+
109
+ private
110
+
111
+ # Makes sure ID is a 24-char string
112
+ # return [String]
113
+ def validate_id(id)
114
+ raise Exception::InvalidIdError.new(id) unless ID_REGEX.match?(id.to_s.downcase)
115
+
116
+ id
117
+ end
118
+
119
+ # Transforms query params from hash to string
120
+ # return [String]
121
+ def transform_query_parameters(params)
122
+ pagination_keys = %i[limit page offset]
123
+ params.map do |k, v|
124
+ if pagination_keys.include?(k)
125
+ "#{k}=#{v}"
126
+ else
127
+ "#{k}=/.*#{v}.*/"
128
+ end
129
+ end.join("&")
130
+ end
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lotr
4
+ module Sdk
5
+ module Exception
6
+ class InvalidIdError < StandardError
7
+ def initialize(id)
8
+ super("#{id} is an invalid ID. Provide a valid id")
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lotr
4
+ module Sdk
5
+ module Exception
6
+ class MissingAccessTokenError < StandardError
7
+ def initialize
8
+ super("Provide client with an access token or set your token to the THE_ONE_ACCESS_TOKEN env variable")
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lotr
4
+ module Sdk
5
+ module Exception
6
+ class MovieNotSupportedError < StandardError
7
+ def initialize(supported_movies)
8
+ msg = "This movie ID is not supported. Supported movies are: #{supported_movies.join(" ")}"
9
+ super(msg)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lotr
4
+ module Sdk
5
+ module Exception
6
+ class ResourceNotFoundError < StandardError
7
+ def initialize(resource_type, id)
8
+ super("Could not find #{resource_type} quote with id: #{id}. Check your ID and try again or provide a valid ID")
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "exception/invalid_id_error"
4
+ require_relative "exception/missing_access_token_error"
5
+ require_relative "exception/movie_not_supported_error"
6
+ require_relative "exception/resource_not_found_error"
7
+
8
+ module Lotr
9
+ module Sdk
10
+ module Exception; end
11
+ end
12
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lotr
4
+ module Sdk
5
+ # Movie represents the data of a movie.
6
+ class Movie
7
+ attr_reader :data, :quotes
8
+
9
+ def initialize(data)
10
+ @data = data
11
+ @quotes = []
12
+ end
13
+
14
+ # Represents the movie ID
15
+ # @return [String]
16
+ def id
17
+ @data["_id"]
18
+ end
19
+
20
+ # Represents the movie title
21
+ # @return [String]
22
+ def name
23
+ @data["name"]
24
+ end
25
+
26
+ # Represents the movie length
27
+ # @return [Integer]
28
+ def run_time_minutes(format: false)
29
+ @data["runtimeInMinutes"]
30
+ end
31
+
32
+ # Represents the movie budget in milions
33
+ # @return [Integer]
34
+ def budget_millions
35
+ @data["budgetInMillions"]
36
+ end
37
+
38
+ # Represents the movie revenue in milions
39
+ # @return [Integer]
40
+ def revenue_millions
41
+ @data["boxOfficeRevenueInMillions"]
42
+ end
43
+
44
+ # Represents the number of Academy Award nominations
45
+ # @return [Integer]
46
+ def academy_award_nominations
47
+ @data["academyAwardNominations"]
48
+ end
49
+
50
+ # Represents the number of Academy Awards won
51
+ # @return [Integer]
52
+ def academy_award_wins
53
+ @data["academyAwardWins"]
54
+ end
55
+
56
+ # Represents the score out of 100 on Rotten Tomatoes
57
+ # @return [Integer]
58
+ def rotten_tomatoes_score
59
+ @data["rottenTomatoesScore"]
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lotr
4
+ module Sdk
5
+ # Quote represents the data of a quote.
6
+ class Quote
7
+ attr_reader :data
8
+
9
+ def initialize(data)
10
+ @data = data
11
+ end
12
+
13
+ # Represents the quote ID
14
+ # @return [String]
15
+ def id
16
+ @data["_id"]
17
+ end
18
+
19
+ # Represents the quote text
20
+ # @return [String]
21
+ def dialog
22
+ @data["dialog"]
23
+ end
24
+
25
+ # Fetch the ID of the movie the quote comes from
26
+ # @return [String]
27
+ def movie
28
+ @data["movie"]
29
+ end
30
+
31
+ # Represents the character that spoke the quote
32
+ # Characters are not supported in this version of the SDK
33
+ # @return [String]
34
+ def character
35
+ @data["character"]
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lotr
4
+ module Sdk
5
+ VERSION = "0.1.1"
6
+ end
7
+ end
data/lib/lotr/sdk.rb ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "http"
4
+ require_relative "sdk/client"
5
+ require_relative "sdk/exception"
6
+ require_relative "sdk/movie"
7
+ require_relative "sdk/quote"
8
+ require_relative "sdk/version"
9
+
10
+ module Lotr
11
+ module Sdk
12
+ end
13
+ end
data/sig/lotr/sdk.rbs ADDED
@@ -0,0 +1,6 @@
1
+ module Lotr
2
+ module Sdk
3
+ VERSION: String
4
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lotr-sdk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Joseph Wan
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-05-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: http
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.14'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.14'
41
+ - !ruby/object:Gem::Dependency
42
+ name: yard
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.6'
55
+ description: Consume information about the Lord of the Rings trilogy
56
+ email:
57
+ - joseph.h.wan@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".rspec"
63
+ - ".rubocop.yml"
64
+ - CHANGELOG.md
65
+ - CODE_OF_CONDUCT.md
66
+ - Gemfile
67
+ - Gemfile.lock
68
+ - MIT-LICENSE
69
+ - README.md
70
+ - Rakefile
71
+ - design.md
72
+ - lib/lotr/sdk.rb
73
+ - lib/lotr/sdk/client.rb
74
+ - lib/lotr/sdk/exception.rb
75
+ - lib/lotr/sdk/exception/invalid_id_error.rb
76
+ - lib/lotr/sdk/exception/missing_access_token_error.rb
77
+ - lib/lotr/sdk/exception/movie_not_supported_error.rb
78
+ - lib/lotr/sdk/exception/resource_not_found_error.rb
79
+ - lib/lotr/sdk/movie.rb
80
+ - lib/lotr/sdk/quote.rb
81
+ - lib/lotr/sdk/version.rb
82
+ - sig/lotr/sdk.rbs
83
+ homepage: https://github.com/joseph1wan/joseph-sdk
84
+ licenses: []
85
+ metadata:
86
+ homepage_uri: https://github.com/joseph1wan/joseph-sdk
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: 2.6.0
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubygems_version: 3.4.13
103
+ signing_key:
104
+ specification_version: 4
105
+ summary: Consume information about the Lord of the Rings trilogy
106
+ test_files: []