api_recipes 0.3.1 → 0.4.0

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
  SHA256:
3
- metadata.gz: 2401e3857b09294af0358e43df2649226bebe025222e264ca72926e7b9669e43
4
- data.tar.gz: c20c10cf84c45ad5e2648066ca3ac92b014c6af00205f21dcaae3d47163d9263
3
+ metadata.gz: 132f12d395ff75b6170f1bc66a9119a696f24b034f23e2d033490bdb2311ef2e
4
+ data.tar.gz: cb607d01e3a1c4c580efdec24f1c35310f36b9da9cb0a83fdb08578b2cb6ab7f
5
5
  SHA512:
6
- metadata.gz: 98587e7fb992ab525e0c293c3581289ba389d293411905f796e727fe5a0994181f9c759a58654c7988c78fb918209d16cd73f034c9dd770c0a9f376ca31c00c5
7
- data.tar.gz: 8ea37f55f698c033453c60843f7cb88cdb14aa28370dbfd3a7938e8356e1433b2ce630cb68d2acf357620e48d84246c5b194f7a55db65004feb4f7b1d104c4fb
6
+ metadata.gz: d88a0be72247c33b132f5b8eac1a6f08d7d13595df16f5716b7accd32dce8b54975ea10924c710a9a201dcefa0b927e639d237f0aca07f259a8d006258cff65f
7
+ data.tar.gz: 834a3f2f58a6d2ee043db4b9a2e4572b8bd140e09ecf19f32c7eeb00b06fb801b13ff279696a763cdc9dcf7fb8fd920089e3ab3bcfdc4cc8bc7963175e2d5dd9
@@ -4,7 +4,7 @@ github:
4
4
  port: 443 # Optional, defaults to: 80 for http and 443 for https
5
5
  base_path: # Optional, defaults to: ''
6
6
  api_version: # Optional, defaults to: ''
7
- timeout: 3 # Optional, defaults to: 1 (time expressed in seconds)
7
+ timeout: 3 # Optional, defaults to: 3 (time expressed in seconds)
8
8
  on_nok_code: :raise # Optional, defaults to :raise. Possible values: [:do_nothing, :raise, :return_false]
9
9
  default_headers:
10
10
  accept: 'application/vnd.github.v3+json'
@@ -5,6 +5,7 @@ require 'api_recipes'
5
5
  # Configure RemoteApi through custom settings
6
6
  FAKE_API_SETTINGS = {
7
7
  host: 'jsonplaceholder.typicode.com',
8
+ timeout: 10,
8
9
  routes: {
9
10
  users: {
10
11
  list: nil,
@@ -10,6 +10,8 @@ end
10
10
  # Let's create a simple class that uses ApiRecipes
11
11
  class MyFancyClass
12
12
  include ApiRecipes
13
+
14
+ endpoint :github
13
15
  end
14
16
 
15
17
 
@@ -27,3 +29,10 @@ end
27
29
  MyFancyClass.github.users.repos(user_id: usernames.first) do |repos|
28
30
  puts repos
29
31
  end
32
+
33
+ # The endpoints are available on instances too
34
+ fancy = MyFancyClass.new
35
+
36
+ fancy.github.users.list do |users|
37
+ puts users.collect{ |user| user['login'] }
38
+ end
@@ -1,3 +1,3 @@
1
1
  module ApiRecipes
2
- VERSION = '0.3.1'
2
+ VERSION = '0.4.0'
3
3
  end
data/lib/api_recipes.rb CHANGED
@@ -12,26 +12,14 @@ module ApiRecipes
12
12
 
13
13
  def self.included(base)
14
14
 
15
- def base.endpoint(endpoint_name, configs, obj = nil)
16
- overwrite = false
17
- # If no obj has given, do not overwrite the EP (i.e. use the one created on configuration phase)
18
- # Else ff an obj has given, overwrite the EP with a new EP with new configs.
19
- # This EP will be accessible by this obj only (both class and instance)
20
- unless obj
21
- obj = self
22
- overwrite = true
23
- end
15
+ def base.endpoint(endpoint_name, configs = {})
24
16
  configs = ApiRecipes._aprcps_merge_endpoints_configs(endpoint_name, configs.deep_symbolize_keys)
25
17
  endpoint_name = endpoint_name.to_sym
26
18
 
27
19
  # Define 'endpoint_name' method for the class
28
- ApiRecipes._aprcps_define_class_endpoint endpoint_name, configs, obj, overwrite
20
+ ApiRecipes._aprcps_define_class_endpoint endpoint_name, configs, self, true
29
21
  # Define 'endpoint_name' method for the class' instances
30
- ApiRecipes._aprcps_define_instance_endpoint endpoint_name, obj
31
- end
32
-
33
- configuration.endpoints_configs.each do |endpoint_name, endpoint_configs|
34
- base.endpoint endpoint_name, endpoint_configs, base
22
+ ApiRecipes._aprcps_define_instance_endpoint endpoint_name, self
35
23
  end
36
24
  end
37
25
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_recipes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alessandro Verlato