the_one_api 0.2.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: 4058d4a0d63b4cf9c206a66c611e5e7c1d40f463d310f0505ccd7f71ad5d3cc9
4
- data.tar.gz: 134fa624639539667cd135c2ab6740d1ad3c70441b013378d350a50ee3c3fe08
3
+ metadata.gz: a1f9c32daa2104160e59593e3854d4e33cb0b6401f0e1600c97625a4166fcabe
4
+ data.tar.gz: 105c1e4ea840549ea4434e479d9d740331a845668a707e459e3936d749d6d5fa
5
5
  SHA512:
6
- metadata.gz: 9b6d34d34ea60827e137ebd71c172e296447f07cbf9e871f00df56528c466014f9f74a3e580e9f15055a6a3722c860865c40da52d94fc51fc1dc6aff75e5f0cd
7
- data.tar.gz: ed19bcc8fc35f82abe45fa81d3bca424969f1a44cb9a9a5a11a1764a1803b4ab3609642ce82c3e6700560bc83a3a9d6f63dc1ecfee35ccea2c87c61c61ce8e3c
6
+ metadata.gz: 54d754600927c9a5b3a470c0f7b09f22d0e9df490317a20c9fa4bd35cc15387146e776b3f91e54d826a28ce7566de8584fcd09545eba110551373f9ef0eb11c1
7
+ data.tar.gz: f981d550128609b811e385ead09d58f2820369bb680d19cdaf82f42612d9cb9f7165b57f024f7ee2dece0cf76b9ddc206a72f6d70450c7a6bc97554ace02cd9f
data/README.md CHANGED
@@ -58,6 +58,19 @@ movie.runtime_in_minutes
58
58
 
59
59
  ```
60
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
+
61
74
  ### Errors
62
75
 
63
76
  The client will raise `TheOneApi::HttpResponseError` when a request returns a bad status code:
@@ -78,18 +91,20 @@ end
78
91
 
79
92
  ## Supported API Features
80
93
 
81
- ### Currently Supported Root Level Endpoints/Operations
94
+ ### Currently Supported Endpoints/Operations
82
95
 
83
- | Endpoint | SDK Entry Point | Operations |
84
- | --------- | ------------------------ | ----------------------------------- |
85
- | `/movie` | `TheOneApi::Client.movie` | list all movies, find a movie by id |
86
- | `/quote` | `TheOneApi::Client.quote` | list all quotes, find a quote 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 |
87
103
 
88
104
  ### Currently Unsupported Features
89
105
 
90
106
  The SDK currently does not explicitly support
91
- + root level endpoints not listed above
92
- + nested endpoints - e.g. `/movie/{id}/quote`
107
+ + endpoints not listed above
93
108
  + Pagination, Sorting and Filtering as described [here](https://the-one-api.dev/documentation#5)
94
109
 
95
110
  However, you can supply custom query parameters as a hash to any of the named resource methods on `TheOneApi::Client`, for example:
@@ -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
@@ -7,5 +7,6 @@ module TheOneApi
7
7
  class Quote < BaseResource
8
8
  get :list, "/quote", rubify_names: true
9
9
  get :find, "/quote/:id", rubify_names: true
10
+ get :list_for_movie, "/movie/:id/quote", rubify_names: true
10
11
  end
11
12
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TheOneApi
4
- VERSION = "0.2.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.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Samberg