fantasticstay_api 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Dockerfile +5 -1
- data/README.md +2 -0
- data/Rakefile +3 -1
- data/fantasticstay_api.gemspec +2 -2
- data/lib/fantasticstay_api/api.rb +10 -9
- data/lib/fantasticstay_api/client.rb +4 -14
- data/lib/fantasticstay_api/configuration.rb +10 -4
- data/lib/fantasticstay_api/version.rb +1 -1
- data/lib/fantasticstay_api.rb +1 -1
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34e6c99e07ab528a63116a7bdfcd764a6cd74047f805ef2121c02f82b7266584
|
4
|
+
data.tar.gz: 4a2af7516ae2ae8385cf20acb58b282d72d9d52e8024df49f3f3db91fffc32c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8be0b2d3027bdf240d35414d4800dfaaf13de5e2c06348dac2c7fbbf38670f362829b29ff898b4cd1c82ee34d17034c9b6ed686ebdaad735f5eabb235487da80
|
7
|
+
data.tar.gz: dced4169e85772446ba7441ea95da1d32f96f8e76d37aaa1a87b1c4aa72193c78a8d0f64334086505a3869050e48a8fc7f0ad85795ff08697d22747bb6e1156a
|
data/Dockerfile
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# FantasticstayApi
|
2
2
|
|
3
|
+
![main workflow](https://github.com/dlage/fantasticstay_api_gem/actions/workflows/main.yml/badge.svg)
|
4
|
+
|
3
5
|
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/fantasticstay_api`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
6
|
|
5
7
|
TODO: Delete this and the text above, and describe your gem
|
data/Rakefile
CHANGED
data/fantasticstay_api.gemspec
CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.license = 'MIT'
|
15
15
|
spec.required_ruby_version = Gem::Requirement.new('>= 2.4.0')
|
16
16
|
|
17
|
-
spec.metadata['allowed_push_host'] =
|
17
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
18
18
|
|
19
19
|
spec.metadata['homepage_uri'] = spec.homepage
|
20
20
|
spec.metadata['source_code_uri'] = 'https://github.com/dlage/fantasticstay_api_gem'
|
@@ -31,9 +31,9 @@ Gem::Specification.new do |spec|
|
|
31
31
|
|
32
32
|
# Uncomment to register a new dependency of your gem
|
33
33
|
# spec.add_dependency "example-gem", "~> 1.0"
|
34
|
+
spec.add_dependency 'api_cache', '~> 0.3.0'
|
34
35
|
spec.add_dependency 'faraday', '~> 1.3.0'
|
35
36
|
spec.add_dependency 'oj', '~> 3.11'
|
36
|
-
spec.add_dependency 'api_cache', '~> 0.3.0'
|
37
37
|
|
38
38
|
# spec.add_dependency 'dry-configurable', '~> 0.12.1'
|
39
39
|
|
@@ -14,7 +14,7 @@ module FantasticstayApi
|
|
14
14
|
include Constants
|
15
15
|
include HttpStatusCodes
|
16
16
|
|
17
|
-
attr_reader(*FantasticstayApi.configuration.property_names
|
17
|
+
attr_reader(*FantasticstayApi.configuration.property_names)
|
18
18
|
|
19
19
|
attr_accessor :current_options
|
20
20
|
|
@@ -28,7 +28,6 @@ module FantasticstayApi
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
API_ENDPOINT = 'https://api.fsapp.io'
|
32
31
|
HTTP_STATUS_MAPPING = {
|
33
32
|
HTTP_BAD_REQUEST_CODE => BadRequestError,
|
34
33
|
HTTP_UNAUTHORIZED_CODE => UnauthorizedError,
|
@@ -48,8 +47,6 @@ module FantasticstayApi
|
|
48
47
|
FantasticstayApi.configuration.property_names.each do |key|
|
49
48
|
send("#{key}=", opts[key])
|
50
49
|
end
|
51
|
-
@api_token = opts[:token] || ENV['FANTASTICSTAY_API_TOKEN']
|
52
|
-
@api_endpoint = opts[:endpoint] || ENV['FANTASTICSTAY_API_ENDPOINT'] || API_ENDPOINT
|
53
50
|
|
54
51
|
yield_or_eval(&block) if block_given?
|
55
52
|
end
|
@@ -69,18 +66,22 @@ module FantasticstayApi
|
|
69
66
|
# provide your own logger
|
70
67
|
logger = Logger.new $stderr
|
71
68
|
logger.level = Logger::DEBUG
|
72
|
-
@client ||= Faraday.new(@
|
69
|
+
@client ||= Faraday.new(@endpoint) do |client|
|
73
70
|
client.request :url_encoded
|
74
71
|
client.adapter Faraday.default_adapter
|
75
72
|
client.headers['Content-Type'] = 'application/json'
|
76
|
-
client.headers['x-api-key'] = @
|
73
|
+
client.headers['x-api-key'] = @token
|
74
|
+
client.headers['User-Agent'] = @user_agent
|
77
75
|
client.response :logger, logger
|
78
76
|
end
|
79
77
|
end
|
80
78
|
|
81
79
|
def request(http_method:, endpoint:, params: {}, cache_ttl: 3600)
|
82
|
-
response = APICache.get(
|
83
|
-
|
80
|
+
response = APICache.get(
|
81
|
+
Digest::SHA256.bubblebabble(@token) + http_method.to_s + endpoint + params.to_s,
|
82
|
+
cache: cache_ttl
|
83
|
+
) do
|
84
|
+
client.public_send(http_method, endpoint, params)
|
84
85
|
end
|
85
86
|
parsed_response = Oj.load(response.body)
|
86
87
|
|
@@ -108,7 +109,7 @@ module FantasticstayApi
|
|
108
109
|
# :nodoc:
|
109
110
|
case method_name.to_s
|
110
111
|
when /^(.*)\?$/
|
111
|
-
|
112
|
+
!send(Regexp.last_match(1).to_s).nil?
|
112
113
|
when /^clear_(.*)$/
|
113
114
|
send("#{Regexp.last_match(1)}=", nil)
|
114
115
|
else
|
@@ -26,10 +26,7 @@ module FantasticstayApi
|
|
26
26
|
http_method: :get,
|
27
27
|
endpoint: 'calendar',
|
28
28
|
params: {
|
29
|
-
listing_id: listing_id,
|
30
|
-
start_date: start_date,
|
31
|
-
end_date: end_date,
|
32
|
-
filters: filters.to_json
|
29
|
+
listing_id: listing_id, start_date: start_date, end_date: end_date, filters: filters.to_json
|
33
30
|
}.merge(global_params)
|
34
31
|
)
|
35
32
|
process_response(response)
|
@@ -50,10 +47,7 @@ module FantasticstayApi
|
|
50
47
|
http_method: :get,
|
51
48
|
endpoint: 'reservations',
|
52
49
|
params: {
|
53
|
-
listing_id: listing_id,
|
54
|
-
filters: filters.to_json,
|
55
|
-
sort: sort[:order],
|
56
|
-
direction: sort[:direction]
|
50
|
+
listing_id: listing_id, filters: filters.to_json, sort: sort[:order], direction: sort[:direction]
|
57
51
|
}.merge!(global_params),
|
58
52
|
cache_ttl: 3600 * 24
|
59
53
|
)
|
@@ -95,13 +89,9 @@ module FantasticstayApi
|
|
95
89
|
case result
|
96
90
|
when Hash
|
97
91
|
result.transform_keys!(&:to_sym)
|
98
|
-
result.
|
99
|
-
process_response(r)
|
100
|
-
end
|
92
|
+
result.each_value { |r| process_response(r) }
|
101
93
|
when Array
|
102
|
-
result.each
|
103
|
-
process_response(r)
|
104
|
-
end
|
94
|
+
result.each { |r| process_response(r) }
|
105
95
|
end
|
106
96
|
result
|
107
97
|
end
|
@@ -6,19 +6,25 @@ require_relative 'version'
|
|
6
6
|
module FantasticstayApi
|
7
7
|
# Stores the configuration
|
8
8
|
class Configuration < API::Config
|
9
|
+
API_ENDPOINT = 'https://api.fsapp.io'
|
10
|
+
API_TOKEN = 'TESTING'
|
11
|
+
|
9
12
|
property :follow_redirects, default: true
|
10
13
|
|
11
14
|
# The api endpoint used to connect to FantasticstayApi if none is set
|
12
|
-
property
|
15
|
+
property :endpoint, default: ENV['FANTASTICSTAY_API_ENDPOINT'] || API_ENDPOINT
|
16
|
+
|
17
|
+
# The token included in request header 'x-api-key'
|
18
|
+
property :token, default: ENV['FANTASTICSTAY_API_TOKEN'] || API_TOKEN
|
13
19
|
|
14
20
|
# The value sent in the http header for 'User-Agent' if none is set
|
15
|
-
property
|
21
|
+
property :user_agent, default: "FantasticstayApi API Ruby Gem #{FantasticstayApi::VERSION}"
|
16
22
|
|
17
23
|
# By default uses the Faraday connection options if none is set
|
18
|
-
property
|
24
|
+
property :connection_options, default: {}
|
19
25
|
|
20
26
|
# By default display 30 resources
|
21
|
-
property :per_page, default:
|
27
|
+
property :per_page, default: 10
|
22
28
|
|
23
29
|
# Add Faraday::RackBuilder to overwrite middleware
|
24
30
|
property :stack
|
data/lib/fantasticstay_api.rb
CHANGED
metadata
CHANGED
@@ -1,57 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fantasticstay_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dinis
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-10-
|
11
|
+
date: 2022-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: api_cache
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.3.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 0.3.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: faraday
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 1.3.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 1.3.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: oj
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: '3.11'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: '3.11'
|
55
55
|
description: A gem that implements functions from the FS API available for its users.
|
56
56
|
email:
|
57
57
|
- dinis@lage.pw
|