smooth_operator 1.22.5 → 1.22.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OGVhYzllZjkzYTdhMzkxMzJkMmYwZWUwMGRkNDIxNDU3ZWY2ZmYxMw==
4
+ NzdmNTA5NmYzMTU2YzczNzYyYjRlOTdlMDkwMDRkOTlmNTI3YjBiYQ==
5
5
  data.tar.gz: !binary |-
6
- NDdkOWFhMGI2NDQ0ZWYwOTQzOWFjOTc0NjExNGZmMzRjYjI1OWI0MQ==
6
+ MmI2Mjc0YWUyYTA0MWIyZjYxNDc0N2EzZDA5Zjg1ZjIzNTk0MDBlNQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NGFkNWJhZGY3NzgxMjViNzA0NzFkY2U0MmMyOTgwN2UwOTNhMjcxNmQ2NThm
10
- MGZmMGQ1MmRhZTgyOWRmYWNiNWYzZDZjZmI4MWE2NThjYjczZTc0NzcyYzg3
11
- YTE0ZmFkZWRmMTQyNTM2NjUzMjcwZWIxOThhZWFkMDMyZWM0MjY=
9
+ N2QyOTcwYzdhMWM1YzkzYTZhMDBjMjA4NjI1NWUwZWM4NWRkZmJjMWQ2N2Vi
10
+ MDZhMjQxYTA0OGFiNDYyZjUyODc0YzBkNThjNGJmOWEzMjJkNDE5OGNlZTUx
11
+ ZDIwOTI2YmY0NGZhNDNiYjQyYWVhZWRjYmU4NjMxZmEwMDBhNGQ=
12
12
  data.tar.gz: !binary |-
13
- NTIyYjUwOWY5M2VlMGFkOWQ1ZjIxMWIyMzdiYmFjY2M4ODAwYmVhNTNkNzRl
14
- ODNmYjcxNzg2MGNmM2MyZGZkZDFhYjliNjVhYTRkNDAxZmJhOWE2NGY5YmVj
15
- YzNjMjc5OTM2OTU0ZmJkMDQyMDMxYmMyZjhkNjg0MjRjZTU0NDM=
13
+ YmE4NTgxNWQwMGM1NDJjMTk5ODU2ZTVmOGYzYzA1MjFlZWM5MzFhZWFkNzdl
14
+ OTNlMDA1N2VkMDlkMmYzMjhiNmE1Y2EyZjJjOWVlOTk2NzY3MjJlNDcwNDI2
15
+ NmM0MzQ3N2M0YmViYjZkMzc0ODZjNDk3OTdiYzU3NTQ5ZDZkNTk=
data/README.md CHANGED
@@ -117,10 +117,16 @@ post = Post.new(id: 2, body: 'editing my second page')
117
117
  post.new_record? # false
118
118
  post.persisted? # true
119
119
 
120
- post.save("#{post.id}/save_and_add_to_list", { admin: true, post: { author: 'Agent Smith', list_id: 1 } }, { timeout: 1 })
120
+ post.save("save_and_add_to_list", { admin: true, post: { author: 'Agent Smith', list_id: 1 } }, { timeout: 1 })
121
121
  # Will make a PUT to 'http://myblog.com/api/v0/posts/2/save_and_add_to_list'
122
122
  # with { admin: true, post: { body: 'editing my second page', list_id: 1 } }
123
123
  # and will only wait 1sec for the server to respond.
124
+
125
+ post.save('/#{post.id}/save_and_add_to_list')
126
+ # Will make a PUT to 'http://myblog.com/api/v0/posts/2/save_and_add_to_list'
127
+
128
+ post.save('/save_and_add_to_list')
129
+ # Will make a PUT to 'http://myblog.com/api/v0/posts/save_and_add_to_list'
124
130
  ```
125
131
 
126
132
  ---
@@ -149,7 +155,7 @@ remote_call = Page.find(:all) # Will make a GET call to 'http://myblog.com/api/v
149
155
 
150
156
  pages = remote_call.data
151
157
 
152
- # If the server response is positive (http code between 200 and 299):
158
+ # If the server response is positive (http code between 200 and 299, or 304):
153
159
  remote_call.ok? # true
154
160
  remote_call.not_processed? # false
155
161
  remote_call.error? # false
@@ -187,6 +193,8 @@ pages = remote_call.data
187
193
  remote_call = Page.find(2) # Will make a GET call to 'http://myblog.com/api/v0/pages/2'
188
194
  # and will return a SmoothOperator::RemoteCall instance
189
195
 
196
+ service_down = remote_call.error?
197
+
190
198
  page = remote_call.data
191
199
  ```
192
200
 
@@ -198,24 +206,59 @@ remote_call = Page.find('my_pages', { q: body_contains: 'link' }, { endpoint_use
198
206
  # will make a GET call to 'http://myblog.com/api/v0/pages/my_pages?q={body_contains="link"}'
199
207
  # and will change the HTTP BASIC AUTH credentials to user: 'admin' and pass: 'new_password' for this connection only.
200
208
 
209
+ @service_down = remote_call.error?
210
+
201
211
  # If the server json response is an Array [{ id: 1 }, { id: 2 }]
202
- pages = remote.data # will return an array with 2 Page's instances
203
- pages[0].id # 1
204
- pages[1].id # 2
212
+ @pages = remote.data # will return an array with 2 Page's instances
213
+ @pages[0].id # 1
214
+ @pages[1].id # 2
205
215
 
206
216
  # If the server json response is a Hash { id: 3 }
207
- page = remote.data # will return a single Page instance
208
- page.id # 3
217
+ @page = remote.data # will return a single Page instance
218
+ @page.id # 3
209
219
 
210
- # If the server json response is Hash with a key called 'pages' { page: 1, total: 3, pages: [{ id: 4 }, { id: 5 }] }
211
- pages = remote.data # will return a single ArrayWithMetaData instance, that will allow you to access to both the Page's instances array and the metadata.
212
- pages.page # 1
213
- pages.total # 3
220
+ # If the server json response is Hash with a key called 'pages' { current_page: 1, total_pages: 3, limit_value: 10, pages: [{ id: 4 }, { id: 5 }] }
221
+ @pages = remote.data # will return a single ArrayWithMetaData instance, that will allow you to access to both the Page's instances array and the metadata.
214
222
 
215
- pages[0].id # 4
216
- pages[1].id # 5
223
+ # @pages is now a valid object to work with kaminari
224
+ @pages.total_pages # 3
225
+ @pages.current_page # 1
226
+ @pages.limit_value # 10
227
+
228
+ @pages[0].id # 4
229
+ @pages[1].id # 5
217
230
  ```
218
231
 
232
+ ### 2.8) Keeping your session alive - custom HTTP Headers
233
+
234
+ Controllers
235
+ ApplicationController
236
+ ```ruby
237
+ ```
238
+
239
+ Models
240
+ SmoothResource
241
+ ```ruby
242
+ class SmoothResource < SmoothOperator::Rails
243
+
244
+ def self.headers
245
+ headers = super
246
+
247
+ headers.merge({
248
+ cookie: current_user.blog_cookie,
249
+ "X_CSRF_TOKEN" => current_user.blog_auth_token
250
+ })
251
+ end
252
+
253
+ protected ############## PROTECTED #################
254
+
255
+ def self.current_user
256
+ User.current_user
257
+ end
258
+
259
+ end
260
+ ```
261
+
219
262
  ---
220
263
 
221
264
  ## 3) Methods
@@ -32,7 +32,7 @@ module SmoothOperator
32
32
  end
33
33
 
34
34
  method_names.each do |method_name|
35
- hash[method_name.to_s] = send(method_name)
35
+ hash[method_name.to_s] = HelperMethods.serialize_normal_attribute(send(method_name), method_name, options[method_name])
36
36
  end
37
37
 
38
38
  hash
@@ -96,7 +96,11 @@ module SmoothOperator
96
96
  end
97
97
 
98
98
  def serialize_normal_attribute(parent_object, attribute_name, options)
99
- object = parent_object.read_attribute_for_serialization(attribute_name)
99
+ if parent_object.respond_to?(:read_attribute_for_serialization)
100
+ object = parent_object.read_attribute_for_serialization(attribute_name)
101
+ else
102
+ object = parent_object
103
+ end
100
104
 
101
105
  if object.is_a?(Array)
102
106
  object.map { |array_entry| attribute_to_hash(array_entry, options) }
@@ -1,3 +1,3 @@
1
1
  module SmoothOperator
2
- VERSION = "1.22.5"
2
+ VERSION = "1.22.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smooth_operator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.22.5
4
+ version: 1.22.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - João Gonçalves
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-06 00:00:00.000000000 Z
11
+ date: 2014-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler