the_one_api 0.1.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eab63a106b4736953d1eaf773cfef554b7fe9a83984a7cd41596451e31c01834
4
- data.tar.gz: 6be4a461d074122e439f9a6bb08cdb3018917d81c0a717d43239610e9b58d7d8
3
+ metadata.gz: a1f9c32daa2104160e59593e3854d4e33cb0b6401f0e1600c97625a4166fcabe
4
+ data.tar.gz: 105c1e4ea840549ea4434e479d9d740331a845668a707e459e3936d749d6d5fa
5
5
  SHA512:
6
- metadata.gz: fade730fc33c878c40b9d1fad97f63385d64217ddfd7fb3a0902288476638b1cbae460e253d8fb8977d7761bbae069edf8799ee46285281561f28987eb23dbec
7
- data.tar.gz: 7ce96e59be310e63a6c70f04e44ec11f26ef04c61aba60ef3d8e61728b127359387e0d404fd942dcf501a0c1bf65567d5ae2d30522d393d3d93b27d10f0dd126
6
+ metadata.gz: 54d754600927c9a5b3a470c0f7b09f22d0e9df490317a20c9fa4bd35cc15387146e776b3f91e54d826a28ce7566de8584fcd09545eba110551373f9ef0eb11c1
7
+ data.tar.gz: f981d550128609b811e385ead09d58f2820369bb680d19cdaf82f42612d9cb9f7165b57f024f7ee2dece0cf76b9ddc206a72f6d70450c7a6bc97554ace02cd9f
data/README.md CHANGED
@@ -4,22 +4,20 @@ This is a Ruby gem that provides an SDK for interacting with [The One API](https
4
4
 
5
5
  ## Installation
6
6
 
7
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
8
-
9
7
  You don't need this source code unless you want to modify the gem. If you just want to use the package, just run:
10
8
 
11
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
9
+ $ gem install the_one_api
12
10
 
13
11
 
14
12
  If you want to build the gem from source:
15
13
 
16
- $ gem build UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
14
+ $ gem build the_one_api
17
15
 
18
16
  ### Installing with Bundler
19
17
 
20
18
  Install the gem and add to the application's Gemfile by executing:
21
19
 
22
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
20
+ $ bundle add the_one_api
23
21
 
24
22
  ### Requirements
25
23
 
@@ -60,6 +58,19 @@ movie.runtime_in_minutes
60
58
 
61
59
  ```
62
60
 
61
+ Query nested API resources (e.g. `/movie/{id}/quotes`) through method on the client named for the kind of entity you want to retrieve chained with a method using the `list_for_` naming convetion:
62
+
63
+ ```ruby
64
+ require 'the_one_api'
65
+
66
+ client = TheOneApi::Client.new("your-API-key")
67
+
68
+ quotes = client.quote.list_for_movie("5cd95395de30eff6ebccde5b")
69
+ quotes.size
70
+ #=> 1000
71
+ ```
72
+
73
+
63
74
  ### Errors
64
75
 
65
76
  The client will raise `TheOneApi::HttpResponseError` when a request returns a bad status code:
@@ -80,15 +91,20 @@ end
80
91
 
81
92
  ## Supported API Features
82
93
 
83
- ### Currently Supported Root Level Endpoints/Operations
94
+ ### Currently Supported Endpoints/Operations
84
95
 
85
- + `/movie` - list all movies, find a movie by id
96
+ | Endpoint | SDK Entry Point | Operation |
97
+ | ------------------- | ---------------------------------------------- | --------------------------------------- |
98
+ | `/movie` | `TheOneApi::Client.movie.list` | list all movies |
99
+ | `/movie/{id}` | `TheOneApi::Client.movie.find({id})` | find a movie by id |
100
+ | `/movie/{id}/quote` | `TheOneApi::Client.quote.list_for_movie({id})` | list all quotes from a particular movie |
101
+ | `/quote` | `TheOneApi::Client.quote.list` | list all quotes |
102
+ | `/quote/{id}` | `TheOneApi::Client.quote.find({id}` | find a quote by id |
86
103
 
87
104
  ### Currently Unsupported Features
88
105
 
89
106
  The SDK currently does not explicitly support
90
- + root level endpoints not listed above
91
- + nested endpoints - e.g. `/movie/{id}/quote`
107
+ + endpoints not listed above
92
108
  + Pagination, Sorting and Filtering as described [here](https://the-one-api.dev/documentation#5)
93
109
 
94
110
  However, you can supply custom query parameters as a hash to any of the named resource methods on `TheOneApi::Client`, for example:
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "the_one_api/resource_wrapper"
4
4
  require "the_one_api/resources/movie"
5
+ require "the_one_api/resources/quote"
5
6
 
6
7
  module TheOneApi
7
8
  # A client for The One Api
@@ -20,5 +21,9 @@ module TheOneApi
20
21
  def movie
21
22
  @movie ||= ResourceWrapper.new(Movie, @api_key)
22
23
  end
24
+
25
+ def quote
26
+ @quote ||= ResourceWrapper.new(Quote, @api_key)
27
+ end
23
28
  end
24
29
  end
@@ -6,21 +6,24 @@ module TheOneApi
6
6
  # Helper class to implement and wire in the response
7
7
  # transformations needed by BaseResource (see below)
8
8
  class BaseResourceProxy < Flexirest::ProxyBase
9
- # if this is a GET request to a single, non-nested resource by id
10
- get(+"\\/[^\\/]+\\/[^\\/]+\\z") do
11
- response = passthrough
12
- translate(response) do |body|
13
- # give back the entity instead of an array of one entity
14
- body["docs"] && body["docs"][0] ? body["docs"][0] : body
15
- end
16
- end
17
- # if this is a GET request to a root-level resource
18
- get(+"\\/[^\\/]+\\z") do
19
- response = passthrough
20
- translate(response) do |body|
21
- # give back the array of returned entities instead of the envelope
22
- # structure that surrounds it
23
- body["docs"] || body
9
+ get(+".+") do
10
+ if @request.method[:method] == :get
11
+ # if this is a GET request to list multiple items
12
+ if @request.method[:name].match? "list"
13
+ response = passthrough
14
+ translate(response) do |body|
15
+ # give back the array of returned entities instead of the envelope
16
+ # structure that surrounds it
17
+ body["docs"] || body
18
+ end
19
+ # if this is a GET request to a single resource by id
20
+ elsif @request.method[:name].match? "find"
21
+ response = passthrough
22
+ translate(response) do |body|
23
+ # give back the entity instead of an array of one entity
24
+ body["docs"] && body["docs"][0] ? body["docs"][0] : body
25
+ end
26
+ end
24
27
  end
25
28
  end
26
29
  end
@@ -28,7 +31,7 @@ module TheOneApi
28
31
  # Common functionality for all API resources, including:
29
32
  # + Adding authentication header
30
33
  # + Unwrapping the `docs` array
31
- # when listing all entities from a resource
34
+ # when listing multiple items from a resource
32
35
  # + Unwrapping the one item returned in the `docs` array
33
36
  # when requesting a single entity by id
34
37
  class BaseResource < Flexirest::Base
@@ -5,8 +5,6 @@ require "the_one_api/resources/base_resource"
5
5
  module TheOneApi
6
6
  # Resource definition for Movies
7
7
  class Movie < BaseResource
8
- before_request :add_authentication_header
9
-
10
8
  get :list, "/movie", rubify_names: true
11
9
  get :find, "/movie/:id", rubify_names: true
12
10
  end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "the_one_api/resources/base_resource"
4
+
5
+ module TheOneApi
6
+ # Resource definition for Quotes
7
+ class Quote < BaseResource
8
+ get :list, "/quote", rubify_names: true
9
+ get :find, "/quote/:id", rubify_names: true
10
+ get :list_for_movie, "/movie/:id/quote", rubify_names: true
11
+ end
12
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TheOneApi
4
- VERSION = "0.1.0"
4
+ VERSION = "0.3.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: the_one_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Samberg
@@ -114,6 +114,7 @@ files:
114
114
  - lib/the_one_api/resource_wrapper.rb
115
115
  - lib/the_one_api/resources/base_resource.rb
116
116
  - lib/the_one_api/resources/movie.rb
117
+ - lib/the_one_api/resources/quote.rb
117
118
  - lib/the_one_api/version.rb
118
119
  homepage: https://github.com/iceberg901/joshua-samberg-sdk
119
120
  licenses:
@@ -134,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
135
  - !ruby/object:Gem::Version
135
136
  version: '0'
136
137
  requirements: []
137
- rubygems_version: 3.4.10
138
+ rubygems_version: 3.4.14
138
139
  signing_key:
139
140
  specification_version: 4
140
141
  summary: An Ruby gem providing an SDK for interacting with The One API