one_api_sdk 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +68 -0
- data/LICENSE.txt +21 -0
- data/README.md +51 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/design.md +46 -0
- data/lib/one_api_sdk/books.rb +39 -0
- data/lib/one_api_sdk/chapters.rb +28 -0
- data/lib/one_api_sdk/characters.rb +39 -0
- data/lib/one_api_sdk/client.rb +48 -0
- data/lib/one_api_sdk/constants.rb +14 -0
- data/lib/one_api_sdk/movies.rb +39 -0
- data/lib/one_api_sdk/quotes.rb +29 -0
- data/lib/one_api_sdk/version.rb +3 -0
- data/lib/one_api_sdk.rb +10 -0
- data/one_api_sdk.gemspec +29 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 748f054e8ea365e38b41221963637eb3966b9ff81ca6713eb5457ea052bfb58f
|
4
|
+
data.tar.gz: 90623cd97462f6c86c5bb873224188e2f2f6b44b4088b2bf5444a96c8541e35b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 993f2e02e93acd446057247da4ad1e4e3765bda24ffc30327f5767930b532bcdf5a5fa58f543a26dd454ac9bd7fa2303de710144c17dff6361c6153a234da78f
|
7
|
+
data.tar.gz: 06f652125b65167787112b5f3679ebbdc4fd52028ee8c3f64c4a0150b652ac9345a3ea6043f40b8092b6e57d7f438e14e5602154194a0917ef5b3a162d5717af
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at reedbshipley@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
one_api_sdk (0.1.0)
|
5
|
+
http
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
addressable (2.8.1)
|
11
|
+
public_suffix (>= 2.0.2, < 6.0)
|
12
|
+
crack (0.4.5)
|
13
|
+
rexml
|
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
|
+
hashdiff (1.0.1)
|
22
|
+
http (4.4.1)
|
23
|
+
addressable (~> 2.3)
|
24
|
+
http-cookie (~> 1.0)
|
25
|
+
http-form_data (~> 2.2)
|
26
|
+
http-parser (~> 1.2.0)
|
27
|
+
http-cookie (1.0.5)
|
28
|
+
domain_name (~> 0.5)
|
29
|
+
http-form_data (2.3.0)
|
30
|
+
http-parser (1.2.3)
|
31
|
+
ffi-compiler (>= 1.0, < 2.0)
|
32
|
+
public_suffix (5.0.0)
|
33
|
+
rake (12.3.3)
|
34
|
+
rexml (3.2.5)
|
35
|
+
rspec (3.11.0)
|
36
|
+
rspec-core (~> 3.11.0)
|
37
|
+
rspec-expectations (~> 3.11.0)
|
38
|
+
rspec-mocks (~> 3.11.0)
|
39
|
+
rspec-core (3.11.0)
|
40
|
+
rspec-support (~> 3.11.0)
|
41
|
+
rspec-expectations (3.11.1)
|
42
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
43
|
+
rspec-support (~> 3.11.0)
|
44
|
+
rspec-mocks (3.11.1)
|
45
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
46
|
+
rspec-support (~> 3.11.0)
|
47
|
+
rspec-support (3.11.1)
|
48
|
+
unf (0.1.4)
|
49
|
+
unf_ext
|
50
|
+
unf_ext (0.0.8.2)
|
51
|
+
vcr (6.1.0)
|
52
|
+
webmock (3.18.1)
|
53
|
+
addressable (>= 2.8.0)
|
54
|
+
crack (>= 0.3.2)
|
55
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
56
|
+
|
57
|
+
PLATFORMS
|
58
|
+
ruby
|
59
|
+
|
60
|
+
DEPENDENCIES
|
61
|
+
one_api_sdk!
|
62
|
+
rake (~> 12.0)
|
63
|
+
rspec (~> 3.0)
|
64
|
+
vcr (~> 6.1)
|
65
|
+
webmock (~> 3.18)
|
66
|
+
|
67
|
+
BUNDLED WITH
|
68
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 Reed Shipley
|
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,51 @@
|
|
1
|
+
# OneApiSdk
|
2
|
+
|
3
|
+
This SDK allows for you to access The One API, an API for The Lord of the Rings, from within your ruby code. You can find the rubydoc documentation HERE. TODO: PUT DOC LINK
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'one_api_sdk'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install one_api_sdk
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
To instantiate the SDK, pass the Access Token retrieved from https://the-one-api.dev/account in the constructor method of the client. All methods take an optional `query_params` parameter as the final argument. The API (from my testing) only allows one query parameter at a time to be processed.
|
23
|
+
|
24
|
+
``` ruby
|
25
|
+
require 'one_api_sdk'
|
26
|
+
client = OneApiSdk::Client.new("YOUR ACCESS TOKEN HERE")
|
27
|
+
|
28
|
+
# without query parameter
|
29
|
+
result = client.books()
|
30
|
+
# example query parameter
|
31
|
+
limited_result = client.books('?limit=2')
|
32
|
+
```
|
33
|
+
|
34
|
+
## Development
|
35
|
+
|
36
|
+
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.
|
37
|
+
|
38
|
+
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).
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/reedship/one_api_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/reedship/one_api_sdk/blob/master/CODE_OF_CONDUCT.md).
|
43
|
+
|
44
|
+
|
45
|
+
## License
|
46
|
+
|
47
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
48
|
+
|
49
|
+
## Code of Conduct
|
50
|
+
|
51
|
+
Everyone interacting in the OneApiSdk project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/one_api_sdk/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "one_api_sdk"
|
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(__FILE__)
|
data/bin/setup
ADDED
data/design.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Design Doc
|
2
|
+
|
3
|
+
## Basic Principles
|
4
|
+
|
5
|
+
When making this sdk I wanted to follow a couple key points.
|
6
|
+
* Top Level Access to all methods
|
7
|
+
|
8
|
+
I didn't want to have the user dig through multiple imported modules or classes to get access to methods. Everything is available from the base `OneApiSdk::Client` class.
|
9
|
+
* Simple configuration
|
10
|
+
|
11
|
+
The API uses only a `Access Token` and the SDK should be just as simple.
|
12
|
+
```ruby
|
13
|
+
client = OneApiSdk::Client.new("YOUR ACCESS TOKEN HERE")
|
14
|
+
```
|
15
|
+
* Self documenting code.
|
16
|
+
|
17
|
+
I wanted documentation to be easily accessible and automatically updating. So i chose to use rubydoc for documentation generation.
|
18
|
+
|
19
|
+
## Structure
|
20
|
+
|
21
|
+
Modules in the project are seperated by their corresponding endpoint, and included into the base `Client` class. There is no configuration for the sdk, due to the time limit, and all requests return the response body by default.
|
22
|
+
```
|
23
|
+
# project root
|
24
|
+
...
|
25
|
+
one_api_sdk.gemspec
|
26
|
+
README.md
|
27
|
+
design.md << you are here
|
28
|
+
lib/
|
29
|
+
one_api_sdk.rb
|
30
|
+
one_api_sdk/
|
31
|
+
books.rb
|
32
|
+
chapters.rb
|
33
|
+
characters.rb
|
34
|
+
client.rb << main entry point
|
35
|
+
constants.rb
|
36
|
+
movies.rb
|
37
|
+
quotes.rb
|
38
|
+
version.rb
|
39
|
+
...
|
40
|
+
```
|
41
|
+
|
42
|
+
## Testing
|
43
|
+
|
44
|
+
All testing is done using VCR cassettes (due to the limited available requests per hour). Repeated HTTP calls use cached responses in individual `YAML` files. I chose this due to the 'one and done' style of this project, in a production environment I would set expiration dates on the cassettes so that cached responses weren't stored for too long where there would be worry surrounding whether or not the cassettes were truly accurate to the current version of the API.
|
45
|
+
|
46
|
+
To run all tests call `rake spec`||`rspec spec/one_api_sdk_spec.rb` and individual sections/tests can be run by running `rspec spec/one_api_sdk_spec.rb:<LINE_NUMBER>`.
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OneApiSdk
|
4
|
+
class Client
|
5
|
+
module Books
|
6
|
+
# BOOK METHODS
|
7
|
+
# TODO: CHECK RETURN VALUES
|
8
|
+
|
9
|
+
# List of all "The Lord of the Rings" books
|
10
|
+
# @return [Array<Hash>] An array of books
|
11
|
+
# @param query_params [String] the query parameters you want to include in your search
|
12
|
+
# IE: "?name=The Two Towers"
|
13
|
+
def books(query_params="")
|
14
|
+
response = call_with_token("#{Constants::BOOK_BASE_PATH}#{query_params}")
|
15
|
+
JSON.parse(response.body)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Request one specific book
|
19
|
+
# @param id [String] the unique id of the book
|
20
|
+
# @param query_params [String] the query parameters you want to include in your search
|
21
|
+
# IE: "?sort=name:asc"
|
22
|
+
# @return [Hash] The returned book object
|
23
|
+
def book(id,query_params="")
|
24
|
+
response = call_with_token("#{Constants::BOOK_BASE_PATH}/#{id}#{query_params}")
|
25
|
+
JSON.parse(response.body)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Request one specific book
|
29
|
+
# @param id [String] the unique id of the book
|
30
|
+
# @param query_params [String] the query parameters you want to include in your search
|
31
|
+
# IE: "?sort=name:desc"
|
32
|
+
# @return [Hash] The returned book object
|
33
|
+
def book_chapters(id,query_params="")
|
34
|
+
response = call_with_token("#{Constants::BOOK_BASE_PATH}/#{id}/chapter#{query_params}")
|
35
|
+
JSON.parse(response.body)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OneApiSdk
|
4
|
+
class Client
|
5
|
+
module Chapters
|
6
|
+
# CHAPTER METHODS
|
7
|
+
# TODO: CHECK RETURN VALUES
|
8
|
+
|
9
|
+
# List all book chapters
|
10
|
+
# @param query_params [String] the query parameters you want to include in your search
|
11
|
+
# IE: "?sort=name:asc"
|
12
|
+
# @return [Array<Hash>] An array of chapters
|
13
|
+
def chapters(query_params="")
|
14
|
+
response = call_with_token("#{Constants::CHAPTER_BASE_PATH}#{query_params}")
|
15
|
+
JSON.parse(response.body)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Request one specific book chapter
|
19
|
+
# @param id [String] the unique id of the chapter
|
20
|
+
# @param options [Array<String>] The query parameters you want passed into the request.
|
21
|
+
# @return [Hash] The returned chapter object
|
22
|
+
def chapter(id,query_params="")
|
23
|
+
response = call_with_token("#{Constants::CHAPTER_BASE_PATH}/#{id}#{query_params}")
|
24
|
+
JSON.parse(response.body)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OneApiSdk
|
4
|
+
class Client
|
5
|
+
module Characters
|
6
|
+
# CHARACTER METHODS
|
7
|
+
# TODO: CHECK RETURN VALUES
|
8
|
+
|
9
|
+
# List of characters including metadata like name, gender, realm, race and more
|
10
|
+
# @param query_params [String] the query parameters you want to include in your search
|
11
|
+
# IE: "?sort=name:asc"
|
12
|
+
# @return [Array<Hash>] An array of characters
|
13
|
+
def characters(query_params="")
|
14
|
+
response = call_with_token("#{Constants::CHARACTER_BASE_PATH}#{query_params}")
|
15
|
+
JSON.parse(response.body)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Request one specific character
|
19
|
+
# @param id [String] the unique id of the character
|
20
|
+
# @param query_params [String] the query parameters you want to include in your search
|
21
|
+
# IE: "?sort=name:asc"
|
22
|
+
# @return [Hash] The returned character object
|
23
|
+
def character(id,query_params="")
|
24
|
+
response = call_with_token("#{Constants::CHARACTER_BASE_PATH}/#{id}#{query_params}")
|
25
|
+
JSON.parse(response.body)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Request all movie quotes for one specific character (only working for the LotR trilogy)
|
29
|
+
# @param id [String] the unique id of the character
|
30
|
+
# @param query_params [String] the query parameters you want to include in your search
|
31
|
+
# IE: "?sort=name:asc"
|
32
|
+
# @return [Hash] The returned character quotes object
|
33
|
+
def character_quotes(id, query_params="")
|
34
|
+
response = call_with_token("#{Constants::CHARACTER_BASE_PATH}/#{id}/quote#{query_params}")
|
35
|
+
JSON.parse(response.body)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'http'
|
4
|
+
require 'json'
|
5
|
+
require 'erb'
|
6
|
+
require 'uri'
|
7
|
+
|
8
|
+
require 'one_api_sdk/books'
|
9
|
+
require 'one_api_sdk/chapters'
|
10
|
+
require 'one_api_sdk/characters'
|
11
|
+
require 'one_api_sdk/constants'
|
12
|
+
require 'one_api_sdk/movies'
|
13
|
+
require 'one_api_sdk/quotes'
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
module OneApiSdk
|
18
|
+
class Client
|
19
|
+
include Books
|
20
|
+
include Chapters
|
21
|
+
include Characters
|
22
|
+
include Constants
|
23
|
+
include Movies
|
24
|
+
include Quotes
|
25
|
+
|
26
|
+
attr_accessor :access_token
|
27
|
+
attr_accessor :base_api_url
|
28
|
+
|
29
|
+
# Initialize using passed in access token
|
30
|
+
# @param
|
31
|
+
def initialize(access_token=ENV['access_token'])
|
32
|
+
@access_token = access_token
|
33
|
+
@base_api_url = Constants::API_BASE_PATH
|
34
|
+
@http ||= HTTP::Client.new
|
35
|
+
end
|
36
|
+
|
37
|
+
# This method calls each method and attaches the access token under the authorization header
|
38
|
+
# @param path [String] the path to the endpoint including any query parameters
|
39
|
+
# @see https://the-one-api.dev/documentation#4 Available Query Parameters
|
40
|
+
# IE: '/books?offset=1'
|
41
|
+
def call_with_token(path)
|
42
|
+
@http
|
43
|
+
.headers(accept: 'application/json', content: 'application/json')
|
44
|
+
.auth("Bearer #{@access_token}")
|
45
|
+
.send('get', URI(@base_api_url + path))
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OneApiSdk
|
4
|
+
class Client
|
5
|
+
module Constants
|
6
|
+
API_BASE_PATH = "https://the-one-api.dev/v2"
|
7
|
+
BOOK_BASE_PATH = "/book"
|
8
|
+
MOVIE_BASE_PATH = "/movie"
|
9
|
+
CHARACTER_BASE_PATH = "/character"
|
10
|
+
QUOTE_BASE_PATH = "/quote"
|
11
|
+
CHAPTER_BASE_PATH = "/chapter"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OneApiSdk
|
4
|
+
class Client
|
5
|
+
module Movies
|
6
|
+
# MOVIE METHODS
|
7
|
+
# TODO: CHECK RETURN VALUES
|
8
|
+
|
9
|
+
# List of all "The Lord of the Rings" movies, including the "The Lord of the Rings" and the "The Hobbit" movies.
|
10
|
+
# @param query_params [String] the query parameters you want to include in your search
|
11
|
+
# IE: "?sort=name:asc"
|
12
|
+
# @return [Array<Hash>] An array of movies
|
13
|
+
def movies(query_params="")
|
14
|
+
response = call_with_token("#{Constants::MOVIE_BASE_PATH}#{query_params}")
|
15
|
+
JSON.parse(response.body)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Request one specific movie
|
19
|
+
# @param id [String] the unique id of the movie
|
20
|
+
# @param query_params [String] the query parameters you want to include in your search
|
21
|
+
# IE: "?sort=name:asc"
|
22
|
+
# @return [Hash] The returned movie object
|
23
|
+
def movie(id,query_params="")
|
24
|
+
response = call_with_token("#{Constants::MOVIE_BASE_PATH}/#{id}#{query_params}")
|
25
|
+
JSON.parse(response.body)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Request all movie quotes for one specific movie (only working for the LotR trilogy)
|
29
|
+
# @param id [String] the unique id of the movie
|
30
|
+
# @param query_params [String] the query parameters you want to include in your search
|
31
|
+
# IE: "?limit=50"
|
32
|
+
# @return [Hash] The returned movie quotes object
|
33
|
+
def movie_quotes(id,query_params="")
|
34
|
+
response = call_with_token("#{Constants::MOVIE_BASE_PATH}/#{id}/quote#{query_params}")
|
35
|
+
JSON.parse(response.body)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OneApiSdk
|
4
|
+
class Client
|
5
|
+
module Quotes
|
6
|
+
# QUOTE METHODS
|
7
|
+
# TODO: CHECK RETURN VALUES
|
8
|
+
|
9
|
+
# List all movie quotes
|
10
|
+
# @param query_params [String] the query parameters you want to include in your search
|
11
|
+
# IE: "?sort=name:asc"
|
12
|
+
# @return [Array<Hash>] An array of quotes
|
13
|
+
def quotes(query_params="")
|
14
|
+
response = call_with_token("#{Constants::QUOTE_BASE_PATH}#{query_params}")
|
15
|
+
JSON.parse(response.body)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Request one specific movie quote
|
19
|
+
# @param id [String] the unique id of the quote
|
20
|
+
# @param query_params [String] the query parameters you want to include in your search
|
21
|
+
# IE: "?sort=name:asc"
|
22
|
+
# @return [Hash] The returned quote object
|
23
|
+
def quote(id,query_params="")
|
24
|
+
response = call_with_token("#{Constants::QUOTE_BASE_PATH}/#{id}#{query_params}")
|
25
|
+
JSON.parse(response.body)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/one_api_sdk.rb
ADDED
data/one_api_sdk.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative 'lib/one_api_sdk/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "one_api_sdk"
|
5
|
+
spec.version = OneApiSdk::VERSION
|
6
|
+
spec.authors = ["Reed Shipley"]
|
7
|
+
spec.email = ["reedbshipley@gmail.com"]
|
8
|
+
|
9
|
+
spec.summary = "This sdk allows you to access the One API, an API for TLOR."
|
10
|
+
spec.homepage = "https://github.com/reedship/one_api_sdk"
|
11
|
+
spec.license = "MIT"
|
12
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
13
|
+
|
14
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
15
|
+
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
spec.metadata["source_code_uri"] = "https://github.com/reedship/one_api_sdk"
|
18
|
+
spec.metadata["changelog_uri"] = "https://github.com/reedship/one_api_sdk/changelog.md"
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
|
+
end
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
spec.add_dependency('http')
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: one_api_sdk
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Reed Shipley
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-09-27 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: '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
|
+
description:
|
28
|
+
email:
|
29
|
+
- reedbshipley@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- ".rspec"
|
36
|
+
- ".travis.yml"
|
37
|
+
- CODE_OF_CONDUCT.md
|
38
|
+
- Gemfile
|
39
|
+
- Gemfile.lock
|
40
|
+
- LICENSE.txt
|
41
|
+
- README.md
|
42
|
+
- Rakefile
|
43
|
+
- bin/console
|
44
|
+
- bin/setup
|
45
|
+
- design.md
|
46
|
+
- lib/one_api_sdk.rb
|
47
|
+
- lib/one_api_sdk/books.rb
|
48
|
+
- lib/one_api_sdk/chapters.rb
|
49
|
+
- lib/one_api_sdk/characters.rb
|
50
|
+
- lib/one_api_sdk/client.rb
|
51
|
+
- lib/one_api_sdk/constants.rb
|
52
|
+
- lib/one_api_sdk/movies.rb
|
53
|
+
- lib/one_api_sdk/quotes.rb
|
54
|
+
- lib/one_api_sdk/version.rb
|
55
|
+
- one_api_sdk.gemspec
|
56
|
+
homepage: https://github.com/reedship/one_api_sdk
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
metadata:
|
60
|
+
allowed_push_host: https://rubygems.org
|
61
|
+
homepage_uri: https://github.com/reedship/one_api_sdk
|
62
|
+
source_code_uri: https://github.com/reedship/one_api_sdk
|
63
|
+
changelog_uri: https://github.com/reedship/one_api_sdk/changelog.md
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: 2.3.0
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubygems_version: 3.1.6
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: This sdk allows you to access the One API, an API for TLOR.
|
83
|
+
test_files: []
|