rest-core 2.1.1 → 2.1.2

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
  SHA1:
3
- metadata.gz: 5cc0c6118d2d5169988871b31d9b5544e2f28f60
4
- data.tar.gz: c73e366ba7c4cdbdec4a5a76528ed5d8df21aed4
3
+ metadata.gz: 71b8ab944328b862d8a3524a01da91432fe7fcb4
4
+ data.tar.gz: 204f46ff9a25281ffdbbe814df50831519a98c88
5
5
  SHA512:
6
- metadata.gz: c175b2f84c14257fe189ae82bee8f1d3a2bd205ac4da36ab8b0b596ccfdf47253d05b8cb4940c4ebe47e770385ed282b6dfadf53db04a1fba67adc4975ae177e
7
- data.tar.gz: 53cd1bed753213a3a27637ceb85acf9577504aaa48cf0b760c48c20a6cd35c87f96f8b8c2dc438b568adc8404d1b4c19066dbb5efc6c40871d5ea91e78cd43e5
6
+ metadata.gz: 67d6c4ee4116a562fa5a16a41b6c94b5b4f0c768abc077e78d1b0a416d28146784a9a358208175de212c9ccac3fe3956a00bda5eabfa81ba714beec2aeeaec7e
7
+ data.tar.gz: 7f723ab6d7e7b295d24b664aa9ef1ce38d56c39e2c2ef75d34aaded046a8aa97d9fb1b16ecf5a3d1867fba596afb46f4203f250b9f729ccad998dfbf887cb72f
data/CHANGES.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # CHANGES
2
2
 
3
+ ## rest-core 2.1.2 -- 2013-05-31
4
+
5
+ ### Incompatible changes
6
+
7
+ * Remove support for Ruby < 1.9.2
8
+
9
+ ### Bugs fixes
10
+
11
+ * [`Client`] Fixed a bug where if we're using duplicated attributes.
12
+
3
13
  ## rest-core 2.1.1 -- 2013-05-21
4
14
 
5
15
  ### Bugs fixes
data/README.md CHANGED
@@ -295,7 +295,7 @@ installed before trying this.
295
295
  [rib]: https://github.com/godfat/rib
296
296
  [rest-more]: https://github.com/cardinalblue/rest-more
297
297
 
298
- ## List of built-in Middlewares:
298
+ ## List of built-in Middleware:
299
299
 
300
300
  * `RC::AuthBasic`
301
301
  * `RC::Bypass`
@@ -317,9 +317,87 @@ installed before trying this.
317
317
  * `RC::Oauth2Query`
318
318
  * `RC::Timeout`
319
319
 
320
- ## Build Your Own Middlewares:
320
+ ## Build Your Own Middleware:
321
321
 
322
- To be added.
322
+ ### How We Pick the Default Value:
323
+
324
+ There are a number of ways to specify a default value, each with different
325
+ priorities. Suppose we have a middleware which remembers an integer:
326
+
327
+ ``` ruby
328
+ class HP
329
+ def self.members; [:hp]; end
330
+ include RC::Middleware
331
+ def call env, &k
332
+ puts "HP: #{hp(env)}"
333
+ app.call(env, &k)
334
+ end
335
+ end
336
+ Mage = RC::Builder.client do
337
+ use HP, 5 # the very last default
338
+ end
339
+ mage = Mage.new
340
+ ```
341
+
342
+ 1. The one passed to the request directly gets the first priority, e.g.
343
+
344
+ ``` ruby
345
+ mage.get('http://example.com/', {}, :hp => 1) # prints HP: 1
346
+ ```
347
+
348
+ 2. The one saved as an instance variable in the client gets the 2nd place.
349
+
350
+ ``` ruby
351
+ mage.hp = 2
352
+ mage.get('http://example.com/') # prints HP: 2
353
+ mage.get('http://example.com/', {}, :hp => 1) # prints HP: 1
354
+ mage.hp # still 2
355
+ mage.hp = false # disable hp
356
+ mage.hp = nil # reset to default
357
+ ```
358
+
359
+ 3. The method defined in the client instance named `default_hp` gets the 3rd.
360
+
361
+ ``` ruby
362
+ class Mage
363
+ def default_hp
364
+ 3
365
+ end
366
+ end
367
+ mage.get('http://example.com/') # prints HP: 3
368
+ mage.hp # 3
369
+ mage.hp = nil # reset default
370
+ Mage.send(:remove_method, :default_hp)
371
+ ```
372
+
373
+ 4. The method defined in the client class named `default_hp` gets the 4rd.
374
+ P.S. In [rest-more][], with `RestCore::Config` it would generate a
375
+ `DefaultAttributes` module which defines this kind of default method and
376
+ then is extended into the client class. You could still define this method
377
+ to override the default though.
378
+
379
+ ``` ruby
380
+ class Mage
381
+ def self.default_hp
382
+ 4
383
+ end
384
+ end
385
+ mage.get('http://example.com/') # prints HP: 4
386
+ mage.hp # 4
387
+ mage.hp = nil # reset to default
388
+ Mage.singleton_class.send(:remove_method, :default_hp)
389
+ ```
390
+
391
+ 5. The one defined in the middleware gets the last place.
392
+
393
+ ``` ruby
394
+ mage.get('http://example.com/') # prints HP: 5
395
+ mage.hp # 5
396
+ mage.hp = nil # reset to default
397
+ ```
398
+
399
+ You can find all the details in client.rb and middleware.rb. See the
400
+ included method hooks.
323
401
 
324
402
  ## Advanced Concurrent HTTP Requests -- Embrace the Future
325
403
 
@@ -19,7 +19,7 @@ class RestCore::Builder
19
19
  struct = if fields.empty?
20
20
  Struct.new(nil)
21
21
  else
22
- Struct.new(*fields)
22
+ Struct.new(*fields.uniq)
23
23
  end
24
24
  client = Class.new(struct)
25
25
  client.const_set('Struct', struct)
@@ -37,13 +37,6 @@ module RestCore::Client
37
37
  private :default_#{name}
38
38
  RUBY
39
39
  }
40
- # if RUBY_VERSION < '1.9.2'
41
- src << <<-RUBY if mod.members.first.kind_of?(String)
42
- def members
43
- super.map(&:to_sym)
44
- end
45
- RUBY
46
- # end
47
40
  accessor = Module.new
48
41
  accessor.module_eval(src.join("\n"), __FILE__, __LINE__)
49
42
  mod.const_set('Accessor', accessor)
@@ -1,4 +1,4 @@
1
1
 
2
2
  module RestCore
3
- VERSION = '2.1.1'
3
+ VERSION = '2.1.2'
4
4
  end
@@ -2,13 +2,13 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "rest-core"
5
- s.version = "2.1.1"
5
+ s.version = "2.1.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = [
9
9
  "Cardinal Blue",
10
10
  "Lin Jen-Shin (godfat)"]
11
- s.date = "2013-05-21"
11
+ s.date = "2013-05-31"
12
12
  s.description = "Modular Ruby clients interface for REST APIs.\n\nThere has been an explosion in the number of REST APIs available today.\nTo address the need for a way to access these APIs easily and elegantly,\nwe have developed rest-core, which consists of composable middleware\nthat allows you to build a REST client for any REST API. Or in the case of\ncommon APIs such as Facebook, Github, and Twitter, you can simply use the\ndedicated clients provided by [rest-more][].\n\n[rest-more]: https://github.com/cardinalblue/rest-more"
13
13
  s.email = ["dev (XD) cardinalblue.com"]
14
14
  s.files = [
@@ -11,4 +11,14 @@ describe RC::Builder do
11
11
  builder.default_engine = RC::Dry
12
12
  builder.client.new.app.class.should.eq RC::Dry
13
13
  end
14
+
15
+ should 'not have duplicated fields' do
16
+ middleware = Class.new do
17
+ def self.members; [:value]; end
18
+ include RC::Middleware
19
+ end
20
+ client = RC::Builder.client(:value){ use middleware }.new
21
+ client.value = 10
22
+ client.value.should.eq 10
23
+ end
14
24
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cardinal Blue
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-21 00:00:00.000000000 Z
12
+ date: 2013-05-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client