activeresource 5.0.0 → 5.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: f09e2bfd3d8332924184d674556d18d2d0533dcf
4
- data.tar.gz: 5dbc9edf5003415fd3565692dffa8a6342d0a1b2
2
+ SHA256:
3
+ metadata.gz: 9e0cde8f42f06f37aa13a7098b9a1e828aac34c90971a62f4c9a1a7fcf529ce7
4
+ data.tar.gz: 11e7f85a7c565de83cb5248d8ee35783b343b8714e8ed9adcf08462f8aaceeda
5
5
  SHA512:
6
- metadata.gz: 27ba6aabd0eea02c3f2adb1d6d92311c94415d9ac32589f24abc517f1384a0ab6471717ab50e017a4993b069452f85e636053e3e49ffeb37c60873fcc4f9f671
7
- data.tar.gz: 3c8c8780b50ada3328e3df5b0d544e19cc3977dd4199c750991f403e00cfaa9c45213328cfdc717ebb0d86bbd931bc8b48724f17d7c56d7f996c6ace763e0ad6
6
+ metadata.gz: 133f4a82c31d9c925bc1c04a304c63e03982d45aa51b97d7e9ba580a433579802fb811a32009d40ebb7fc84e947fe65c60fd658b2cebb2f2f4c724efc536f528
7
+ data.tar.gz: 0f0042b3b644fe8584d34403913f2e11363a684fe438d536303871baaed2a98f26319b0e1dcd036364b42597b48e76c5713a627ea4431a2b2ec9263fce98b3a6
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2006-2016 David Heinemeier Hansson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc CHANGED
@@ -30,10 +30,6 @@ Or added to a Gemfile:
30
30
 
31
31
  gem 'activeresource'
32
32
 
33
- For compatibility with Rails 5, use:
34
-
35
- gem 'activeresource', github: 'rails/activeresource', branch: 'master'
36
-
37
33
  Source code can be downloaded on GitHub
38
34
 
39
35
  * https://github.com/rails/activeresource/tree/master/activeresource
@@ -57,6 +53,11 @@ life cycle methods that operate against a persistent store.
57
53
  As you can see, the methods are quite similar to Active Record's methods for dealing with database
58
54
  records. But rather than dealing directly with a database record, you're dealing with HTTP resources (which may or may not be database records).
59
55
 
56
+ Connection settings (`site`, `headers`, `user`, `password`, `proxy`) and the connections themselves are store in
57
+ thread-local variables to make them thread-safe, so you can also set these dynamically, even in a multi-threaded environment, for instance:
58
+
59
+ ActiveResource::Base.site = api_site_for(request)
60
+
60
61
  ==== Authentication
61
62
 
62
63
  Active Resource supports the token based authentication provided by Rails through the <tt>ActionController::HttpAuthentication::Token</tt> class using custom headers.
@@ -64,8 +65,32 @@ Active Resource supports the token based authentication provided by Rails throug
64
65
  class Person < ActiveResource::Base
65
66
  self.headers['Authorization'] = 'Token token="abcd"'
66
67
  end
67
-
68
- You can also set any specific HTTP header using the same way.
68
+
69
+ You can also set any specific HTTP header using the same way. As mentioned above, headers are thread-safe, so you can set headers dynamically, even in a multi-threaded environment:
70
+
71
+ ActiveResource::Base.headers['Authorization'] = current_session_api_token
72
+
73
+ Global Authentication to be used across all subclasses of ActiveResource::Base should be handled using the ActiveResource::Connection class.
74
+
75
+ ActiveResource::Base.connection.auth_type = :bearer
76
+ ActiveResource::Base.connection.bearer_token = @bearer_token
77
+
78
+ class Person < ActiveResource::Base
79
+ self.connection.auth_type = :bearer
80
+ self.connection.bearer_token = @bearer_token
81
+ end
82
+
83
+ ActiveResource supports 2 options for HTTP authentication today.
84
+
85
+ 1. Basic
86
+
87
+ ActiveResource::Connection.new("http://my%40email.com:%31%32%33@localhost")
88
+ # username: my@email.com password: 123
89
+
90
+ 2. Bearer Token
91
+
92
+ ActiveResource::Base.connection.auth_type = :bearer
93
+ ActiveResource::Base.connection.bearer_token = @bearer_token
69
94
 
70
95
  ==== Protocol
71
96
 
@@ -115,7 +140,7 @@ Collections can also be requested in a similar fashion
115
140
 
116
141
  # Expects a response of
117
142
  #
118
- # [
143
+ # [
119
144
  # {"id":1,"first":"Tyler","last":"Durden"},
120
145
  # {"id":2,"first":"Tony","last":"Stark",}
121
146
  # ]
@@ -205,7 +230,7 @@ class definition below:
205
230
  end
206
231
 
207
232
  post = Post.find(1) # issues GET http://blog.io/posts/1.json
208
- comments = post.comments # issues GET http://blog.io/posts/1/comments.json
233
+ comments = post.comments # issues GET http://blog.io/comments.json?post_id=1
209
234
 
210
235
 
211
236
  If you control the server, you may wish to include nested resources thus avoiding a
@@ -221,6 +246,19 @@ The server-side model can be adjusted as follows to include comments in the resp
221
246
  end
222
247
  end
223
248
 
249
+ ==== Logging
250
+
251
+ Active Resource instruments the event `request.active_resource` when doing a request
252
+ to the remote service. You can subscribe to it by doing:
253
+
254
+ ActiveSupport::Notifications.subscribe('request.active_resource') do |name, start, finish, id, payload|
255
+
256
+ The `payload` is a `Hash` with the following keys:
257
+
258
+ * `method` as a `Symbol`
259
+ * `request_uri` as a `String`
260
+ * `result` as an `Net::HTTPResponse`
261
+
224
262
  == License
225
263
 
226
264
  Active Resource is released under the MIT license:
@@ -236,9 +274,9 @@ See {CONTRIBUTING}[https://github.com/rails/activeresource/blob/master/CONTRIBUT
236
274
 
237
275
  == Support
238
276
 
239
- API documentation is at
277
+ Full API documentation is available at
240
278
 
241
- * http://rubydoc.info/gems/activeresource/4.0.0/frames
279
+ * http://rubydoc.info/gems/activeresource
242
280
 
243
281
  Bug reports and feature requests can be filed with the rest for the Ruby on Rails project here:
244
282
 
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveResource
4
+ class ActiveJobSerializer < ActiveJob::Serializers::ObjectSerializer
5
+ def serialize(resource)
6
+ super(
7
+ "class" => resource.class.name,
8
+ "persisted" => resource.persisted?,
9
+ "prefix_options" => resource.prefix_options.as_json,
10
+ "attributes" => resource.attributes.as_json
11
+ )
12
+ end
13
+
14
+ def deserialize(hash)
15
+ hash["class"].constantize.new(hash["attributes"]).tap do |resource|
16
+ resource.persisted = hash["persisted"]
17
+ resource.prefix_options = hash["prefix_options"]
18
+ end
19
+ end
20
+
21
+ private
22
+ def klass
23
+ ActiveResource::Base
24
+ end
25
+ end
26
+ end
@@ -1,6 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveResource::Associations::Builder
2
4
  class Association #:nodoc:
3
-
4
5
  # providing a Class-Variable, which will have a different store of subclasses
5
6
  class_attribute :valid_options
6
7
  self.valid_options = [:class_name]
@@ -25,8 +26,8 @@ module ActiveResource::Associations::Builder
25
26
 
26
27
  private
27
28
 
28
- def validate_options
29
- options.assert_valid_keys(self.class.valid_options)
30
- end
29
+ def validate_options
30
+ options.assert_valid_keys(self.class.valid_options)
31
+ end
31
32
  end
32
33
  end
@@ -1,4 +1,6 @@
1
- module ActiveResource::Associations::Builder
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveResource::Associations::Builder
2
4
  class BelongsTo < Association
3
5
  self.valid_options += [:foreign_key]
4
6
 
@@ -8,7 +10,7 @@ module ActiveResource::Associations::Builder
8
10
  validate_options
9
11
  reflection = model.create_reflection(self.class.macro, name, options)
10
12
  model.defines_belongs_to_finder_method(reflection)
11
- return reflection
13
+ reflection
12
14
  end
13
15
  end
14
16
  end
@@ -1,4 +1,6 @@
1
- module ActiveResource::Associations::Builder
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveResource::Associations::Builder
2
4
  class HasMany < Association
3
5
  self.macro = :has_many
4
6
 
@@ -1,7 +1,9 @@
1
- module ActiveResource::Associations::Builder
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveResource::Associations::Builder
2
4
  class HasOne < Association
3
5
  self.macro = :has_one
4
-
6
+
5
7
  def build
6
8
  validate_options
7
9
  model.create_reflection(self.class.macro, name, options).tap do |reflection|
@@ -1,10 +1,11 @@
1
- module ActiveResource::Associations
1
+ # frozen_string_literal: true
2
2
 
3
+ module ActiveResource::Associations
3
4
  module Builder
4
- autoload :Association, 'active_resource/associations/builder/association'
5
- autoload :HasMany, 'active_resource/associations/builder/has_many'
6
- autoload :HasOne, 'active_resource/associations/builder/has_one'
7
- autoload :BelongsTo, 'active_resource/associations/builder/belongs_to'
5
+ autoload :Association, "active_resource/associations/builder/association"
6
+ autoload :HasMany, "active_resource/associations/builder/has_many"
7
+ autoload :HasOne, "active_resource/associations/builder/has_one"
8
+ autoload :BelongsTo, "active_resource/associations/builder/belongs_to"
8
9
  end
9
10
 
10
11
 
@@ -112,7 +113,7 @@ module ActiveResource::Associations
112
113
  # <tt>belongs_to :customer, :foreign_key => 'user_id'</tt>
113
114
  # Creates a belongs_to association called customer which would be resolved by the foreign_key <tt>user_id</tt> instead of <tt>customer_id</tt>
114
115
  #
115
- def belongs_to(name, options={})
116
+ def belongs_to(name, options = {})
116
117
  Builder::BelongsTo.build(self, name, options)
117
118
  end
118
119
 
@@ -147,7 +148,7 @@ module ActiveResource::Associations
147
148
  elsif attributes.include?(method_name)
148
149
  attributes[method_name]
149
150
  elsif !new_record?
150
- instance_variable_set(ivar_name, reflection.klass.find(:all, :params => {:"#{self.class.element_name}_id" => self.id}))
151
+ instance_variable_set(ivar_name, reflection.klass.find(:all, params: { :"#{self.class.element_name}_id" => self.id }))
151
152
  else
152
153
  instance_variable_set(ivar_name, self.class.collection_parser.new)
153
154
  end
@@ -165,11 +166,10 @@ module ActiveResource::Associations
165
166
  elsif attributes.include?(method_name)
166
167
  attributes[method_name]
167
168
  elsif reflection.klass.respond_to?(:singleton_name)
168
- instance_variable_set(ivar_name, reflection.klass.find(:params => {:"#{self.class.element_name}_id" => self.id}))
169
+ instance_variable_set(ivar_name, reflection.klass.find(params: { :"#{self.class.element_name}_id" => self.id }))
169
170
  else
170
- instance_variable_set(ivar_name, reflection.klass.find(:one, :from => "/#{self.class.collection_name}/#{self.id}/#{method_name}#{self.class.format_extension}"))
171
+ instance_variable_set(ivar_name, reflection.klass.find(:one, from: "/#{self.class.collection_name}/#{self.id}/#{method_name}#{self.class.format_extension}"))
171
172
  end
172
173
  end
173
174
  end
174
-
175
175
  end