aga-request 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/request/base.rb +5 -3
- data/lib/request/resources/http.rb +46 -22
- data/lib/request/version.rb +1 -1
- metadata +31 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a00fbef7308e4a5cd61fd3227a06467cbbe82a01f48c69fedc24f9e846490642
|
4
|
+
data.tar.gz: e8a7ef87bb251566b9eb87b483211265e90cfeacae28a8d829f9e327e31ddae9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b809408a7a31881aaaa11315498b39312d98d23fbeed05f5b62ea747604913c549dedac85667c26938f48d2f0d2b55ab02c941ce282a430335f974d620a1e93d
|
7
|
+
data.tar.gz: 211dc87b4885f67207fd37299c7f7f9d79f236ffe0fec630bbc08c0007d87f994ccaef7b4b6e44322426781a54f400c241007b866196cac9c2e711c071a67125
|
data/lib/request/base.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
4
|
-
require '
|
5
|
-
require '
|
3
|
+
require 'faraday'
|
4
|
+
require 'active_support'
|
5
|
+
require 'active_support/cache'
|
6
6
|
|
7
7
|
module Request
|
8
8
|
class Base
|
9
9
|
class << self
|
10
10
|
attr_accessor :app_info
|
11
|
+
|
12
|
+
def initialize; end
|
11
13
|
end
|
12
14
|
|
13
15
|
self.app_info = ::ENV['APP_INFO'] || "#{::Request::NAME} V#{::Request.version}"
|
@@ -2,37 +2,61 @@
|
|
2
2
|
|
3
3
|
module Request
|
4
4
|
class Http < Base
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
def initialize(api_key: nil, api_secret: nil, cache_options: {})
|
6
|
+
super()
|
7
|
+
@api_key = api_key
|
8
|
+
@api_secret = api_secret
|
9
|
+
@cache = ActiveSupport::Cache.lookup_store(:memory_store, cache_options || default_cache)
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
+
def get(endpoint, params = {}, headers = {})
|
13
|
+
response = cached_request(:get, endpoint, params, headers)
|
14
|
+
JSON.parse(response.body)
|
15
|
+
end
|
12
16
|
|
13
|
-
|
14
|
-
|
15
|
-
|
17
|
+
def post(endpoint, body = {}, headers = {})
|
18
|
+
response = cached_request(:post, endpoint, body, headers)
|
19
|
+
JSON.parse(response.body)
|
20
|
+
end
|
16
21
|
|
17
|
-
|
18
|
-
|
22
|
+
def put(endpoint, body = {}, headers = {})
|
23
|
+
response = cached_request(:put, endpoint, body, headers)
|
24
|
+
JSON.parse(response.body)
|
25
|
+
end
|
19
26
|
|
20
|
-
|
27
|
+
def delete(endpoint, params = {}, headers = {})
|
28
|
+
response = cached_request(:delete, endpoint, params, headers)
|
29
|
+
JSON.parse(response.body)
|
30
|
+
end
|
21
31
|
|
22
|
-
|
23
|
-
case name
|
24
|
-
when 'GET', 'get'
|
25
|
-
req = Net::HTTP::Get.new(uri)
|
26
|
-
when 'POST', 'post'
|
27
|
-
req = Net::HTTP::Post.new(uri)
|
28
|
-
end
|
32
|
+
private
|
29
33
|
|
30
|
-
|
34
|
+
def cached_request(method, endpoint, payload = {}, headers = {})
|
35
|
+
cache_key = [method, endpoint, payload, headers]
|
36
|
+
if @cache.exist?(cache_key)
|
37
|
+
@cache.read(cache_key)
|
38
|
+
else
|
39
|
+
response = make_request(method, endpoint, payload, headers)
|
40
|
+
@cache.write(cache_key, response)
|
41
|
+
response
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def make_request(method, endpoint, payload, headers)
|
46
|
+
connection = Faraday.new(endpoint) do |conn|
|
47
|
+
conn.request :url_encoded
|
48
|
+
conn.adapter Faraday.default_adapter
|
31
49
|
end
|
32
50
|
|
33
|
-
|
34
|
-
|
51
|
+
connection.public_send(method) do |request|
|
52
|
+
request.headers.merge!(headers)
|
53
|
+
request.url(endpoint)
|
54
|
+
request.body = payload.to_json if %i[post put].include?(method)
|
35
55
|
end
|
36
56
|
end
|
57
|
+
|
58
|
+
def default_cache
|
59
|
+
{ size: 64.megabytes, expires_in: 1.minutes }
|
60
|
+
end
|
37
61
|
end
|
38
62
|
end
|
data/lib/request/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aga-request
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefano Baldazzi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-03-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zeitwerk
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 7.0.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 7.0.0
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bump
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +66,20 @@ dependencies:
|
|
52
66
|
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: 3.1.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: faraday
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.7'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.7'
|
55
83
|
- !ruby/object:Gem::Dependency
|
56
84
|
name: rake
|
57
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -172,5 +200,5 @@ requirements: []
|
|
172
200
|
rubygems_version: 3.3.24
|
173
201
|
signing_key:
|
174
202
|
specification_version: 4
|
175
|
-
summary: request0.0.
|
203
|
+
summary: request0.0.1
|
176
204
|
test_files: []
|