You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*[#63](https://github.com/codegram/hyperclient/pull/63): You can omit the navigational elements, `api.links.products` is now equivalent to `api.products` (by @dblock).
Accessing embedded resources is similar to accessing links:
64
70
65
71
```ruby
66
-
api.embedded.posts
72
+
api._embedded.posts
73
+
```
74
+
75
+
Or omit the `_embedded` keyword. By default Hyperclient will look for a "posts" link, then for an embedded "posts" collection:
76
+
77
+
```ruby
78
+
api.posts
67
79
```
68
80
69
81
And you can also iterate between them:
@@ -80,10 +92,25 @@ You can even chain different calls (this also applies for links):
80
92
api.embedded.posts.first.links.author
81
93
```
82
94
95
+
Or omit the navigational structures:
96
+
97
+
```ruby
98
+
api.posts.first.author
99
+
```
100
+
101
+
If you have a named link that retrieves an embedded collection of the same name, you can collapse the nested reference. The following statements produce identical results:
102
+
103
+
```ruby
104
+
api.links.posts.embedded.posts.first
105
+
```
106
+
107
+
```ruby
108
+
api.posts.first
109
+
```
110
+
83
111
### Attributes
84
112
85
-
Not only you might have links and embedded resources in a Resource, but also
86
-
its attributes:
113
+
Not only you might have links and embedded resources in a Resource, but also its attributes:
OK, navigating an API is really cool, but you may want to actually do something
111
-
with it, right?
140
+
OK, navigating an API is really cool, but you may want to actually do something with it, right?
112
141
113
-
Hyperclient uses [Faraday][faraday] under the hood to perform HTTP calls. You can
114
-
call any valid HTTP method on any Resource:
142
+
Hyperclient uses [Faraday][faraday] under the hood to perform HTTP calls. You can call any valid HTTP method on any Resource:
115
143
116
144
```ruby
117
-
post = api.embedded.posts.first
118
-
post.get
119
-
post.head
120
-
post.put({title:'New title'})
121
-
post.patch({title:'New title'})
122
-
post.delete
123
-
post.options
124
-
125
-
posts = api.links.posts
126
-
posts.post({title:"I'm a blogger!", body:'Wohoo!!'})
145
+
post = api._embedded.posts.first
146
+
post._get
147
+
post._head
148
+
post._put(title:'New title')
149
+
post._patch(title:'New title')
150
+
post._delete
151
+
post._options
152
+
153
+
posts = api._links.posts
154
+
posts._post(title:"I'm a blogger!", body:'Wohoo!!')
127
155
```
128
156
129
157
If you have a templated link you can expand it like so:
130
158
131
159
```ruby
132
-
api.links.post.expand(:id => 3).first
160
+
api._links.post._expand(id:3).first
161
+
# => #<Resource ...>
162
+
```
163
+
164
+
You can omit the "_expand" keyword.
165
+
166
+
```ruby
167
+
api.post(id:3).first
133
168
# => #<Resource ...>
134
169
```
135
170
136
-
You can access the Faraday connection (to add middlewares or do whatever
137
-
you want) by calling `connection` on the entry point. As an example, you could use the [faraday-http-cache-middleware](https://github.com/plataformatec/faraday-http-cache)
138
-
:
171
+
You can access the Faraday connection (to add middlewares or do whatever you want) by calling `connection` on the entry point. As an example, you could use the [faraday-http-cache-middleware](https://github.com/plataformatec/faraday-http-cache):
139
172
140
173
```ruby
141
174
api.connection.use :http_cache
@@ -168,7 +201,7 @@ There's also a PHP library named [HyperClient](https://github.com/FoxyCart/Hyper
168
201
169
202
## License
170
203
171
-
MIT License. Copyright 2012 [Codegram Technologies][codegram]
204
+
MIT License. Copyright 2012-2014[Codegram Technologies][codegram]
0 commit comments