api-extensions 0.0.2 → 0.0.3
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 +8 -8
- data/README.md +38 -2
- data/features/step_definitions/expand_steps.rb +5 -3
- data/lib/api/extensions.rb +10 -1
- data/lib/api/extensions/expand.rb +10 -3
- data/lib/api/extensions/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
Zjc1Mzk1NDQ4OGIyMDU2OWMzZmIxZDJhMjgyYzdlYmRmYmRiMTM0NA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NzJjM2I5YjU5YWJmMWEwZDMyNmFiZTkxZjc1MWIwNjYwZjY5ZmQ4NA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YTU5NDIyOTcxZDZiZTQ3MjY4ODUzNmNkNGJmN2ZmMzYzYWE3NzIzZWUyZWNm
|
10
|
+
MGE0MmQ4YjMwNmFhZjljZTRlZTBkYTdlOTUxZTM3ZjhmZDJhNzg4OWI4ZDZj
|
11
|
+
MjQwYTdlYWQxYTg2NWRkZWNjNDNkYzExMmUzMTBiNmU1MWM0Y2E=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NGUyNmYwMWRlNmJmNTYxYmRjZGE3MmUyOGRlZDJlNTFmMzk0ODhmYzljMjZh
|
14
|
+
ZjM5MTUxMTk0MGY2ZGJhZWIxYTE3NzM1NGE3ZmQ1YjZjZGQ4ZmI5NjE1MjY2
|
15
|
+
ZTkzMzhhMmQxYmM4MjI0YjdiMTAwM2QyYjk5ZTc0MmFhNzcyZWI=
|
data/README.md
CHANGED
@@ -6,6 +6,7 @@ at [the api-doc repo](https://github.com/ncuesta/api-doc).
|
|
6
6
|
Included extensions:
|
7
7
|
|
8
8
|
- `fields`
|
9
|
+
- `expand`
|
9
10
|
|
10
11
|
## Installation
|
11
12
|
|
@@ -23,6 +24,22 @@ Or install it yourself as:
|
|
23
24
|
|
24
25
|
## Usage
|
25
26
|
|
27
|
+
### Including all extensions
|
28
|
+
|
29
|
+
As a more convenient way of including **all** the extensions, you may just include the module
|
30
|
+
`Api::Extensions::All` in your class and you will automatically have included all of the extensions
|
31
|
+
listed below.
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
require 'api/extensions/expand'
|
35
|
+
|
36
|
+
class MyApiHandler
|
37
|
+
include Api::Extensions::All
|
38
|
+
|
39
|
+
expand_with :my_resource_fetching_method
|
40
|
+
end
|
41
|
+
```
|
42
|
+
|
26
43
|
### `expand` extension
|
27
44
|
|
28
45
|
The behavior of this extension is best described at
|
@@ -37,9 +54,12 @@ Please note that this extension **requires that the including class responds to
|
|
37
54
|
require 'api/extensions/expand'
|
38
55
|
|
39
56
|
class MyApiHandler
|
57
|
+
include Api::Extensions::Expand
|
58
|
+
|
59
|
+
expand_with :go_fetch
|
40
60
|
|
41
|
-
def
|
42
|
-
|
61
|
+
def go_fetch(url)
|
62
|
+
# Go fetch the resource at the given URL and return it
|
43
63
|
end
|
44
64
|
|
45
65
|
def handle(request)
|
@@ -85,3 +105,19 @@ $ rake features
|
|
85
105
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
86
106
|
4. Push to the branch (`git push origin my-new-feature`)
|
87
107
|
5. Create new Pull Request
|
108
|
+
|
109
|
+
## Changelog
|
110
|
+
|
111
|
+
### v0.0.3
|
112
|
+
|
113
|
+
* Switched `expand` to some metaprogramming: made the fetch method configurable (was hardcoded to `get`)
|
114
|
+
* Added a *meta module* `All` for including all API extensions in a single sentence
|
115
|
+
|
116
|
+
### v0.0.2
|
117
|
+
|
118
|
+
* Added `expand` extension
|
119
|
+
|
120
|
+
### v0.0.1
|
121
|
+
|
122
|
+
* Initial version
|
123
|
+
* Included `fields` extension
|
@@ -3,10 +3,12 @@ require 'api/extensions/expand'
|
|
3
3
|
Before do
|
4
4
|
@expand_processor = Object.new
|
5
5
|
class << @expand_processor
|
6
|
-
|
7
|
-
|
6
|
+
include Api::Extensions::Expand
|
7
|
+
|
8
|
+
expand_with :go_fetch
|
8
9
|
|
9
|
-
|
10
|
+
def go_fetch url
|
11
|
+
end
|
10
12
|
end
|
11
13
|
end
|
12
14
|
|
data/lib/api/extensions.rb
CHANGED
@@ -4,5 +4,14 @@ require 'api/extensions/version'
|
|
4
4
|
|
5
5
|
module Api
|
6
6
|
module Extensions
|
7
|
+
module All
|
8
|
+
# Convenience module for including all extensions at once
|
9
|
+
def self.included(base)
|
10
|
+
base.class_eval %Q{
|
11
|
+
include Api::Extensions::Expand
|
12
|
+
include Api::Extensions::Fields
|
13
|
+
}
|
14
|
+
end
|
15
|
+
end
|
7
16
|
end
|
8
|
-
end
|
17
|
+
end
|
@@ -6,9 +6,11 @@
|
|
6
6
|
module Api
|
7
7
|
module Extensions
|
8
8
|
module Expand
|
9
|
-
#
|
9
|
+
# Add expand_with class method on inclusion
|
10
10
|
def self.included(base)
|
11
|
-
|
11
|
+
@@fetch_method_for_expand = :get
|
12
|
+
|
13
|
+
base.class_eval 'def self.expand_with(symbol); @@fetch_method_for_expand = symbol; end'
|
12
14
|
end
|
13
15
|
|
14
16
|
# Process the expand functional extension
|
@@ -44,7 +46,7 @@ module Api
|
|
44
46
|
def expand(resource, link)
|
45
47
|
if resource['links'].include?(link)
|
46
48
|
sub_resource_uri = resource['links'][link]['href']
|
47
|
-
sub_resource =
|
49
|
+
sub_resource = send(fetch_method_for_expand, sub_resource_uri)
|
48
50
|
|
49
51
|
# 'self' links replace the original resource
|
50
52
|
if link == 'self'
|
@@ -56,6 +58,11 @@ module Api
|
|
56
58
|
|
57
59
|
resource
|
58
60
|
end
|
61
|
+
|
62
|
+
private
|
63
|
+
def fetch_method_for_expand
|
64
|
+
@@fetch_method_for_expand
|
65
|
+
end
|
59
66
|
end
|
60
67
|
end
|
61
68
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api-extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nahuel Cuesta Luengo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-05-
|
11
|
+
date: 2013-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|