api_recipes 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/examples/config/apis.yml +1 -1
- data/examples/custom_configs.rb +1 -0
- data/examples/simple_usage.rb +9 -0
- data/lib/api_recipes/version.rb +1 -1
- data/lib/api_recipes.rb +3 -15
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 132f12d395ff75b6170f1bc66a9119a696f24b034f23e2d033490bdb2311ef2e
|
4
|
+
data.tar.gz: cb607d01e3a1c4c580efdec24f1c35310f36b9da9cb0a83fdb08578b2cb6ab7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d88a0be72247c33b132f5b8eac1a6f08d7d13595df16f5716b7accd32dce8b54975ea10924c710a9a201dcefa0b927e639d237f0aca07f259a8d006258cff65f
|
7
|
+
data.tar.gz: 834a3f2f58a6d2ee043db4b9a2e4572b8bd140e09ecf19f32c7eeb00b06fb801b13ff279696a763cdc9dcf7fb8fd920089e3ab3bcfdc4cc8bc7963175e2d5dd9
|
data/examples/config/apis.yml
CHANGED
@@ -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:
|
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'
|
data/examples/custom_configs.rb
CHANGED
data/examples/simple_usage.rb
CHANGED
@@ -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
|
data/lib/api_recipes/version.rb
CHANGED
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
|
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,
|
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,
|
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
|
|