fantasticstay_api 0.1.3 → 0.1.5
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 +4 -4
- data/CHANGELOG.md +1 -0
- data/Gemfile +0 -2
- data/Gemfile.lock +36 -38
- data/bin/console +0 -1
- data/fantasticstay_api.gemspec +2 -2
- data/lib/fantasticstay_api/api.rb +37 -49
- data/lib/fantasticstay_api/version.rb +1 -1
- data/lib/fantasticstay_api.rb +1 -35
- metadata +18 -8
- data/lib/fantasticstay_api/api/config/property.rb +0 -25
- data/lib/fantasticstay_api/api/config/property_set.rb +0 -119
- data/lib/fantasticstay_api/api/config.rb +0 -101
- data/lib/fantasticstay_api/configuration.rb +0 -32
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9a727acfeab9f3a592ea54d2fe8622a2b116b47868a930bcda001d4d029487bc
|
|
4
|
+
data.tar.gz: afb8961fb5454320a021b6f5891aa1990de185ec1a7b79d2592d7d69f6cdfafd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7068b3721b8d27d6e74c1b454c39579014d12cf2c57b28c67210eb70b29f6300dfb9b495683a51923922a4b559a5aadeca307961bd786bbf51956f54648cfe55
|
|
7
|
+
data.tar.gz: 5ea6380129337d84b23a29dadcab7c5be2ef565eb27019c5b65776bc37ffc2467b820564e708374f770f22ce8ffd17a697ab1dbccbf3083992e34f53b9bb4023
|
data/CHANGELOG.md
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
* 0.1.5 Upgrade to faraday 2.6.0
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,51 +1,49 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
fantasticstay_api (0.1.
|
|
4
|
+
fantasticstay_api (0.1.3)
|
|
5
5
|
api_cache (~> 0.3.0)
|
|
6
|
-
faraday (~>
|
|
6
|
+
faraday (~> 2.6.0)
|
|
7
7
|
oj (~> 3.11)
|
|
8
8
|
|
|
9
9
|
GEM
|
|
10
10
|
remote: https://rubygems.org/
|
|
11
11
|
specs:
|
|
12
|
-
addressable (2.
|
|
13
|
-
public_suffix (>= 2.0.2, <
|
|
12
|
+
addressable (2.8.1)
|
|
13
|
+
public_suffix (>= 2.0.2, < 6.0)
|
|
14
14
|
api_cache (0.3.0)
|
|
15
15
|
ast (2.4.2)
|
|
16
16
|
crack (0.4.5)
|
|
17
17
|
rexml
|
|
18
|
-
diff-lcs (1.
|
|
19
|
-
dotenv (2.
|
|
20
|
-
faraday (
|
|
21
|
-
faraday-net_http (
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
faraday-net_http (1.0.1)
|
|
18
|
+
diff-lcs (1.5.0)
|
|
19
|
+
dotenv (2.8.1)
|
|
20
|
+
faraday (2.6.0)
|
|
21
|
+
faraday-net_http (>= 2.0, < 3.1)
|
|
22
|
+
ruby2_keywords (>= 0.0.4)
|
|
23
|
+
faraday-net_http (3.0.1)
|
|
25
24
|
hashdiff (1.0.1)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
parser (3.0.0.0)
|
|
25
|
+
oj (3.13.21)
|
|
26
|
+
parallel (1.22.1)
|
|
27
|
+
parser (3.1.2.1)
|
|
30
28
|
ast (~> 2.4.1)
|
|
31
|
-
public_suffix (
|
|
32
|
-
rainbow (3.
|
|
33
|
-
rake (13.0.
|
|
34
|
-
regexp_parser (2.
|
|
35
|
-
rexml (3.2.
|
|
36
|
-
rspec (3.
|
|
37
|
-
rspec-core (~> 3.
|
|
38
|
-
rspec-expectations (~> 3.
|
|
39
|
-
rspec-mocks (~> 3.
|
|
40
|
-
rspec-core (3.
|
|
41
|
-
rspec-support (~> 3.
|
|
42
|
-
rspec-expectations (3.
|
|
29
|
+
public_suffix (5.0.0)
|
|
30
|
+
rainbow (3.1.1)
|
|
31
|
+
rake (13.0.6)
|
|
32
|
+
regexp_parser (2.6.0)
|
|
33
|
+
rexml (3.2.5)
|
|
34
|
+
rspec (3.12.0)
|
|
35
|
+
rspec-core (~> 3.12.0)
|
|
36
|
+
rspec-expectations (~> 3.12.0)
|
|
37
|
+
rspec-mocks (~> 3.12.0)
|
|
38
|
+
rspec-core (3.12.0)
|
|
39
|
+
rspec-support (~> 3.12.0)
|
|
40
|
+
rspec-expectations (3.12.0)
|
|
43
41
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
44
|
-
rspec-support (~> 3.
|
|
45
|
-
rspec-mocks (3.
|
|
42
|
+
rspec-support (~> 3.12.0)
|
|
43
|
+
rspec-mocks (3.12.0)
|
|
46
44
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
47
|
-
rspec-support (~> 3.
|
|
48
|
-
rspec-support (3.
|
|
45
|
+
rspec-support (~> 3.12.0)
|
|
46
|
+
rspec-support (3.12.0)
|
|
49
47
|
rubocop (0.93.1)
|
|
50
48
|
parallel (~> 1.10)
|
|
51
49
|
parser (>= 2.7.1.5)
|
|
@@ -55,14 +53,14 @@ GEM
|
|
|
55
53
|
rubocop-ast (>= 0.6.0)
|
|
56
54
|
ruby-progressbar (~> 1.7)
|
|
57
55
|
unicode-display_width (>= 1.4.0, < 2.0)
|
|
58
|
-
rubocop-ast (1.
|
|
59
|
-
parser (>=
|
|
56
|
+
rubocop-ast (1.23.0)
|
|
57
|
+
parser (>= 3.1.1.0)
|
|
60
58
|
ruby-progressbar (1.11.0)
|
|
61
|
-
ruby2_keywords (0.0.
|
|
62
|
-
unicode-display_width (1.
|
|
63
|
-
vcr (6.
|
|
64
|
-
webmock (3.
|
|
65
|
-
addressable (>= 2.
|
|
59
|
+
ruby2_keywords (0.0.5)
|
|
60
|
+
unicode-display_width (1.8.0)
|
|
61
|
+
vcr (6.1.0)
|
|
62
|
+
webmock (3.18.1)
|
|
63
|
+
addressable (>= 2.8.0)
|
|
66
64
|
crack (>= 0.3.2)
|
|
67
65
|
hashdiff (>= 0.4.0, < 2.0.0)
|
|
68
66
|
|
data/bin/console
CHANGED
data/fantasticstay_api.gemspec
CHANGED
|
@@ -32,10 +32,10 @@ Gem::Specification.new do |spec|
|
|
|
32
32
|
# Uncomment to register a new dependency of your gem
|
|
33
33
|
# spec.add_dependency "example-gem", "~> 1.0"
|
|
34
34
|
spec.add_dependency 'api_cache', '~> 0.3.0'
|
|
35
|
-
spec.add_dependency 'faraday', '~>
|
|
35
|
+
spec.add_dependency 'faraday', '~> 2.6.0'
|
|
36
36
|
spec.add_dependency 'oj', '~> 3.11'
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
spec.add_dependency 'dry-configurable', '~> 0.13'
|
|
39
39
|
|
|
40
40
|
# For more information and examples about making a new gem, checkout our
|
|
41
41
|
# guide at: https://bundler.io/guides/creating_gem.html
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require_relative 'api_exceptions'
|
|
4
|
-
require_relative 'configuration'
|
|
5
4
|
require_relative 'constants'
|
|
6
5
|
require_relative 'http_status_codes'
|
|
6
|
+
require 'dry-configurable'
|
|
7
7
|
require 'api_cache'
|
|
8
8
|
require 'digest/bubblebabble'
|
|
9
9
|
|
|
@@ -13,20 +13,7 @@ module FantasticstayApi
|
|
|
13
13
|
include ApiExceptions
|
|
14
14
|
include Constants
|
|
15
15
|
include HttpStatusCodes
|
|
16
|
-
|
|
17
|
-
attr_reader(*FantasticstayApi.configuration.property_names)
|
|
18
|
-
|
|
19
|
-
attr_accessor :current_options
|
|
20
|
-
|
|
21
|
-
# Callback to update current configuration options
|
|
22
|
-
class_eval do
|
|
23
|
-
FantasticstayApi.configuration.property_names.each do |key|
|
|
24
|
-
define_method "#{key}=" do |arg|
|
|
25
|
-
instance_variable_set("@#{key}", arg)
|
|
26
|
-
current_options.merge!({ "#{key}": arg })
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
16
|
+
include Dry::Configurable
|
|
30
17
|
|
|
31
18
|
HTTP_STATUS_MAPPING = {
|
|
32
19
|
HTTP_BAD_REQUEST_CODE => BadRequestError,
|
|
@@ -36,16 +23,37 @@ module FantasticstayApi
|
|
|
36
23
|
HTTP_UNPROCESSABLE_ENTITY_CODE => UnprocessableEntityError,
|
|
37
24
|
'default' => ApiError
|
|
38
25
|
}.freeze
|
|
26
|
+
API_ENDPOINT = 'https://api.fsapp.io'
|
|
27
|
+
API_TOKEN = 'TESTING'
|
|
28
|
+
|
|
29
|
+
setting :follow_redirects, default: true
|
|
30
|
+
|
|
31
|
+
# The api endpoint used to connect to FantasticstayApi if none is set
|
|
32
|
+
setting :endpoint, default: ENV['FANTASTICSTAY_API_ENDPOINT'] || API_ENDPOINT, reader: true
|
|
33
|
+
|
|
34
|
+
# The token included in request header 'x-api-key'
|
|
35
|
+
setting :token, default: ENV['FANTASTICSTAY_API_TOKEN'] || API_TOKEN, reader: true
|
|
36
|
+
|
|
37
|
+
# The value sent in the http header for 'User-Agent' if none is set
|
|
38
|
+
setting :user_agent, default: "FantasticstayApi API Ruby Gem #{FantasticstayApi::VERSION}"
|
|
39
|
+
|
|
40
|
+
# By default uses the Faraday connection options if none is set
|
|
41
|
+
setting :connection_options, default: {}
|
|
42
|
+
|
|
43
|
+
# By default display 30 resources
|
|
44
|
+
setting :per_page, default: 10
|
|
45
|
+
|
|
46
|
+
# Add Faraday::RackBuilder to overwrite middleware
|
|
47
|
+
setting :stack
|
|
39
48
|
|
|
40
49
|
# Create new API
|
|
41
50
|
#
|
|
42
51
|
# @api public
|
|
43
52
|
def initialize(options = {}, &block)
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
send("#{key}=", opts[key])
|
|
53
|
+
configure do |c|
|
|
54
|
+
options.each_key do |key|
|
|
55
|
+
c.send("#{key}=", options[key])
|
|
56
|
+
end
|
|
49
57
|
end
|
|
50
58
|
|
|
51
59
|
yield_or_eval(&block) if block_given?
|
|
@@ -63,29 +71,28 @@ module FantasticstayApi
|
|
|
63
71
|
private
|
|
64
72
|
|
|
65
73
|
def client
|
|
66
|
-
|
|
67
|
-
logger = Logger.new $stderr
|
|
68
|
-
logger.level = Logger::DEBUG
|
|
69
|
-
@client ||= Faraday.new(@endpoint) do |client|
|
|
74
|
+
@client ||= Faraday.new(config.endpoint) do |client|
|
|
70
75
|
client.request :url_encoded
|
|
71
76
|
client.adapter Faraday.default_adapter
|
|
72
77
|
client.headers['Content-Type'] = 'application/json'
|
|
73
|
-
client.headers['x-api-key'] =
|
|
74
|
-
client.headers['User-Agent'] =
|
|
75
|
-
client.response :logger, logger
|
|
78
|
+
client.headers['x-api-key'] = config.token
|
|
79
|
+
client.headers['User-Agent'] = config.user_agent
|
|
76
80
|
end
|
|
77
81
|
end
|
|
78
82
|
|
|
79
83
|
def request(http_method:, endpoint:, params: {}, cache_ttl: 3600)
|
|
80
84
|
response = APICache.get(
|
|
81
|
-
Digest::SHA256.bubblebabble(
|
|
85
|
+
Digest::SHA256.bubblebabble(config.token) + http_method.to_s + endpoint + params.to_s,
|
|
82
86
|
cache: cache_ttl
|
|
83
87
|
) do
|
|
84
88
|
client.public_send(http_method, endpoint, params)
|
|
85
89
|
end
|
|
86
|
-
parsed_response = Oj.load(response.body)
|
|
87
90
|
|
|
88
|
-
|
|
91
|
+
process_http_response(response)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def process_http_response(response)
|
|
95
|
+
return Oj.load(response.body) if response_successful?(response)
|
|
89
96
|
|
|
90
97
|
raise error_class(response), "Code: #{response.status}, response: #{response.body}"
|
|
91
98
|
end
|
|
@@ -101,24 +108,5 @@ module FantasticstayApi
|
|
|
101
108
|
def response_successful?(response)
|
|
102
109
|
response.status == HTTP_OK_CODE
|
|
103
110
|
end
|
|
104
|
-
|
|
105
|
-
# Responds to attribute query or attribute clear
|
|
106
|
-
#
|
|
107
|
-
# @api private
|
|
108
|
-
def method_missing(method_name, *args, &block)
|
|
109
|
-
# :nodoc:
|
|
110
|
-
case method_name.to_s
|
|
111
|
-
when /^(.*)\?$/
|
|
112
|
-
!send(Regexp.last_match(1).to_s).nil?
|
|
113
|
-
when /^clear_(.*)$/
|
|
114
|
-
send("#{Regexp.last_match(1)}=", nil)
|
|
115
|
-
else
|
|
116
|
-
super
|
|
117
|
-
end
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
def respond_to_missing?(method_name, include_private = false)
|
|
121
|
-
method_name.to_s.start_with?('clear_') || super
|
|
122
|
-
end
|
|
123
111
|
end
|
|
124
112
|
end
|
data/lib/fantasticstay_api.rb
CHANGED
|
@@ -13,35 +13,6 @@ module FantasticstayApi
|
|
|
13
13
|
LIBDIR = File.expand_path(LIBNAME.to_s, __dir__)
|
|
14
14
|
|
|
15
15
|
class << self
|
|
16
|
-
# The client configuration
|
|
17
|
-
#
|
|
18
|
-
# @return [Configuration]
|
|
19
|
-
#
|
|
20
|
-
# @api public
|
|
21
|
-
def configuration
|
|
22
|
-
@configuration ||= Configuration.new
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
alias config configuration
|
|
26
|
-
|
|
27
|
-
# Configure options
|
|
28
|
-
#
|
|
29
|
-
# @example
|
|
30
|
-
# FantasticstayApi.configure do |c|
|
|
31
|
-
# c.some_option = true
|
|
32
|
-
# end
|
|
33
|
-
#
|
|
34
|
-
# @yield the configuration block
|
|
35
|
-
# @yieldparam configuration [FantasticstayApi::Configuration]
|
|
36
|
-
# the configuration instance
|
|
37
|
-
#
|
|
38
|
-
# @return [nil]
|
|
39
|
-
#
|
|
40
|
-
# @api public
|
|
41
|
-
def configure
|
|
42
|
-
yield configuration
|
|
43
|
-
end
|
|
44
|
-
|
|
45
16
|
# Alias for FantasticstayApi::Client.new
|
|
46
17
|
#
|
|
47
18
|
# @param [Hash] options
|
|
@@ -70,20 +41,15 @@ module FantasticstayApi
|
|
|
70
41
|
def method_missing(method_name, *args, &block)
|
|
71
42
|
if new.respond_to?(method_name)
|
|
72
43
|
new.send(method_name, *args, &block)
|
|
73
|
-
elsif configuration.respond_to?(method_name)
|
|
74
|
-
FantasticstayApi.configuration.send(method_name, *args, &block)
|
|
75
44
|
else
|
|
76
45
|
super.respond_to_missing?
|
|
77
46
|
end
|
|
78
47
|
end
|
|
79
48
|
|
|
80
49
|
def respond_to_missing?(method_name, include_private = false)
|
|
81
|
-
new.respond_to?(method_name, include_private) ||
|
|
82
|
-
configuration.respond_to?(method_name) ||
|
|
83
|
-
super(method_name, include_private)
|
|
50
|
+
new.respond_to?(method_name, include_private) || super(method_name, include_private)
|
|
84
51
|
end
|
|
85
52
|
end
|
|
86
53
|
end
|
|
87
54
|
|
|
88
55
|
require_relative 'fantasticstay_api/client'
|
|
89
|
-
require_relative 'fantasticstay_api/configuration'
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
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.5
|
|
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-28 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: api_cache
|
|
@@ -30,14 +30,14 @@ dependencies:
|
|
|
30
30
|
requirements:
|
|
31
31
|
- - "~>"
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
|
-
version:
|
|
33
|
+
version: 2.6.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: 2.6.0
|
|
41
41
|
- !ruby/object:Gem::Dependency
|
|
42
42
|
name: oj
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -52,6 +52,20 @@ dependencies:
|
|
|
52
52
|
- - "~>"
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
54
|
version: '3.11'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: dry-configurable
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0.13'
|
|
62
|
+
type: :runtime
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0.13'
|
|
55
69
|
description: A gem that implements functions from the FS API available for its users.
|
|
56
70
|
email:
|
|
57
71
|
- dinis@lage.pw
|
|
@@ -77,12 +91,8 @@ files:
|
|
|
77
91
|
- fantasticstay_api.gemspec
|
|
78
92
|
- lib/fantasticstay_api.rb
|
|
79
93
|
- lib/fantasticstay_api/api.rb
|
|
80
|
-
- lib/fantasticstay_api/api/config.rb
|
|
81
|
-
- lib/fantasticstay_api/api/config/property.rb
|
|
82
|
-
- lib/fantasticstay_api/api/config/property_set.rb
|
|
83
94
|
- lib/fantasticstay_api/api_exceptions.rb
|
|
84
95
|
- lib/fantasticstay_api/client.rb
|
|
85
|
-
- lib/fantasticstay_api/configuration.rb
|
|
86
96
|
- lib/fantasticstay_api/constants.rb
|
|
87
97
|
- lib/fantasticstay_api/http_status_codes.rb
|
|
88
98
|
- lib/fantasticstay_api/version.rb
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module FantasticstayApi
|
|
4
|
-
class API
|
|
5
|
-
class Config
|
|
6
|
-
# Property objects provide an interface for configuration options
|
|
7
|
-
class Property
|
|
8
|
-
attr_reader :name, :default, :required
|
|
9
|
-
|
|
10
|
-
def initialize(name, options)
|
|
11
|
-
@name = name
|
|
12
|
-
@default = options.fetch(:default, nil)
|
|
13
|
-
@required = options.fetch(:required, nil)
|
|
14
|
-
@options = options
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
# @api private
|
|
18
|
-
def define_accessor_methods(properties)
|
|
19
|
-
properties.define_reader_method(self, name, :public)
|
|
20
|
-
properties.define_writer_method(self, "#{name}=", :public)
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'set'
|
|
4
|
-
|
|
5
|
-
module FantasticstayApi
|
|
6
|
-
class API
|
|
7
|
-
class Config
|
|
8
|
-
# Class responsible for storing configuration properties
|
|
9
|
-
class PropertySet
|
|
10
|
-
include Enumerable
|
|
11
|
-
|
|
12
|
-
attr_reader :parent, :properties
|
|
13
|
-
|
|
14
|
-
# Initialize an PropertySet
|
|
15
|
-
#
|
|
16
|
-
# @param [Object] parent
|
|
17
|
-
# @param [Set] properties
|
|
18
|
-
#
|
|
19
|
-
# @return [undefined]
|
|
20
|
-
#
|
|
21
|
-
# @api private
|
|
22
|
-
def initialize(parent = nil, properties = Set.new)
|
|
23
|
-
@parent = parent
|
|
24
|
-
@properties = properties
|
|
25
|
-
@map = {}
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
# Iterate over properties
|
|
29
|
-
#
|
|
30
|
-
# @yield [property]
|
|
31
|
-
#
|
|
32
|
-
# @yieldparam [Property] property
|
|
33
|
-
#
|
|
34
|
-
# @return [self]
|
|
35
|
-
#
|
|
36
|
-
# @api public
|
|
37
|
-
def each
|
|
38
|
-
return to_enum unless block_given?
|
|
39
|
-
|
|
40
|
-
@map.each { |name, property| yield property if name.is_a?(Symbol) }
|
|
41
|
-
self
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
# Adds property to the set
|
|
45
|
-
#
|
|
46
|
-
# @example
|
|
47
|
-
# properties_set << property
|
|
48
|
-
#
|
|
49
|
-
# @param [Property] property
|
|
50
|
-
#
|
|
51
|
-
# @return [self]
|
|
52
|
-
#
|
|
53
|
-
# @api public
|
|
54
|
-
def <<(property)
|
|
55
|
-
properties << property
|
|
56
|
-
update_map(property.name, property.default)
|
|
57
|
-
property.define_accessor_methods(self)
|
|
58
|
-
self
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
# Access property by name
|
|
62
|
-
#
|
|
63
|
-
# @api public
|
|
64
|
-
def [](name)
|
|
65
|
-
@map[name]
|
|
66
|
-
end
|
|
67
|
-
alias fetch []
|
|
68
|
-
|
|
69
|
-
# Set property value by name
|
|
70
|
-
#
|
|
71
|
-
# @api public
|
|
72
|
-
def []=(name, property)
|
|
73
|
-
update_map(name, property)
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
# Update map with index
|
|
77
|
-
#
|
|
78
|
-
# @api private
|
|
79
|
-
def update_map(name, property)
|
|
80
|
-
@map[name.to_sym] = @map[name.to_s.freeze] = property
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
# Convert properties to a hash of property names and
|
|
84
|
-
# corresponding values
|
|
85
|
-
#
|
|
86
|
-
# @api public
|
|
87
|
-
def to_hash
|
|
88
|
-
properties.each_with_object({}) do |property, props|
|
|
89
|
-
name = property.name
|
|
90
|
-
props[name] = self[name]
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
# Check if properties exist
|
|
95
|
-
#
|
|
96
|
-
# @api public
|
|
97
|
-
def empty?
|
|
98
|
-
@map.empty?
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
# @api private
|
|
102
|
-
def define_reader_method(property, method_name, visibility)
|
|
103
|
-
property_set = self
|
|
104
|
-
parent.send(:define_method, method_name) { property_set[property.name] }
|
|
105
|
-
parent.send(visibility, method_name)
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
# @api private
|
|
109
|
-
def define_writer_method(property, method_name, visibility)
|
|
110
|
-
property_set = self
|
|
111
|
-
parent.send(:define_method, method_name) do |value|
|
|
112
|
-
property_set[property.name] = value
|
|
113
|
-
end
|
|
114
|
-
parent.send(visibility, method_name)
|
|
115
|
-
end
|
|
116
|
-
end
|
|
117
|
-
end
|
|
118
|
-
end
|
|
119
|
-
end
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative 'config/property'
|
|
4
|
-
require_relative 'config/property_set'
|
|
5
|
-
|
|
6
|
-
module FantasticstayApi
|
|
7
|
-
class API
|
|
8
|
-
# A base class for constructing api configuration
|
|
9
|
-
class Config
|
|
10
|
-
# Defines a property on an object's class or instance
|
|
11
|
-
#
|
|
12
|
-
# @example
|
|
13
|
-
# class Configuration < Api::Config
|
|
14
|
-
# property :adapter, default: :net_http
|
|
15
|
-
# property :user, required: true
|
|
16
|
-
# end
|
|
17
|
-
#
|
|
18
|
-
# @param [Symbol] name
|
|
19
|
-
# the name of a property
|
|
20
|
-
#
|
|
21
|
-
# @param [#to_hash] options
|
|
22
|
-
# the extra options
|
|
23
|
-
#
|
|
24
|
-
# @return [self]
|
|
25
|
-
#
|
|
26
|
-
# @api public
|
|
27
|
-
def self.property(name, options = {})
|
|
28
|
-
property_set << Property.new(name, options)
|
|
29
|
-
update_subclasses(name, options)
|
|
30
|
-
self
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def self.update_subclasses(name, options)
|
|
34
|
-
@subclasses.each { |klass| klass.property(name, options) } if defined?(@subclasses) && @subclasses
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
# Check if property is defined
|
|
38
|
-
#
|
|
39
|
-
# @param [Symbol] name
|
|
40
|
-
# the name to check
|
|
41
|
-
#
|
|
42
|
-
# @return [Boolean]
|
|
43
|
-
#
|
|
44
|
-
# @api public
|
|
45
|
-
def self.property?(name)
|
|
46
|
-
property_set.include?(name)
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
class << self
|
|
50
|
-
attr_reader :property_set
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
instance_variable_set('@property_set', PropertySet.new(self))
|
|
54
|
-
|
|
55
|
-
def self.inherited(descendant)
|
|
56
|
-
super
|
|
57
|
-
(@subclasses ||= Set.new) << descendant
|
|
58
|
-
descendant.instance_variable_set(
|
|
59
|
-
'@property_set',
|
|
60
|
-
PropertySet.new(descendant, property_set.properties.dup)
|
|
61
|
-
)
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def property_names
|
|
65
|
-
self.class.property_set.properties.map(&:name)
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def self.property_names
|
|
69
|
-
property_set.properties.map(&:name)
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
# Fetch all the properties and their values
|
|
73
|
-
#
|
|
74
|
-
# @return [Hash[Symbol]]
|
|
75
|
-
#
|
|
76
|
-
# @api public
|
|
77
|
-
def fetch(value = nil)
|
|
78
|
-
if value
|
|
79
|
-
self.class.property_set[value]
|
|
80
|
-
else
|
|
81
|
-
self.class.property_set.to_hash
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
# Provide access to properties
|
|
86
|
-
#
|
|
87
|
-
# @example
|
|
88
|
-
# config.call do |config|
|
|
89
|
-
# config.adapter = :net_http
|
|
90
|
-
# end
|
|
91
|
-
#
|
|
92
|
-
# @return [self]
|
|
93
|
-
#
|
|
94
|
-
# @api private
|
|
95
|
-
def call(&block)
|
|
96
|
-
block.call(self) if block_given?
|
|
97
|
-
self
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
end
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative 'api/config'
|
|
4
|
-
require_relative 'version'
|
|
5
|
-
|
|
6
|
-
module FantasticstayApi
|
|
7
|
-
# Stores the configuration
|
|
8
|
-
class Configuration < API::Config
|
|
9
|
-
API_ENDPOINT = 'https://api.fsapp.io'
|
|
10
|
-
API_TOKEN = 'TESTING'
|
|
11
|
-
|
|
12
|
-
property :follow_redirects, default: true
|
|
13
|
-
|
|
14
|
-
# The api endpoint used to connect to FantasticstayApi if none is set
|
|
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
|
|
19
|
-
|
|
20
|
-
# The value sent in the http header for 'User-Agent' if none is set
|
|
21
|
-
property :user_agent, default: "FantasticstayApi API Ruby Gem #{FantasticstayApi::VERSION}"
|
|
22
|
-
|
|
23
|
-
# By default uses the Faraday connection options if none is set
|
|
24
|
-
property :connection_options, default: {}
|
|
25
|
-
|
|
26
|
-
# By default display 30 resources
|
|
27
|
-
property :per_page, default: 10
|
|
28
|
-
|
|
29
|
-
# Add Faraday::RackBuilder to overwrite middleware
|
|
30
|
-
property :stack
|
|
31
|
-
end
|
|
32
|
-
end
|