fantasticstay_api 0.1.3 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -0
- data/Gemfile +0 -2
- data/Gemfile.lock +44 -39
- data/bin/console +0 -1
- data/fantasticstay_api.gemspec +2 -2
- data/lib/fantasticstay_api/api.rb +37 -49
- data/lib/fantasticstay_api/client.rb +11 -0
- 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: 3edde0d39d9a83238e729e588238d8fbeffca50ea873da073de943729dcdca07
|
4
|
+
data.tar.gz: 3abc453bfc9599a7767eeb42534cbe99cc14a8484ae6a4cfb8b5bb3840c01339
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df0c54d26a59fce2a7aa02b1c58fcc7234745213409ab8684194bcbd22332eacd1a2c0bc555b50d46ebc9803423619aa96a8af809d803bcbe4ff82db60ed638a
|
7
|
+
data.tar.gz: 68bc2fc9c89a243ed8a0e4162f6c10cbc4d8ad26d694abbd9853d0690f2fa3e92302faa7ffb7b3043f7c60c37a14d4bf1bf7dc78e8c63154f502e2cffe1e23c7
|
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,56 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
fantasticstay_api (0.1.
|
4
|
+
fantasticstay_api (0.1.5)
|
5
5
|
api_cache (~> 0.3.0)
|
6
|
-
|
6
|
+
dry-configurable (~> 0.13)
|
7
|
+
faraday (~> 2.6.0)
|
7
8
|
oj (~> 3.11)
|
8
9
|
|
9
10
|
GEM
|
10
11
|
remote: https://rubygems.org/
|
11
12
|
specs:
|
12
|
-
addressable (2.
|
13
|
-
public_suffix (>= 2.0.2, <
|
13
|
+
addressable (2.8.1)
|
14
|
+
public_suffix (>= 2.0.2, < 6.0)
|
14
15
|
api_cache (0.3.0)
|
15
16
|
ast (2.4.2)
|
17
|
+
concurrent-ruby (1.1.10)
|
16
18
|
crack (0.4.5)
|
17
19
|
rexml
|
18
|
-
diff-lcs (1.
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
diff-lcs (1.5.0)
|
21
|
+
dry-configurable (0.16.1)
|
22
|
+
dry-core (~> 0.6)
|
23
|
+
zeitwerk (~> 2.6)
|
24
|
+
dry-core (0.9.1)
|
25
|
+
concurrent-ruby (~> 1.0)
|
26
|
+
zeitwerk (~> 2.6)
|
27
|
+
faraday (2.6.0)
|
28
|
+
faraday-net_http (>= 2.0, < 3.1)
|
29
|
+
ruby2_keywords (>= 0.0.4)
|
30
|
+
faraday-net_http (3.0.1)
|
25
31
|
hashdiff (1.0.1)
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
parser (3.0.0.0)
|
32
|
+
oj (3.13.21)
|
33
|
+
parallel (1.22.1)
|
34
|
+
parser (3.1.2.1)
|
30
35
|
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.
|
36
|
+
public_suffix (5.0.0)
|
37
|
+
rainbow (3.1.1)
|
38
|
+
rake (13.0.6)
|
39
|
+
regexp_parser (2.6.0)
|
40
|
+
rexml (3.2.5)
|
41
|
+
rspec (3.12.0)
|
42
|
+
rspec-core (~> 3.12.0)
|
43
|
+
rspec-expectations (~> 3.12.0)
|
44
|
+
rspec-mocks (~> 3.12.0)
|
45
|
+
rspec-core (3.12.0)
|
46
|
+
rspec-support (~> 3.12.0)
|
47
|
+
rspec-expectations (3.12.0)
|
43
48
|
diff-lcs (>= 1.2.0, < 2.0)
|
44
|
-
rspec-support (~> 3.
|
45
|
-
rspec-mocks (3.
|
49
|
+
rspec-support (~> 3.12.0)
|
50
|
+
rspec-mocks (3.12.0)
|
46
51
|
diff-lcs (>= 1.2.0, < 2.0)
|
47
|
-
rspec-support (~> 3.
|
48
|
-
rspec-support (3.
|
52
|
+
rspec-support (~> 3.12.0)
|
53
|
+
rspec-support (3.12.0)
|
49
54
|
rubocop (0.93.1)
|
50
55
|
parallel (~> 1.10)
|
51
56
|
parser (>= 2.7.1.5)
|
@@ -55,23 +60,23 @@ GEM
|
|
55
60
|
rubocop-ast (>= 0.6.0)
|
56
61
|
ruby-progressbar (~> 1.7)
|
57
62
|
unicode-display_width (>= 1.4.0, < 2.0)
|
58
|
-
rubocop-ast (1.
|
59
|
-
parser (>=
|
63
|
+
rubocop-ast (1.23.0)
|
64
|
+
parser (>= 3.1.1.0)
|
60
65
|
ruby-progressbar (1.11.0)
|
61
|
-
ruby2_keywords (0.0.
|
62
|
-
unicode-display_width (1.
|
63
|
-
vcr (6.
|
64
|
-
webmock (3.
|
65
|
-
addressable (>= 2.
|
66
|
+
ruby2_keywords (0.0.5)
|
67
|
+
unicode-display_width (1.8.0)
|
68
|
+
vcr (6.1.0)
|
69
|
+
webmock (3.18.1)
|
70
|
+
addressable (>= 2.8.0)
|
66
71
|
crack (>= 0.3.2)
|
67
72
|
hashdiff (>= 0.4.0, < 2.0.0)
|
73
|
+
zeitwerk (2.6.1)
|
68
74
|
|
69
75
|
PLATFORMS
|
70
76
|
aarch64-linux
|
71
77
|
x86_64-linux
|
72
78
|
|
73
79
|
DEPENDENCIES
|
74
|
-
dotenv (~> 2.7)
|
75
80
|
fantasticstay_api!
|
76
81
|
rake (~> 13.0)
|
77
82
|
rspec (~> 3.0)
|
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
|
@@ -82,6 +82,17 @@ module FantasticstayApi
|
|
82
82
|
process_response(response)
|
83
83
|
end
|
84
84
|
|
85
|
+
# FantasticstayApi::Client.new.search(query)
|
86
|
+
def search(query, type = nil, global_params = {})
|
87
|
+
response = request(
|
88
|
+
http_method: :get,
|
89
|
+
endpoint: 'search',
|
90
|
+
params: { q: query, type: type }.merge!(global_params),
|
91
|
+
cache_ttl: 3600 * 24
|
92
|
+
)
|
93
|
+
process_response(response)
|
94
|
+
end
|
95
|
+
|
85
96
|
protected
|
86
97
|
|
87
98
|
def process_response(response)
|
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.6
|
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-29 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
|